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

fix: prefix node builtins for bundled files #12698

Closed
wants to merge 8 commits into from

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Sep 21, 2024

Adds a rollup plugin to prefix all builtin node imports (including transitive dependencies). ChatGPT helped with this one so I'm sure it can be improved. Additionally, for some reason, it makes the build faster by a few ms (I thought an additional plugin would make it slower).

This solves the issue of current and potentially future transitive imports from not having the node: prefix.

Before:

build results before plugin

After:

build results after plugin


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Sep 21, 2024

🦋 Changeset detected

Latest commit: e67b38a

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-node 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

@Conduitry
Copy link
Member

I feel like we ought to be able to do this with the resolveId hook and then marking that rewritten module name as external. Have you already tried this? Hacking at the final string feels quite brittle.

@eltigerchino
Copy link
Member Author

eltigerchino commented Sep 21, 2024

Yeah I've tried resolveId but that didn't work for the transitive imports. I wasn't sure if there was another way. Thinking about it we should probably close this since it's so risky with the current regex

@eltigerchino
Copy link
Member Author

I've updated the regex to match on import declarations (from '...') to be less brittle (but brittle nevertheless).

@benmccann
Copy link
Member

benmccann commented Sep 23, 2024

Hmm. I don't know. Personally I'm not a fan of complicating our build process in this way. I think it's better to ensure that polka and sirv include node: from the beginning. Maybe there's a test that can be added in their test suites or something along those lines. Or maybe it could be a feature in @rollup/plugin-node-resolve?

@eltigerchino
Copy link
Member Author

eltigerchino commented Sep 25, 2024

I think I'll close this. It's unlikely we'll be adding new dependencies and it might be better practice to update the deps with the non-node prefixes.

https://github.com/lukeed/sirv/blob/50b1964b8a8342e14a711d47f793298c2a7aeeb7/packages/sirv/index.js#L1-L3

https://github.com/lukeed/totalist/blob/4b071d3e54d466a4059de89006c752da782c8b02/src/sync.js#L1-L2

@benmccann benmccann deleted the adapter-node-prefix-builtins branch September 25, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants