From 955f299ae3ebce55994b48c1650f0950eecff6bb Mon Sep 17 00:00:00 2001 From: brees_dev <61703886+brees-worth@users.noreply.github.com> Date: Fri, 1 Jul 2022 17:14:05 +0100 Subject: [PATCH 1/6] fix(lerna run): add double quotes around script target for Nx --- .../powered-by-nx/packages/package-1/package.json | 5 +++-- commands/run/__tests__/run-command.test.js | 7 +++++++ commands/run/index.js | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/commands/run/__tests__/__fixtures__/powered-by-nx/packages/package-1/package.json b/commands/run/__tests__/__fixtures__/powered-by-nx/packages/package-1/package.json index b6b638e487..9978bcb211 100644 --- a/commands/run/__tests__/__fixtures__/powered-by-nx/packages/package-1/package.json +++ b/commands/run/__tests__/__fixtures__/powered-by-nx/packages/package-1/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "scripts": { "fail": "exit 1", - "my-script": "echo package-1" + "my-script": "echo package-1", + "another-script:but-with-colons": "echo package-1-script-with-colons" } -} +} \ No newline at end of file diff --git a/commands/run/__tests__/run-command.test.js b/commands/run/__tests__/run-command.test.js index 83dfbecbe6..3e95157577 100644 --- a/commands/run/__tests__/run-command.test.js +++ b/commands/run/__tests__/run-command.test.js @@ -331,6 +331,13 @@ describe("RunCommand", () => { expect(collectedOutput).toContain("Successfully ran target"); }); + it("runs a script with a colon in the script name", async () => { + collectedOutput = ""; + await lernaRun(testDir)("another-script:but-with-colons"); + expect(collectedOutput).toContain("package-1-script-with-colons"); + expect(collectedOutput).toContain("Successfully ran target"); + }); + it("runs a script only in scoped packages", async () => { collectedOutput = ""; await lernaRun(testDir)("my-script", "--scope", "package-1"); diff --git a/commands/run/index.js b/commands/run/index.js index 298af74d8f..370ecbbefc 100644 --- a/commands/run/index.js +++ b/commands/run/index.js @@ -179,7 +179,7 @@ class RunCommand extends Command { const { targetDependencies, options } = this.prepNxOptions(); if (this.packagesWithScript.length === 1) { const { runOne } = require("nx/src/command-line/run-one"); - const fullQualifiedTarget = this.packagesWithScript.map((p) => p.name)[0] + ":" + this.script; + const fullQualifiedTarget = this.packagesWithScript.map((p) => p.name)[0] + ":\"" + this.script+ "\""; return runOne( process.cwd(), { From ba2605e4c74dc307588761aa96e57868518de0af Mon Sep 17 00:00:00 2001 From: brees-worth <61703886+brees-worth@users.noreply.github.com> Date: Tue, 5 Jul 2022 17:15:44 +0100 Subject: [PATCH 2/6] chore: prettier fix --- commands/run/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/run/index.js b/commands/run/index.js index 370ecbbefc..f30133700d 100644 --- a/commands/run/index.js +++ b/commands/run/index.js @@ -179,7 +179,7 @@ class RunCommand extends Command { const { targetDependencies, options } = this.prepNxOptions(); if (this.packagesWithScript.length === 1) { const { runOne } = require("nx/src/command-line/run-one"); - const fullQualifiedTarget = this.packagesWithScript.map((p) => p.name)[0] + ":\"" + this.script+ "\""; + const fullQualifiedTarget = this.packagesWithScript.map((p) => p.name)[0] + ':"' + this.script + '"'; return runOne( process.cwd(), { From aa2ade99d8290f807c4f6d87e311012d77d9b986 Mon Sep 17 00:00:00 2001 From: brees-worth <61703886+brees-worth@users.noreply.github.com> Date: Tue, 5 Jul 2022 17:33:15 +0100 Subject: [PATCH 3/6] feat: additional e2e test for #3215 --- e2e/tests/lerna-run/lerna-run.spec.ts | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/e2e/tests/lerna-run/lerna-run.spec.ts b/e2e/tests/lerna-run/lerna-run.spec.ts index b14bc54cc0..4b482849e9 100644 --- a/e2e/tests/lerna-run/lerna-run.spec.ts +++ b/e2e/tests/lerna-run/lerna-run.spec.ts @@ -312,6 +312,20 @@ describe("useNx", () => { "print-name": "echo test-package-3", }, }); + await fixture.lerna("create package-4 -y"); + await fixture.addScriptsToPackage({ + packagePath: "packages/package-4", + scripts: { + "print:name": "echo test-package-4", + }, + }); + await fixture.lerna("create package-5 -y"); + await fixture.addScriptsToPackage({ + packagePath: "packages/package-5", + scripts: { + "print:name": "echo test-package-5", + }, + }); }); afterAll(() => fixture.destroy()); @@ -357,6 +371,44 @@ test-package-X > Lerna (powered by Nx) Successfully ran target print-name for 3 projects +lerna notice cli v999.9.9-e2e.0 + +`); + }); + + it("should run script with colon on all child package using nx", async () => { + const output = await fixture.lerna(`run print:name`); + + expect(output.combinedOutput).toMatchInlineSnapshot(` + + > Lerna (powered by Nx) Running target print:name for 2 project(s): + + - package-X + - package-X + + + +> package-X:"print:name" + + +> package-X@0.0.0 print:name +> echo test-package-X + +test-package-X + +> package-X:"print:name" + + +> package-X@0.0.0 print:name +> echo test-package-X + +test-package-X + + + + > Lerna (powered by Nx) Successfully ran target print:name for 2 projects + + lerna notice cli v999.9.9-e2e.0 `); From ddc0ded1a5b19128c80af2d959bbe57b50626782 Mon Sep 17 00:00:00 2001 From: brees-worth <61703886+brees-worth@users.noreply.github.com> Date: Wed, 6 Jul 2022 08:50:58 +0100 Subject: [PATCH 4/6] feat(e2e): additional test for run one case --- e2e/tests/lerna-run/lerna-run.spec.ts | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/e2e/tests/lerna-run/lerna-run.spec.ts b/e2e/tests/lerna-run/lerna-run.spec.ts index 4b482849e9..c972ddb8ed 100644 --- a/e2e/tests/lerna-run/lerna-run.spec.ts +++ b/e2e/tests/lerna-run/lerna-run.spec.ts @@ -317,6 +317,7 @@ describe("useNx", () => { packagePath: "packages/package-4", scripts: { "print:name": "echo test-package-4", + "print:name:run-one-only": "echo test-package-4-run-one-only", }, }); await fixture.lerna("create package-5 -y"); @@ -371,6 +372,35 @@ test-package-X > Lerna (powered by Nx) Successfully ran target print-name for 3 projects +lerna notice cli v999.9.9-e2e.0 + +`); + }); + + it("should run script with colon on single child package using nx", async () => { + const output = await fixture.lerna(`run print:name:run-one-only`); + + expect(output.combinedOutput).toMatchInlineSnapshot(` + + > Lerna (powered by Nx) Running target print:name:run-one-only for 1 project(s): + + - package-X + + + +> package-X:"print:name:run-one-only" + + +> package-X@0.0.0 print:name:run-one-only +> echo test-package-X-run-one-only + +test-package-X-run-one-only + + + + > Lerna (powered by Nx) Successfully ran target print:name for 1 projects + + lerna notice cli v999.9.9-e2e.0 `); From 3a38c9a12e3c787a5d795f8536fa088b7fc079eb Mon Sep 17 00:00:00 2001 From: brees-worth <61703886+brees-worth@users.noreply.github.com> Date: Wed, 6 Jul 2022 09:03:49 +0100 Subject: [PATCH 5/6] feat(run): make script quoting conditional on colon --- commands/run/index.js | 11 +++- e2e/tests/lerna-run/lerna-run.spec.ts | 75 +++++++++++++++++---------- 2 files changed, 58 insertions(+), 28 deletions(-) diff --git a/commands/run/index.js b/commands/run/index.js index f30133700d..45a39e75cb 100644 --- a/commands/run/index.js +++ b/commands/run/index.js @@ -170,6 +170,15 @@ class RunCommand extends Command { return chain; } + addQuotesAroundScriptNameIfItHasAColon(scriptName) { + // Nx requires quotes around script names of the form script:name + if(scriptName.includes(':')) { + return `"${scriptName}"`; + } else { + return scriptName; + } + } + runScriptsUsingNx() { if (this.options.ci) { process.env.CI = "true"; @@ -179,7 +188,7 @@ class RunCommand extends Command { const { targetDependencies, options } = this.prepNxOptions(); if (this.packagesWithScript.length === 1) { const { runOne } = require("nx/src/command-line/run-one"); - const fullQualifiedTarget = this.packagesWithScript.map((p) => p.name)[0] + ':"' + this.script + '"'; + const fullQualifiedTarget = this.packagesWithScript.map((p) => p.name)[0] + ':' + this.addQuotesAroundScriptNameIfItHasAColon(this.script); return runOne( process.cwd(), { diff --git a/e2e/tests/lerna-run/lerna-run.spec.ts b/e2e/tests/lerna-run/lerna-run.spec.ts index c972ddb8ed..b3d4513521 100644 --- a/e2e/tests/lerna-run/lerna-run.spec.ts +++ b/e2e/tests/lerna-run/lerna-run.spec.ts @@ -317,7 +317,8 @@ describe("useNx", () => { packagePath: "packages/package-4", scripts: { "print:name": "echo test-package-4", - "print:name:run-one-only": "echo test-package-4-run-one-only", + "print-name-run-one-only": "echo test-package-4-run-one-only", + "print:name:run-one-only": "echo test-package-4-run-one-only-with-colon", }, }); await fixture.lerna("create package-5 -y"); @@ -377,34 +378,54 @@ lerna notice cli v999.9.9-e2e.0 `); }); - it("should run script with colon on single child package using nx", async () => { - const output = await fixture.lerna(`run print:name:run-one-only`); + describe('run one', () => { + it("should run script on single child package using nx", async () => { + const output = await fixture.lerna(`run print-name-run-one-only`); + - expect(output.combinedOutput).toMatchInlineSnapshot(` - - > Lerna (powered by Nx) Running target print:name:run-one-only for 1 project(s): - - - package-X - - - -> package-X:"print:name:run-one-only" - - -> package-X@0.0.0 print:name:run-one-only -> echo test-package-X-run-one-only - -test-package-X-run-one-only - - - - > Lerna (powered by Nx) Successfully ran target print:name for 1 projects - - -lerna notice cli v999.9.9-e2e.0 + expect(output.combinedOutput).toMatchInlineSnapshot(` + + > package-X:print-name-run-one-only + + + > package-X@0.0.0 print-name-run-one-only + > echo test-package-X-run-one-only + + test-package-X-run-one-only + + + + > Lerna (powered by Nx) Successfully ran target print-name-run-one-only for project package-X + + + lerna notice cli v999.9.9-e2e.0 + + `); + }); + + it("should run script with colon on single child package using nx", async () => { + const output = await fixture.lerna(`run print:name:run-one-only`); + + expect(output.combinedOutput).toMatchInlineSnapshot(` -`); - }); + > package-X:"print:name:run-one-only" + + + > package-X@0.0.0 print:name:run-one-only + > echo test-package-X-run-one-only-with-colon + + test-package-X-run-one-only-with-colon + + + + > Lerna (powered by Nx) Successfully ran target print:name:run-one-only for project package-X + + + lerna notice cli v999.9.9-e2e.0 + + `); + }); + }) it("should run script with colon on all child package using nx", async () => { const output = await fixture.lerna(`run print:name`); From 88b623275b3fb811931d1ad1db89a248974c1ab6 Mon Sep 17 00:00:00 2001 From: brees-worth <61703886+brees-worth@users.noreply.github.com> Date: Wed, 6 Jul 2022 10:46:21 +0100 Subject: [PATCH 6/6] chore: prettier --- commands/run/index.js | 7 +++++-- e2e/tests/lerna-run/lerna-run.spec.ts | 9 ++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/commands/run/index.js b/commands/run/index.js index 45a39e75cb..56dbeb5ed9 100644 --- a/commands/run/index.js +++ b/commands/run/index.js @@ -172,7 +172,7 @@ class RunCommand extends Command { addQuotesAroundScriptNameIfItHasAColon(scriptName) { // Nx requires quotes around script names of the form script:name - if(scriptName.includes(':')) { + if (scriptName.includes(":")) { return `"${scriptName}"`; } else { return scriptName; @@ -188,7 +188,10 @@ class RunCommand extends Command { const { targetDependencies, options } = this.prepNxOptions(); if (this.packagesWithScript.length === 1) { const { runOne } = require("nx/src/command-line/run-one"); - const fullQualifiedTarget = this.packagesWithScript.map((p) => p.name)[0] + ':' + this.addQuotesAroundScriptNameIfItHasAColon(this.script); + const fullQualifiedTarget = + this.packagesWithScript.map((p) => p.name)[0] + + ":" + + this.addQuotesAroundScriptNameIfItHasAColon(this.script); return runOne( process.cwd(), { diff --git a/e2e/tests/lerna-run/lerna-run.spec.ts b/e2e/tests/lerna-run/lerna-run.spec.ts index b3d4513521..fb7ddee83e 100644 --- a/e2e/tests/lerna-run/lerna-run.spec.ts +++ b/e2e/tests/lerna-run/lerna-run.spec.ts @@ -378,10 +378,9 @@ lerna notice cli v999.9.9-e2e.0 `); }); - describe('run one', () => { + describe("run one", () => { it("should run script on single child package using nx", async () => { const output = await fixture.lerna(`run print-name-run-one-only`); - expect(output.combinedOutput).toMatchInlineSnapshot(` @@ -402,10 +401,10 @@ lerna notice cli v999.9.9-e2e.0 `); }); - + it("should run script with colon on single child package using nx", async () => { const output = await fixture.lerna(`run print:name:run-one-only`); - + expect(output.combinedOutput).toMatchInlineSnapshot(` > package-X:"print:name:run-one-only" @@ -425,7 +424,7 @@ lerna notice cli v999.9.9-e2e.0 `); }); - }) + }); it("should run script with colon on all child package using nx", async () => { const output = await fixture.lerna(`run print:name`);