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): Use bin scripts defined in a workspace package before the workspace root. #9079

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ Array [
]
`;

exports[`should add package with no-lockfile option 2`] = `
Array [
"info No lockfile found.",
"[1/4] Resolving packages...",
"[2/4] Fetching packages...",
"[3/4] Linking dependencies...",
"[4/4] Building fresh packages...",
"success Saved 1 new dependency.",
"info Direct dependencies",
"└─ [email protected]",
"info All dependencies",
"└─ [email protected]",
]
`;

exports[`should add package with no-lockfile option in front 1`] = `
Array [
"info No lockfile found.",
Expand Down
56 changes: 56 additions & 0 deletions __tests__/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,62 @@ test('adds cwd node_modules/.bin to path when in a workspace usig nohoist', ():
expect(envPaths).toContain(path.join(config.cwd, 'packages', 'pkg1', 'node_modules', '.bin'));
}));

// Regression test for https://github.com/yarnpkg/yarn/issues/8590
test('uses transitive script from workspace root', (): Promise<void> =>
runRun(
['eslint'],
{},
'issue-8590',
(config): ?Promise<void> => {
expect(execCommand).toBeCalledWith({
stage: 'eslint',
config,
cmd: `${config.cwd}/node_modules/.bin/eslint`,
cwd: config.cwd,
isInteractive: true,
customShell: undefined,
});
},
));

// Regression test for https://github.com/yarnpkg/yarn/issues/8590
test('uses transitive script from workspace package A', (): Promise<void> =>
runRunInWorkspacePackage(
'packages/workspace-a',
['eslint'],
{},
'issue-8590',
(config): ?Promise<void> => {
expect(execCommand).toBeCalledWith({
stage: 'eslint',
config,
cmd: `${config.cwd}/packages/workspace-a/node_modules/.bin/eslint`,
cwd: `${config.cwd}/packages/workspace-a`,
isInteractive: true,
customShell: undefined,
});
},
));

// Regression test for https://github.com/yarnpkg/yarn/issues/8590
test('uses transitive script from workspace package B', (): Promise<void> =>
runRunInWorkspacePackage(
'packages/workspace-b',
['eslint'],
{},
'issue-8590',
(config): ?Promise<void> => {
expect(execCommand).toBeCalledWith({
stage: 'eslint',
config,
cmd: `${config.cwd}/packages/workspace-b/node_modules/.bin/eslint`,
cwd: `${config.cwd}/packages/workspace-b`,
isInteractive: true,
customShell: undefined,
});
},
));

test('runs script with custom script-shell', (): Promise<void> =>
runRunWithCustomShell('/usr/bin/dummy', ['start'], {}, 'script-shell', async (config): ?Promise<void> => {
const pkg = await fs.readJson(path.join(config.cwd, 'package.json'));
Expand Down
Empty file.
13 changes: 13 additions & 0 deletions __tests__/fixtures/run/issue-8590/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "yarn-issue-8590",
"version": "1.0.0",
"main": "index.js",
"author": "yarn",
"license": "MIT",
"private": true,
"workspaces": {
"packages": [
"packages/*"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "workspace-a",
"version": "1.0.0",
"dependencies": {
"eslint": "8.57.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "workspace-b",
"version": "1.0.0",
"dependencies": {
"eslint": "1.0.0"
}
}
6 changes: 5 additions & 1 deletion src/cli/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export async function getBinEntries(config: Config): Promise<Map<string, string>
for (const binFolder of binFolders) {
if (await fs.exists(binFolder)) {
for (const name of await fs.readdir(binFolder)) {
binEntries.set(name, path.join(binFolder, name));
const existingDepth = binEntries.get(name) ? binEntries.get(name).split(path.sep).length : 0;
const newDepth = binFolder.split(path.sep).length;
if (newDepth >= existingDepth) {
binEntries.set(name, path.join(binFolder, name));
}
}
}
}
Expand Down