@@ -792,7 +792,10 @@ function buildConfiguration(test, baseline, realConfig, scenario, testDirectory)
792792 ? path . resolve (
793793 testDirectory ,
794794 config . entry
795- ? / \. (?: c | m ) ? j s $ / . test ( config . entry )
795+ ? // Keep entries that already have an extension (JS or HTML).
796+ // Bare names still get `.js` — the historical default entry shape.
797+ / \. (?: c | m ) ? j s $ / i. test ( config . entry ) ||
798+ / \. h t m l $ / i. test ( config . entry )
796799 ? config . entry
797800 : `${ config . entry } .js`
798801 : "./index.js"
@@ -868,6 +871,51 @@ function addBuildBench({
868871 ) ;
869872}
870873
874+ /**
875+ * Resolve the on-disk file the watch scenario rewrites to trigger a rebuild.
876+ * @param {NonNullable<Configuration["entry"]> } entry webpack entry
877+ * @returns {string } absolute path of one entry file
878+ */
879+ const resolveWatchEntryPath = ( entry ) => {
880+ if ( typeof entry === "string" ) return path . resolve ( entry ) ;
881+ if ( Array . isArray ( entry ) ) {
882+ const first = entry . find ( ( item ) => typeof item === "string" ) ;
883+ if ( typeof first === "string" ) return path . resolve ( first ) ;
884+ } else if ( entry && typeof entry === "object" ) {
885+ for ( const value of Object . values ( entry ) ) {
886+ if ( typeof value === "string" ) return path . resolve ( value ) ;
887+ if ( Array . isArray ( value ) ) {
888+ const first = value . find ( ( item ) => typeof item === "string" ) ;
889+ if ( typeof first === "string" ) return path . resolve ( first ) ;
890+ } else if (
891+ value &&
892+ typeof value === "object" &&
893+ "import" in value &&
894+ value . import
895+ ) {
896+ const imp = value . import ;
897+ if ( typeof imp === "string" ) return path . resolve ( imp ) ;
898+ if ( Array . isArray ( imp ) ) {
899+ const first = imp . find ( ( item ) => typeof item === "string" ) ;
900+ if ( typeof first === "string" ) return path . resolve ( first ) ;
901+ }
902+ }
903+ }
904+ }
905+ throw new Error ( "Watch bench needs a string path in `entry`." ) ;
906+ } ;
907+
908+ /**
909+ * Append a no-op change that keeps the entry parseable (JS statement or HTML comment).
910+ * @param {string } entryPath entry file path
911+ * @param {string } originalContent original file contents
912+ * @returns {string } mutated contents
913+ */
914+ const mutateWatchEntryContent = ( entryPath , originalContent ) =>
915+ / \. h t m l $ / i. test ( entryPath )
916+ ? `${ originalContent } <!-- watch test -->`
917+ : `${ originalContent } ;console.log('watch test')` ;
918+
871919/**
872920 * @param {object } params params
873921 * @param {Bench } params.bench bench
@@ -882,7 +930,7 @@ async function addWatchBench({ bench, taskName, collectBy, webpack, config }) {
882930 throw new Error ( `No entry for "${ taskName } " bench.` ) ;
883931 }
884932
885- const entry = path . resolve ( /** @type { string } */ ( config . entry ) ) ;
933+ const entry = resolveWatchEntryPath ( config . entry ) ;
886934 const originalEntryContent = await fs . readFile ( entry , "utf8" ) ;
887935
888936 /** @type {Watching | undefined } */
@@ -937,7 +985,7 @@ async function addWatchBench({ bench, taskName, collectBy, webpack, config }) {
937985 ( resolve , reject ) => {
938986 writeFile (
939987 entry ,
940- ` ${ originalEntryContent } ;console.log('watch test')` ,
988+ mutateWatchEntryContent ( entry , originalEntryContent ) ,
941989 ( err ) => {
942990 if ( err ) {
943991 reject ( err ) ;
0 commit comments