Skip to content

Commit 7d241b2

Browse files
committed
refactor(scripts): reorganize and standardize script infrastructure
- Reorganize scripts into focused categories: npm/, validation/, maintenance/, ci/ - Migrate from console to logger (@socketsecurity/lib) for consistent output - Standardize error handling with descriptive messages and proper exit codes - Extract validation boilerplate into shared validation-runner utility - Convert Promise.all to Promise.allSettled for better error handling - Add type annotations to improve type coverage - Correct root path resolution in validation scripts - Remove unused scripts and utilities (get-local-package-aliases, etc.) - Add @fileoverview headers to all script files - Standardize logger method usage across all scripts
1 parent e90b22b commit 7d241b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1633
-1065
lines changed

scripts/build.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import path from 'node:path'
77
import { fileURLToPath } from 'node:url'
88

99
import colors from 'yoctocolors-cjs'
10+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
11+
1012
import { runCommand } from './utils/run-command.mjs'
1113

14+
const logger = getDefaultLogger()
15+
1216
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1317
const rootPath = path.resolve(__dirname, '..')
1418
const registryPath = path.join(rootPath, 'registry')
@@ -20,7 +24,6 @@ const isQuiet = args.includes('--quiet') || args.includes('--silent')
2024
async function main() {
2125
// Build the @socketsecurity/registry package.
2226
// This is required before running tests that import from it.
23-
2427
// Pass all arguments through to the registry build script.
2528
const buildArgs = ['run', 'build']
2629
if (args.length > 0) {
@@ -33,7 +36,7 @@ async function main() {
3336

3437
if (exitCode !== 0) {
3538
if (!isQuiet) {
36-
console.error(colors.red('✗ Failed to build @socketsecurity/registry'))
39+
logger.error(colors.red('✗ Failed to build @socketsecurity/registry'))
3740
}
3841
process.exitCode = exitCode
3942
return
@@ -43,6 +46,6 @@ async function main() {
4346
}
4447

4548
main().catch(error => {
46-
console.error(colors.red('✗ Build failed:'), error)
49+
logger.error(colors.red('✗ Build failed:'), error)
4750
process.exitCode = 1
4851
})

scripts/check.mjs

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@ import path from 'node:path'
1313
import { fileURLToPath } from 'node:url'
1414

1515
import { getDefaultLogger } from '@socketsecurity/lib/logger'
16+
import { printFooter, printHeader } from '@socketsecurity/lib/stdio/header'
1617

17-
const logger = getDefaultLogger()
18-
19-
import {
20-
printError,
21-
printFooter,
22-
printHeader,
23-
printSuccess,
24-
} from './utils/cli-helpers.mjs'
2518
import { runCommand, runParallel } from './utils/run-command.mjs'
2619

20+
const logger = getDefaultLogger()
21+
2722
const __dirname = path.dirname(fileURLToPath(import.meta.url))
2823
const rootPath = path.resolve(__dirname, '..')
2924
const registryDistPath = path.join(rootPath, 'registry', 'dist', 'index.js')
@@ -37,7 +32,7 @@ async function main() {
3732
if (!existsSync(registryDistPath)) {
3833
const buildExitCode = await runCommand('pnpm', ['run', 'build'])
3934
if (buildExitCode !== 0) {
40-
printError('Build failed')
35+
logger.error('Build failed')
4136
process.exitCode = buildExitCode
4237
return
4338
}
@@ -66,14 +61,49 @@ async function main() {
6661
},
6762
},
6863
{
69-
args: ['scripts/validate-no-link-deps.mjs'],
64+
args: ['scripts/validation/no-link-deps.mjs'],
65+
command: 'node',
66+
options: {
67+
...(process.platform === 'win32' && { shell: true }),
68+
},
69+
},
70+
{
71+
args: ['scripts/validation/bundle-deps.mjs'],
72+
command: 'node',
73+
options: {
74+
...(process.platform === 'win32' && { shell: true }),
75+
},
76+
},
77+
{
78+
args: ['scripts/validation/esbuild-minify.mjs'],
79+
command: 'node',
80+
options: {
81+
...(process.platform === 'win32' && { shell: true }),
82+
},
83+
},
84+
{
85+
args: ['scripts/validation/no-cdn-refs.mjs'],
86+
command: 'node',
87+
options: {
88+
...(process.platform === 'win32' && { shell: true }),
89+
},
90+
},
91+
{
92+
args: ['scripts/validation/markdown-filenames.mjs'],
93+
command: 'node',
94+
options: {
95+
...(process.platform === 'win32' && { shell: true }),
96+
},
97+
},
98+
{
99+
args: ['scripts/validation/file-size.mjs'],
70100
command: 'node',
71101
options: {
72102
...(process.platform === 'win32' && { shell: true }),
73103
},
74104
},
75105
{
76-
args: ['scripts/validate-bundle-deps.mjs'],
106+
args: ['scripts/validation/file-count.mjs'],
77107
command: 'node',
78108
options: {
79109
...(process.platform === 'win32' && { shell: true }),
@@ -85,16 +115,19 @@ async function main() {
85115
const failed = exitCodes.some(code => code !== 0)
86116

87117
if (failed) {
88-
printError('Some checks failed')
118+
logger.error('Some checks failed')
89119
process.exitCode = 1
90120
} else {
91-
printSuccess('All checks passed')
121+
logger.success('All checks passed')
92122
printFooter()
93123
}
94124
} catch (error) {
95-
printError(`Check failed: ${error.message}`)
125+
logger.error(`Check failed: ${error.message}`)
96126
process.exitCode = 1
97127
}
98128
}
99129

100-
main().catch(e => logger.error(e))
130+
main().catch(e => {
131+
logger.error(e)
132+
process.exitCode = 1
133+
})

scripts/generate-actions-allow-list.mjs renamed to scripts/ci/generate-actions-allow-list.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const logger = getDefaultLogger()
1010
import {
1111
ROOT_DOT_GITHUB_ACTIONS_PATH,
1212
ROOT_DOT_GITHUB_WORKFLOWS_PATH,
13-
} from './constants/paths.mjs'
13+
} from '../constants/paths.mjs'
1414

1515
/**
1616
* Extract action dependencies from a workflow or action file.

scripts/inline-action-versions-as-shas.mjs renamed to scripts/ci/inline-action-versions-as-shas.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import path from 'node:path'
77
import { resolveRefToSha } from '@socketsecurity/lib/github'
88
import { getDefaultLogger } from '@socketsecurity/lib/logger'
99

10-
import { ROOT_PATH } from './constants/paths.mjs'
10+
import { ROOT_PATH } from '../constants/paths.mjs'
1111

1212
const logger = getDefaultLogger()
1313

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const logger = getDefaultLogger()
1010
import {
1111
ROOT_DOT_GITHUB_ACTIONS_PATH,
1212
ROOT_DOT_GITHUB_WORKFLOWS_PATH,
13-
} from './constants/paths.mjs'
13+
} from '../constants/paths.mjs'
1414

1515
/**
1616
* Extract structured dependency information from a workflow or action file.

scripts/claude.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
*/
88

99
// Simply import and run the modular version.
10-
import './claude/index.mjs'
10+
import './claude/cli.mjs'

scripts/claude/commands/audit.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ async function runAudit(claudeCmd, options = {}) {
1919
log.step('Gathering project information')
2020

2121
// Run various checks.
22-
const [npmAudit, depCheck, licenseCheck] = await Promise.all([
22+
const results = await Promise.allSettled([
2323
runCommandWithOutput('npm', ['audit', '--json']),
2424
runCommandWithOutput('pnpm', ['licenses', 'list', '--json']),
2525
fs.readFile(path.join(rootPath, 'package.json'), 'utf8'),
2626
])
2727

28+
const npmAudit =
29+
results[0].status === 'fulfilled' ? results[0].value : { stdout: '' }
30+
const depCheck =
31+
results[1].status === 'fulfilled' ? results[1].value : { stdout: '' }
32+
const licenseCheck =
33+
results[2].status === 'fulfilled' ? results[2].value : '{}'
34+
2835
const packageJson = JSON.parse(licenseCheck)
2936

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

scripts/claude/config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { fileURLToPath } from 'node:url'
99

1010
import colors from 'yoctocolors-cjs'
1111

12+
import { LOG_SYMBOLS } from '@socketsecurity/lib/logger'
13+
1214
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1315
const rootPath = path.join(__dirname, '..', '..')
1416
const parentPath = path.join(rootPath, '..')
@@ -91,7 +93,7 @@ const log = {
9193
info: msg => console.log(msg),
9294
progress: msg => {
9395
process.stdout.write('\r\x1b[K')
94-
process.stdout.write(` ${msg}`)
96+
process.stdout.write(` ${LOG_SYMBOLS.reason} ${msg}`)
9597
},
9698
step: msg => console.log(`\n${msg}`),
9799
substep: msg => console.log(` ${msg}`),

scripts/claude/parallel-execution.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ async function executeParallel(tasks, workers = 3) {
3838
}
3939
}
4040

41-
return Promise.all(results)
41+
const settled = await Promise.allSettled(results)
42+
return settled.map(r => (r.status === 'fulfilled' ? r.value : undefined))
4243
}
4344

4445
/**

0 commit comments

Comments
 (0)