Skip to content

Commit

Permalink
fix: separate dev dist (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkx authored Jan 25, 2024
1 parent 50fa6b5 commit ae9c5e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/modernjs-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const getDefaultConfig = ({ allInOneEntries }: { allInOneEntries: Set<string> })
disableFilenameHash: true,
disableSourceMap: !isDev(),
distPath: {
...(process.env.WEBX_DIST ? { root: process.env.WEBX_DIST } : null),
html: '.',
},
polyfill: 'off',
Expand Down
10 changes: 8 additions & 2 deletions tests/e2e/tests/webx-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<void>((resolve) => {
const handler = (chunk: unknown) => {
Expand All @@ -57,6 +62,7 @@ export function startDev({ beforeAll, afterAll, afterEach }: typeof test) {
};
childProcess.stdout?.addListener('data', handler);
}),
childProcess.catch((reason): Promise<void> => Promise.reject(reason.message)),
wait(20 * 1000).then((): Promise<void> => Promise.reject('Timeout')),
]);
});
Expand Down

0 comments on commit ae9c5e9

Please sign in to comment.