From be6ca03896003a0fe3c14a3911a92adc63ff4634 Mon Sep 17 00:00:00 2001 From: Julien Ripouteau Date: Sat, 24 Feb 2024 16:04:53 +0100 Subject: [PATCH] feat: do not run assets bundler when disabled in rc file (#4429) --- src/internal_helpers.ts | 4 +++ tests/commands/serve.spec.ts | 47 +++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/internal_helpers.ts b/src/internal_helpers.ts index b9c79688..802f3bcc 100644 --- a/src/internal_helpers.ts +++ b/src/internal_helpers.ts @@ -49,6 +49,10 @@ function generateJsFilenames(filename: string) { export async function detectAssetsBundler( app: ApplicationService ): Promise { + if (app.rcFile.assetsBundler === false) { + return false + } + if (app.rcFile.assetsBundler) { return app.rcFile.assetsBundler } diff --git a/tests/commands/serve.spec.ts b/tests/commands/serve.spec.ts index 4cb91d6d..355ce769 100644 --- a/tests/commands/serve.spec.ts +++ b/tests/commands/serve.spec.ts @@ -222,7 +222,11 @@ test.group('Serve command', () => { ) }) - test('do not attempt to serve assets when --no-assets flag is used', async ({ fs, cleanup }) => { + test('do not attempt to serve assets when --no-assets flag is used', async ({ + assert, + fs, + cleanup, + }) => { await fs.create('bin/server.js', '') await fs.create( 'node_modules/ts-node/package.json', @@ -253,6 +257,47 @@ 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('do not launch assets bundler when disabled in rc file', async ({ fs, cleanup, assert }) => { + await fs.create('bin/server.js', '') + 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', '') + await fs.create('vite.config.js', '') + + const ace = await new AceFactory().make(fs.baseUrl, { + importer: (filePath) => { + return import(filePath) + }, + }) + + ace.app.rcFile.assetsBundler = false + ace.ui.switchMode('raw') + + const command = await ace.create(Serve, ['--no-clear']) + 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 }) => {