Skip to content

Commit

Permalink
fix(git): match git dependencies by name instead of whole url
Browse files Browse the repository at this point in the history
Summary

This is a fix for issue #2840 .

It fixes the issue by comparing the name of the git repo with the entries on the lockfile, instead of comparing the whole git url (which wouldn't match with the version already on the lockfile, since the url would be different).

Test plan

We tested with multiple git repositories, including the ones that were given as an example on the issue page.
  • Loading branch information
davidreis97 authored and kaylieEB committed Dec 4, 2017
1 parent b827eae commit 2065988
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 6 deletions.
21 changes: 21 additions & 0 deletions __tests__/commands/add.js
Expand Up @@ -609,6 +609,27 @@ test.concurrent('upgrade scenario 2 (with sub dependencies)', (): Promise<void>
});
});

test.concurrent('install another fork of an existing package', (): Promise<void> => {
// When installing a package with the same name as an existing one but from a different repo,
// the old one should be replaced with the new one in the lock file.
const firstSource = 'davidreis97/example-yarn-package#master';
const secondSource = 'yarnpkg/example-yarn-package#master';
const pkgName = 'example-yarn-package';
return runAdd([firstSource], {}, 'install-forked-git', async (config, reporter): Promise<void> => {
let lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock')));
expect(lockfile.indexOf(`${pkgName}@${firstSource}:`)).toEqual(0);
expect(lockfile.indexOf(`${pkgName}@${secondSource}:`)).toEqual(-1);

const add = new Add([secondSource], {}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await add.init();

lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock')));

expect(lockfile.indexOf(`${pkgName}@${firstSource}:`)).toEqual(-1);
expect(lockfile.indexOf(`${pkgName}@${secondSource}:`)).toEqual(0);
});
});

test.concurrent('downgrade scenario', (): Promise<void> => {
// left-pad first installed 1.1.0 then downgraded to 0.0.9
// files in mirror, yarn.lock, package.json and node_modules should reflect that
Expand Down
6 changes: 6 additions & 0 deletions __tests__/fixtures/add/install-forked-git/package.json
@@ -0,0 +1,6 @@
{
"name": "install-forked-git",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,50 @@
HTTP/1.1 200 OK
Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
Strict-Transport-Security: max-age=31536000
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-XSS-Protection: 1; mode=block
ETag: "36952fd724b4f5fc4240d20b883deda155134db3"
Content-Type: text/plain; charset=utf-8
Cache-Control: max-age=300
X-Geo-Block-List:
X-GitHub-Request-Id: F20A:258A9:CAEC81:D518BE:5A205A53
Content-Length: 485
Accept-Ranges: bytes
Date: Thu, 30 Nov 2017 19:21:56 GMT
Via: 1.1 varnish
Connection: keep-alive
X-Served-By: cache-mad9433-MAD
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1512069716.351893,VS0,VE140
Vary: Authorization,Accept-Encoding
Access-Control-Allow-Origin: *
X-Fastly-Request-ID: 182c3a5089ec0a3c1eeb6f16e623487b0393aa8d
Expires: Thu, 30 Nov 2017 19:26:56 GMT
Source-Age: 0

{
"name": "example-yarn-package",
"version": "1.0.0",
"description": "An example package to demonstrate Yarn",
"main": "index.js",
"repository": {
"url": "github.com/yarnpkg/example-yarn-package",
"type": "git"
},
"scripts": {
"test": "jest"
},
"author": "Yarn Contributors",
"license": "BSD-2-Clause",
"dependencies": {
"lodash": "^4.16.2"
},
"devDependencies": {
"jest-cli": "15.1.1"
},
"jest": {
"testEnvironment": "node"
}
}
@@ -0,0 +1,50 @@
HTTP/1.1 200 OK
Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
Strict-Transport-Security: max-age=31536000
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-XSS-Protection: 1; mode=block
ETag: "36952fd724b4f5fc4240d20b883deda155134db3"
Content-Type: text/plain; charset=utf-8
Cache-Control: max-age=300
X-Geo-Block-List:
X-GitHub-Request-Id: 73C6:3A6F:4C9B26:521B93:5A205A9B
Content-Length: 485
Accept-Ranges: bytes
Date: Thu, 30 Nov 2017 19:23:08 GMT
Via: 1.1 varnish
Connection: keep-alive
X-Served-By: cache-mad9433-MAD
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1512069788.063184,VS0,VE123
Vary: Authorization,Accept-Encoding
Access-Control-Allow-Origin: *
X-Fastly-Request-ID: 082c2b71081ca345fdae028f317f58914a3f27fe
Expires: Thu, 30 Nov 2017 19:28:08 GMT
Source-Age: 0

{
"name": "example-yarn-package",
"version": "1.0.0",
"description": "An example package to demonstrate Yarn",
"main": "index.js",
"repository": {
"url": "github.com/yarnpkg/example-yarn-package",
"type": "git"
},
"scripts": {
"test": "jest"
},
"author": "Yarn Contributors",
"license": "BSD-2-Clause",
"dependencies": {
"lodash": "^4.16.2"
},
"devDependencies": {
"jest-cli": "15.1.1"
},
"jest": {
"testEnvironment": "node"
}
}
@@ -0,0 +1,22 @@
HTTP/1.1 200 OK
Server: GitHub.com
Date: Thu, 30 Nov 2017 18:04:38 GMT
Content-Type: text/html; charset=utf-8
Status: 200 OK
Cache-Control: no-cache
Vary: X-PJAX
X-UA-Compatible: IE=Edge,chrome=1
Set-Cookie: logged_in=no; domain=.github.com; path=/; expires=Mon, 30 Nov 2037 18:04:38 -0000; secure; HttpOnly
Set-Cookie: _gh_sess=eyJzZXNzaW9uX2lkIjoiNWUzN2ZjMzQ1NzAxZTdiMTYwMjUyNjEwNDFlOWU2MDkiLCJsYXN0X3JlYWRfZnJvbV9yZXBsaWNhcyI6MTUxMjA2NTA3ODYzNSwic3B5X3JlcG8iOiJkYXZpZHJlaXM5Ny9leGFtcGxlLXlhcm4tcGFja2FnZSIsInNweV9yZXBvX2F0IjoxNTEyMDY1MDc4LCJfY3NyZl90b2tlbiI6Ilc2ZS9VY2dpNkZ1M2xDcnRDa2JLY2tOdS9KUmh5djZOaU5pTHN1SEZVZW89IiwiZmxhc2giOnsiZGlzY2FyZCI6WyJhbmFseXRpY3NfbG9jYXRpb24iXSwiZmxhc2hlcyI6eyJhbmFseXRpY3NfbG9jYXRpb24iOiIvPHVzZXItbmFtZT4vPHJlcG8tbmFtZT4ifX19--42e9c0d2914379c385b7ba452dcdb16dd9b2806e; path=/; secure; HttpOnly
X-Request-Id: 19e3889a0c30643447b97012ce7ca286
X-Runtime: 0.211652
Expect-CT: max-age=2592000, report-uri="https://api.github.com/_private/browser/errors"
Content-Security-Policy: default-src 'none'; base-uri 'self'; block-all-mixed-content; child-src render.githubusercontent.com; connect-src 'self' uploads.github.com status.github.com collector.githubapp.com api.github.com www.google-analytics.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com wss://live.github.com; font-src assets-cdn.github.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; img-src 'self' data: assets-cdn.github.com identicons.github.com collector.githubapp.com github-cloud.s3.amazonaws.com *.githubusercontent.com; media-src 'none'; script-src assets-cdn.github.com; style-src 'unsafe-inline' assets-cdn.github.com
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
Public-Key-Pins: max-age=0; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho="; pin-sha256="k2v657xBsOVe1PQRwOsHsw3bsGT2VzIqz5K+59sNQws="; pin-sha256="K87oWBWM9UZfyddvDfoxL+8lpNyoUB2ptGtn0fv6G2Q="; pin-sha256="IQBnNBEiFuhj+8x6X8XLgh01V9Ic5/V3IRQLNFFc7v4="; pin-sha256="iie1VXtL7HzAMF+/PVPR9xzT80kQxdZeJ+zduCB3uj0="; pin-sha256="LvRiGEjRqfzurezaWuj8Wie2gyHMrW5Q06LspMnox7A="; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-XSS-Protection: 1; mode=block
X-Runtime-rack: 0.220571
X-GitHub-Request-Id: F043:3B8C:1C5A8A7:330DFDC:5A204835

@@ -0,0 +1,22 @@
HTTP/1.1 200 OK
Server: GitHub.com
Date: Thu, 30 Nov 2017 18:17:52 GMT
Content-Type: text/html; charset=utf-8
Status: 200 OK
Cache-Control: no-cache
Vary: X-PJAX
X-UA-Compatible: IE=Edge,chrome=1
Set-Cookie: logged_in=no; domain=.github.com; path=/; expires=Mon, 30 Nov 2037 18:17:52 -0000; secure; HttpOnly
Set-Cookie: _gh_sess=eyJzZXNzaW9uX2lkIjoiYzJjNDMxOWI3NmVhYjQxNDY0NzczMGIxNjVhYzY4NmMiLCJsYXN0X3JlYWRfZnJvbV9yZXBsaWNhcyI6MTUxMjA2NTg3MjgzNSwic3B5X3JlcG8iOiJ5YXJucGtnL2V4YW1wbGUteWFybi1wYWNrYWdlIiwic3B5X3JlcG9fYXQiOjE1MTIwNjU4NzIsIl9jc3JmX3Rva2VuIjoiKzVKWFFMbVNwTDZubEZnTFRIV3RqakpTOFVoZTlKeXV0YWhWd3p1U09ZVT0iLCJmbGFzaCI6eyJkaXNjYXJkIjpbImFuYWx5dGljc19sb2NhdGlvbiJdLCJmbGFzaGVzIjp7ImFuYWx5dGljc19sb2NhdGlvbiI6Ii88dXNlci1uYW1lPi88cmVwby1uYW1lPiJ9fX0%3D--eb2c6172e33b3c510669a66c4216a0377ad5d95c; path=/; secure; HttpOnly
X-Request-Id: b40e6b8f6e8cf58a9088881b5f288969
X-Runtime: 0.210270
Expect-CT: max-age=2592000, report-uri="https://api.github.com/_private/browser/errors"
Content-Security-Policy: default-src 'none'; base-uri 'self'; block-all-mixed-content; child-src render.githubusercontent.com; connect-src 'self' uploads.github.com status.github.com collector.githubapp.com api.github.com www.google-analytics.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com wss://live.github.com; font-src assets-cdn.github.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; img-src 'self' data: assets-cdn.github.com identicons.github.com collector.githubapp.com github-cloud.s3.amazonaws.com *.githubusercontent.com; media-src 'none'; script-src assets-cdn.github.com; style-src 'unsafe-inline' assets-cdn.github.com
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
Public-Key-Pins: max-age=0; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho="; pin-sha256="k2v657xBsOVe1PQRwOsHsw3bsGT2VzIqz5K+59sNQws="; pin-sha256="K87oWBWM9UZfyddvDfoxL+8lpNyoUB2ptGtn0fv6G2Q="; pin-sha256="IQBnNBEiFuhj+8x6X8XLgh01V9Ic5/V3IRQLNFFc7v4="; pin-sha256="iie1VXtL7HzAMF+/PVPR9xzT80kQxdZeJ+zduCB3uj0="; pin-sha256="LvRiGEjRqfzurezaWuj8Wie2gyHMrW5Q06LspMnox7A="; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-XSS-Protection: 1; mode=block
X-Runtime-rack: 0.218641
X-GitHub-Request-Id: F724:3BA3:1FF90CB:3E5AD51:5A204B50

12 changes: 6 additions & 6 deletions src/cli/commands/install.js
Expand Up @@ -27,6 +27,7 @@ import map from '../../util/map.js';
import {version as YARN_VERSION, getInstallationMethod} from '../../util/yarn-version.js';
import WorkspaceLayout from '../../workspace-layout.js';
import ResolutionMap from '../../resolution-map.js';
import guessName from '../../util/guess-name';

const emoji = require('node-emoji');
const invariant = require('invariant');
Expand Down Expand Up @@ -234,14 +235,13 @@ export class Install {
// exclude package names that are in install args
const excludeNames = [];
for (const pattern of excludePatterns) {
// can't extract a package name from this
if (getExoticResolver(pattern)) {
continue;
excludeNames.push(guessName(pattern));
} else {
// extract the name
const parts = normalizePattern(pattern);
excludeNames.push(parts.name);
}

// extract the name
const parts = normalizePattern(pattern);
excludeNames.push(parts.name);
}

const stripExcluded = (manifest: Manifest) => {
Expand Down

0 comments on commit 2065988

Please sign in to comment.