From ae9c5e99f7c2f4e7ca8e098b4d1b2eed4249affe Mon Sep 17 00:00:00 2001 From: Tmk Date: Fri, 26 Jan 2024 01:50:30 +0800 Subject: [PATCH] fix: separate dev dist (#13) --- packages/modernjs-plugin/src/index.ts | 1 + tests/e2e/tests/webx-test.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/modernjs-plugin/src/index.ts b/packages/modernjs-plugin/src/index.ts index aee9ebed..a816d994 100644 --- a/packages/modernjs-plugin/src/index.ts +++ b/packages/modernjs-plugin/src/index.ts @@ -40,6 +40,7 @@ const getDefaultConfig = ({ allInOneEntries }: { allInOneEntries: Set }) disableFilenameHash: true, disableSourceMap: !isDev(), distPath: { + ...(process.env.WEBX_DIST ? { root: process.env.WEBX_DIST } : null), html: '.', }, polyfill: 'off', diff --git a/tests/e2e/tests/webx-test.ts b/tests/e2e/tests/webx-test.ts index 7e7440a6..3c7d896e 100644 --- a/tests/e2e/tests/webx-test.ts +++ b/tests/e2e/tests/webx-test.ts @@ -19,6 +19,8 @@ const webxTest = createWebxTest({ extensionPath: 'UNKNOWN', }); +const DEV_DIST_DIR = 'node_modules/.cache/dev-dist'; + export const test = webxTest.extend<{ packageName: string; packageDir: string; @@ -30,7 +32,7 @@ export const test = webxTest.extend<{ if (packagesInfo.length === 0) throw new Error(`Cannot find ${packageName}`); return use(packagesInfo[0].path); }, - extensionPath: async ({ packageDir }, use) => use(path.join(packageDir, 'dist')), + extensionPath: async ({ packageDir }, use) => use(path.resolve(packageDir, DEV_DIST_DIR)), }); export const expect = test.expect; @@ -44,7 +46,10 @@ export function startDev({ beforeAll, afterAll, afterEach }: typeof test) { const { stdout: dirtyFiles } = await execa('git', ['ls-files', '--modified'], { cwd: packageDir }); if (!!dirtyFiles) throw new Error('make sure all modifications have been staged'); const PORT = String(await getRandomPort()); - childProcess = execa('pnpm', ['dev'], { cwd: packageDir, env: { PORT } }); + childProcess = execa('pnpm', ['dev'], { + cwd: packageDir, + env: { PORT, WEBX_DIST: DEV_DIST_DIR }, + }); await Promise.race([ new Promise((resolve) => { const handler = (chunk: unknown) => { @@ -57,6 +62,7 @@ export function startDev({ beforeAll, afterAll, afterEach }: typeof test) { }; childProcess.stdout?.addListener('data', handler); }), + childProcess.catch((reason): Promise => Promise.reject(reason.message)), wait(20 * 1000).then((): Promise => Promise.reject('Timeout')), ]); });