Skip to content

Commit 765a1f9

Browse files
committed
feat: support TypeScript 6.0
1 parent 145f2c6 commit 765a1f9

3 files changed

Lines changed: 73 additions & 45 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"ts-morph": "^27.0.2"
8686
},
8787
"peerDependencies": {
88-
"typescript": "^4.0.0 || ^5.0.0"
88+
"typescript": "^5.0.0 || ^6.0.0"
8989
},
9090
"author": "virk,adonisjs",
9191
"license": "MIT",

src/dev_server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export class DevServer {
314314
await this.#hooks.runner('devServerStarted').run(this, info, displayMessage)
315315
} catch (error) {
316316
this.ui.logger.error('One of the "devServerStarted" hooks failed')
317-
this.ui.logger.fatal(error)
317+
this.ui.logger.fatal(error as Error)
318318
}
319319

320320
displayMessage.render()
@@ -535,7 +535,7 @@ export class DevServer {
535535
}
536536
} catch (error) {
537537
this.ui.logger.error('Unable to rescan routes because of the following error')
538-
this.ui.logger.fatal(error)
538+
this.ui.logger.fatal(error as Error)
539539
}
540540
}
541541

@@ -598,7 +598,7 @@ export class DevServer {
598598
}
599599
} catch (error) {
600600
this.ui.logger.error('Unable to process and scan routes because of the following error')
601-
this.ui.logger.fatal(error)
601+
this.ui.logger.fatal(error as Error)
602602
}
603603
}, 'processRoutes')
604604

tests/code_transformer.spec.ts

Lines changed: 69 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,11 @@ test.group('Code transformer | addMiddlewareToStack', (group) => {
193193
assert.fail('Should have thrown an error')
194194
} catch (error) {
195195
assert.instanceOf(error, CodemodException)
196-
assert.include(error.message, 'start/kernel.ts')
197-
assert.isDefined(error.instructions)
198-
assert.include(error.instructions, `() => import('@adonisjs/static/static_middleware')`)
196+
if (error instanceof CodemodException) {
197+
assert.include(error.message, 'start/kernel.ts')
198+
assert.isDefined(error.instructions)
199+
assert.include(error.instructions, `() => import('@adonisjs/static/static_middleware')`)
200+
}
199201
}
200202
})
201203

@@ -213,8 +215,10 @@ test.group('Code transformer | addMiddlewareToStack', (group) => {
213215
assert.fail('Should have thrown an error')
214216
} catch (error) {
215217
assert.instanceOf(error, CodemodException)
216-
assert.isDefined(error.instructions)
217-
assert.include(error.instructions, `auth: () => import('#middleware/auth_middleware')`)
218+
if (error instanceof CodemodException) {
219+
assert.isDefined(error.instructions)
220+
assert.include(error.instructions, `auth: () => import('#middleware/auth_middleware')`)
221+
}
218222
}
219223
})
220224

@@ -232,9 +236,11 @@ test.group('Code transformer | addMiddlewareToStack', (group) => {
232236
assert.fail('Should have thrown an error')
233237
} catch (error) {
234238
assert.instanceOf(error, CodemodException)
235-
assert.include(error.message, 'server.use')
236-
assert.isDefined(error.instructions)
237-
assert.include(error.instructions, `() => import('@adonisjs/static/static_middleware')`)
239+
if (error instanceof CodemodException) {
240+
assert.include(error.message, 'server.use')
241+
assert.isDefined(error.instructions)
242+
assert.include(error.instructions, `() => import('@adonisjs/static/static_middleware')`)
243+
}
238244
}
239245
})
240246

@@ -381,10 +387,12 @@ test.group('Code transformer | defineEnvValidations', (group) => {
381387
assert.fail('Should have thrown an error')
382388
} catch (error) {
383389
assert.instanceOf(error, CodemodException)
384-
assert.include(error.message, 'start/env.ts')
385-
assert.isDefined(error.instructions)
386-
assert.include(error.instructions, 'REDIS_HOST: Env.schema.string.optional()')
387-
assert.include(error.instructions, 'REDIS_PORT: Env.schema.number()')
390+
if (error instanceof CodemodException) {
391+
assert.include(error.message, 'start/env.ts')
392+
assert.isDefined(error.instructions)
393+
assert.include(error.instructions, 'REDIS_HOST: Env.schema.string.optional()')
394+
assert.include(error.instructions, 'REDIS_PORT: Env.schema.number()')
395+
}
388396
}
389397
})
390398

@@ -404,9 +412,11 @@ test.group('Code transformer | defineEnvValidations', (group) => {
404412
assert.fail('Should have thrown an error')
405413
} catch (error) {
406414
assert.instanceOf(error, CodemodException)
407-
assert.include(error.message, 'Env.create')
408-
assert.isDefined(error.instructions)
409-
assert.include(error.instructions, 'MY_VAR: Env.schema.string()')
415+
if (error instanceof CodemodException) {
416+
assert.include(error.message, 'Env.create')
417+
assert.isDefined(error.instructions)
418+
assert.include(error.instructions, 'MY_VAR: Env.schema.string()')
419+
}
410420
}
411421
})
412422

@@ -454,9 +464,11 @@ test.group('Code transformer | updateRcFile errors', (group) => {
454464
assert.fail('Should have thrown an error')
455465
} catch (error) {
456466
assert.instanceOf(error, CodemodException)
457-
assert.include(error.message, 'adonisrc.ts')
458-
assert.isDefined(error.instructions)
459-
assert.include(error.instructions, 'defineConfig')
467+
if (error instanceof CodemodException) {
468+
assert.include(error.message, 'adonisrc.ts')
469+
assert.isDefined(error.instructions)
470+
assert.include(error.instructions, 'defineConfig')
471+
}
460472
}
461473
})
462474

