diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap index c7154dd81b..17422d3df0 100644 --- a/__tests__/__snapshots__/index.js.snap +++ b/__tests__/__snapshots__/index.js.snap @@ -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", + "└─ repeating@3.0.0", + "info All dependencies", + "└─ repeating@3.0.0", +] +`; + exports[`should add package with no-lockfile option in front 1`] = ` Array [ "info No lockfile found.", diff --git a/__tests__/commands/run.js b/__tests__/commands/run.js index 35a1221e56..54b0a68e56 100644 --- a/__tests__/commands/run.js +++ b/__tests__/commands/run.js @@ -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 => + runRun( + ['eslint'], + {}, + 'issue-8590', + (config): ?Promise => { + 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 => + runRunInWorkspacePackage( + 'packages/workspace-a', + ['eslint'], + {}, + 'issue-8590', + (config): ?Promise => { + 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 => + runRunInWorkspacePackage( + 'packages/workspace-b', + ['eslint'], + {}, + 'issue-8590', + (config): ?Promise => { + 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 => runRunWithCustomShell('/usr/bin/dummy', ['start'], {}, 'script-shell', async (config): ?Promise => { const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); diff --git a/__tests__/fixtures/run/issue-8590/node_modules/.bin/eslint b/__tests__/fixtures/run/issue-8590/node_modules/.bin/eslint new file mode 100644 index 0000000000..e69de29bb2 diff --git a/__tests__/fixtures/run/issue-8590/package.json b/__tests__/fixtures/run/issue-8590/package.json new file mode 100644 index 0000000000..3f00c261e5 --- /dev/null +++ b/__tests__/fixtures/run/issue-8590/package.json @@ -0,0 +1,13 @@ +{ + "name": "yarn-issue-8590", + "version": "1.0.0", + "main": "index.js", + "author": "yarn", + "license": "MIT", + "private": true, + "workspaces": { + "packages": [ + "packages/*" + ] + } +} diff --git a/__tests__/fixtures/run/issue-8590/packages/workspace-a/node_modules/.bin/eslint b/__tests__/fixtures/run/issue-8590/packages/workspace-a/node_modules/.bin/eslint new file mode 100644 index 0000000000..e69de29bb2 diff --git a/__tests__/fixtures/run/issue-8590/packages/workspace-a/package.json b/__tests__/fixtures/run/issue-8590/packages/workspace-a/package.json new file mode 100644 index 0000000000..c1b5493a98 --- /dev/null +++ b/__tests__/fixtures/run/issue-8590/packages/workspace-a/package.json @@ -0,0 +1,7 @@ +{ + "name": "workspace-a", + "version": "1.0.0", + "dependencies": { + "eslint": "8.57.0" + } +} diff --git a/__tests__/fixtures/run/issue-8590/packages/workspace-b/node_modules/.bin/eslint b/__tests__/fixtures/run/issue-8590/packages/workspace-b/node_modules/.bin/eslint new file mode 100644 index 0000000000..e69de29bb2 diff --git a/__tests__/fixtures/run/issue-8590/packages/workspace-b/package.json b/__tests__/fixtures/run/issue-8590/packages/workspace-b/package.json new file mode 100644 index 0000000000..fcf1d95436 --- /dev/null +++ b/__tests__/fixtures/run/issue-8590/packages/workspace-b/package.json @@ -0,0 +1,7 @@ +{ + "name": "workspace-b", + "version": "1.0.0", + "dependencies": { + "eslint": "1.0.0" + } +} diff --git a/src/cli/commands/run.js b/src/cli/commands/run.js index f0dfbf455d..d11bb09ef7 100644 --- a/src/cli/commands/run.js +++ b/src/cli/commands/run.js @@ -55,7 +55,11 @@ export async function getBinEntries(config: Config): Promise 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)); + } } } }