Skip to content

Commit

Permalink
fix(core): call pnpm run without -- for pnpm v7
Browse files Browse the repository at this point in the history
Starting in pnpm v7 all command line arguments after the script name are passed to a script's arguments when using `pnpm run <script>`, including `--`. This can cause problems when there are no command line arguments, because it will pass `--` without anything following, which some scripts can't handle. In order to preserve the old functionality, we check if the pnpm version is less than 7.0.0. If it is, we include `--` before the args, otherwise we don't.

Closes #10111
  • Loading branch information
Methuselah96 committed May 16, 2022
1 parent e6f73a8 commit 52ce818
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/nx/src/utils/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { dirSync } from 'tmp';
import { promisify } from 'util';
import { readJsonFile, writeJsonFile } from './fileutils';
import { PackageJson } from './package-json';
import { gte } from 'semver';
import { gte, lt } from 'semver';

const execAsync = promisify(exec);

Expand Down Expand Up @@ -67,6 +67,7 @@ export function getPackageManagerCommand(
if (gte(pnpmVersion, '6.13.0')) {
useExec = true;
}
const includeDoubleDashBeforeArgs = lt(pnpmVersion, '7.0.0');
return {
install: 'pnpm install --no-frozen-lockfile', // explicitly disable in case of CI
ciInstall: 'pnpm install --frozen-lockfile',
Expand All @@ -75,7 +76,10 @@ export function getPackageManagerCommand(
addGlobal: 'pnpm add -g',
rm: 'pnpm rm',
exec: useExec ? 'pnpm exec' : 'pnpx',
run: (script: string, args: string) => `pnpm run ${script} -- ${args}`,
run: (script: string, args: string) =>
includeDoubleDashBeforeArgs
? `pnpm run ${script} -- ${args}`
: `pnpm run ${script} ${args}`,
list: 'pnpm ls --depth 100',
};
},
Expand Down

0 comments on commit 52ce818

Please sign in to comment.