From ad73816012184048b84d86dede26cf287b42d3c9 Mon Sep 17 00:00:00 2001 From: Mike DiDomizio Date: Sat, 8 Apr 2023 11:19:53 -0400 Subject: [PATCH] Fix commands run on paths with danger-pr in them --- .../utils/_tests/dangerRunToRunnerCLI.test.ts | 14 ++++++++++++++ source/commands/utils/dangerRunToRunnerCLI.ts | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/source/commands/utils/_tests/dangerRunToRunnerCLI.test.ts b/source/commands/utils/_tests/dangerRunToRunnerCLI.test.ts index cf9e226ea..608f93607 100644 --- a/source/commands/utils/_tests/dangerRunToRunnerCLI.test.ts +++ b/source/commands/utils/_tests/dangerRunToRunnerCLI.test.ts @@ -116,3 +116,17 @@ describe("it can handle the command when running from pkg", () => { ) }) }) + +it("should properly replace `danger-runner` in a path that contains an additional `danger-pr` in it", () => { + expect( + dangerRunToRunnerCLI([ + "/Users/Mike.DiDomizio/.nvm/versions/node/v16.13.2/bin/node", + "/Users/Mike.DiDomizio/projects/test/danger-project-setup/node_modules/danger/distribution/commands/danger-pr.js", + "https://github.com/facebook/react/pull/11865" + ]) + ).toEqual([ + "/Users/Mike.DiDomizio/.nvm/versions/node/v16.13.2/bin/node", + "/Users/Mike.DiDomizio/projects/test/danger-project-setup/node_modules/danger/distribution/commands/danger-runner.js", + "https://github.com/facebook/react/pull/11865", + ]) +}) diff --git a/source/commands/utils/dangerRunToRunnerCLI.ts b/source/commands/utils/dangerRunToRunnerCLI.ts index b84750f8d..9c252a453 100644 --- a/source/commands/utils/dangerRunToRunnerCLI.ts +++ b/source/commands/utils/dangerRunToRunnerCLI.ts @@ -15,7 +15,8 @@ const dangerRunToRunnerCLI = (argv: string[]) => { // convert let newJSFile = argv[1] usesProcessSeparationCommands.forEach((name) => { - newJSFile = newJSFile.replace("danger-" + name, "danger-runner") + const re = new RegExp(`danger-${name}\.js$`) + newJSFile = newJSFile.replace(re, "danger-runner.js") }) // Support re-routing internally in npx for danger-ts