Skip to content

build: add ts support in core modules#62146

Open
marco-ippolito wants to merge 7 commits intonodejs:mainfrom
marco-ippolito:native-ts
Open

build: add ts support in core modules#62146
marco-ippolito wants to merge 7 commits intonodejs:mainfrom
marco-ippolito:native-ts

Conversation

@marco-ippolito
Copy link
Member

@marco-ippolito marco-ippolito commented Mar 7, 2026

Let's try again.
This PR allows Node.js source code to be written in TS.
This is semver major because the build now always requires rust to be installed.
This adds swc as a rust crate dependency and it's only use during build time.
Technically we could replace amaro wasm with this for type stripping but it's not the goal of this PR and in needs other considerations.
I moved an internal from .js and .ts to showcase
Also added a flag so that the transpiled code can be writte on the fs for debugging.
A lot of the addition are vendored crates sorry for the massive PR
I used AI to help me out with things I dont know (rust) so please review carefully
I had to bump the rustc from 1.82 to 1.85, obviously this cannot land if we dont update that on the CI machines

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/build
  • @nodejs/gyp
  • @nodejs/security-wg
  • @nodejs/tsc

@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. dependencies Pull requests that update a dependency file. doc Issues and PRs related to the documentations. needs-ci PRs that need a full CI run. labels Mar 7, 2026
@marco-ippolito marco-ippolito added semver-major PRs that contain breaking changes and should be released in the next major version. strip-types Issues or PRs related to strip-types support labels Mar 7, 2026
@marco-ippolito marco-ippolito changed the title build: add type ts support in core build: add ts support in core Mar 7, 2026
@marco-ippolito marco-ippolito changed the title build: add ts support in core build: add ts support in core modules Mar 7, 2026
@marco-ippolito marco-ippolito marked this pull request as ready for review March 7, 2026 15:28
@marco-ippolito marco-ippolito added the blocked PRs that are blocked by other issues or PRs. label Mar 7, 2026
@anonrig
Copy link
Member

anonrig commented Mar 7, 2026

@marco-ippolito do you know what steps are needed to run and expose Rust code just like C++?

@marco-ippolito
Copy link
Member Author

marco-ippolito commented Mar 7, 2026

@marco-ippolito do you know what steps are needed to run and expose Rust code just like C++?

its already done in this PR, see d9ee95f

basically add the crate in the deps/crates cargo.toml, create a header file if doesnt come with the crate and add it to the node gyp

@ljharb
Copy link
Member

ljharb commented Mar 7, 2026

Will this type strip at runtime? Or will it do it at build time?

@marco-ippolito
Copy link
Member Author

marco-ippolito commented Mar 7, 2026

Will this type strip at runtime? Or will it do it at build time?

Build time

@ljharb
Copy link
Member

ljharb commented Mar 7, 2026

How does this interact with the --node-builtin-modules-path flag? will it still type strip at runtime in that case?

../../common.gypi
../../configure
../../configure.py
../../deps/crates/crates.gyp
Copy link
Contributor

Choose a reason for hiding this comment

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

Not that this will have been deleted by

node/Makefile

Line 1220 in 3725bd2

$(RM) -r $(TARNAME)/deps/crates

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I still figure out the shared build with nix. I have never touched this part so I dont really know how it works

@marco-ippolito
Copy link
Member Author

How does this interact with the --node-builtin-modules-path flag? will it still type strip at runtime in that case?

Yes, I tested it, it works fine. it plugs in the js2c module

@mcollina
Copy link
Member

mcollina commented Mar 7, 2026

I'm relatively concerned about adding 1 million and 300 hundred thousand lines of code, even if they are just dependencies.

Is there a solution that does not require this much?

@marco-ippolito
Copy link
Member Author

marco-ippolito commented Mar 7, 2026

I dont think so since we are vendoring dependencies. I think the only solution is to have an automation generate them but its kinda impossible to review anyways. (The temporal PR from @legendecas had the same problem)

@legendecas
Copy link
Member

legendecas commented Mar 7, 2026

I think the question should be is it necessary to have every swc dependencies to be included?

I listed the newly added dependencies, and the followings are the biggest deps that I doubt if they are required:

9.6M	deps/crates/vendor/tracing          => Diagnostic purpose
5.1M	deps/crates/vendor/libc             => Indirect dep of crates `cpufeatures` and `num_cpus`
2.8M	deps/crates/vendor/regex-automata   => Regex engine
1.6M	deps/crates/vendor/bitvec           => Indirect dep of swc_sourcemap
1.6M	deps/crates/vendor/zerocopy         => Indirect dep of hashbrown
1.3M	deps/crates/vendor/zerocopy-derive  => Indirect dep of hashbrown
1.0M	deps/crates/vendor/idna             => Indirect dep of crate `url`

Additionally, crates like wasm-bindgen are not technically needed for the PR purpose.

I think technically many of these deps can be stripped down.

@marco-ippolito
Copy link
Member Author

Can I just like delete them and see if it builds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked PRs that are blocked by other issues or PRs. build Issues and PRs related to build files or the CI. dependencies Pull requests that update a dependency file. doc Issues and PRs related to the documentations. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version. strip-types Issues or PRs related to strip-types support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants