Skip to content

fix(deps): skip node: protocol imports in --install#1464

Merged
antongolub merged 1 commit into
google:mainfrom
AnnasMazhar:fix/skip-node-builtin-imports
May 10, 2026
Merged

fix(deps): skip node: protocol imports in --install#1464
antongolub merged 1 commit into
google:mainfrom
AnnasMazhar:fix/skip-node-builtin-imports

Conversation

@AnnasMazhar
Copy link
Copy Markdown
Contributor

@AnnasMazhar AnnasMazhar commented May 9, 2026

Fixes #1462

import fs from "node:fs"
import path from "node:path"
// zx --install no longer tries to install `node@latest`

parsePackageName() now returns early when the import specifier contains :, since npm package names cannot contain colons. This skips all protocol imports (node:, npm:, jsr:, file:) without being affected by the build pipeline's replaceAll("node:", "") post-processing step.

  • Setup Set the latest Node.js LTS version.
  • Build: I've run npm build before committing and verified the bundle updates correctly.
  • Tests: I've run test and confirmed all tests succeed. Added tests to cover my changes if needed.
  • Docs: I've added or updated relevant documentation as needed.
  • Sign Commits have verified signatures and follow conventional commits spec
  • CoC: My changes follow the project's coding guidelines and Code of Conduct.
  • Review: This PR represents original work and is not solely generated by AI tools.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 9, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@AnnasMazhar AnnasMazhar marked this pull request as ready for review May 9, 2026 12:19
@AnnasMazhar
Copy link
Copy Markdown
Contributor Author

I have signed the Google CLA.

@AnnasMazhar AnnasMazhar force-pushed the fix/skip-node-builtin-imports branch from 4991ffb to 6d4f5b8 Compare May 9, 2026 12:27
Comment thread src/deps.ts Outdated

// Skip protocol specifiers (node:, npm:, jsr:, file: etc.)
// npm package names cannot contain colons, so this is a safe check
if (path.includes(':')) return
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice fix. I think this might be a little too broad though, since it’d skip any import with a : in it, not just protocol imports like node:. Maybe worth checking for an actual protocol prefix instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing. On it now.

@AnnasMazhar AnnasMazhar force-pushed the fix/skip-node-builtin-imports branch from 6d4f5b8 to 981bee9 Compare May 9, 2026 13:32
@AnnasMazhar
Copy link
Copy Markdown
Contributor Author

Good catch — updated to use /^[a-z]+:/i.test(path) instead. This only matches actual protocol prefixes (a word followed by colon at the start of the specifier), so it won't false-positive on anything that isn't a protocol import.

@antongolub antongolub self-requested a review May 10, 2026 13:48
Comment thread src/deps.ts Outdated

// Skip protocol specifiers (node:, npm:, jsr:, file: etc.)
// A protocol is a word followed by a colon at the start of the specifier
if (/^[a-z]+:/i.test(path)) return
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd suggest even shorter: if (!path || path.includes(':')) return

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes Sir 👍

@AnnasMazhar AnnasMazhar force-pushed the fix/skip-node-builtin-imports branch from 981bee9 to f73a5cc Compare May 10, 2026 14:26
@AnnasMazhar
Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion. Applied. Is there anything else I can do to improve my contribution?

@AnnasMazhar AnnasMazhar force-pushed the fix/skip-node-builtin-imports branch from f73a5cc to 84b65ea Compare May 10, 2026 14:34
@antongolub
Copy link
Copy Markdown
Collaborator

antongolub commented May 10, 2026

  1. Do not revert the upstream changes (deps, types, etc). Rebase and rebuild is required.
  2. I'm afraid, unverified commits cannot be landed here
  3. Omit test/export.test.js changes

@antongolub antongolub added the bug label May 10, 2026
@AnnasMazhar AnnasMazhar force-pushed the fix/skip-node-builtin-imports branch from 84b65ea to 97d40a4 Compare May 10, 2026 15:01
@AnnasMazhar
Copy link
Copy Markdown
Contributor Author

Thanks for your patience @antongolub. Applied the change. Please review.

@antongolub
Copy link
Copy Markdown
Collaborator

@AnnasMazhar AnnasMazhar force-pushed the fix/skip-node-builtin-imports branch from 97d40a4 to b6a565b Compare May 10, 2026 15:30
@AnnasMazhar
Copy link
Copy Markdown
Contributor Author

Apologies for being dim. Thank you for handholding 👍 @antongolub

Copy link
Copy Markdown
Collaborator

@antongolub antongolub left a comment

Choose a reason for hiding this comment

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

lgtm. Thanks for the fix.

@antongolub antongolub merged commit b6bc975 into google:main May 10, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: --install treats node: built-in imports as node@latest

3 participants