@@ -146,7 +146,11 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, sourceBuil
146
146
// default none; override via BUILD_CACHE_COMPRESSION=gzip|brotli
147
147
compression : cacheCompressionOption ?? false ,
148
148
buildDependencies : {
149
- config : [ path . resolve ( 'build.mjs' ) ] ,
149
+ config : [
150
+ path . resolve ( 'build.mjs' ) ,
151
+ path . resolve ( 'package.json' ) ,
152
+ path . resolve ( 'package-lock.json' ) ,
153
+ ] ,
150
154
} ,
151
155
} ,
152
156
optimization : {
@@ -391,14 +395,17 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, sourceBuil
391
395
err ||
392
396
( stats && typeof stats . hasErrors === 'function' && stats . hasErrors ( ) )
393
397
)
394
- callback ( err , stats )
398
+ const ret = callback ( err , stats )
395
399
if ( process . env . BUILD_WATCH_ONCE ) {
396
- watching . close ( ( closeErr ) => {
397
- if ( closeErr ) console . error ( 'Error closing watcher:' , closeErr )
398
- // Exit explicitly to prevent hanging processes in CI
399
- // Use non-zero exit code when errors occurred
400
- process . exit ( hasErrors || closeErr ? 1 : 0 )
401
- } )
400
+ const finalize = ( ) =>
401
+ watching . close ( ( closeErr ) => {
402
+ if ( closeErr ) console . error ( 'Error closing watcher:' , closeErr )
403
+ // Exit explicitly to prevent hanging processes in CI
404
+ // Use non-zero exit code when errors occurred
405
+ process . exit ( hasErrors || closeErr ? 1 : 0 )
406
+ } )
407
+ if ( ret && typeof ret . then === 'function' ) ret . then ( finalize , finalize )
408
+ else finalize ( )
402
409
}
403
410
} )
404
411
}
@@ -421,27 +428,24 @@ async function zipFolder(dir) {
421
428
}
422
429
423
430
async function copyFiles ( entryPoints , targetDir ) {
424
- if ( ! fs . existsSync ( targetDir ) ) await fs . mkdir ( targetDir , { recursive : true } )
431
+ await fs . ensureDir ( targetDir )
425
432
await Promise . all (
426
433
entryPoints . map ( async ( entryPoint ) => {
427
434
try {
428
- if ( await fs . pathExists ( entryPoint . src ) ) {
429
- await fs . copy ( entryPoint . src , `${ targetDir } /${ entryPoint . dst } ` )
430
- } else {
431
- // Skip missing CSS in development (placeholders will be created later)
432
- const isCss = String ( entryPoint . dst ) . endsWith ( '.css' )
433
- if ( ! isProduction || isCss ) {
434
- if ( ! isProduction && isCss ) {
435
- console . log (
436
- `[build] Skipping missing CSS file: ${ entryPoint . src } -> ${ entryPoint . dst } (placeholder will be created)` ,
437
- )
438
- return
439
- }
435
+ await fs . copy ( entryPoint . src , `${ targetDir } /${ entryPoint . dst } ` )
436
+ } catch ( e ) {
437
+ const isCss = String ( entryPoint . dst ) . endsWith ( '.css' )
438
+ if ( e && e . code === 'ENOENT' ) {
439
+ if ( ! isProduction && isCss ) {
440
+ console . log (
441
+ `[build] Skipping missing CSS file: ${ entryPoint . src } -> ${ entryPoint . dst } (placeholder will be created)` ,
442
+ )
443
+ return
440
444
}
441
- throw new Error ( `Missing build artifact: ${ entryPoint . src } ` )
445
+ console . error ( 'Missing build artifact:' , entryPoint . src )
446
+ } else {
447
+ console . error ( 'Copy failed:' , entryPoint , e )
442
448
}
443
- } catch ( e ) {
444
- console . error ( 'Copy failed:' , entryPoint , e )
445
449
throw e
446
450
}
447
451
} ) ,
@@ -466,6 +470,15 @@ async function finishOutput(outputDirSuffix, sourceBuildDir = outdir) {
466
470
467
471
{ src : `${ sourceBuildDir } /IndependentPanel.js` , dst : 'IndependentPanel.js' } ,
468
472
{ src : 'src/pages/IndependentPanel/index.html' , dst : 'IndependentPanel.html' } ,
473
+ // Dev-only: copy external source maps for CSP-safe debugging
474
+ ...( isProduction
475
+ ? [ ]
476
+ : [
477
+ { src : `${ sourceBuildDir } /content-script.js.map` , dst : 'content-script.js.map' } ,
478
+ { src : `${ sourceBuildDir } /background.js.map` , dst : 'background.js.map' } ,
479
+ { src : `${ sourceBuildDir } /popup.js.map` , dst : 'popup.js.map' } ,
480
+ { src : `${ sourceBuildDir } /IndependentPanel.js.map` , dst : 'IndependentPanel.js.map' } ,
481
+ ] ) ,
469
482
]
470
483
471
484
// chromium
0 commit comments