Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/orange-geckos-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@swc/cli": patch
---

fix(cli): Clone config instead of updating it
18 changes: 13 additions & 5 deletions packages/cli/src/swc/dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,20 @@ export default async function dir({
swcOptions: Options;
callbacks?: Callbacks;
}) {
const { watch } = cliOptions;
// Deep clone the configuration objects to prevent reuse between calls
const clonedCliOptions = JSON.parse(JSON.stringify(cliOptions));
const clonedSwcOptions = JSON.parse(JSON.stringify(swcOptions));

await beforeStartCompilation(cliOptions);
await initialCompilation(cliOptions, swcOptions, callbacks);
await beforeStartCompilation(clonedCliOptions);

if (watch) {
await watchCompilation(cliOptions, swcOptions, callbacks);
await initialCompilation(clonedCliOptions, clonedSwcOptions, callbacks);

if (clonedCliOptions.watch) {
const watcher = await watchCompilation(
clonedCliOptions,
clonedSwcOptions,
callbacks
);
return watcher;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add this line?

}
}
5 changes: 4 additions & 1 deletion packages/cli/src/swc/dirWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export default async function handleCompile(opts: {
);
const sourceFileName = slash(relative(dirname(dest), opts.filename));

const options = { ...opts.swcOptions, sourceFileName };
// Create a deep copy of the options to prevent mutation affecting other compilations
const options = JSON.parse(
JSON.stringify({ ...opts.swcOptions, sourceFileName })
);

const result = await compile(opts.filename, options, opts.sync, dest);

Expand Down