feat!: add Deno support via node: protocol in ESM output#166
feat!: add Deno support via node: protocol in ESM output#166watsonarw wants to merge 3 commits intothecodrr:masterfrom
Conversation
- Split tsdown config for separate CJS and ESM builds - Update deprecated removeNodeProtocol option in tsdown config - Enable node: protocol in ESM output for cross-runtime compatibility - Bump minimum Node version to v12.20.0 (when node: protocol was added) This enables Deno support (without import maps) and protects against builtin package name squatting attacks. BREAKING CHANGE: Requires Node.js >=12.20.0
tsdown handles the node: protocol in build outputs, but making source consistent with ESM output will be less confusing
|
I notice that #151 was proposing bumping the minimum node version to >=16. If you're happy to go to >=16 (which was EOL in Sept 2023), I can amend this to also use the |
|
@watsonarw Only add the https://www.electronjs.org/docs/latest/tutorial/electron-timelines |
|
Thinking about the sequencing of getting this merged. I expect that it wouldn't make sense to do a release with this change while the tests are failing on main, would it make sense to fix all of those first and do a The build logs in Github Actions are expired, but if it helps I can run it locally and create a new issue documenting the failing tests for discussion about fixing them |
Closes #165
Summary
This PR adds Deno support by enabling the
node:protocol for Node.js builtin imports in ESM builds. This allows the library to work with Deno without requiring import maps.Changes
1. Upgrade tsdown to latest version
tsdownfrom0.12.5to0.18.1to access latest features and the updated API2. Enable
node:protocol in ESM outputremoveNodeProtocoloption tonodeProtocoloptionnode:protocol in ESM output while keeping CJS output unchanged12.20.0(whennode:protocol was introduced)3. Update source code to use node: prefix
node:prefix to all Node.js builtin imports in source files (16 imports across 12 files)Breaking Changes
12.20.0(previously12.0.0)This is required to support the
node:protocol for builtin imports.Benefits
Testing
master... This PR has not changed any functionality, just build outputs and import statements. The same tests failing on master fail on this branch, no new tests are failing. I actually tried fixing the tests, but realised that some might be actual bugs that I'm not familiar enough with the codebase to tackle properly, so I gave up...npm run buildbefore and after each change.0.18.1resulted in a few non-functional changes to the output filesifstatements now have{ }blocks where they previously didn'tnode:prefix to the built-in imports in the ESM output, nothing else compared to above