Skip to content

fix(cli): Fix configuration reuse issue in swcDir() by deep clone#95

Merged
kdy1 merged 5 commits intoswc-project:mainfrom
CodeMan62:fix/config-reuse
May 1, 2025
Merged

fix(cli): Fix configuration reuse issue in swcDir() by deep clone#95
kdy1 merged 5 commits intoswc-project:mainfrom
CodeMan62:fix/config-reuse

Conversation

@CodeMan62
Copy link
Copy Markdown

  • Issue: The swcDir() function in the @swc project was experiencing configuration reuse issues due to shared references in the options object. This led to unintended side effects when compiling different module types (ESM and CommonJS) in the same process.

  • Fix: Implemented a deepClone function to ensure complete isolation of configuration objects. This prevents shared references and ensures that modifications to one configuration do not affect others.

  • Testing:

    • Created a comprehensive test suite to verify the functionality of the deepClone function. The tests demonstrated that deep cloning maintains object isolation, while shallow cloning does not.
    • Conducted end-to-end tests by simulating the compilation of both ESM and CommonJS modules. Verified that the output file extensions were correct and that the configurations were isolated, confirming the effectiveness of the fix.

related issue link:- #97

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 24, 2025

🦋 Changeset detected

Latest commit: 9fbb393

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@swc/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CodeMan62
Copy link
Copy Markdown
Author

CodeMan62 commented Apr 25, 2025

The reason for checks not passing is not code as I have check that it's a build error that I was also getting locally when I tried to build here is what error is you can see full in CI check fails too. which we should fix asap I see the related issue too swc-project/swc#89

packages/cli prepublishOnly$ pnpm build
packages/cli prepublishOnly: > @swc/cli@0.7.3 build /Users/runner/work/pkgs/pkgs/packages/cli
packages/cli prepublishOnly: > swc src --strip-leading-paths -d lib --ignore '**/*.test.ts' --ignore '**/__mocks__/**'
packages/cli prepublishOnly: node:internal/modules/cjs/loader:1215
packages/cli prepublishOnly:   throw err;
packages/cli prepublishOnly:   ^
packages/cli prepublishOnly: Error: Cannot find module '../lib/swc/bin.js'
packages/cli prepublishOnly: Require stack:
packages/cli prepublishOnly: - /Users/runner/work/pkgs/pkgs/packages/cli/bin/swc.js
packages/cli prepublishOnly:     at Module._resolveFilename (node:internal/modules/cjs/loader:1212:15)
packages/cli prepublishOnly:     at Module._load (node:internal/modules/cjs/loader:1043:27)
packages/cli prepublishOnly:     at Module.require (node:internal/modules/cjs/loader:1298:19)
packages/cli prepublishOnly:     at require (node:internal/modules/helpers:182:18)
packages/cli prepublishOnly:     at Object.<anonymous> (/Users/runner/work/pkgs/pkgs/packages/cli/bin/swc.js:4:1)
packages/cli prepublishOnly:     at Module._compile (node:internal/modules/cjs/loader:1529:14)
packages/cli prepublishOnly:     at Module._extensions..js (node:internal/modules/cjs/loader:1613:10)
packages/cli prepublishOnly:     at Module.load (node:internal/modules/cjs/loader:1275:32)
packages/cli prepublishOnly:     at Module._load (node:internal/modules/cjs/loader:[109](https://github.com/swc-project/pkgs/actions/runs/14650662047/job/41115433572?pr=95#step:3:119)6:12)
packages/cli prepublishOnly:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:164:12) {
packages/cli prepublishOnly:   code: 'MODULE_NOT_FOUND',
packages/cli prepublishOnly:   requireStack: [ '/Users/runner/work/pkgs/pkgs/packages/cli/bin/swc.js' ]
packages/cli prepublishOnly: }
packages/cli prepublishOnly: Node.js v20.19.0
packages/cli prepublishOnly:  ELIFECYCLE  Command failed with exit code 1.
packages/cli prepublishOnly: Failed
 ELIFECYCLE  Command failed with exit code 1.

@kdy1 kdy1 self-assigned this May 1, 2025
kdy1
kdy1 previously approved these changes May 1, 2025
@kdy1
Copy link
Copy Markdown
Member

kdy1 commented May 1, 2025

I'll merge this after fixing CI

@CodeMan62
Copy link
Copy Markdown
Author

I'll merge this after fixing CI

I request you to move #10404 issue from swc to this repo

@kdy1
Copy link
Copy Markdown
Member

kdy1 commented May 1, 2025

Done 👍

@kdy1 kdy1 enabled auto-merge (squash) May 1, 2025 18:33
result.map = JSON.stringify(sourceMap);
}
return result;
} catch (err: any) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you revert these kinds of changes? It seems like CI is failing because of it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

let me do

@CodeMan62
Copy link
Copy Markdown
Author

give me a bit time i am facing a error while committing my changes the error says commit is empty let me try to solve

auto-merge was automatically disabled May 1, 2025 19:05

Head branch was pushed to by a user without write access

@CodeMan62
Copy link
Copy Markdown
Author

@kdy1 CI passed 😆 good catch

@kdy1 kdy1 changed the title Fix configuration reuse issue in swcDir() by implementing deep cloning fix(cli): Fix configuration reuse issue in swcDir() by deep clone May 1, 2025
@kdy1 kdy1 merged commit 0475403 into swc-project:main May 1, 2025
10 checks passed
kdy1 added a commit that referenced this pull request May 12, 2025
kdy1 added a commit that referenced this pull request May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants