Skip to content

Commit

Permalink
Add Bun support
Browse files Browse the repository at this point in the history
This adds a `package.json` `"exports"` condition for Bun which always chooses the CommonJS version of the export (for both ESM & CJS).

This package uses `__esModule` to tell bundlers that it was ESM converted into CommonJS. Bun supports this both at runtime and when using the bundler, but Node.js does not support this at runtime and that causes a compatibility issue when importing `@playwright/test` (which is our fault). It's unfortunately a compatibility issue whether or not we support `__esModule`, because choosing to not support it breaks libraries which presently only work when using a bundler.

Since Bun automatically converts CommonJS <> ESM and `module.exports` with dynamic properties are supported, we can choose to always use the CommonJS entry point for Playwright in Bun.

There were other changes necessary to get Playwright to work, which are mostly in oven-sh/bun#7958
 

Signed-off-by: Jarred Sumner <[email protected]>
  • Loading branch information
Jarred-Sumner authored Jan 5, 2024
1 parent fad703d commit 86282b2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"exports": {
".": {
"types": "./index.d.ts",
"bun": "./index.js",
"import": "./index.mjs",
"require": "./index.js",
"default": "./index.js"
Expand All @@ -27,6 +28,7 @@
"./lib/internalsForTest": "./lib/internalsForTest.js",
"./lib/plugins": "./lib/plugins/index.js",
"./jsx-runtime": {
"bun": "./jsx-runtime.js",
"import": "./jsx-runtime.mjs",
"require": "./jsx-runtime.js",
"default": "./jsx-runtime.js"
Expand All @@ -41,6 +43,7 @@
},
"./test": {
"types": "./test.d.ts",
"bun": "./test.js",
"import": "./test.mjs",
"require": "./test.js",
"default": "./test.js"
Expand Down

0 comments on commit 86282b2

Please sign in to comment.