Skip to content

Commit 9bdfa08

Browse files
committed
refactor(scripts): use spawnSync from @socketsecurity/lib in biome.mjs
- Replace node:child_process execSync with @socketsecurity/lib/spawn spawnSync - Cleaner error handling with status code check
1 parent 9b88255 commit 9bdfa08

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

scripts/utils/biome.mjs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Formats content using Biome CLI via pnpm exec.
44
*/
55

6-
import { execSync } from 'node:child_process'
6+
import { spawnSync } from '@socketsecurity/lib/spawn'
77

88
/**
99
* Format content using Biome.
@@ -13,18 +13,15 @@ export function biomeFormat(content, options = {}) {
1313

1414
// Use stdin mode to avoid path-based exclusions in biome.json.
1515
const extension = filepath.split('.').pop() || 'json'
16-
try {
17-
const result = execSync(
18-
`pnpm exec biome format --stdin-file-path="temp.${extension}"`,
19-
{
20-
cwd: process.cwd(),
21-
input: content,
22-
encoding: 'utf8',
23-
},
24-
)
25-
return result
26-
} catch {
27-
// If biome format fails, return original content.
28-
return content
29-
}
16+
const result = spawnSync(
17+
'pnpm',
18+
['exec', 'biome', 'format', `--stdin-file-path=temp.${extension}`],
19+
{
20+
cwd: process.cwd(),
21+
input: content,
22+
encoding: 'utf8',
23+
},
24+
)
25+
// If biome format fails, return original content.
26+
return result.status === 0 ? result.stdout : content
3027
}

scripts/utils/templates.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ import {
4040
import { getLicenseContent } from '../constants/utils.mjs'
4141
import { biomeFormat } from './biome.mjs'
4242

43-
const _require = createRequire(import.meta.url)
44-
4543
// File extension constants.
4644
const EXT_JSON = '.json'
4745
const EXT_MD = '.md'

0 commit comments

Comments
 (0)