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

feat(run): Include the workspace root .bin in env path #4848

Merged
merged 11 commits into from
Nov 20, 2017
22 changes: 22 additions & 0 deletions __tests__/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'run');
const runRun = buildRun.bind(null, BufferReporter, fixturesLoc, (args, flags, config, reporter): Promise<void> => {
return run(config, reporter, flags, args);
});
const runRunInWorkspacePackage = function(cwd, ...args): Promise<void> {
return buildRun.bind(null, BufferReporter, fixturesLoc, (args, flags, config, reporter): Promise<void> => {
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<void> => {
return runRun([], {}, 'no-args', (config, reporter): ?Promise<void> => {
Expand Down Expand Up @@ -133,3 +144,14 @@ test('adds quotes if args have spaces and quotes', (): Promise<void> => {
expect(execCommand).toBeCalledWith(...args);
});
});

test('adds workspace root node_modules/.bin to path when in a workspace', (): Promise<void> => {
return runRunInWorkspacePackage('packages/pkg1', ['env'], {}, 'workspace', (config, reporter): ?Promise<void> => {
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'));
});
});
Empty file.
5 changes: 5 additions & 0 deletions __tests__/fixtures/run/workspace/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 @@
{}
3 changes: 3 additions & 0 deletions src/util/execute-lifecycle-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down