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(run): add double quotes around script target containing colon #246

Merged
merged 1 commit into from Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/run/package.json
Expand Up @@ -43,6 +43,8 @@
"devDependencies": {
"@types/execa": "^2.0.0",
"@types/p-map": "^2.0.0",
"globby": "^11.1.0",
"jest-circus": "^28.1.2",
"perf_hooks": "^0.0.1",
"yargs-parser": "^21.0.1"
}
Expand Down
Expand Up @@ -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"
}
}
7 changes: 7 additions & 0 deletions packages/run/src/__tests__/run-command.spec.ts
Expand Up @@ -383,6 +383,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');
Expand Down
8 changes: 7 additions & 1 deletion packages/run/src/run-command.ts
Expand Up @@ -205,6 +205,11 @@ export class RunCommand extends Command<RunCommandOption & FilterOptions> {
return chain;
}

/** Nx requires quotes around script names of the form script:name*/
escapeScriptNameQuotes(scriptName: string) {
return scriptName.includes(':') ? `"${scriptName}"` : scriptName;
}

async runScriptsUsingNx() {
if (this.options.ci) {
process.env.CI = 'true';
Expand All @@ -214,7 +219,8 @@ export class RunCommand extends Command<RunCommandOption & FilterOptions> {
const { targetDependencies, options } = await this.prepNxOptions();
if (this.packagesWithScript.length === 1) {
const { runOne } = await import('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.escapeScriptNameQuotes(this.script);
return (runOne as any)(
process.cwd(),
{
Expand Down
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.