Skip to content

Commit 2e31dfe

Browse files
committed
refactor(scripts): standardize and improve script infrastructure
- Replace console with logger in scripts and configs - Replace \u2234 with logger.progress() for better output - Use logger in validation scripts - Use single-line @babel/traverse imports - Remove local package alias system (load.cjs, register-loader, alias-loader, get-local-package-aliases) - Improve lint progress output and formatting - Align CDN validator with socket-cli implementation
1 parent 1fbfe13 commit 2e31dfe

22 files changed

+771
-783
lines changed

scripts/build.mjs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function buildSource(options = {}) {
4040
if (!skipClean) {
4141
const exitCode = await runSequence([
4242
{
43-
args: ['scripts/load.cjs', 'clean', '--dist', '--quiet'],
43+
args: ['scripts/clean.mjs', '--dist', '--quiet'],
4444
command: 'node',
4545
},
4646
])
@@ -66,7 +66,7 @@ async function buildSource(options = {}) {
6666
} catch (error) {
6767
if (!quiet) {
6868
logger.error('Source build failed')
69-
console.error(error)
69+
logger.error(error)
7070
}
7171
return { exitCode: 1, buildTime: 0, result: null }
7272
}
@@ -87,7 +87,7 @@ async function buildTypes(options = {}) {
8787

8888
if (!skipClean) {
8989
commands.push({
90-
args: ['scripts/load.cjs', 'clean', '--types', '--quiet'],
90+
args: ['scripts/clean.mjs', '--types', '--quiet'],
9191
command: 'node',
9292
})
9393
}
@@ -235,28 +235,28 @@ async function main() {
235235

236236
// Show help if requested
237237
if (values.help) {
238-
console.log('Build Runner')
239-
console.log('\nUsage: pnpm build [options]')
240-
console.log('\nOptions:')
241-
console.log(' --help Show this help message')
242-
console.log(' --src Build source code only')
243-
console.log(' --types Build TypeScript declarations only')
244-
console.log(
238+
logger.log('Build Runner')
239+
logger.log('\nUsage: pnpm build [options]')
240+
logger.log('\nOptions:')
241+
logger.log(' --help Show this help message')
242+
logger.log(' --src Build source code only')
243+
logger.log(' --types Build TypeScript declarations only')
244+
logger.log(
245245
' --watch Watch mode with incremental builds (68% faster rebuilds)',
246246
)
247-
console.log(' --needed Only build if dist files are missing')
248-
console.log(' --analyze Show bundle size analysis')
249-
console.log(' --quiet, --silent Suppress progress messages')
250-
console.log(' --verbose Show detailed build output')
251-
console.log('\nExamples:')
252-
console.log(' pnpm build # Full build (source + types)')
253-
console.log(' pnpm build --src # Build source only')
254-
console.log(' pnpm build --types # Build types only')
255-
console.log(
247+
logger.log(' --needed Only build if dist files are missing')
248+
logger.log(' --analyze Show bundle size analysis')
249+
logger.log(' --quiet, --silent Suppress progress messages')
250+
logger.log(' --verbose Show detailed build output')
251+
logger.log('\nExamples:')
252+
logger.log(' pnpm build # Full build (source + types)')
253+
logger.log(' pnpm build --src # Build source only')
254+
logger.log(' pnpm build --types # Build types only')
255+
logger.log(
256256
' pnpm build --watch # Watch mode with incremental builds',
257257
)
258-
console.log(' pnpm build --analyze # Build with size analysis')
259-
console.log(
258+
logger.log(' pnpm build --analyze # Build with size analysis')
259+
logger.log(
260260
'\nNote: Watch mode uses esbuild context API for 68% faster rebuilds',
261261
)
262262
process.exitCode = 0
@@ -291,7 +291,7 @@ async function main() {
291291
}
292292
exitCode = await buildTypes({ quiet, verbose })
293293
if (exitCode === 0 && !quiet) {
294-
console.log(colors.green('✓ Type Declarations'))
294+
logger.log(colors.green('✓ Type Declarations'))
295295
}
296296
}
297297
// Build source only
@@ -306,7 +306,7 @@ async function main() {
306306
} = await buildSource({ quiet, verbose, analyze: values.analyze })
307307
exitCode = srcExitCode
308308
if (exitCode === 0 && !quiet) {
309-
console.log(colors.green(`✓ Source Bundle (${buildTime}ms)`))
309+
logger.log(colors.green(`✓ Source Bundle (${buildTime}ms)`))
310310

311311
if (values.analyze && result?.metafile) {
312312
const analysis = analyzeMetafile(result.metafile)
@@ -327,7 +327,7 @@ async function main() {
327327
// Clean all directories first (once)
328328
exitCode = await runSequence([
329329
{
330-
args: ['scripts/load.cjs', 'clean', '--dist', '--types', '--quiet'],
330+
args: ['scripts/clean.mjs', '--dist', '--types', '--quiet'],
331331
command: 'node',
332332
},
333333
])
@@ -340,7 +340,7 @@ async function main() {
340340
}
341341

342342
if (!quiet) {
343-
console.log(colors.green('✓ Build Cleaned'))
343+
logger.log(colors.green('✓ Build Cleaned'))
344344
}
345345

346346
// Run source and types builds in parallel
@@ -361,9 +361,7 @@ async function main() {
361361
// Log completion messages
362362
if (!quiet) {
363363
if (srcResult.exitCode === 0) {
364-
console.log(
365-
colors.green(`✓ Source Bundle (${srcResult.buildTime}ms)`),
366-
)
364+
logger.log(colors.green(`✓ Source Bundle (${srcResult.buildTime}ms)`))
367365

368366
if (values.analyze && srcResult.result?.metafile) {
369367
const analysis = analyzeMetafile(srcResult.result.metafile)
@@ -376,7 +374,7 @@ async function main() {
376374
}
377375

378376
if (typesExitCode === 0) {
379-
console.log(colors.green('✓ Type Declarations'))
377+
logger.log(colors.green('✓ Type Declarations'))
380378
}
381379
}
382380

@@ -386,9 +384,9 @@ async function main() {
386384
// Print final status and footer
387385
if (!quiet) {
388386
if (exitCode === 0) {
389-
console.log(colors.green('✓ Build completed successfully!'))
387+
logger.log(colors.green('✓ Build completed successfully!'))
390388
} else {
391-
console.error(colors.red('✗ Build failed'))
389+
logger.error(colors.red('✗ Build failed'))
392390
}
393391
printFooter()
394392
}

scripts/bump.mjs

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import semver from 'semver'
1414
import colors from 'yoctocolors-cjs'
1515

1616
import { parseArgs } from '@socketsecurity/lib/argv/parse'
17+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
18+
19+
const logger = getDefaultLogger()
1720

1821
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1922
const rootPath = path.join(__dirname, '..')
@@ -61,33 +64,33 @@ if (hasInteractivePrompts) {
6164

6265
// Simple inline logger.
6366
const log = {
64-
info: msg => console.log(msg),
65-
error: msg => console.error(`${colors.red('✗')} ${msg}`),
66-
success: msg => console.log(`${colors.green('✓')} ${msg}`),
67-
step: msg => console.log(`\n${msg}`),
68-
substep: msg => console.log(` ${msg}`),
69-
progress: msg => process.stdout.write(` ∴ ${msg}`),
67+
info: msg => logger.log(msg),
68+
error: msg => logger.error(`${colors.red('✗')} ${msg}`),
69+
success: msg => logger.log(`${colors.green('✓')} ${msg}`),
70+
step: msg => logger.log(`\n${msg}`),
71+
substep: msg => logger.log(` ${msg}`),
72+
progress: msg => logger.progress(msg),
7073
done: msg => {
7174
process.stdout.write('\r\x1b[K')
72-
console.log(` ${colors.green('✓')} ${msg}`)
75+
logger.log(` ${colors.green('✓')} ${msg}`)
7376
},
7477
failed: msg => {
7578
process.stdout.write('\r\x1b[K')
76-
console.log(` ${colors.red('✗')} ${msg}`)
79+
logger.log(` ${colors.red('✗')} ${msg}`)
7780
},
78-
warn: msg => console.log(`${colors.yellow('⚠')} ${msg}`),
81+
warn: msg => logger.log(`${colors.yellow('⚠')} ${msg}`),
7982
}
8083

8184
function printHeader(title) {
82-
console.log(`\n${'─'.repeat(60)}`)
83-
console.log(` ${title}`)
84-
console.log(`${'─'.repeat(60)}`)
85+
logger.log(`\n${'─'.repeat(60)}`)
86+
logger.log(` ${title}`)
87+
logger.log(`${'─'.repeat(60)}`)
8588
}
8689

8790
function printFooter(message) {
88-
console.log(`\n${'─'.repeat(60)}`)
91+
logger.log(`\n${'─'.repeat(60)}`)
8992
if (message) {
90-
console.log(` ${colors.green('✓')} ${message}`)
93+
logger.log(` ${colors.green('✓')} ${message}`)
9194
}
9295
}
9396

@@ -258,7 +261,7 @@ async function checkGitStatus() {
258261
if (result.stdout.trim()) {
259262
log.error('Working directory is not clean')
260263
log.info('Uncommitted changes:')
261-
console.log(result.stdout)
264+
logger.log(result.stdout)
262265
return false
263266
}
264267
return true
@@ -421,11 +424,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
421424
* Uses interactive prompts if available, falls back to basic readline prompts.
422425
*/
423426
async function reviewChangelog(claudeCmd, changelogEntry, interactive = false) {
424-
console.log(`\n${colors.blue('━'.repeat(60))}`)
425-
console.log(colors.blue('Proposed Changelog Entry:'))
426-
console.log(colors.blue('━'.repeat(60)))
427-
console.log(changelogEntry)
428-
console.log(`${colors.blue('━'.repeat(60))}\n`)
427+
logger.log(`\n${colors.blue('━'.repeat(60))}`)
428+
logger.log(colors.blue('Proposed Changelog Entry:'))
429+
logger.log(colors.blue('━'.repeat(60)))
430+
logger.log(changelogEntry)
431+
logger.log(`${colors.blue('━'.repeat(60))}\n`)
429432

430433
// Use interactive prompts if available and requested.
431434
if (interactive && prompts) {
@@ -470,11 +473,11 @@ Provide the refined changelog entry in the same format.`
470473
changelogEntry = refineResult.stdout.trim()
471474
log.done('Changelog refined')
472475

473-
console.log(`\n${colors.blue('━'.repeat(60))}`)
474-
console.log(colors.blue('Refined Changelog Entry:'))
475-
console.log(colors.blue('━'.repeat(60)))
476-
console.log(changelogEntry)
477-
console.log(`${colors.blue('━'.repeat(60))}\n`)
476+
logger.log(`\n${colors.blue('━'.repeat(60))}`)
477+
logger.log(colors.blue('Refined Changelog Entry:'))
478+
logger.log(colors.blue('━'.repeat(60)))
479+
logger.log(changelogEntry)
480+
logger.log(`${colors.blue('━'.repeat(60))}\n`)
478481
} else {
479482
log.failed('Failed to refine changelog')
480483
}
@@ -501,10 +504,10 @@ async function interactiveReviewChangelog(claudeCmd, changelogEntry) {
501504

502505
while (true) {
503506
// Show the current changelog.
504-
console.log(`\n${colors.cyan('Current Changelog Entry:')}`)
505-
console.log(colors.dim('─'.repeat(60)))
506-
console.log(currentEntry)
507-
console.log(`${colors.dim('─'.repeat(60))}\n`)
507+
logger.log(`\n${colors.cyan('Current Changelog Entry:')}`)
508+
logger.log(colors.dim('─'.repeat(60)))
509+
logger.log(currentEntry)
510+
logger.log(`${colors.dim('─'.repeat(60))}\n`)
508511

509512
// Offer action choices.
510513
const action = await prompts.select({
@@ -540,7 +543,7 @@ async function interactiveReviewChangelog(claudeCmd, changelogEntry) {
540543
}
541544

542545
if (action === 'manual') {
543-
console.log(
546+
logger.log(
544547
'\nEnter the changelog manually (paste and press Enter twice when done):',
545548
)
546549
const rl = createReadline()
@@ -692,41 +695,41 @@ async function main() {
692695

693696
// Show help if requested.
694697
if (values.help) {
695-
console.log('\nUsage: pnpm bump [options]')
696-
console.log('\nOptions:')
697-
console.log(' --help Show this help message')
698-
console.log(' --bump <type> Version bump type (default: patch)')
699-
console.log(
698+
logger.log('\nUsage: pnpm bump [options]')
699+
logger.log('\nOptions:')
700+
logger.log(' --help Show this help message')
701+
logger.log(' --bump <type> Version bump type (default: patch)')
702+
logger.log(
700703
' Can be: major, minor, patch, premajor, preminor,',
701704
)
702-
console.log(
705+
logger.log(
703706
' prepatch, prerelease, or a specific version',
704707
)
705-
console.log(' --interactive Force interactive changelog review')
706-
console.log(' --no-interactive Disable interactive mode')
707-
console.log(' --skip-changelog Skip changelog generation with Claude')
708-
console.log(' --skip-checks Skip git status/branch checks')
709-
console.log(' --no-push Do not push changes to remote')
710-
console.log(' --force Force bump even with warnings')
711-
console.log('\nExamples:')
712-
console.log(
708+
logger.log(' --interactive Force interactive changelog review')
709+
logger.log(' --no-interactive Disable interactive mode')
710+
logger.log(' --skip-changelog Skip changelog generation with Claude')
711+
logger.log(' --skip-checks Skip git status/branch checks')
712+
logger.log(' --no-push Do not push changes to remote')
713+
logger.log(' --force Force bump even with warnings')
714+
logger.log('\nExamples:')
715+
logger.log(
713716
' pnpm bump # Bump patch (interactive by default)',
714717
)
715-
console.log(' pnpm bump --bump=minor # Bump minor version')
716-
console.log(' pnpm bump --no-interactive # Use basic prompts')
717-
console.log(' pnpm bump --bump=2.0.0 # Set specific version')
718-
console.log(
718+
logger.log(' pnpm bump --bump=minor # Bump minor version')
719+
logger.log(' pnpm bump --no-interactive # Use basic prompts')
720+
logger.log(' pnpm bump --bump=2.0.0 # Set specific version')
721+
logger.log(
719722
' pnpm bump --skip-changelog # Skip AI changelog generation',
720723
)
721-
console.log('\nRequires:')
722-
console.log(' - claude-console (or claude) CLI tool installed')
723-
console.log(' - Clean git working directory')
724-
console.log(' - Main/master branch (unless --force)')
724+
logger.log('\nRequires:')
725+
logger.log(' - claude-console (or claude) CLI tool installed')
726+
logger.log(' - Clean git working directory')
727+
logger.log(' - Main/master branch (unless --force)')
725728
if (hasInteractivePrompts) {
726-
console.log('\nInteractive mode: Available ✓ (default)')
729+
logger.log('\nInteractive mode: Available ✓ (default)')
727730
} else {
728-
console.log('\nInteractive mode: Not available')
729-
console.log(' (install @socketsecurity/lib or build local registry)')
731+
logger.log('\nInteractive mode: Not available')
732+
logger.log(' (install @socketsecurity/lib or build local registry)')
730733
}
731734
process.exitCode = 0
732735
return
@@ -902,6 +905,6 @@ async function main() {
902905
}
903906

904907
main().catch(e => {
905-
console.error(e)
908+
logger.error(e)
906909
process.exitCode = 1
907910
})

scripts/check.mjs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,12 @@
1212
import { getDefaultLogger } from '@socketsecurity/lib/logger'
1313
import { printFooter, printHeader } from '@socketsecurity/lib/stdio/header'
1414

15-
import { getLocalPackageAliases } from './utils/get-local-package-aliases.mjs'
1615
import { runParallel } from './utils/run-command.mjs'
1716

1817
// Initialize logger
1918
const logger = getDefaultLogger()
2019

21-
// Determine which TypeScript config to use based on local package detection
22-
const localPackageAliases = getLocalPackageAliases(process.cwd())
23-
const hasLocalPackages = Object.keys(localPackageAliases).length > 0
24-
const tsConfigPath = hasLocalPackages
25-
? '.config/tsconfig.check.local.json'
26-
: '.config/tsconfig.check.json'
20+
const tsConfigPath = '.config/tsconfig.check.json'
2721

2822
async function main() {
2923
try {

0 commit comments

Comments
 (0)