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

fix(core): call pnpm run without -- for pnpm v7 #10305

Merged
merged 1 commit into from May 16, 2022

Conversation

Methuselah96
Copy link
Contributor

@Methuselah96 Methuselah96 commented May 16, 2022

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

Current Behavior

Appending -- to pnpm run <script> when there are no arguments.

Expected Behavior

Only include -- for pnpm <7.0.0.

Related Issue(s)

Fixes #10111

@nx-cloud
Copy link

nx-cloud bot commented May 16, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 707a3b4. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 12 targets

Sent with 💌 from NxCloud.

@vercel
Copy link

vercel bot commented May 16, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
nx-dev ✅ Ready (Inspect) Visit Preview May 16, 2022 at 2:11PM (UTC)

@@ -67,6 +67,7 @@ export function getPackageManagerCommand(
if (gte(pnpmVersion, '6.13.0')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you perhaps fix useExec to const useExec = gte(pnpmVersion, '6.13.0');?
You did it the right way and seeing the useExec above kinda hurts the eyes 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, agreed. Updated.

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 nrwl#10111
run: (script: string, args: string) =>
includeDoubleDashBeforeArgs
? `pnpm run ${script} -- ${args}`
: `pnpm run ${script} ${args}`,

Choose a reason for hiding this comment

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

In case anyone is looking to patch v13, I created this patch for @nrwl/tao@13.8.0:

diff --git a/src/shared/package-manager.js b/src/shared/package-manager.js
index b74ffe01bc7cb161ac46462d723d8f521ec5a849..2ced85a576ad95bc2d18b363529d721d471408b2 100644
--- a/src/shared/package-manager.js
+++ b/src/shared/package-manager.js
@@ -39,17 +39,25 @@ function getPackageManagerCommand(packageManager = detectPackageManager()) {
         }),
         pnpm: () => {
             const [major, minor] = getPackageManagerVersion('pnpm').split('.');
+            const majorVersion = +major
+
             let useExec = false;
-            if (+major >= 6 && +minor >= 13) {
+            if (majorVersion >= 6 && +minor >= 13) {
                 useExec = true;
             }
+
+            const includeDoubleDashBeforeArgs = majorVersion < 7;
+            
             return {
                 install: 'pnpm install --no-frozen-lockfile',
                 add: 'pnpm add',
                 addDev: 'pnpm add -D',
                 rm: 'pnpm rm',
                 exec: useExec ? 'pnpm exec' : 'pnpx',
-                run: (script, args) => `pnpm run ${script} -- ${args}`,
+                run: (script, args) =>
+                    includeDoubleDashBeforeArgs
+                        ? `pnpm run ${script} -- ${args}`
+                        : `pnpm run ${script} ${args}`,
                 list: 'pnpm ls --depth 100',
             };
         },

@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

run-many appends a "--" argument when invoking packages' scripts
5 participants