diff --git a/__tests__/commands/run.js b/__tests__/commands/run.js index 7477289c04..4c4476a7d8 100644 --- a/__tests__/commands/run.js +++ b/__tests__/commands/run.js @@ -26,6 +26,17 @@ const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'run'); const runRun = buildRun.bind(null, BufferReporter, fixturesLoc, (args, flags, config, reporter): Promise => { return run(config, reporter, flags, args); }); +const runRunInWorkspacePackage = function(cwd, ...args): Promise { + return buildRun.bind(null, BufferReporter, fixturesLoc, (args, flags, config, reporter): Promise => { + const originalCwd = config.cwd; + config.cwd = path.join(originalCwd, cwd); + const retVal = run(config, reporter, flags, args); + retVal.then(() => { + config.cwd = originalCwd; + }); + return retVal; + })(...args); +}; test('lists all available commands with no arguments', (): Promise => { return runRun([], {}, 'no-args', (config, reporter): ?Promise => { @@ -133,3 +144,14 @@ test('adds quotes if args have spaces and quotes', (): Promise => { expect(execCommand).toBeCalledWith(...args); }); }); + +test('adds workspace root node_modules/.bin to path when in a workspace', (): Promise => { + return runRunInWorkspacePackage('packages/pkg1', ['env'], {}, 'workspace', (config, reporter): ?Promise => { + const logEntry = reporter.getBuffer().find(entry => entry.type === 'log'); + const parsedLogData = JSON.parse(logEntry ? logEntry.data.toString() : '{}'); + const envPaths = (parsedLogData.PATH || parsedLogData.Path).split(path.delimiter); + + expect(envPaths).toContain(path.join(config.cwd, 'node_modules', '.bin')); + expect(envPaths).toContain(path.join(config.cwd, 'packages', 'pkg1', 'node_modules', '.bin')); + }); +}); diff --git a/__tests__/fixtures/run/workspace/node_modules/.bin/cat-names b/__tests__/fixtures/run/workspace/node_modules/.bin/cat-names new file mode 100644 index 0000000000..e69de29bb2 diff --git a/__tests__/fixtures/run/workspace/package.json b/__tests__/fixtures/run/workspace/package.json new file mode 100644 index 0000000000..c4ac3364a3 --- /dev/null +++ b/__tests__/fixtures/run/workspace/package.json @@ -0,0 +1,5 @@ +{ + "workspaces": [ + "packages/*" + ] +} diff --git a/__tests__/fixtures/run/workspace/packages/pkg1/node_modules/.bin/cat-names b/__tests__/fixtures/run/workspace/packages/pkg1/node_modules/.bin/cat-names new file mode 100644 index 0000000000..e69de29bb2 diff --git a/__tests__/fixtures/run/workspace/packages/pkg1/package.json b/__tests__/fixtures/run/workspace/packages/pkg1/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/__tests__/fixtures/run/workspace/packages/pkg1/package.json @@ -0,0 +1 @@ +{} diff --git a/src/util/execute-lifecycle-script.js b/src/util/execute-lifecycle-script.js index 2e44d6e9ad..b89d002355 100644 --- a/src/util/execute-lifecycle-script.js +++ b/src/util/execute-lifecycle-script.js @@ -148,6 +148,9 @@ export async function makeEnv( // add .bin folders to PATH for (const registry of Object.keys(registries)) { const binFolder = path.join(config.registries[registry].folder, '.bin'); + if (config.workspacesEnabled && config.workspaceRootFolder) { + pathParts.unshift(path.join(config.workspaceRootFolder, binFolder)); + } pathParts.unshift(path.join(config.linkFolder, binFolder)); pathParts.unshift(path.join(cwd, binFolder)); }