refactor: Bundle browser-test-runner#3333
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request refactors the browser-test-runner package to introduce Rollup-based bundling, modernize the module system to ESM, and improve path resolution for better compatibility with Electron and Karma test environments.
- Introduced Rollup bundling to generate CommonJS, ES module, and Electron preload outputs
- Migrated from CommonJS
requireto ES moduleimportsyntax - Updated path resolution to use
fileURLToPathandimport.meta.urlfor ESM compatibility
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
packages/browser-test-runner/tsconfig.json |
Updated TypeScript compiler options to use module: "preserve" and moduleResolution: "bundler" for better bundler compatibility |
packages/browser-test-runner/src/karma-setup.js |
Changed from CommonJS require to ES module import for the expect library |
packages/browser-test-runner/src/createWebpackConfig.ts |
Explicitly set timers: false in webpack fallback configuration |
packages/browser-test-runner/src/createKarmaConfig.ts |
Updated path resolution to use fileURLToPath and import.meta.url for locating setup and preload files in ESM context |
packages/browser-test-runner/rollup.config.mts |
Added new Rollup configuration to bundle exports (CJS and ESM), preload file (CJS), karma-setup (ESM), and TypeScript declarations |
packages/browser-test-runner/package.json |
Updated entry points to use bundled outputs, added build scripts, and added Rollup-related devDependencies |
package-lock.json |
Updated lock file with new dependencies for Rollup, rimraf, tsx, and their transitive dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "dist/preload.cjs", | ||
| "dist/karma-setup.js", |
There was a problem hiding this comment.
The files field specifies dist/karma-setup.js and dist/preload.cjs which are generated by the rollup bundler, but it doesn't include the sourcemap files that are generated alongside them. According to the rollup.config.mts, all bundled outputs have sourcemap: true, which means .map files will be generated. These sourcemap files should either be included in the published package (recommended for debugging) or explicitly excluded from the files array. Consider adding dist/karma-setup.js.map and dist/preload.cjs.map to the files array, or add !**/*.map to explicitly exclude them if they shouldn't be published.
| "dist/preload.cjs", | |
| "dist/karma-setup.js", | |
| "dist/preload.cjs", | |
| "dist/preload.cjs.map", | |
| "dist/karma-setup.js", | |
| "dist/karma-setup.js.map", |
This pull request refactors the build and packaging process for the
browser-test-runnerpackage, introducing Rollup for bundling, improving module resolution, and updating various scripts and dependencies. The changes make the package outputs more consistent, enhance compatibility (especially for Electron and Karma), and modernize the codebase with ES module syntax and improved path handling.Changes
Build & packaging improvements:
rollup.config.mtsconfiguration to bundle outputs for CommonJS, ES modules, Electron preload, and type declarations using Rollup.package.jsonto definemain,module, andtypesentry points, specify more granular files for publishing, and add build scripts (prebuild,postbuild,reset-self).package.json.tsconfig.jsonto use"module": "preserve"and"moduleResolution": "bundler"for better compatibility with modern bundlers.Code modernization & compatibility:
requireto ES moduleimportsyntax inkarma-setup.jsforexpect.createKarmaConfig.tsto usefileURLToPathandimport.meta.urlfor locating setup and preload files, ensuring compatibility with ESM and Electron environments. [1] [2]createWebpackConfig.tsto explicitly settimers: falsein thefallbackobject for module resolution.