Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stubs): use "import type" when possible #4259

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stubs/make/command/main.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
to: {{ app.commandsPath(entity.path, commandFileName) }}
---
import { BaseCommand } from '@adonisjs/core/ace'
import { CommandOptions } from '@adonisjs/core/types/ace'
import type { CommandOptions } from '@adonisjs/core/types/ace'

export default class {{ commandName }} extends BaseCommand {
static commandName = '{{ commandTerminalName }}'
Expand Down
2 changes: 1 addition & 1 deletion stubs/make/controller/api.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---
to: {{ app.httpControllersPath(entity.path, controllerFileName) }}
---
import { HttpContext } from '@adonisjs/core/http'
import type { HttpContext } from '@adonisjs/core/http'

export default class {{ controllerName }} {
/**
Expand Down
2 changes: 1 addition & 1 deletion stubs/make/controller/main.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---
to: {{ app.httpControllersPath(entity.path, controllerFileName) }}
---
// import { HttpContext } from '@adonisjs/core/http'
// import type { HttpContext } from '@adonisjs/core/http'

export default class {{ controllerName }} {
}
2 changes: 1 addition & 1 deletion stubs/make/controller/resource.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---
to: {{ app.httpControllersPath(entity.path, controllerFileName) }}
---
import { HttpContext } from '@adonisjs/core/http'
import type { HttpContext } from '@adonisjs/core/http'

export default class {{ controllerName }} {
/**
Expand Down
2 changes: 1 addition & 1 deletion stubs/make/listener/for_event.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
---
to: {{ app.listenersPath(entity.path, listenerFileName) }}
---
import {{ eventName }} from '{{ eventImportPath }}'
import type {{ eventName }} from '{{ eventImportPath }}'

export default class {{ listenerName }} {
async handle(event: {{ eventName }}) {}
Expand Down
4 changes: 2 additions & 2 deletions stubs/make/middleware/main.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
---
to: {{ app.middlewarePath(entity.path, middlewareFileName) }}
---
import { HttpContext } from '@adonisjs/core/http'
import { NextFn } from '@adonisjs/core/types/http'
import type { HttpContext } from '@adonisjs/core/http'
import type { NextFn } from '@adonisjs/core/types/http'

export default class {{ middlewareName }} {
async handle(ctx: HttpContext, next: NextFn) {
Expand Down
2 changes: 1 addition & 1 deletion stubs/make/provider/main.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---
to: {{ app.providersPath(entity.path, providerFileName) }}
---
import { ApplicationService } from '@adonisjs/core/types'
import type { ApplicationService } from '@adonisjs/core/types'

export default class {{ providerName }} {
constructor(protected app: ApplicationService) {}
Expand Down
6 changes: 3 additions & 3 deletions tests/stubs/make_controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test.group('Make controller', () => {

assert.equal(destination, join(BASE_PATH, 'app/controllers/users_controller.ts'))
assert.match(contents, /export default class UsersController {/)
assert.match(contents, new RegExp("// import { HttpContext } from '@adonisjs/core/http'"))
assert.match(contents, new RegExp("// import type { HttpContext } from '@adonisjs/core/http'"))
})

test('prepare resourceful controller stub', async ({ assert }) => {
Expand All @@ -51,7 +51,7 @@ test.group('Make controller', () => {

assert.equal(destination, join(BASE_PATH, 'app/controllers/users_controller.ts'))
assert.match(contents, /export default class UsersController {/)
assert.match(contents, new RegExp("import { HttpContext } from '@adonisjs/core/http'"))
assert.match(contents, new RegExp("import type { HttpContext } from '@adonisjs/core/http'"))
assert.match(contents, new RegExp('async index\\({}: HttpContext\\) {}'))
assert.match(contents, new RegExp('async create\\({}: HttpContext\\) {}'))
assert.match(contents, new RegExp('async store\\({ request }: HttpContext\\) {}'))
Expand All @@ -76,7 +76,7 @@ test.group('Make controller', () => {

assert.equal(destination, join(BASE_PATH, 'app/controllers/users_controller.ts'))
assert.match(contents, /export default class UsersController {/)
assert.match(contents, new RegExp("import { HttpContext } from '@adonisjs/core/http'"))
assert.match(contents, new RegExp("import type { HttpContext } from '@adonisjs/core/http'"))
assert.match(contents, new RegExp('async index\\({}: HttpContext\\) {}'))
assert.notMatch(contents, new RegExp('async create\\({}: HttpContext\\) {}'))
assert.match(contents, new RegExp('async store\\({ request }: HttpContext\\) {}'))
Expand Down
2 changes: 1 addition & 1 deletion tests/stubs/make_listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test.group('Make listener', () => {
assert.match(contents, new RegExp('export default class SendEmail {'))
assert.match(
contents,
new RegExp("import UserRegistered from '#events/users/user_registered.ts'")
new RegExp("import type UserRegistered from '#events/users/user_registered.ts'")
)
assert.match(contents, new RegExp('async handle\\(event: UserRegistered\\) {'))
})
Expand Down
4 changes: 2 additions & 2 deletions tests/stubs/make_middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ test.group('Make middleware', () => {

assert.equal(destination, join(BASE_PATH, 'app/middleware/auth_middleware.ts'))
assert.match(contents, new RegExp('export default class AuthMiddleware {'))
assert.match(contents, new RegExp("import { HttpContext } from '@adonisjs/core/http'"))
assert.match(contents, new RegExp("import { NextFn } from '@adonisjs/core/types/http'"))
assert.match(contents, new RegExp("import type { HttpContext } from '@adonisjs/core/http'"))
assert.match(contents, new RegExp("import type { NextFn } from '@adonisjs/core/types/http'"))
assert.match(contents, new RegExp('export default class AuthMiddleware {'))
assert.match(contents, new RegExp('async handle\\(ctx: HttpContext, next: NextFn\\) {'))
})
Expand Down
5 changes: 4 additions & 1 deletion tests/stubs/make_provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ test.group('Make provider', () => {

assert.equal(destination, join(BASE_PATH, 'providers/app_provider.ts'))
assert.match(contents, new RegExp('export default class AppProvider {'))
assert.match(contents, new RegExp("import { ApplicationService } from '@adonisjs/core/types'"))
assert.match(
contents,
new RegExp("import type { ApplicationService } from '@adonisjs/core/types'")
)
assert.match(contents, new RegExp('constructor\\(protected app: ApplicationService\\) {}'))
assert.match(contents, new RegExp('register\\(\\)'))
assert.match(contents, new RegExp('async boot\\(\\)'))
Expand Down
Loading