Skip to content

Commit 60e0552

Browse files
committed
refactor(scripts): reorganize and standardize script infrastructure
- Organize validation scripts into subdirectory - Remove loader infrastructure (load.cjs, register-loader, alias-loader) - Remove get-local-package-aliases utility - Update script paths and imports - Correct rootPath in validation scripts - Fix linting errors and import ordering - Align CDN validator with socket-cli implementation - Convert Promise.all to Promise.allSettled for better error handling - Add file validation checks (bundle-deps, CDN refs, esbuild minify) - Remove dotenvx and npm-run-all2 dependencies - Update prompts import path - Use single-line array format in update script
1 parent 86885d7 commit 60e0552

20 files changed

+1124
-545
lines changed

scripts/build.mjs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function buildSource(options = {}) {
4343
if (!skipClean) {
4444
const exitCode = await runSequence([
4545
{
46-
args: ['scripts/load.cjs', 'clean', '--dist', '--quiet'],
46+
args: ['scripts/clean.mjs', '--dist', '--quiet'],
4747
command: 'node',
4848
},
4949
])
@@ -94,7 +94,7 @@ async function buildTypes(options = {}) {
9494

9595
if (!skipClean) {
9696
commands.push({
97-
args: ['scripts/load.cjs', 'clean', '--types', '--quiet'],
97+
args: ['scripts/clean.mjs', '--types', '--quiet'],
9898
command: 'node',
9999
})
100100
}
@@ -338,7 +338,7 @@ async function main() {
338338
}
339339
exitCode = await runSequence([
340340
{
341-
args: ['scripts/load.cjs', 'clean', '--dist', '--types', '--quiet'],
341+
args: ['scripts/clean.mjs', '--dist', '--types', '--quiet'],
342342
command: 'node',
343343
},
344344
])
@@ -351,7 +351,7 @@ async function main() {
351351
}
352352

353353
// Run source and types builds in parallel
354-
const [srcResult, typesExitCode] = await Promise.all([
354+
const results = await Promise.allSettled([
355355
buildSource({
356356
quiet,
357357
verbose,
@@ -361,6 +361,13 @@ async function main() {
361361
buildTypes({ quiet, verbose, skipClean: true }),
362362
])
363363

364+
const srcResult =
365+
results[0].status === 'fulfilled'
366+
? results[0].value
367+
: { exitCode: 1, buildTime: 0, result: null }
368+
const typesExitCode =
369+
results[1].status === 'fulfilled' ? results[1].value : 1
370+
364371
// Log completion messages in order
365372
if (!quiet) {
366373
if (srcResult.exitCode === 0) {

scripts/check.mjs

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ async function main() {
206206
logger.progress('Validating no link: dependencies')
207207
}
208208
exitCode = await runCommandQuiet('node', [
209-
'scripts/validate-no-link-deps.mjs',
209+
'scripts/validate/no-link-deps.mjs',
210210
]).then(r => r.exitCode)
211211
if (exitCode !== 0) {
212212
if (!quiet) {
@@ -227,7 +227,7 @@ async function main() {
227227
logger.progress('Validating bundle dependencies')
228228
}
229229
exitCode = await runCommandQuiet('node', [
230-
'scripts/validate-bundle-deps.mjs',
230+
'scripts/validate/bundle-deps.mjs',
231231
]).then(r => r.exitCode)
232232
if (exitCode !== 0) {
233233
if (!quiet) {
@@ -242,6 +242,111 @@ async function main() {
242242
}
243243
}
244244

245+
// Run esbuild minify validation check
246+
if (runAll) {
247+
if (!quiet) {
248+
logger.progress('Validating esbuild minify setting')
249+
}
250+
exitCode = await runCommandQuiet('node', [
251+
'scripts/validate/esbuild-minify.mjs',
252+
]).then(r => r.exitCode)
253+
if (exitCode !== 0) {
254+
if (!quiet) {
255+
logger.error('esbuild minify validation failed')
256+
}
257+
process.exitCode = exitCode
258+
return
259+
}
260+
if (!quiet) {
261+
logger.clearLine().done('esbuild minify validated')
262+
logger.error('')
263+
}
264+
}
265+
266+
// Run CDN references validation check
267+
if (runAll) {
268+
if (!quiet) {
269+
logger.progress('Validating no CDN references')
270+
}
271+
exitCode = await runCommandQuiet('node', [
272+
'scripts/validate/no-cdn-refs.mjs',
273+
]).then(r => r.exitCode)
274+
if (exitCode !== 0) {
275+
if (!quiet) {
276+
logger.error('CDN references validation failed')
277+
}
278+
process.exitCode = exitCode
279+
return
280+
}
281+
if (!quiet) {
282+
logger.clearLine().done('No CDN references found')
283+
logger.error('')
284+
}
285+
}
286+
287+
// Run markdown filenames validation check
288+
if (runAll) {
289+
if (!quiet) {
290+
logger.progress('Validating markdown filenames')
291+
}
292+
exitCode = await runCommandQuiet('node', [
293+
'scripts/validate/markdown-filenames.mjs',
294+
]).then(r => r.exitCode)
295+
if (exitCode !== 0) {
296+
if (!quiet) {
297+
logger.error('Markdown filenames validation failed')
298+
}
299+
process.exitCode = exitCode
300+
return
301+
}
302+
if (!quiet) {
303+
logger.clearLine().done('Markdown filenames validated')
304+
logger.error('')
305+
}
306+
}
307+
308+
// Run file size validation check
309+
if (runAll) {
310+
if (!quiet) {
311+
logger.progress('Validating file sizes')
312+
}
313+
exitCode = await runCommandQuiet('node', [
314+
'scripts/validate/file-size.mjs',
315+
]).then(r => r.exitCode)
316+
if (exitCode !== 0) {
317+
if (!quiet) {
318+
logger.error('File size validation failed')
319+
}
320+
process.exitCode = exitCode
321+
return
322+
}
323+
if (!quiet) {
324+
logger.clearLine().done('File sizes validated')
325+
logger.error('')
326+
}
327+
}
328+
329+
// Run file count validation check
330+
if (runAll) {
331+
if (!quiet) {
332+
logger.progress('Validating file count')
333+
}
334+
exitCode = await runCommandQuiet('node', [
335+
'scripts/validate/file-count.mjs',
336+
]).then(r => r.exitCode)
337+
if (exitCode !== 0) {
338+
if (!quiet) {
339+
logger.error('File count validation failed')
340+
}
341+
process.exitCode = exitCode
342+
return
343+
}
344+
if (!quiet) {
345+
logger.clearLine().done('File count validated')
346+
logger.error('')
347+
}
348+
}
349+
245350
if (!quiet) {
246351
logger.success('All checks passed')
247352
printFooter()

scripts/claude.mjs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { deleteAsync as del } from 'del'
1919
import colors from 'yoctocolors-cjs'
2020

2121
import { parseArgs } from '@socketsecurity/lib/argv/parse'
22+
import { LOG_SYMBOLS } from '@socketsecurity/lib/logger'
2223
import { spawn } from '@socketsecurity/lib/spawn'
2324

2425
const __dirname = path.dirname(fileURLToPath(import.meta.url))
@@ -98,7 +99,7 @@ const log = {
9899
substep: msg => console.log(` ${msg}`),
99100
progress: msg => {
100101
process.stdout.write('\r\x1b[K')
101-
process.stdout.write(` ${msg}`)
102+
process.stdout.write(` ${LOG_SYMBOLS.reason} ${msg}`)
102103
},
103104
done: msg => {
104105
process.stdout.write('\r\x1b[K')
@@ -1914,7 +1915,8 @@ async function executeParallel(tasks, workers = 3) {
19141915
}
19151916
}
19161917

1917-
return Promise.all(results)
1918+
const settled = await Promise.allSettled(results)
1919+
return settled.map(r => (r.status === 'fulfilled' ? r.value : undefined))
19181920
}
19191921

19201922
/**
@@ -3420,12 +3422,19 @@ async function runAudit(claudeCmd, options = {}) {
34203422
log.step('Gathering project information')
34213423

34223424
// Run various checks.
3423-
const [npmAudit, depCheck, licenseCheck] = await Promise.all([
3425+
const results = await Promise.allSettled([
34243426
runCommandWithOutput('npm', ['audit', '--json']),
34253427
runCommandWithOutput('pnpm', ['licenses', 'list', '--json']),
34263428
fs.readFile(path.join(rootPath, 'package.json'), 'utf8'),
34273429
])
34283430

3431+
const npmAudit =
3432+
results[0].status === 'fulfilled' ? results[0].value : { stdout: '' }
3433+
const depCheck =
3434+
results[1].status === 'fulfilled' ? results[1].value : { stdout: '' }
3435+
const licenseCheck =
3436+
results[2].status === 'fulfilled' ? results[2].value : '{}'
3437+
34293438
const packageJson = JSON.parse(licenseCheck)
34303439

34313440
const prompt = `Perform a comprehensive audit of the project:

scripts/cover.mjs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ console.log('')
4040
// Filter out custom flags that vitest doesn't understand
4141
const customFlags = ['--code-only', '--type-only', '--summary']
4242
const vitestArgs = [
43-
'-q',
44-
'run',
45-
'-f',
46-
'.env.test',
47-
'--',
4843
'vitest',
4944
'--config',
5045
'.config/vitest.config.mts',
@@ -88,8 +83,13 @@ try {
8883
}
8984
// Handle --code-only flag
9085
else if (values['code-only']) {
91-
codeCoverageResult = await runCommandQuiet('dotenvx', vitestArgs, {
86+
codeCoverageResult = await runCommandQuiet('pnpm', vitestArgs, {
9287
cwd: rootPath,
88+
env: {
89+
...process.env,
90+
NODE_COMPILE_CACHE: './.cache',
91+
VITEST: '1',
92+
},
9393
})
9494
exitCode = codeCoverageResult.exitCode
9595

@@ -139,8 +139,13 @@ try {
139139
}
140140
// Default: run both code and type coverage
141141
else {
142-
codeCoverageResult = await runCommandQuiet('dotenvx', vitestArgs, {
142+
codeCoverageResult = await runCommandQuiet('pnpm', vitestArgs, {
143143
cwd: rootPath,
144+
env: {
145+
...process.env,
146+
NODE_COMPILE_CACHE: './.cache',
147+
VITEST: '1',
148+
},
144149
})
145150
exitCode = codeCoverageResult.exitCode
146151

scripts/load.cjs

Lines changed: 0 additions & 48 deletions
This file was deleted.

scripts/register-loader.mjs

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)