Skip to content

Commit df107f7

Browse files
committed
refactor: add recursive option to safeMkdir calls
- Add { recursive: true } option to all safeMkdir calls for consistency - Ensures directories are created with proper parent directory handling - Aligns with safeMkdir best practices
1 parent 1ff0b6d commit df107f7

File tree

18 files changed

+39
-33
lines changed

18 files changed

+39
-33
lines changed

packages/cli/src/bootstrap/node.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async function downloadCli(): Promise<void> {
4646
const dlxDir = getDlxDir()
4747
const cliDir = getCliPackageDir()
4848

49-
await safeMkdir(dlxDir)
49+
await safeMkdir(dlxDir, { recursive: true })
5050

5151
console.error(`Downloading ${packageName}...`)
5252

@@ -77,7 +77,7 @@ async function downloadCli(): Promise<void> {
7777
try {
7878
const tarballPath = path.join(dlxDir, tarballName.trim())
7979

80-
await safeMkdir(cliDir)
80+
await safeMkdir(cliDir, { recursive: true })
8181

8282
const tarExtractProcess = spawn(
8383
'tar',

packages/cli/src/commands/fix/ghsa-tracker.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function saveGhsaTracker(
4646
const trackerPath = path.join(cwd, TRACKER_FILE)
4747

4848
// Ensure .socket directory exists.
49-
await safeMkdir(path.dirname(trackerPath))
49+
await safeMkdir(path.dirname(trackerPath), { recursive: true })
5050

5151
await writeJson(trackerPath, tracker, { spaces: 2 })
5252
debug(`ghsa-tracker: saved ${tracker.fixed.length} records to ${trackerPath}`)

packages/cli/src/commands/install/setup-tab-completion.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function setupTabCompletion(targetName: string): Promise<
4242

4343
if (!fs.existsSync(targetDir)) {
4444
debug('create: target dir')
45-
safeMkdirSync(targetDir)
45+
safeMkdirSync(targetDir, { recursive: true })
4646
}
4747

4848
updateInstalledTabCompletionScript(targetPath)

packages/cli/src/commands/optimize/cmd-optimize.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async function _createTempFixture(sourceDir: string): Promise<string> {
6868
)
6969

7070
// Copy the fixture files to the temp directory.
71-
await safeMkdir(tempDir)
71+
await safeMkdir(tempDir, { recursive: true })
7272

7373
// Copy package.json.
7474
const sourcePackageJson = path.join(sourceDir, PACKAGE_JSON)

packages/cli/src/commands/patch/handle-patch-get.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export async function handlePatchGet({
6565

6666
// Create output directory if it doesn't exist.
6767
if (!existsSync(targetDir)) {
68-
await safeMkdir(targetDir)
68+
await safeMkdir(targetDir, { recursive: true })
6969
}
7070

7171
spinner?.text('Copying patch files')
@@ -88,7 +88,7 @@ export async function handlePatchGet({
8888
// Create subdirectories if needed.
8989
if (!existsSync(targetFileDir)) {
9090
// eslint-disable-next-line no-await-in-loop
91-
await safeMkdir(targetFileDir)
91+
await safeMkdir(targetFileDir, { recursive: true })
9292
}
9393

9494
// eslint-disable-next-line no-await-in-loop

packages/cli/src/commands/scan/create-scan-from-github.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ async function streamDownloadWithFetch(
467467
// before starting the download.
468468
const dir = path.dirname(localPath)
469469
if (!existsSync(dir)) {
470-
safeMkdirSync(dir)
470+
safeMkdirSync(dir, { recursive: true })
471471
}
472472

473473
const fileStream = createWriteStream(localPath)

packages/cli/src/commands/self-update/handle-self-update.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ async function updateStubBinary(
158158
const downloadsDir = getSocketCliUpdaterDownloadsDir()
159159
const stagingDir = getSocketCliUpdaterStagingDir()
160160

161-
await safeMkdir(downloadsDir)
162-
await safeMkdir(stagingDir)
161+
await safeMkdir(downloadsDir, { recursive: true })
162+
await safeMkdir(stagingDir, { recursive: true })
163163

164164
const timestamp = Date.now()
165165
const tarballPath = path.join(downloadsDir, `stub-${timestamp}.tgz`)
@@ -377,7 +377,7 @@ Examples
377377

378378
// Create temporary directory for download.
379379
const tempDir = path.join(os.tmpdir(), `socket-update-${Date.now()}`)
380-
await safeMkdir(tempDir)
380+
await safeMkdir(tempDir, { recursive: true })
381381

382382
try {
383383
const tarballPath = path.join(tempDir, 'package.tgz')

packages/cli/src/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const compressed = readFileSync(cliBzPath)
2727
const decompressed = brotliDecompressSync(compressed)
2828

2929
// Ensure build/ directory exists.
30-
safeMkdirSync(buildPath)
30+
safeMkdirSync(buildPath, { recursive: true })
3131

3232
// Write to build/ directory (gitignored, local to package).
3333
const tempCliPath = path.join(buildPath, `cli-runtime-${process.pid}.js`)

packages/cli/src/utils/dlx/binary.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ async function downloadBinary(
202202

203203
try {
204204
// Ensure directory exists.
205-
await safeMkdir(path.dirname(destPath))
205+
await safeMkdir(path.dirname(destPath), { recursive: true })
206206

207207
// Get the response as a buffer and compute hash.
208208
const arrayBuffer = await response.arrayBuffer()
@@ -391,7 +391,7 @@ export async function dlxBinary(
391391

392392
if (downloaded) {
393393
// Ensure cache directory exists.
394-
await safeMkdir(cacheEntryDir)
394+
await safeMkdir(cacheEntryDir, { recursive: true })
395395

396396
// Download the binary.
397397
computedChecksum = await downloadBinary(url, binaryPath, checksum)

packages/cli/src/utils/git/github.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export async function writeCache(
8282
const githubCachePath = getGithubCachePath()
8383
const cacheJsonPath = path.join(githubCachePath, `${key}.json`)
8484
if (!existsSync(githubCachePath)) {
85-
await safeMkdir(githubCachePath)
85+
await safeMkdir(githubCachePath, { recursive: true })
8686
}
8787
await writeJson(cacheJsonPath, data as JsonContent)
8888
}

0 commit comments

Comments
 (0)