@@ -278,7 +278,12 @@ class EsbuildStep extends Step {
278278 constructor ( options , watchPaths = [ ] ) {
279279 // Starting esbuild steps in parallel showed longer overall time.
280280 super ( { concurrent : false } ) ;
281- this . _options = options ;
281+ options = {
282+ sourcemap : withSourceMaps ? 'linked' : false ,
283+ platform : 'node' ,
284+ format : 'cjs' ,
285+ ...options ,
286+ } ;
282287 this . _watchPaths = watchPaths ;
283288 if ( options . bundle ) {
284289 // For bundled outputs we always want a metafile so we can emit a
@@ -292,6 +297,7 @@ class EsbuildStep extends Step {
292297 if ( ! options . logOverride [ 'direct-eval' ] )
293298 options . logOverride [ 'direct-eval' ] = 'silent' ;
294299 }
300+ this . _options = options ;
295301 }
296302
297303 /** @override */
@@ -539,9 +545,6 @@ for (const pkg of workspace.packages()) {
539545 steps . push ( new EsbuildStep ( {
540546 entryPoints : [ path . join ( pkg . path , 'src/**/*.ts' ) ] ,
541547 outdir : `${ path . join ( pkg . path , 'lib' ) } ` ,
542- sourcemap : withSourceMaps ? 'linked' : false ,
543- platform : 'node' ,
544- format : 'cjs' ,
545548 plugins : [ dynamicImportToRequirePlugin ] ,
546549 } ) ) ;
547550}
@@ -565,9 +568,6 @@ steps.push(new EsbuildStep({
565568 filePath ( 'packages/playwright-core/src/tools/utils/socketConnection.ts' ) ,
566569 ] ,
567570 outdir : filePath ( 'packages/playwright-core/lib' ) ,
568- sourcemap : withSourceMaps ? 'linked' : false ,
569- platform : 'node' ,
570- format : 'cjs' ,
571571 plugins : [ dynamicImportToRequirePlugin ] ,
572572} ) ) ;
573573
@@ -578,55 +578,17 @@ steps.push(new EsbuildStep({
578578 bundle : true ,
579579 entryPoints : [ filePath ( 'packages/playwright-core/src/utilsBundle.ts' ) ] ,
580580 outfile : filePath ( 'packages/playwright-core/lib/utilsBundle.js' ) ,
581- sourcemap : withSourceMaps ? 'linked' : false ,
582- platform : 'node' ,
583- format : 'cjs' ,
584581 external : [ 'fsevents' , 'express' , '@anthropic-ai/sdk' ] ,
585582 alias : {
586583 'raw-body' : filePath ( 'utils/build/raw-body.ts' ) ,
587584 } ,
588585} , [ filePath ( 'packages/playwright-core/src/utilsBundle.ts' ) , filePath ( 'utils/build/raw-body.ts' ) ] ) ) ;
589586
590- // Any import whose specifier ends with `/utilsBundle` (relative, any
591- // depth — the dynamic-import-to-require plugin emits depth-based paths
592- // like `./utilsBundle`, `../utilsBundle`, `../../utilsBundle` depending
593- // on the source file) must be kept external and rewritten to the sibling
594- // `./utilsBundle` at bundle output level, because the bundle file lives
595- // at lib/coreBundle.js right next to lib/utilsBundle.js regardless of
596- // where the original source lived.
597- const externalizeUtilsBundlePlugin = {
598- name : 'externalize-utilsBundle' ,
599- setup ( build ) {
600- build . onResolve ( { filter : / u t i l s B u n d l e / } , args => {
601- // Bare absolute specifier used by the dynamic-import-to-require
602- // plugin for source files that live OUTSIDE playwright-core/src
603- // (e.g., packages/utils/*.ts). These end up inlined into
604- // coreBundle.js, so the runtime path resolves correctly against
605- // lib/coreBundle.js's sibling lib/utilsBundle.js.
606- if ( args . path === 'playwright-core/lib/utilsBundle' )
607- return { path : './utilsBundle' , external : true } ;
608- if ( ! args . path . startsWith ( '.' ) )
609- return ;
610- // Match `<depth>/utilsBundle` or `<depth>/utilsBundle.js` so
611- // depth-based relative paths like ./utilsBundle, ../utilsBundle,
612- // ../../utilsBundle all normalize to a single external at the
613- // bundle output level. The `.js` suffix form is used by direct
614- // require() call sites (e.g. tools/cli-client/program.ts).
615- if ( ! / ( ^ | \/ ) u t i l s B u n d l e ( \. j s ) ? $ / . test ( args . path ) )
616- return ;
617- return { path : './utilsBundle' , external : true } ;
618- } ) ;
619- } ,
620- } ;
621-
622587// Build playwright-core as a single bundle.
623588steps . push ( new EsbuildStep ( {
624589 bundle : true ,
625590 entryPoints : [ filePath ( 'packages/playwright-core/src/coreBundle.ts' ) ] ,
626591 outfile : filePath ( 'packages/playwright-core/lib/coreBundle.js' ) ,
627- sourcemap : withSourceMaps ? 'linked' : false ,
628- platform : 'node' ,
629- format : 'cjs' ,
630592 external : [
631593 '../../api.json' ,
632594 './help.json' ,
@@ -637,7 +599,11 @@ steps.push(new EsbuildStep({
637599 'chromium-bidi/*' ,
638600 'mitt' ,
639601 ] ,
640- plugins : [ externalizeUtilsBundlePlugin , dynamicImportToRequirePlugin ] ,
602+ plugins : [ {
603+ name : 'externalize-utilsBundle' ,
604+ setup : build => build . onResolve ( { filter : / u t i l s B u n d l e / } ,
605+ ( ) => ( { path : './utilsBundle' , external : true } ) ) ,
606+ } , dynamicImportToRequirePlugin ] ,
641607} , [ playwrightCoreSrc ] ) ) ;
642608
643609function assertCoreBundleHasNoNodeModules ( ) {
@@ -673,9 +639,6 @@ steps.push(new CustomCallbackStep(assertCoreBundleHasNoNodeModules));
673639 bundle : true ,
674640 entryPoints : [ filePath ( 'packages/playwright/src/transform/esmLoader.ts' ) ] ,
675641 outfile : filePath ( 'packages/playwright/lib/transform/esmLoader.js' ) ,
676- sourcemap : withSourceMaps ? 'linked' : false ,
677- platform : 'node' ,
678- format : 'cjs' ,
679642 external : [
680643 'playwright-core' ,
681644 'playwright-core/*' ,
@@ -696,9 +659,6 @@ steps.push(new EsbuildStep({
696659 filePath ( 'packages/playwright/src/mcp/**/*.ts' ) ,
697660 ] ,
698661 outdir : filePath ( 'packages/playwright/lib' ) ,
699- sourcemap : withSourceMaps ? 'linked' : false ,
700- platform : 'node' ,
701- format : 'cjs' ,
702662 plugins : [ dynamicImportToRequirePlugin ] ,
703663} ) ) ;
704664
@@ -709,9 +669,6 @@ steps.push(new EsbuildStep({
709669 bundle : true ,
710670 entryPoints : [ filePath ( 'packages/playwright/src/transform/babelBundle.ts' ) ] ,
711671 outfile : filePath ( 'packages/playwright/lib/transform/babelBundle.js' ) ,
712- sourcemap : withSourceMaps ? 'linked' : false ,
713- platform : 'node' ,
714- format : 'cjs' ,
715672 external : [
716673 '../package' ,
717674 ] ,
@@ -723,9 +680,6 @@ steps.push(new EsbuildStep({
723680 bundle : true ,
724681 entryPoints : [ filePath ( 'packages/playwright/src/matchers/expect.ts' ) ] ,
725682 outfile : filePath ( 'packages/playwright/lib/matchers/expect.js' ) ,
726- sourcemap : withSourceMaps ? 'linked' : false ,
727- platform : 'node' ,
728- format : 'cjs' ,
729683 external : [
730684 'playwright-core' ,
731685 'playwright-core/*' ,
@@ -741,9 +695,6 @@ steps.push(new EsbuildStep({
741695 bundle : true ,
742696 entryPoints : [ filePath ( 'packages/playwright/src/common/index.ts' ) ] ,
743697 outfile : filePath ( 'packages/playwright/lib/common/index.js' ) ,
744- sourcemap : withSourceMaps ? 'linked' : false ,
745- platform : 'node' ,
746- format : 'cjs' ,
747698 external : [
748699 'playwright-core' ,
749700 'playwright-core/*' ,
@@ -762,9 +713,6 @@ steps.push(new EsbuildStep({
762713 bundle : true ,
763714 entryPoints : [ filePath ( 'packages/playwright/src/runner/index.ts' ) ] ,
764715 outfile : filePath ( 'packages/playwright/lib/runner/index.js' ) ,
765- sourcemap : withSourceMaps ? 'linked' : false ,
766- platform : 'node' ,
767- format : 'cjs' ,
768716 external : [
769717 'playwright-core' ,
770718 'playwright-core/*' ,
@@ -786,9 +734,6 @@ steps.push(new EsbuildStep({
786734 bundle : true ,
787735 entryPoints : [ filePath ( 'packages/playwright/src/isomorphic/index.ts' ) ] ,
788736 outfile : filePath ( 'packages/playwright/lib/isomorphic.js' ) ,
789- sourcemap : withSourceMaps ? 'linked' : false ,
790- platform : 'node' ,
791- format : 'cjs' ,
792737 external : [
793738 ] ,
794739 plugins : [ dynamicImportToRequirePlugin ] ,
@@ -801,9 +746,6 @@ steps.push(new EsbuildStep({
801746 bundle : true ,
802747 entryPoints : [ filePath ( 'packages/playwright/src/loader/loaderProcessEntry.ts' ) ] ,
803748 outfile : filePath ( 'packages/playwright/lib/loader/loaderProcessEntry.js' ) ,
804- sourcemap : withSourceMaps ? 'linked' : false ,
805- platform : 'node' ,
806- format : 'cjs' ,
807749 external : [
808750 'playwright-core' ,
809751 'playwright-core/*' ,
@@ -823,9 +765,6 @@ steps.push(new EsbuildStep({
823765 bundle : true ,
824766 entryPoints : [ filePath ( 'packages/playwright/src/worker/workerProcessEntry.ts' ) ] ,
825767 outfile : filePath ( 'packages/playwright/lib/worker/workerProcessEntry.js' ) ,
826- sourcemap : withSourceMaps ? 'linked' : false ,
827- platform : 'node' ,
828- format : 'cjs' ,
829768 external : [
830769 'playwright-core' ,
831770 'playwright-core/*' ,
@@ -846,9 +785,6 @@ steps.push(new EsbuildStep({
846785 bundle : true ,
847786 entryPoints : [ filePath ( 'packages/playwright-core/src/server/electron/loader.ts' ) ] ,
848787 outfile : filePath ( 'packages/playwright-core/lib/server/electron/loader.js' ) ,
849- sourcemap : withSourceMaps ? 'linked' : false ,
850- platform : 'node' ,
851- format : 'cjs' ,
852788 external : [ 'electron' ] ,
853789} , [ playwrightCoreSrc ] ) ) ;
854790
0 commit comments