Skip to content

Commit

Permalink
fix(core): call pnpm run without -- for pnpm v7 (#10305)
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 c7ec631 commit 7b7fc89
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/nx/src/utils/package-manager.ts
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 @@ -63,10 +63,8 @@ export function getPackageManagerCommand(
}),
pnpm: () => {
const pnpmVersion = getPackageManagerVersion('pnpm');
let useExec = false;
if (gte(pnpmVersion, '6.13.0')) {
useExec = true;
}
const useExec = gte(pnpmVersion, '6.13.0');
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 +73,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

1 comment on commit 7b7fc89

@vercel
Copy link

@vercel vercel bot commented on 7b7fc89 May 16, 2022

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
nx-dev-nrwl.vercel.app

Please sign in to comment.