diff --git a/commands/build.ts b/commands/build.ts index e4613af3..a90c85b2 100644 --- a/commands/build.ts +++ b/commands/build.ts @@ -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, + }, }) /** diff --git a/commands/serve.ts b/commands/serve.ts index f9514b23..2422e429 100644 --- a/commands/serve.ts +++ b/commands/serve.ts @@ -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, + }, }) /** diff --git a/package.json b/package.json index 0f7bb3f4..890dbd0a 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/tests/commands/build.spec.ts b/tests/commands/build.spec.ts index 7d615fb4..da9eee11 100644 --- a/tests/commands/build.spec.ts +++ b/tests/commands/build.spec.ts @@ -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) + }, + }), + ], + onBuildStarting: [ + async () => ({ + default: async () => { + assert.isTrue(true) + }, + }), + ], + } + + ace.ui.switchMode('normal') + + const command = await ace.create(Build, []) + await command.exec() + }) }) diff --git a/tests/commands/serve.spec.ts b/tests/commands/serve.spec.ts index 19535059..4cb91d6d 100644 --- a/tests/commands/serve.spec.ts +++ b/tests/commands/serve.spec.ts @@ -222,11 +222,7 @@ test.group('Serve command', () => { ) }) - test('do not attempt to serve assets when --no-assets flag is used', async ({ - assert, - fs, - cleanup, - }) => { + test('do not attempt to serve assets when --no-assets flag is used', async ({ fs, cleanup }) => { await fs.create('bin/server.js', '') await fs.create( 'node_modules/ts-node/package.json', @@ -257,11 +253,43 @@ 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 }) => { + assert.plan(1) + + await fs.create( + 'bin/server.js', + ` + process.send({ isAdonisJS: true, environment: 'web' }); + ` + ) + 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), + }), + ], + } + + ace.ui.switchMode('raw') + + const command = await ace.create(Serve, ['--no-assets', '--no-clear']) + cleanup(() => command.devServer.close()) + await command.exec() + await sleep(1200) }) })