Skip to content
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

fix(run): change run command to prioritize cwd/node_modules/.bin #7750

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa

## Master

- Change run command to prioritize cwd/node_modules/.bin. Fixes run/bin in workspaces when the same binary is hoisted and installed in a workspace package.
[#7748](https://github.com/yarnpkg/yarn/issues/7748) - [**priceld**](https://github.com/priceld)

- Prints workspace names with `yarn workspaces` (silence with `-s`)

[#7722](https://github.com/yarnpkg/yarn/pull/7722) - [**Orta**](https://twitter.com/orta)
Expand Down
30 changes: 29 additions & 1 deletion __tests__/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ test('adds workspace root node_modules/.bin to path when in a workspace', (): Pr
expect(envPaths).toContain(path.join(config.cwd, 'packages', 'pkg1', 'node_modules', '.bin'));
}));

test('adds cwd node_modules/.bin to path when in a workspace usig nohoist', (): Promise<void> =>
test('adds cwd node_modules/.bin to path when in a workspace using nohoist', (): Promise<void> =>
runRunInWorkspacePackage('packages/pkg1', ['env'], {}, 'nohoist-workspace', (config, reporter): ?Promise<void> => {
const logEntry = reporter.getBuffer().find(entry => entry.type === 'log');
const parsedLogData = JSON.parse(logEntry ? logEntry.data.toString() : '{}');
Expand All @@ -230,3 +230,31 @@ test('runs script with custom script-shell', (): Promise<void> =>
customShell: '/usr/bin/dummy',
});
}));

test('runs workspace bin before hoisted bin', (): Promise<void> =>
runRunInWorkspacePackage('packages/pkg1', ['duplicated-bin'], {}, 'workspace-bins', (config): ?Promise<void> => {
const expectedCwd = path.join(config.cwd, 'packages', 'pkg1');
const script = path.join(expectedCwd, 'node_modules', '.bin', 'duplicated-bin');

expect(execCommand).toBeCalledWith({
stage: 'duplicated-bin',
config,
cmd: script,
cwd: expectedCwd,
isInteractive: true,
});
}));

test('runs hoisted bin if workspace bin is not found', (): Promise<void> =>
runRunInWorkspacePackage('packages/pkg1', ['hoisted-bin'], {}, 'workspace-bins', (config): ?Promise<void> => {
const expectedCwd = path.join(config.cwd, 'packages', 'pkg1');
const script = path.join(config.cwd, 'node_modules', '.bin', 'hoisted-bin');

expect(execCommand).toBeCalledWith({
stage: 'hoisted-bin',
config,
cmd: script,
cwd: expectedCwd,
isInteractive: true,
});
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 09 Dec 2019 21:52:06 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 1181
Cache-Control: max-age=3600, public
Content-Disposition: inline
Etag: W/"78309fbf8af4479c47eca65b0c5e3f51"
Referrer-Policy: strict-origin-when-cross-origin
Set-Cookie: experimentation_subject_id=ImJmMDg0YTIyLWM5OTgtNDNmOC05MmIxLTBmNzU2YWZkMzNjYSI%3D--a0c3f65ca95e8147c43e228efaf2525fcb3e3688; domain=.gitlab.com; path=/; expires=Fri, 09 Dec 2039 21:52:06 -0000; secure; HttpOnly
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: DENY
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 4YrYRJQgtK1
X-Runtime: 0.059498
X-Ua-Compatible: IE=edge
X-Xss-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000
Referrer-Policy: strict-origin-when-cross-origin
GitLab-LB: fe-12-lb-gprd
GitLab-SV: web-15-sv-gprd

{
"name": "kanban",
"version": "0.0.1",
"repository": "gitlab.com/leanlabsio/kanban",
"scripts": {
"install": "npm install",
"build": "grunt build",
"watch": "grunt watch"
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-cli": "~0.1.13",
"grunt-contrib-copy": "^0.5.0",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-uglify": "~0.7.0",
"grunt-sass": "1.0.0",
"grunt-contrib-connect": "~0.8.0",
"grunt-connect-proxy": "~0.1.11"
},
"dependencies": {
"angular": "=1.5.6",
"angular-lodash": "https://github.com/EMSSConsulting/angular-lodash.git#68a726c",
"foundation-sites": "5.5.2",
"angular-foundation": "https://github.com/pineconellc/angular-foundation.git#8f3f260",
"angular-loading-bar": "=0.5.2",
"angular-storage": "=0.0.6",
"angular-ui-router": "=0.3.0",
"angularjs-datepicker": "=0.2.15",
"font-awesome": "=4.6.3",
"markdown-it": "=5.0.2",
"markdown-it-emoji": "=1.1.0",
"ng-sortable": "=1.3.6",
"sass-flex-mixin": "=1.0.3",
"lodash": "=4.13.1",
"twemoji": "=2.1.0",
"angular-file-upload": "=2.3.4"
}
}
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions __tests__/fixtures/run/workspace-bins/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"workspaces": [
"packages/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 3 additions & 1 deletion src/cli/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ export async function getBinEntries(config: Config): Promise<Map<string, string>

// Setup the node_modules/.bin folders for analysis
for (const registryFolder of config.registryFolders) {
binFolders.add(path.resolve(config.cwd, registryFolder, '.bin'));
// Paths should be added in reverse order of precedence (if a bin exists in
// multiple paths, the last path that was added containing the bin will be used)
binFolders.add(path.resolve(config.lockfileFolder, registryFolder, '.bin'));
binFolders.add(path.resolve(config.cwd, registryFolder, '.bin'));
}

// Same thing, but for the pnp dependencies, located inside the cache
Expand Down