Skip to content

Commit c4d9566

Browse files
authored
Fix executeHooks to quote args for shell command (#8383)
1 parent d00c986 commit c4d9566

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

.changeset/brave-cameras-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphql-codegen/cli": patch
3+
---
4+
5+
Fix `executeHooks` to quote args for shell command

packages/graphql-codegen-cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"listr2": "^4.0.5",
7171
"log-symbols": "^4.0.0",
7272
"mkdirp": "^1.0.4",
73+
"shell-quote": "^1.7.3",
7374
"string-env-interpolation": "^1.0.1",
7475
"ts-log": "^2.2.3",
7576
"tslib": "^2.4.0",
@@ -83,6 +84,7 @@
8384
"@types/is-glob": "4.0.2",
8485
"@types/js-yaml": "4.0.5",
8586
"@types/mkdirp": "1.0.2",
87+
"@types/shell-quote": "^1.7.1",
8688
"bdd-stdin": "0.2.0",
8789
"change-case-all": "1.0.14",
8890
"js-yaml": "4.1.0",

packages/graphql-codegen-cli/src/hooks.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Types } from '@graphql-codegen/plugin-helpers';
22
import { debugLog } from './utils/debugging.js';
33
import { exec } from 'child_process';
44
import { delimiter, sep } from 'path';
5+
import { quote } from 'shell-quote';
56

67
const DEFAULT_HOOKS: Types.LifecycleHooksDefinition<string[]> = {
78
afterStart: [],
@@ -76,10 +77,11 @@ async function executeHooks(
7677
): Promise<void> {
7778
debugLog(`Running lifecycle hook "${hookName}" scripts...`);
7879

80+
const quotedArgs = quote(args);
7981
for (const script of scripts) {
8082
if (typeof script === 'string') {
81-
debugLog(`Running lifecycle hook "${hookName}" script: ${script} with args: ${args.join(' ')}...`);
82-
await execShellCommand(`${script} ${args.join(' ')}`);
83+
debugLog(`Running lifecycle hook "${hookName}" script: ${script} with args: ${quotedArgs}...`);
84+
await execShellCommand(`${script} ${quotedArgs}`);
8385
} else {
8486
debugLog(`Running lifecycle hook "${hookName}" script: ${script.name} with args: ${args.join(' ')}...`);
8587
await script(...args);
@@ -94,7 +96,7 @@ export const lifecycleHooks = (_hooks: Partial<Types.LifecycleHooksDefinition> =
9496
afterStart: async (): Promise<void> => executeHooks('afterStart', hooks.afterStart),
9597
onWatchTriggered: async (event: string, path: string): Promise<void> =>
9698
executeHooks('onWatchTriggered', hooks.onWatchTriggered, [event, path]),
97-
onError: async (error: string): Promise<void> => executeHooks('onError', hooks.onError, [`"${error}"`]),
99+
onError: async (error: string): Promise<void> => executeHooks('onError', hooks.onError, [error]),
98100
afterOneFileWrite: async (path: string): Promise<void> =>
99101
executeHooks('afterOneFileWrite', hooks.afterOneFileWrite, [path]),
100102
afterAllFileWrite: async (paths: string[]): Promise<void> =>

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3558,6 +3558,11 @@
35583558
"@types/mime" "^1"
35593559
"@types/node" "*"
35603560

3561+
"@types/shell-quote@^1.7.1":
3562+
version "1.7.1"
3563+
resolved "https://registry.yarnpkg.com/@types/shell-quote/-/shell-quote-1.7.1.tgz#2d059091214a02c29f003f591032172b2aff77e8"
3564+
integrity sha512-SWZ2Nom1pkyXCDohRSrkSKvDh8QOG9RfAsrt5/NsPQC4UQJ55eG0qClA40I+Gkez4KTQ0uDUT8ELRXThf3J5jw==
3565+
35613566
"@types/stack-utils@^2.0.0":
35623567
version "2.0.1"
35633568
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.1.tgz#20f18294f797f2209b5f65c8e3b5c8e8261d127c"
@@ -11925,6 +11930,11 @@ shebang-regex@^3.0.0:
1192511930
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
1192611931
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
1192711932

11933+
shell-quote@^1.7.3:
11934+
version "1.7.3"
11935+
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.3.tgz#aa40edac170445b9a431e17bb62c0b881b9c4123"
11936+
integrity sha512-Vpfqwm4EnqGdlsBFNmHhxhElJYrdfcxPThu+ryKS5J8L/fhAwLazFZtq+S+TWZ9ANj2piSQLGj6NQg+lKPmxrw==
11937+
1192811938
shiki@0.10.1:
1192911939
version "0.10.1"
1193011940
resolved "https://registry.yarnpkg.com/shiki/-/shiki-0.10.1.tgz#6f9a16205a823b56c072d0f1a0bcd0f2646bef14"

0 commit comments

Comments
 (0)