-
-
Notifications
You must be signed in to change notification settings - Fork 425
feat(ui): flag git and https dependencies #2234
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * Detect whether a dependency version specifier points to a URL or Git source | ||
| * rather than the npm registry. | ||
| * | ||
| * These bypass npm registry integrity checks and can be manipulated. | ||
| * @see https://docs.npmjs.com/cli/v11/configuring-npm/package-json#git-urls-as-dependencies | ||
| * @see https://docs.npmjs.com/cli/v11/configuring-npm/package-json#urls-as-dependencies | ||
| */ | ||
| export function isUrlDependency(version: string): boolean { | ||
| // npm: protocol aliases are safe (resolved from the registry) | ||
| if (version.startsWith('npm:')) return false | ||
|
|
||
| // Protocols: git:, git+https:, git+ssh:, git+http:, https:, http:, file: | ||
| if (/^[a-z][a-z+]*:/i.test(version)) return true | ||
|
|
||
| // GitHub shorthand: user/repo or user/repo#ref | ||
| // Also matches github:, gist:, bitbucket:, gitlab: (already caught above by protocol check) | ||
| if (/^[^@][^/]*\/[^/]+/.test(version)) return true | ||
|
|
||
| return false | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { isUrlDependency } from '#shared/utils/version-source' | ||
|
|
||
| describe('version-source', () => { | ||
| describe('isUrlDependency', () => { | ||
| it('returns false for semver ranges', () => { | ||
| expect(isUrlDependency('^1.0.0')).toBe(false) | ||
| expect(isUrlDependency('~2.3.4')).toBe(false) | ||
| expect(isUrlDependency('>=1.0.0 <2.0.0')).toBe(false) | ||
| expect(isUrlDependency('*')).toBe(false) | ||
| expect(isUrlDependency('1.0.0')).toBe(false) | ||
| expect(isUrlDependency('2.0.0-beta.1')).toBe(false) | ||
| }) | ||
|
|
||
| it('returns false for npm: protocol aliases', () => { | ||
| expect(isUrlDependency('npm:other-pkg@^1.0.0')).toBe(false) | ||
| expect(isUrlDependency('npm:@scope/pkg@2.0.0')).toBe(false) | ||
| }) | ||
|
|
||
| it('returns true for git: protocol', () => { | ||
| expect(isUrlDependency('git://github.com/user/repo.git')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for git+https: protocol', () => { | ||
| expect(isUrlDependency('git+https://github.com/user/repo.git')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for git+ssh: protocol', () => { | ||
| expect(isUrlDependency('git+ssh://git@github.com:user/repo.git')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for git+http: protocol', () => { | ||
| expect(isUrlDependency('git+http://github.com/user/repo.git')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for https: URLs', () => { | ||
| expect(isUrlDependency('https://github.com/user/repo/tarball/main')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for http: URLs', () => { | ||
| expect(isUrlDependency('http://example.com/pkg.tgz')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for file: protocol', () => { | ||
| expect(isUrlDependency('file:../local-pkg')).toBe(true) | ||
| expect(isUrlDependency('file:./packages/my-lib')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for GitHub shorthand (user/repo)', () => { | ||
| expect(isUrlDependency('user/repo')).toBe(true) | ||
| expect(isUrlDependency('user/repo#branch')).toBe(true) | ||
| expect(isUrlDependency('user/repo#semver:^1.0.0')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for github: prefix', () => { | ||
| expect(isUrlDependency('github:user/repo')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for gist: prefix', () => { | ||
| expect(isUrlDependency('gist:11081aaa281')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for bitbucket: prefix', () => { | ||
| expect(isUrlDependency('bitbucket:user/repo')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true for gitlab: prefix', () => { | ||
| expect(isUrlDependency('gitlab:user/repo')).toBe(true) | ||
| }) | ||
|
|
||
| it('returns false for scoped packages in semver ranges', () => { | ||
| // Scoped packages start with @ so they won't match the user/repo pattern | ||
| expect(isUrlDependency('@scope/pkg')).toBe(false) | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 198
🏁 Script executed:
cat -n shared/utils/version-source.ts | head -50Repository: npmx-dev/npmx.dev
Length of output: 1099
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 88
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 88
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 177
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 3367
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 3321
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 3114
Exclude workspace and link protocols from external source detection.
The protocol regex
/^[a-z][a-z+]*:/imatchesworkspace:andlink:protocols used by pnpm and Yarn for local monorepo references, causing false positives. These are local, not external sources, and conflict with the function's documented purpose. Add explicitfalsereturns for these protocols before the generic regex check:Suggested fix
export function isUrlDependency(version: string): boolean { // npm: protocol aliases are safe (resolved from the registry) if (version.startsWith('npm:')) return false + // workspace: and link: are local monorepo references, not external sources + if (version.startsWith('workspace:') || version.startsWith('link:')) return false + // Protocols: git:, git+https:, git+ssh:, git+http:, https:, http:, file: if (/^[a-z][a-z+]*:/i.test(version)) return trueAdd test cases for these protocols to prevent regression.
📝 Committable suggestion