Skip to content

Commit

Permalink
fix(misc): respect cwd when adding node_modules/.bin to PATH in run-c…
Browse files Browse the repository at this point in the history
…ommands(#18429)
  • Loading branch information
jonathanmorley committed Aug 11, 2023
1 parent 3ddb188 commit eafc8af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
26 changes: 26 additions & 0 deletions packages/nx/src/executors/run-commands/run-commands.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,32 @@ describe('Run Commands', () => {
expect(result).toEqual(expect.objectContaining({ success: true }));
expect(normalize(readFile(f))).toBe(childFolder);
});

it('should add node_modules/.bins to the env for the cwd', async () => {
const root = dirSync().name;
const childFolder = dirSync({ dir: root }).name;
const f = fileSync().name;

const result = await runCommands(
{
commands: [
{
command: `echo $PATH >> ${f}`,
},
],
cwd: childFolder,
parallel: true,
__unparsed__: [],
},
{ root } as any
);

expect(result).toEqual(expect.objectContaining({ success: true }));
expect(normalize(readFile(f))).toContain(
`${childFolder}/node_modules/.bin`
);
expect(normalize(readFile(f))).toContain(`${root}/node_modules/.bin`);
});
});

describe('dotenv', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/nx/src/executors/run-commands/run-commands.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function createProcess(
return new Promise((res) => {
const childProcess = exec(commandConfig.command, {
maxBuffer: LARGE_BUFFER,
env: processEnv(color),
env: processEnv(color, cwd),
cwd,
});
/**
Expand Down Expand Up @@ -277,10 +277,10 @@ function calculateCwd(
return path.join(context.root, cwd);
}

function processEnv(color: boolean) {
function processEnv(color: boolean, cwd: string) {
const env = {
...process.env,
...appendLocalEnv(),
...appendLocalEnv({ cwd: cwd ?? process.cwd() }),
};

if (color) {
Expand Down

1 comment on commit eafc8af

@vercel
Copy link

@vercel vercel bot commented on eafc8af Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.