Skip to content

Commit 10521a9

Browse files
committed
Switch execSync to spawnSync
1 parent 6b97753 commit 10521a9

11 files changed

Lines changed: 51 additions & 26 deletions

File tree

ark/attest/__tests__/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const runThenGetContents = (templatePath: string): string => {
77
const tempPath = templatePath + ".temp.ts"
88
copyFileSync(templatePath, tempPath)
99
try {
10-
shell(`node --import=tsx ${tempPath}`, {
10+
shell("node", ["--import=tsx", tempPath], {
1111
cwd: dirName(),
1212
env: {
1313
ATTEST_failOnMissingSnapshots: "0"

ark/attest/cache/snapshots.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ const runFormatterIfAvailable = (queuedUpdates: QueuedUpdate[]) => {
198198
const { formatCmd: formatter, shouldFormat } = getConfig()
199199
if (!shouldFormat) return
200200

201+
if (formatter.length === 0)
202+
throw new Error("config formatCmd must be at least length 1")
203+
201204
try {
202205
const updatedPaths = [
203206
...new Set(
@@ -206,7 +209,9 @@ const runFormatterIfAvailable = (queuedUpdates: QueuedUpdate[]) => {
206209
)
207210
)
208211
]
209-
shell(`${formatter} ${updatedPaths.join(" ")}`)
212+
const command = formatter[0]
213+
const args = formatter.slice(1)
214+
shell(command, [...args, "--", ...updatedPaths])
210215
} catch {
211216
// If formatter is unavailable or skipped, do nothing.
212217
}

ark/attest/cli/trace.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ const generateTraceData = (
266266
): string => {
267267
try {
268268
const output = getShellOutput(
269-
`${baseDiagnosticTscCmd} --project ${tsconfigPath} --generateTrace ${traceDir}`,
269+
baseDiagnosticTscCmd,
270+
["--project", tsconfigPath, "--generateTrace", traceDir],
270271
{ cwd: packageDir }
271272
)
272273
process.stdout.write(output) // Display tsc output directly

ark/attest/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type BaseAttestConfig = {
4444
benchErrorOnThresholdExceeded: BenchErrorConfig
4545
filter: string | undefined
4646
testDeclarationAliases: string[]
47-
formatCmd: string
47+
formatCmd: string[]
4848
shouldFormat: boolean
4949
/**
5050
* Provided options will override the following defaults.
@@ -75,7 +75,7 @@ export const getDefaultAttestConfig = (): BaseAttestConfig => ({
7575
benchErrorOnThresholdExceeded: true,
7676
filter: undefined,
7777
testDeclarationAliases: ["bench", "it", "test"],
78-
formatCmd: `npm exec --no -- prettier --write`,
78+
formatCmd: ["npm", "exec", "--no", "--", "prettier", "--write"],
7979
shouldFormat: true,
8080
typeToStringFormat: {}
8181
})

ark/attest/fixtures.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export const setup = (options?: Partial<AttestConfig>): typeof teardown => {
2727
)
2828
// if we're in our own repo, we need to pnpm to use the root script to execute ts directly
2929
if (fileName().endsWith("ts"))
30-
shell(`pnpm attest precache ${precachePath}`)
30+
shell("pnpm", ["attest", "precache", precachePath])
3131
// otherwise, just use npm to run the CLI command from build output
32-
else shell(`npm exec -c "attest precache ${precachePath}"`)
32+
else shell("npm", ["exec", "-c", "attest", "precache", precachePath])
3333
})
3434
}
3535
return teardown

ark/fs/fs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ export const readPackageJson = (startDir = dirOfCaller()): any =>
174174

175175
export const getSourceControlPaths = (): string[] =>
176176
// include tracked and untracked files as long as they are not ignored
177-
getShellOutput("git ls-files --exclude-standard --cached --others")
177+
getShellOutput("git", [
178+
"ls-files",
179+
"--exclude-standard",
180+
"--cached",
181+
"--others"
182+
])
178183
.split("\n")
179184
.filter(path => existsSync(path) && statSync(path).isFile())
180185

ark/fs/shell.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { execSync, type ExecSyncOptions } from "node:child_process"
1+
import { spawnSync, type SpawnSyncOptions } from "node:child_process"
22
import * as process from "node:process"
33

4-
export type ShellOptions = Omit<ExecSyncOptions, "stdio"> & {
4+
export type ShellOptions = Omit<SpawnSyncOptions, "stdio"> & {
55
env?: Record<string, string | undefined>
66
}
77

88
/** Run the cmd synchronously. Output goes to terminal. */
99
export const shell = (
1010
cmd: string,
11+
args: string[],
1112
{ env, ...otherOptions }: ShellOptions = {}
1213
): void => {
13-
execSync(cmd, {
14+
spawnSync(cmd, args, {
1415
env: { ...process.env, ...env },
1516
...otherOptions,
1617
stdio: "inherit"
@@ -20,9 +21,10 @@ export const shell = (
2021
/** Run the cmd synchronously, returning output as a string */
2122
export const getShellOutput = (
2223
cmd: string,
24+
args: string[],
2325
{ env, ...otherOptions }: ShellOptions = {}
2426
): string =>
25-
execSync(cmd, {
27+
spawnSync(cmd, args, {
2628
env: { ...process.env, ...env },
2729
...otherOptions,
2830
stdio: "pipe"

ark/repo/build.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ const outDir = fromCwd("out")
1919
const packageName = readPackageJson(process.cwd()).name
2020

2121
const buildCurrentProject = () =>
22-
shell(
23-
`node ${fromHere("node_modules", "typescript", "lib", "tsc.js")} --project tsconfig.build.json`
24-
)
22+
shell("node", [
23+
fromHere("node_modules", "typescript", "lib", "tsc.js"),
24+
"--project",
25+
"tsconfig.build.json"
26+
])
2527

2628
try {
2729
rmRf(outDir)

ark/repo/dtsGen.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ export const dtsGen = () => {
1414

1515
console.log(`✍️ Generating DTS bundle for ${pkg.name}...`)
1616

17-
shell("pnpm tsup index.ts --dts-only --dts-resolve --format esm --out-dir .")
17+
shell("pnpm", [
18+
"tsup",
19+
"index.ts",
20+
"--dts-only",
21+
"--dts-resolve",
22+
"--format",
23+
"esm",
24+
"--out-dir",
25+
"."
26+
])
1827

1928
const expectedDtsBundlePath = join(pkg.path, "index.d.ts")
2029

ark/repo/publish.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { packages, type ArkPackage } from "./shared.ts"
33

44
const tagsToPublish: string[] = []
55

6-
const existingTags = getShellOutput("git tag").split("\n")
6+
const existingTags = getShellOutput("git", ["tag"]).split("\n")
77

88
const publishPackage = (pkg: ArkPackage, alias?: string) => {
99
const tagName = `${alias ?? pkg.name}@${pkg.version}`
1010

1111
if (!existingTags.includes(tagName)) {
1212
if (alias) rewritePackageJsonName(pkg.packageJsonPath, alias)
1313

14-
shell(`git tag ${tagName}`)
14+
shell("git", ["tag", tagName])
1515
tagsToPublish.push(tagName)
16-
shell("pnpm publish --no-git-checks", { cwd: pkg.path })
16+
shell("pnpm", ["publish", "--no-git-checks"], { cwd: pkg.path })
1717

1818
if (alias) rewritePackageJsonName(pkg.packageJsonPath, pkg.name)
1919
}
@@ -34,7 +34,7 @@ for (const pkg of packages) {
3434
}
3535
}
3636

37-
shell("git push --tags")
37+
shell("git", ["push", "--tags"])
3838

3939
for (const tagName of tagsToPublish)
40-
shell(`gh release create ${tagName} --latest`)
40+
shell("gh", ["release", "create", tagName, "--latest"])

0 commit comments

Comments
 (0)