Skip to content

Commit

Permalink
fix: replace .mjs with .js extension for browser modules (#887)
Browse files Browse the repository at this point in the history
The Babel interpretation should be used when modules are
imported for the browser, which is not the case if the
extension is .mjs (in which case Node interpretation is used).
See https://esbuild.github.io/content-types/#default-interop
  • Loading branch information
steabert authored Jan 12, 2024
1 parent 49a1763 commit 4a67ac8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
6 changes: 3 additions & 3 deletions overlay/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ if (!existsSync(buildDir)) {

for (
const output of [
{ format: 'esm', ext: 'mjs' },
{ format: 'cjs', ext: 'cjs' },
{ format: 'esm', name: 'index-esm.js' },
{ format: 'cjs', name: 'index-cjs.js' },
]
) {
buildSync({
platform: 'browser',
entryPoints: ['src/index.ts'],
outfile: join(buildDir, `index.${output.ext}`),
outfile: join(buildDir, output.name),
format: output.format,
external: ['@juggle/resize-observer', 'react', 'react-dom', 'pepjs'],
bundle: true,
Expand Down
11 changes: 6 additions & 5 deletions overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"registry": "https://registry.npmjs.org/"
},
"types": "./dist/index.d.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"main": "./dist/index-cjs.js",
"module": "./dist/index-esm.js",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
"require": "./dist/index-cjs.js",
"import": "./dist/index-esm.js"
},
"files": [
"dist/**/*",
Expand All @@ -31,7 +31,8 @@
"@juggle/resize-observer": "^3.3.1",
"pepjs": ">= 0.4.3 < 1",
"react": "^17.0.1 || ^18.0.0",
"react-dom": "^17.0.1 || ^18.0.0"
"react-dom": "^17.0.1 || ^18.0.0",
"styled-components": "^5.3.5"
},
"devDependencies": {
"@juggle/resize-observer": "3.4.0",
Expand Down
4 changes: 2 additions & 2 deletions player/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ if (!existsSync(buildDir)) {
}

const bundles = [
{ format: 'esm', name: 'index.mjs' },
{ format: 'cjs', name: 'index.cjs' },
{ format: 'esm', name: 'index-esm.js' },
{ format: 'cjs', name: 'index-cjs.js' },
]

for (
Expand Down
8 changes: 4 additions & 4 deletions player/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"registry": "https://registry.npmjs.org/"
},
"types": "./dist/index.d.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"main": "./dist/index-cjs.js",
"module": "./dist/index-esm.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
"require": "./dist/index-cjs.js",
"import": "./dist/index-esm.js"
}
},
"files": [
Expand Down
8 changes: 4 additions & 4 deletions streams/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ if (!existsSync(buildDir)) {
const browserBundles = [
{
format: 'esm',
name: 'browser.mjs',
name: 'browser-esm.js',
external: ['debug', 'ts-md5', 'ws'],
inject: ['polyfill.mjs'],
},
{
format: 'cjs',
name: 'browser.cjs',
name: 'browser-cjs.js',
external: ['debug', 'ts-md5', 'ws'],
inject: ['polyfill.mjs'],
},
{
format: 'esm',
name: 'browser-light.mjs',
name: 'browser-light-esm.js',
external: ['buffer', 'debug', 'process', 'stream', 'ts-md5', 'ws'],
},
{
format: 'cjs',
name: 'browser-light.cjs',
name: 'browser-light-cjs.js',
external: ['buffer', 'debug', 'process', 'stream', 'ts-md5', 'ws'],
},
]
Expand Down
12 changes: 6 additions & 6 deletions streams/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"types": "./dist/src/index.browser.d.ts",
"browser": {
"types": "./dist/src/index.browser.d.ts",
"require": "./dist/browser.cjs",
"import": "./dist/browser.mjs"
"require": "./dist/browser-cjs.js",
"import": "./dist/browser-esm.js"
},
"node": {
"types": "./dist/src/index.node.d.ts",
Expand All @@ -35,13 +35,13 @@
},
"./light": {
"types": "./dist/src/index.browser.d.ts",
"require": "./dist/browser-light.cjs",
"import": "./dist/browser-light.mjs"
"require": "./dist/browser-light-cjs.js",
"import": "./dist/browser-light-esm.js"
}
},
"browser": {
"./dist/node.cjs": "./dist/browser.cjs",
"./dist/node.mjs": "./dist/browser.mjs",
"./dist/node.cjs": "./dist/browser-cjs.js",
"./dist/node.mjs": "./dist/browser-esm.js",
"stream": "stream-browserify"
},
"files": [
Expand Down

0 comments on commit 4a67ac8

Please sign in to comment.