Skip to content

Commit

Permalink
feat(npm): handle github dependencies with semver versions (#28261)
Browse files Browse the repository at this point in the history
  • Loading branch information
fehnomenal authored Jul 20, 2024
1 parent f3ef173 commit 8dfb34b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
26 changes: 26 additions & 0 deletions lib/modules/manager/npm/extract/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,32 @@ exports[`modules/manager/npm/extract/index .extractPackageFile() extracts non-np
"sourceUrl": "https://github.com/Owner/P",
"versioning": "npm",
},
{
"currentRawValue": "github:owner/q#semver:1.1.0",
"currentValue": "1.1.0",
"datasource": "github-tags",
"depName": "q",
"depType": "dependencies",
"gitRef": true,
"packageName": "owner/q",
"pinDigests": false,
"prettyDepType": "dependency",
"sourceUrl": "https://github.com/owner/q",
"versioning": "npm",
},
{
"currentRawValue": "github:owner/r#semver:^1.0.0",
"currentValue": "^1.0.0",
"datasource": "github-tags",
"depName": "r",
"depType": "dependencies",
"gitRef": true,
"packageName": "owner/r",
"pinDigests": false,
"prettyDepType": "dependency",
"sourceUrl": "https://github.com/owner/r",
"versioning": "npm",
},
],
"extractedConstraints": {},
"managerData": {
Expand Down
18 changes: 16 additions & 2 deletions lib/modules/manager/npm/extract/common/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,22 @@ export function extractDependency(
dep.versioning = npmVersioningId;
dep.packageName = githubOwnerRepo;
} else {
dep.skipReason = 'unversioned-reference';
return dep;
// <protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
// https://docs.npmjs.com/cli/v10/configuring-npm/package-json#git-urls-as-dependencies
const len = 7; // length of 'semver:'
const maybeVersion = depRefPart.substring(len);

if (depRefPart.startsWith('semver:') && isValid(maybeVersion)) {
dep.currentRawValue = dep.currentValue;
dep.currentValue = maybeVersion;
dep.datasource = GithubTagsDatasource.id;
dep.versioning = npmVersioningId;
dep.packageName = githubOwnerRepo;
dep.pinDigests = false;
} else {
dep.skipReason = 'unversioned-reference';
return dep;
}
}
dep.sourceUrl = `https://github.com/${githubOwnerRepo}`;
dep.gitRef = true;
Expand Down
14 changes: 14 additions & 0 deletions lib/modules/manager/npm/extract/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ describe('modules/manager/npm/extract/index', () => {
n: 'git+https://github.com/owner/n#v2.0.0',
o: 'git@github.com:owner/o.git#v2.0.0',
p: 'Owner/P.git#v2.0.0',
q: 'github:owner/q#semver:1.1.0',
r: 'github:owner/r#semver:^1.0.0',
},
};
const pJsonStr = JSON.stringify(pJson);
Expand Down Expand Up @@ -691,6 +693,18 @@ describe('modules/manager/npm/extract/index', () => {
datasource: 'github-tags',
sourceUrl: 'https://github.com/Owner/P',
},
{
depName: 'q',
currentValue: '1.1.0',
datasource: 'github-tags',
sourceUrl: 'https://github.com/owner/q',
},
{
depName: 'r',
currentValue: '^1.0.0',
datasource: 'github-tags',
sourceUrl: 'https://github.com/owner/r',
},
],
});
});
Expand Down

0 comments on commit 8dfb34b

Please sign in to comment.