@@ -14,10 +14,17 @@ import { parseArgs } from '@socketsecurity/lib/argv/parse'
1414import { logger } from '@socketsecurity/lib/logger'
1515import { printFooter , printHeader } from '@socketsecurity/lib/stdio/header'
1616
17+ import {
18+ analyzeMetafile ,
19+ buildConfig ,
20+ watchConfig ,
21+ } from '../.config/esbuild.config.mjs'
1722import { runSequence } from './utils/run-command.mjs'
18- import { analyzeMetafile , buildConfig , watchConfig } from '../.config/esbuild.config.mjs'
1923
20- const rootPath = path . resolve ( path . dirname ( fileURLToPath ( import . meta. url ) ) , '..' )
24+ const rootPath = path . resolve (
25+ path . dirname ( fileURLToPath ( import . meta. url ) ) ,
26+ '..' ,
27+ )
2128
2229/**
2330 * Build source code with esbuild.
@@ -33,7 +40,10 @@ async function buildSource(options = {}) {
3340 // Clean dist directory if needed
3441 if ( ! skipClean ) {
3542 const exitCode = await runSequence ( [
36- { args : [ 'scripts/load.cjs' , 'clean' , '--dist' , '--quiet' ] , command : 'node' }
43+ {
44+ args : [ 'scripts/load.cjs' , 'clean' , '--dist' , '--quiet' ] ,
45+ command : 'node' ,
46+ } ,
3747 ] )
3848 if ( exitCode !== 0 ) {
3949 if ( ! quiet ) {
@@ -49,7 +59,7 @@ async function buildSource(options = {}) {
4959 const logLevel = quiet ? 'silent' : verbose ? 'info' : 'warning'
5060 const result = await build ( {
5161 ...buildConfig ,
52- logLevel
62+ logLevel,
5363 } )
5464 const buildTime = Date . now ( ) - startTime
5565
@@ -68,7 +78,11 @@ async function buildSource(options = {}) {
6878 * Returns exitCode for external logging.
6979 */
7080async function buildTypes ( options = { } ) {
71- const { quiet = false , skipClean = false , verbose : _verbose = false } = options
81+ const {
82+ quiet = false ,
83+ skipClean = false ,
84+ verbose : _verbose = false ,
85+ } = options
7286
7387 if ( ! quiet ) {
7488 logger . substep ( 'Building TypeScript declarations' )
@@ -77,7 +91,10 @@ async function buildTypes(options = {}) {
7791 const commands = [ ]
7892
7993 if ( ! skipClean ) {
80- commands . push ( { args : [ 'scripts/load.cjs' , 'clean' , '--types' , '--quiet' ] , command : 'node' } )
94+ commands . push ( {
95+ args : [ 'scripts/load.cjs' , 'clean' , '--types' , '--quiet' ] ,
96+ command : 'node' ,
97+ } )
8198 }
8299
83100 commands . push ( {
@@ -122,7 +139,7 @@ async function watchBuild(options = {}) {
122139 {
123140 name : 'rebuild-logger' ,
124141 setup ( build ) {
125- build . onEnd ( ( result ) => {
142+ build . onEnd ( result => {
126143 if ( result . errors . length > 0 ) {
127144 if ( ! quiet ) {
128145 logger . error ( 'Rebuild failed' )
@@ -137,9 +154,9 @@ async function watchBuild(options = {}) {
137154 }
138155 }
139156 } )
140- }
141- }
142- ]
157+ } ,
158+ } ,
159+ ] ,
143160 } )
144161
145162 // Enable watch mode
@@ -226,7 +243,9 @@ async function main() {
226243 console . log ( ' --help Show this help message' )
227244 console . log ( ' --src Build source code only' )
228245 console . log ( ' --types Build TypeScript declarations only' )
229- console . log ( ' --watch Watch mode with incremental builds (68% faster rebuilds)' )
246+ console . log (
247+ ' --watch Watch mode with incremental builds (68% faster rebuilds)' ,
248+ )
230249 console . log ( ' --needed Only build if dist files are missing' )
231250 console . log ( ' --analyze Show bundle size analysis' )
232251 console . log ( ' --quiet, --silent Suppress progress messages' )
@@ -235,9 +254,13 @@ async function main() {
235254 console . log ( ' pnpm build # Full build (source + types)' )
236255 console . log ( ' pnpm build --src # Build source only' )
237256 console . log ( ' pnpm build --types # Build types only' )
238- console . log ( ' pnpm build --watch # Watch mode with incremental builds' )
257+ console . log (
258+ ' pnpm build --watch # Watch mode with incremental builds' ,
259+ )
239260 console . log ( ' pnpm build --analyze # Build with size analysis' )
240- console . log ( '\nNote: Watch mode uses esbuild context API for 68% faster rebuilds' )
261+ console . log (
262+ '\nNote: Watch mode uses esbuild context API for 68% faster rebuilds' ,
263+ )
241264 process . exitCode = 0
242265 return
243266 }
@@ -279,18 +302,22 @@ async function main() {
279302 if ( ! quiet ) {
280303 logger . step ( 'Building source only' )
281304 }
282- const { buildTime, exitCode : srcExitCode , result } = await buildSource ( { quiet, verbose, analyze : values . analyze } )
305+ const {
306+ buildTime,
307+ exitCode : srcExitCode ,
308+ result,
309+ } = await buildSource ( { quiet, verbose, analyze : values . analyze } )
283310 exitCode = srcExitCode
284311 if ( exitCode === 0 && ! quiet ) {
285312 logger . substep ( `Source build complete in ${ buildTime } ms` )
286313
287- if ( values . analyze && result ?. [ ' metafile' ] ) {
288- const analysis = analyzeMetafile ( result [ ' metafile' ] )
314+ if ( values . analyze && result ?. metafile ) {
315+ const analysis = analyzeMetafile ( result . metafile )
289316 logger . info ( 'Build output:' )
290- for ( const file of analysis [ ' files' ] ) {
291- logger . substep ( `${ file [ ' name' ] } : ${ file [ ' size' ] } ` )
317+ for ( const file of analysis . files ) {
318+ logger . substep ( `${ file . name } : ${ file . size } ` )
292319 }
293- logger . step ( `Total bundle size: ${ analysis [ ' totalSize' ] } ` )
320+ logger . step ( `Total bundle size: ${ analysis . totalSize } ` )
294321 }
295322 }
296323 }
@@ -305,7 +332,10 @@ async function main() {
305332 logger . substep ( 'Cleaning build directories' )
306333 }
307334 exitCode = await runSequence ( [
308- { args : [ 'scripts/load.cjs' , 'clean' , '--dist' , '--types' , '--quiet' ] , command : 'node' }
335+ {
336+ args : [ 'scripts/load.cjs' , 'clean' , '--dist' , '--types' , '--quiet' ] ,
337+ command : 'node' ,
338+ } ,
309339 ] )
310340 if ( exitCode !== 0 ) {
311341 if ( ! quiet ) {
@@ -317,22 +347,27 @@ async function main() {
317347
318348 // Run source and types builds in parallel
319349 const [ srcResult , typesExitCode ] = await Promise . all ( [
320- buildSource ( { quiet, verbose, skipClean : true , analyze : values . analyze } ) ,
321- buildTypes ( { quiet, verbose, skipClean : true } )
350+ buildSource ( {
351+ quiet,
352+ verbose,
353+ skipClean : true ,
354+ analyze : values . analyze ,
355+ } ) ,
356+ buildTypes ( { quiet, verbose, skipClean : true } ) ,
322357 ] )
323358
324359 // Log completion messages in order
325360 if ( ! quiet ) {
326- if ( srcResult [ ' exitCode' ] === 0 ) {
327- logger . substep ( `Source build complete in ${ srcResult [ ' buildTime' ] } ms` )
361+ if ( srcResult . exitCode === 0 ) {
362+ logger . substep ( `Source build complete in ${ srcResult . buildTime } ms` )
328363
329- if ( values . analyze && srcResult [ ' result' ] ?. [ ' metafile' ] ) {
330- const analysis = analyzeMetafile ( srcResult [ ' result' ] [ ' metafile' ] )
364+ if ( values . analyze && srcResult . result ?. metafile ) {
365+ const analysis = analyzeMetafile ( srcResult . result . metafile )
331366 logger . info ( 'Build output:' )
332- for ( const file of analysis [ ' files' ] ) {
333- logger . substep ( `${ file [ ' name' ] } : ${ file [ ' size' ] } ` )
367+ for ( const file of analysis . files ) {
368+ logger . substep ( `${ file . name } : ${ file . size } ` )
334369 }
335- logger . step ( `Total bundle size: ${ analysis [ ' totalSize' ] } ` )
370+ logger . step ( `Total bundle size: ${ analysis . totalSize } ` )
336371 }
337372 }
338373
@@ -341,7 +376,7 @@ async function main() {
341376 }
342377 }
343378
344- exitCode = srcResult [ ' exitCode' ] !== 0 ? srcResult [ ' exitCode' ] : typesExitCode
379+ exitCode = srcResult . exitCode !== 0 ? srcResult . exitCode : typesExitCode
345380 }
346381
347382 // Print final status and footer
@@ -363,4 +398,4 @@ async function main() {
363398 }
364399}
365400
366- main ( ) . catch ( console . error )
401+ main ( ) . catch ( console . error )
0 commit comments