@@ -471,8 +483,10 @@ test.group('Code transformer | updateRcFile errors', (group) => {
471483
assert.fail('Should have thrown an error')
472484
} catch (error) {
473485
assert.instanceOf(error, CodemodException)
474-
assert.include(error.message, 'defineConfig')
475-
assert.isDefined(error.instructions)
486+
if (error instanceof CodemodException) {
487+
assert.include(error.message, 'defineConfig')
488+
assert.isDefined(error.instructions)
489+
}
476490
}
477491
})
478492
})
@@ -956,10 +970,12 @@ test.group('Code transformer | addJapaPlugin', (group) => {
956970
assert.fail('Should have thrown an error')
957971
} catch (error) {
958972
assert.instanceOf(error, CodemodException)
959-
assert.include(error.message, 'tests/bootstrap.ts')
960-
assert.isDefined(error.instructions)
961-
assert.include(error.instructions, `import { fooPlugin } from '@adonisjs/foo/plugin/japa'`)
962-
assert.include(error.instructions, 'fooPlugin()')
973+
if (error instanceof CodemodException) {
974+
assert.include(error.message, 'tests/bootstrap.ts')
975+
assert.isDefined(error.instructions)
976+
assert.include(error.instructions, `import { fooPlugin } from '@adonisjs/foo/plugin/japa'`)
977+
assert.include(error.instructions, 'fooPlugin()')
978+
}
963979
}
964980
})
965981

@@ -1038,10 +1054,12 @@ test.group('Code transformer | addPolicies', (group) => {
10381054
assert.fail('Should have thrown an error')
10391055
} catch (error) {
10401056
assert.instanceOf(error, CodemodException)
1041-
assert.include(error.message, 'app/policies/main.ts')
1042-
assert.isDefined(error.instructions)
1043-
assert.include(error.instructions, `PostPolicy: () => import('#policies/post_policy')`)
1044-
assert.include(error.instructions, `UserPolicy: () => import('#policies/user_policy')`)
1057+
if (error instanceof CodemodException) {
1058+
assert.include(error.message, 'app/policies/main.ts')
1059+
assert.isDefined(error.instructions)
1060+
assert.include(error.instructions, `PostPolicy: () => import('#policies/post_policy')`)
1061+
assert.include(error.instructions, `UserPolicy: () => import('#policies/user_policy')`)
1062+
}
10451063
}
10461064
})
10471065

@@ -1057,8 +1075,10 @@ test.group('Code transformer | addPolicies', (group) => {
10571075
assert.fail('Should have thrown an error')
10581076
} catch (error) {
10591077
assert.instanceOf(error, CodemodException)
1060-
assert.isDefined(error.instructions)
1061-
assert.include(error.instructions, `PostPolicy: () => import('#policies/post_policy')`)
1078+
if (error instanceof CodemodException) {
1079+
assert.isDefined(error.instructions)
1080+
assert.include(error.instructions, `PostPolicy: () => import('#policies/post_policy')`)
1081+
}
10621082
}
10631083
})
10641084

@@ -1074,8 +1094,10 @@ test.group('Code transformer | addPolicies', (group) => {
10741094
assert.fail('Should have thrown an error')
10751095
} catch (error) {
10761096
assert.instanceOf(error, CodemodException)
1077-
assert.isDefined(error.instructions)
1078-
assert.include(error.instructions, `PostPolicy: () => import('#policies/post_policy')`)
1097+
if (error instanceof CodemodException) {
1098+
assert.isDefined(error.instructions)
1099+
assert.include(error.instructions, `PostPolicy: () => import('#policies/post_policy')`)
1100+
}
10791101
}
10801102
})
10811103

@@ -1211,10 +1233,12 @@ test.group('Code transformer | addVitePlugin', (group) => {
12111233
assert.fail('Should have thrown an error')
12121234
} catch (error) {
12131235
assert.instanceOf(error, CodemodException)
1214-
assert.include(error.message, 'vite.config.ts')
1215-
assert.isDefined(error.instructions)
1216-
assert.include(error.instructions, `import vue from 'vue'`)
1217-
assert.include(error.instructions, 'vue()')
1236+
if (error instanceof CodemodException) {
1237+
assert.include(error.message, 'vite.config.ts')
1238+
assert.isDefined(error.instructions)
1239+
assert.include(error.instructions, `import vue from 'vue'`)
1240+
assert.include(error.instructions, 'vue()')
1241+
}
12181242
}
12191243
})
12201244

@@ -1232,8 +1256,10 @@ test.group('Code transformer | addVitePlugin', (group) => {
12321256
assert.fail('Should have thrown an error')
12331257
} catch (error) {
12341258
assert.instanceOf(error, CodemodException)
1235-
assert.isDefined(error.instructions)
1236-
assert.include(error.instructions, 'vue()')
1259+
if (error instanceof CodemodException) {
1260+
assert.isDefined(error.instructions)
1261+
assert.include(error.instructions, 'vue()')
1262+
}
12371263
}
12381264
})
12391265

@@ -1250,9 +1276,11 @@ test.group('Code transformer | addVitePlugin', (group) => {
12501276
])
12511277
assert.fail('Should have thrown an error')
12521278
} catch (error) {
1253-
assert.instanceOf(error, CodemodException)
1254-
assert.isDefined(error.instructions)
1255-
assert.include(error.instructions, 'vue()')
1279+
if (error instanceof CodemodException) {
1280+
assert.instanceOf(error, CodemodException)
1281+
assert.isDefined(error.instructions)
1282+
assert.include(error.instructions, 'vue()')
1283+
}
12561284
}
12571285
})
12581286
})

0 commit comments

Comments
 (0)