Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 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
25 changes: 20 additions & 5 deletions packages/cli/src/swc/dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,27 @@ 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);
if (!clonedCliOptions.watch) {
return initialCompilation(
clonedCliOptions,
clonedSwcOptions,
callbacks
);
}

await initialCompilation(clonedCliOptions, clonedSwcOptions, callbacks);
Copy link
Member

Choose a reason for hiding this comment

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

This is invoking it twice I guess?

Copy link
Author

@CodeMan62 CodeMan62 Jun 3, 2025

Choose a reason for hiding this comment

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

ahh, you're right i think i made a mistake i am fixing


const watcher = await watchCompilation(
clonedCliOptions,
clonedSwcOptions,
callbacks
);

return watcher;
}
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