Skip to content
Snippets Groups Projects
Commit c2eb51df authored by Rhys Arkins's avatar Rhys Arkins
Browse files

feat(npm): support long git references

Part of #415
parent 50b1b48d
No related branches found
No related tags found
No related merge requests found
...@@ -153,12 +153,11 @@ async function extractDependencies(content, fileName, config) { ...@@ -153,12 +153,11 @@ async function extractDependencies(content, fileName, config) {
return dep; return dep;
} }
const [depNamePart, depRefPart] = hashSplit; const [depNamePart, depRefPart] = hashSplit;
const depNamePartSplit = depNamePart.split(':'); const githubOwnerRepo = depNamePart
if (depNamePartSplit.length === 2 && depNamePartSplit[0] !== 'github') { .replace(/^github:/, '')
dep.skipReason = 'unknown-version'; .replace(/^git\+/, '')
return dep; .replace(/^https:\/\/github\.com\//, '')
} .replace(/\.git$/, '');
const githubOwnerRepo = depNamePart.replace('github:', '');
const githubRepoSplit = githubOwnerRepo.split('/'); const githubRepoSplit = githubOwnerRepo.split('/');
if (githubRepoSplit.length !== 2) { if (githubRepoSplit.length !== 2) {
dep.skipReason = 'unknown-version'; dep.skipReason = 'unknown-version';
......
...@@ -5,3 +5,5 @@ exports[`workers/branch/package-json .bumpPackageVersion() increments 1`] = `"{\ ...@@ -5,3 +5,5 @@ exports[`workers/branch/package-json .bumpPackageVersion() increments 1`] = `"{\
exports[`workers/branch/package-json .bumpPackageVersion() updates 1`] = `"{\\"name\\":\\"some-package\\",\\"version\\":\\"0.1.0\\"}"`; exports[`workers/branch/package-json .bumpPackageVersion() updates 1`] = `"{\\"name\\":\\"some-package\\",\\"version\\":\\"0.1.0\\"}"`;
exports[`workers/branch/package-json .updateDependency(fileContent, depType, depName, newValue) replaces a github dependency value 1`] = `"{\\"dependencies\\":{\\"gulp\\":\\"gulpjs/gulp#v4.0.0\\"}}"`; exports[`workers/branch/package-json .updateDependency(fileContent, depType, depName, newValue) replaces a github dependency value 1`] = `"{\\"dependencies\\":{\\"gulp\\":\\"gulpjs/gulp#v4.0.0\\"}}"`;
exports[`workers/branch/package-json .updateDependency(fileContent, depType, depName, newValue) replaces a github fully specified version 1`] = `"{\\"dependencies\\":{\\"n\\":\\"git+https://github.com/owner/n#v1.1.0\\"}}"`;
...@@ -194,6 +194,40 @@ Object { ...@@ -194,6 +194,40 @@ Object {
"skipReason": "unknown-version", "skipReason": "unknown-version",
"versionScheme": "semver", "versionScheme": "semver",
}, },
Object {
"currentValue": "github:owner/k#49b5aca",
"depName": "k",
"depType": "dependencies",
"prettyDepType": "dependency",
"skipReason": "unversioned-reference",
"versionScheme": "semver",
},
Object {
"currentValue": "github:owner/l.git#abcdef0",
"depName": "l",
"depType": "dependencies",
"prettyDepType": "dependency",
"skipReason": "unversioned-reference",
"versionScheme": "semver",
},
Object {
"currentRawValue": "https://github.com/owner/m.git#v1.0.0",
"currentValue": "v1.0.0",
"depName": "m",
"depType": "dependencies",
"prettyDepType": "dependency",
"purl": "pkg:github/owner/m?ref=tags",
"versionScheme": "semver",
},
Object {
"currentRawValue": "git+https://github.com/owner/n#v2.0.0",
"currentValue": "v2.0.0",
"depName": "n",
"depType": "dependencies",
"prettyDepType": "dependency",
"purl": "pkg:github/owner/n?ref=tags",
"versionScheme": "semver",
},
], ],
"lernaClient": undefined, "lernaClient": undefined,
"lernaDir": undefined, "lernaDir": undefined,
......
...@@ -183,6 +183,10 @@ describe('manager/npm/extract', () => { ...@@ -183,6 +183,10 @@ describe('manager/npm/extract', () => {
h: 'github:-hello/world#v1.0.0', h: 'github:-hello/world#v1.0.0',
i: '@foo/bar#v2.0.0', i: '@foo/bar#v2.0.0',
j: 'github:frank#v0.0.1', j: 'github:frank#v0.0.1',
k: 'github:owner/k#49b5aca',
l: 'github:owner/l.git#abcdef0',
m: 'https://github.com/owner/m.git#v1.0.0',
n: 'git+https://github.com/owner/n#v2.0.0',
}, },
}; };
const pJsonStr = JSON.stringify(pJson); const pJsonStr = JSON.stringify(pJson);
......
...@@ -40,6 +40,23 @@ describe('workers/branch/package-json', () => { ...@@ -40,6 +40,23 @@ describe('workers/branch/package-json', () => {
const res = npmUpdater.updateDependency(input, upgrade); const res = npmUpdater.updateDependency(input, upgrade);
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
it('replaces a github fully specified version', () => {
const upgrade = {
depType: 'dependencies',
depName: 'n',
currentValue: 'v1.0.0',
currentRawValue: 'git+https://github.com/owner/n#v1.0.0',
newValue: 'v1.1.0',
};
const input = JSON.stringify({
dependencies: {
n: 'git+https://github.com/owner/n#v1.0.0',
},
});
const res = npmUpdater.updateDependency(input, upgrade);
expect(res).toMatchSnapshot();
expect(res.includes('v1.1.0')).toBe(true);
});
it('updates resolutions too', () => { it('updates resolutions too', () => {
const upgrade = { const upgrade = {
depType: 'dependencies', depType: 'dependencies',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment