Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace tsx with swc #487

Merged
merged 5 commits into from
Mar 15, 2024
Merged

chore: replace tsx with swc #487

merged 5 commits into from
Mar 15, 2024

Conversation

SukkaW
Copy link
Contributor

@SukkaW SukkaW commented Mar 11, 2024

The PR replaces tsx with @swc-node/register.

bunchee already prefers swc, it doesn't make sense to use esbuild as the build script loader. Let's switch it to swc.

@@ -12,7 +12,7 @@
"clean": "rm -rf ./dist",
"typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
"prepublishOnly": "pnpm clean && pnpm build && chmod +x ./dist/bin/cli.js && pnpm test",
"build": "tsx ./src/bin/index.ts --runtime node",
"build": "SWC_NODE_IGNORE_DYNAMIC=true node -r @swc-node/register ./src/bin/index.ts --runtime node",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SWC_NODE_IGNORE_DYNAMIC is introduced in swc-project/swc-node#745.

Copy link
Owner

Choose a reason for hiding this comment

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

it's fine to not pass SWC_NODE_IGNORE_DYNAMIC=true, as core package will be bundled as require("bunchee") and we also don't have dynamic import case

@huozhi
Copy link
Owner

huozhi commented Mar 11, 2024

We were also using tsx in tests, could you also replace them together? thanks!

@huozhi
Copy link
Owner

huozhi commented Mar 11, 2024

Some tests are failing

@SukkaW
Copy link
Contributor Author

SukkaW commented Mar 11, 2024

Some tests are failing

I am still experimenting with things here and there. I am tracking CI at here: SukkaW#1

@SukkaW SukkaW force-pushed the replace-tsx branch 2 times, most recently from a3292ab to fefb08e Compare March 12, 2024 06:18
@SukkaW
Copy link
Contributor Author

SukkaW commented Mar 15, 2024

@huozhi All tests passed on my machine. CI passes as well (SukkaW#1).

@huozhi
Copy link
Owner

huozhi commented Mar 15, 2024

Looks good, is SWC_NODE_IGNORE_DYNAMIC still required?

@SukkaW
Copy link
Contributor Author

SukkaW commented Mar 15, 2024

Looks good, is SWC_NODE_IGNORE_DYNAMIC still required?

Yes.

By default, SWC transforms all dynamic imports into Promise.resolve(require()), which disrupts the importing of pure ESM modules in CommonJS. To maintain the original dynamic import syntax, the SWC_NODE_IGNORE_DYNAMIC environment variable is necessary.

@huozhi
Copy link
Owner

huozhi commented Mar 15, 2024

I mean we don't have any case like that in bunchee so probably don't need it. I'll land this since everything looks good! Thanks!

It sounds like a good feature to add into swc compilation. e.g. if the input is a cjs file and using dynamic import, SWC should preserve it. Are we having this in swc plugin? @SukkaW

@huozhi huozhi merged commit 830fbf7 into huozhi:main Mar 15, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants