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

Use swc / ts-node instead of babel #2228

Closed
wants to merge 22 commits into from

Conversation

cspotcode
Copy link

@cspotcode cspotcode commented Dec 10, 2020

I'm sending this PR to get a second opinion on these changes and to show that tests are passing. But if it's not merge-able, I think we should close it to keep the PR queue tidy.

What's the problem this PR addresses?

Slow developer experience working in berry's codebase due to babel.

How did you fix it?

Switched to an experimental ts-node swc compiler. ts-node loads configuration from tsconfig.json like usual. It is configured to use an experimental swc compiler, where we configure swc to match your tsconfig flags.

3x modes are possible: ts-node with caching, swc without caching, and swc with caching. Additionally, setup-ts-execution.js supports an env var to switch back to the babel compiler.

Most of this switching complexity is meant to be removed if/when berry officially switches to ts-node or swc.

swc does not elide type-only imports unless they are import type. So I also added import type where necessary, and added the necessary tsconfig flag to enforce this when typechecking.

All releases are marked "decline" because I don't think these code changes affect the published packages. Unless they affect the emitted .d.ts?

I had to forcibly add the native bits of swc in .yarn/unplugged for tests to pass. Is there a better way?

Issues uncovered while testing

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@cspotcode cspotcode requested a review from arcanis as a code owner December 10, 2020 03:26
@cspotcode
Copy link
Author

The plugin-compat failure is unrelated to these changes; looks like it's failing across the board due to changes in ts 4.2 dev builds.
cspotcode#2

@merceyz
Copy link
Member

merceyz commented Dec 10, 2020

Some context:

@paul-soporan looked into using swc earlier and found some bugs that needed to be fixed first https://github.com/swc-project/swc/issues?q=is%3Aissue+author%3Apaul-soporan+

@arcanis looked at using esbuild for bundling Yarn but it also has a transpile only function that is also an option I suppose https://esbuild.github.io/api/#transform-api

I had to forcibly add the native bits of swc in .yarn/unplugged for tests to pass. Is there a better way?

We looked at using their WASM version instead as native isn't really an option due to things like #1939

@cspotcode
Copy link
Author

cspotcode commented Dec 10, 2020 via email

@paul-soporan
Copy link
Member

I see there's one bug remaining, specifically pertaining to the "lazy"
option of swc. Does yarn currently use a lazy-equivalent behavior?

I don't think there's any lazy-equivalent behavior at the moment (unless @babel/register happens to do some magic under-the-hood by default, but I doubt it), so the lazy flag for swc isn't important (I only opened the issue so that it can eventually be fixed). The important bugs have been fixed very quickly and swc is definitely usable.

@cspotcode
Copy link
Author

cspotcode commented Jun 4, 2021

Linking related swc tickets:

swc-project/swc#1787 This bug is a blocker

swc-project/swc#1786 not strictly a blocker, but it forces us to add a dependency on @swc/helpers in every package

swc-project/swc#1060 swc added ability to elide type-only imports without requiring import type, so I may be able to revert all the import type changes in this PR

@cspotcode
Copy link
Author

Linking to another swc issue:

swc-project/swc#1788

@merceyz
Copy link
Member

merceyz commented Jun 4, 2021

Found another bug swc-project/swc#1790, I updated the OP to contain the issues reported upstream

@cspotcode
Copy link
Author

cspotcode commented Jun 5, 2021

I think we're hitting nodejs/node#36616, specifically nodejs/node#36616 (comment)

I tried implementing caching in the ts-node swc codepath, but it was still slower than babel. Then I tried switching to @swc/core and it was fast, even though cache was being used for everything, so swc was never invoked! I now believe that merely loading @swc/wasm causes a ~4 second slowdown.

Other related issues:
nodejs/help#2823
swc-project/swc#1352

@cspotcode
Copy link
Author

To reproduce the node bug above, do the following:

echo "require('@swc/wasm'); process.on('exit', console.log.bind(console, 'we should be terminated!')); process.exit()" | node

You will see "we should be terminated" immediately but will have to wait ~4 seconds till the process exits.

@arcanis
Copy link
Member

arcanis commented Oct 12, 2021

@cspotcode I'll close this issue since we try to move the build pipelines to ESBuild (so it'd be ideal to switch the runtime to its compiler rather than swc), but we're still interested by the general idea of bringing local dev in sync with pre-built binaries!

@arcanis arcanis closed this Oct 12, 2021
@cspotcode
Copy link
Author

Ok, sounds good. Truth be told I haven't had any time to attempt a fix for the underlying node / WASM issue we were hitting.

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.

4 participants