Skip to content

fix(plugin): parse package specifiers with npm-package-arg and sanitize win32 cache paths#21135

Merged
thdxr merged 4 commits intoanomalyco:devfrom
Hona:fix/plugin-illegal-win-path
Apr 6, 2026
Merged

fix(plugin): parse package specifiers with npm-package-arg and sanitize win32 cache paths#21135
thdxr merged 4 commits intoanomalyco:devfrom
Hona:fix/plugin-illegal-win-path

Conversation

@Hona
Copy link
Copy Markdown
Member

@Hona Hona commented Apr 5, 2026

Fixes #21126
Fixes #21099

Replace filesystem-illegal characters in package cache directory names on Windows by adding a sanitize() helper and using it in directory(). Fix parsing of plugin specifiers by splitting on the first "@" after position 0 so scoped names and git URLs are handled correctly. Add unit tests for parsePluginSpecifier covering plain, scoped, and git URL cases.
Copilot AI review requested due to automatic review settings April 5, 2026 22:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes plugin spec parsing for npm/git URL forms and improves Windows compatibility when deriving npm install cache directories.

Changes:

  • Add unit tests covering parsePluginSpecifier for unscoped/scoped packages, semver versions, and git URL versions (including git@...).
  • Update parsePluginSpecifier to split on the version separator without breaking git+ssh URLs that include an additional @.
  • Sanitize npm package cache directory names on Windows to avoid illegal filename characters.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/opencode/test/plugin/shared.test.ts Adds coverage for plugin specifier parsing across common npm and git URL patterns.
packages/opencode/src/plugin/shared.ts Adjusts parsing logic to correctly separate package name and version for git URL specs.
packages/opencode/src/npm/index.ts Adds Win32 directory-name sanitization for npm cache install directories.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Hona added 2 commits April 6, 2026 09:05
Always define the illegal-character set and export Npm.sanitize, but only perform character substitution on Windows (no-op on other platforms). This exposes sanitize for testing and avoids unnecessary replacements on non-Windows systems. Adds unit tests to verify scoped package handling and git+https spec sanitization on Windows.
Add npm-package-arg (and types) and switch plugin specifier parsing to use it. parsePluginSpecifier now relies on npa to correctly handle aliases, npm: protocol specs, git URLs and unversioned specs; resolvePluginTarget builds the install target from the parsed result. Npm.sanitize was simplified to only apply Windows-specific illegal-character replacement, and tests were updated/added to cover the new parsing and sanitize behaviors. Package.json and lockfile updated to include the new dependency.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Hona Hona changed the title fix(win32): Sanitize npm package dirs and fix plugin parsing fix(plugin): parse package specifiers with npm-package-arg and sanitize win32 cache paths Apr 6, 2026
@Hona
Copy link
Copy Markdown
Member Author

Hona commented Apr 6, 2026

/review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

lgtm

@thdxr thdxr enabled auto-merge (squash) April 6, 2026 00:25
@thdxr thdxr merged commit 68f4aa2 into anomalyco:dev Apr 6, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants