Skip to content

Commit

Permalink
Revert "fix: should copy publicDir to the environment distDir when mu…
Browse files Browse the repository at this point in the history
…ltiple environments (#4220)" (#4240)
  • Loading branch information
chenjiahan authored Dec 22, 2024
1 parent 058993d commit 9863b72
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 53 deletions.
39 changes: 0 additions & 39 deletions e2e/cases/server/public-dir/publicDir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,45 +170,6 @@ test('should serve publicDir for preview server correctly', async ({
await rsbuild.close();
});

test('should copy publicDir to the environment distDir when multiple environments', async () => {
await fse.outputFile(join(__dirname, 'public', 'test-temp-file.txt'), 'a');

const rsbuild = await build({
cwd,
rsbuildConfig: {
environments: {
web1: {
output: {
distPath: {
root: 'dist-build-web-1',
},
},
},
web2: {
output: {
distPath: {
root: 'dist-build-web-2',
},
},
},
},
},
});
const files = await rsbuild.unwrapOutputJSON();
const filenames = Object.keys(files);

expect(
filenames.some((filename) =>
filename.includes('dist-build-web-1/test-temp-file.txt'),
),
).toBeTruthy();
expect(
filenames.some((filename) =>
filename.includes('dist-build-web-2/test-temp-file.txt'),
),
).toBeTruthy();
});

test('should serve publicDir for preview server with assetPrefix correctly', async ({
page,
}) => {
Expand Down
20 changes: 6 additions & 14 deletions packages/core/src/plugins/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const pluginServer = (): RsbuildPlugin => ({

api.onAfterStartDevServer(onStartServer);
api.onAfterStartProdServer(onStartServer);
api.onBeforeBuild(async ({ isFirstCompile, environments }) => {
api.onBeforeBuild(async ({ isFirstCompile }) => {
if (!isFirstCompile) {
return;
}
Expand All @@ -45,22 +45,14 @@ export const pluginServer = (): RsbuildPlugin => ({
continue;
}

const distPaths = [
...new Set(Object.values(environments).map((e) => e.distPath)),
];

try {
// async errors will missing error stack on copy, move
// https://github.com/jprichardson/node-fs-extra/issues/769
await Promise.all(
distPaths.map((distPath) =>
fs.promises.cp(normalizedPath, distPath, {
recursive: true,
// dereference symlinks
dereference: true,
}),
),
);
await fs.promises.cp(normalizedPath, api.context.distPath, {
recursive: true,
// dereference symlinks
dereference: true,
});
} catch (err) {
if (err instanceof Error) {
err.message = `Copy public dir (${normalizedPath}) to dist failed:\n${err.message}`;
Expand Down

0 comments on commit 9863b72

Please sign in to comment.