Skip to content

Commit

Permalink
feat: add hooks for build and dev server
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Feb 24, 2024
1 parent f01d683 commit 8326b22
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
4 changes: 4 additions & 0 deletions commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export default class Build extends BaseCommand {
const bundler = new assembler.Bundler(this.app.appRoot, ts, {
assets: await this.#getAssetsBundlerConfig(),
metaFiles: this.app.rcFile.metaFiles,
hooks: {
onBuildStarting: this.app.rcFile.unstable_assembler?.onBuildStarting,
onBuildCompleted: this.app.rcFile.unstable_assembler?.onBuildCompleted,
}

Check failure on line 111 in commands/build.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `,`

Check failure on line 111 in commands/build.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (20.10.0)

Insert `,`

Check failure on line 111 in commands/build.ts

View workflow job for this annotation

GitHub Actions / test / test_windows (20.10.0)

Insert `,`

Check failure on line 111 in commands/build.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (21.x)

Insert `,`
})

/**
Expand Down
4 changes: 4 additions & 0 deletions commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export default class Serve extends BaseCommand {
scriptArgs: [],
assets: await this.#getAssetsBundlerConfig(),
metaFiles: this.app.rcFile.metaFiles,
hooks: {
onDevServerStarted: this.app.rcFile.unstable_assembler?.onDevServerStarted,
onSourceFileChanged: this.app.rcFile.unstable_assembler?.onSourceFileChanged,
}

Check failure on line 124 in commands/serve.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `,`

Check failure on line 124 in commands/serve.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (20.10.0)

Insert `,`

Check failure on line 124 in commands/serve.ts

View workflow job for this annotation

GitHub Actions / test / test_windows (20.10.0)

Insert `,`

Check failure on line 124 in commands/serve.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (21.x)

Insert `,`
})

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"index:commands": "node --loader=ts-node/esm toolkit/main.js index build/commands"
},
"devDependencies": {
"@adonisjs/assembler": "^7.1.0",
"@adonisjs/assembler": "^7.2.1",
"@adonisjs/eslint-config": "^1.2.0",
"@adonisjs/prettier-config": "^1.2.0",
"@adonisjs/tsconfig": "^1.2.0",
Expand Down Expand Up @@ -117,7 +117,7 @@
},
"dependencies": {
"@adonisjs/ace": "^13.0.0",
"@adonisjs/application": "^8.0.2",
"@adonisjs/application": "^8.1.0",
"@adonisjs/bodyparser": "^10.0.1",
"@adonisjs/config": "^5.0.1",
"@adonisjs/encryption": "^6.0.1",
Expand Down
50 changes: 50 additions & 0 deletions tests/commands/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,54 @@ test.group('Build command', (group) => {
})
)
})

test('correctly pass hooks to the bundler', async ({ assert, fs }) => {
assert.plan(2)

await fs.create(
'tsconfig.json',
JSON.stringify({
include: ['**/*'],
exclude: [],
compilerOptions: {
target: 'ESNext',
module: 'NodeNext',
lib: ['ESNext'],
strict: true,
noUnusedLocals: true,
},
})
)

await fs.create('adonisrc.ts', `export default {}`)
await fs.create('index.ts', '')

const ace = await new AceFactory().make(fs.baseUrl, {
importer: (filePath) => {
return import(filePath)
},
})

ace.app.rcFile.unstable_assembler = {
onBuildCompleted: [
async () => ({
default: async () => {
assert.isTrue(true)
}

Check failure on line 387 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `,`

Check failure on line 387 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (20.10.0)

Insert `,`

Check failure on line 387 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_windows (20.10.0)

Insert `,`

Check failure on line 387 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (21.x)

Insert `,`
})

Check failure on line 388 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `,`

Check failure on line 388 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (20.10.0)

Insert `,`

Check failure on line 388 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_windows (20.10.0)

Insert `,`

Check failure on line 388 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (21.x)

Insert `,`
],
onBuildStarting: [
async () => ({
default: async () => {
assert.isTrue(true)
}

Check failure on line 394 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `,`

Check failure on line 394 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (20.10.0)

Insert `,`

Check failure on line 394 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_windows (20.10.0)

Insert `,`

Check failure on line 394 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (21.x)

Insert `,`
})

Check failure on line 395 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `,`

Check failure on line 395 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (20.10.0)

Insert `,`

Check failure on line 395 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_windows (20.10.0)

Insert `,`

Check failure on line 395 in tests/commands/build.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (21.x)

Insert `,`
],
}

ace.ui.switchMode('normal')

const command = await ace.create(Build, [])
await command.exec()
})
})
35 changes: 32 additions & 3 deletions tests/commands/serve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,40 @@ test.group('Serve command', () => {
cleanup(() => command.devServer.close())
await command.exec()
await sleep(600)
})

assert.notExists(
ace.ui.logger.getLogs().find((log) => {
return log.message.match(/starting "vite" dev server/)
test('correctly pass hooks to the devserver', async ({ assert, fs, cleanup }) => {

Check failure on line 262 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Delete `·`

Check failure on line 262 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (20.10.0)

Delete `·`

Check failure on line 262 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_windows (20.10.0)

Delete `·`

Check failure on line 262 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (21.x)

Delete `·`
assert.plan(1)

await fs.create('bin/server.js', `

Check failure on line 265 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Replace `'bin/server.js',` with `⏎······'bin/server.js',⏎·····`

Check failure on line 265 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (20.10.0)

Replace `'bin/server.js',` with `⏎······'bin/server.js',⏎·····`

Check failure on line 265 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_windows (20.10.0)

Replace `'bin/server.js',` with `␍⏎······'bin/server.js',␍⏎·····`

Check failure on line 265 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (21.x)

Replace `'bin/server.js',` with `⏎······'bin/server.js',⏎·····`
process.send({ isAdonisJS: true, environment: 'web' });
`)

Check failure on line 267 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `⏎····`

Check failure on line 267 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (20.10.0)

Insert `⏎····`

Check failure on line 267 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_windows (20.10.0)

Insert `␍⏎····`

Check failure on line 267 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (21.x)

Insert `⏎····`
await fs.create(
'node_modules/ts-node/package.json',
JSON.stringify({
name: 'ts-node',
exports: { './esm': './esm.js' },
})
)
await fs.create('node_modules/ts-node/esm.js', '')

const ace = await new AceFactory().make(fs.baseUrl, {
importer: (filePath) => import(filePath),
})

ace.app.rcFile.unstable_assembler = {
onDevServerStarted: [
async () => ({
default: async () => assert.isTrue(true)

Check failure on line 284 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `,`

Check failure on line 284 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (20.10.0)

Insert `,`

Check failure on line 284 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_windows (20.10.0)

Insert `,`

Check failure on line 284 in tests/commands/serve.spec.ts

View workflow job for this annotation

GitHub Actions / test / test_linux (21.x)

Insert `,`
})
],
}

ace.ui.switchMode('raw')

const command = await ace.create(Serve, ['--no-assets', '--no-clear'])
cleanup(() => command.devServer.close())
await command.exec()
await sleep(1200)
})
})

0 comments on commit 8326b22

Please sign in to comment.