@@ -146,7 +146,11 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, sourceBuil
146146 // default none; override via BUILD_CACHE_COMPRESSION=gzip|brotli
147147 compression : cacheCompressionOption ?? false ,
148148 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+ ] ,
150154 } ,
151155 } ,
152156 optimization : {
@@ -391,14 +395,17 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, sourceBuil
391395 err ||
392396 ( stats && typeof stats . hasErrors === 'function' && stats . hasErrors ( ) )
393397 )
394- callback ( err , stats )
398+ const ret = callback ( err , stats )
395399 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 ( )
402409 }
403410 } )
404411 }
@@ -421,27 +428,24 @@ async function zipFolder(dir) {
421428}
422429
423430async function copyFiles ( entryPoints , targetDir ) {
424- if ( ! fs . existsSync ( targetDir ) ) await fs . mkdir ( targetDir , { recursive : true } )
431+ await fs . ensureDir ( targetDir )
425432 await Promise . all (
426433 entryPoints . map ( async ( entryPoint ) => {
427434 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
440444 }
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 )
442448 }
443- } catch ( e ) {
444- console . error ( 'Copy failed:' , entryPoint , e )
445449 throw e
446450 }
447451 } ) ,
@@ -466,6 +470,15 @@ async function finishOutput(outputDirSuffix, sourceBuildDir = outdir) {
466470
467471 { src : `${ sourceBuildDir } /IndependentPanel.js` , dst : 'IndependentPanel.js' } ,
468472 { 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+ ] ) ,
469482 ]
470483
471484 // chromium
0 commit comments