Skip to content

Commit

Permalink
Use alternative strategy that works better for ESM builds
Browse files Browse the repository at this point in the history
Add a new top-level export map entry for `initializeProvider` that maps
correctly onto CJS and ESM builds, and add a fallback JavaScript file
at the root of the repository for build systems that don't support
export maps.

This gives the best of both worlds: build systems that support exports
will behave correctly, and those that don't will get the CJS fallback.
  • Loading branch information
Gudahtt committed Nov 27, 2024
1 parent c242046 commit 8d85f6b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ gen_enforced_field(WorkspaceCwd, 'exports["./package.json"]', './package.json').

% The list of files included in the package must only include files generated
% during the build step.
gen_enforced_field(WorkspaceCwd, 'files', ['dist', 'stream-provider.js']).
gen_enforced_field(WorkspaceCwd, 'files', ['dist', 'initializeInpageProvider.d.ts', 'initializeInpageProvider.js', 'stream-provider.js']).

% If a dependency is listed under "dependencies", it should not be listed under
% "devDependencies".
Expand Down
5 changes: 5 additions & 0 deletions initializeInpageProvider.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable import/extensions */

// Re-exported for compatibility with build tools that don't support the
// `exports` field in package.json
export * from './dist/initializeInpageProvider.cjs';
5 changes: 5 additions & 0 deletions initializeInpageProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable import/extensions,import/no-unresolved */

// Re-exported for compatibility with build tools that don't support the
// `exports` field in package.json
module.exports = require('./dist/initializeInpageProvider.cjs');
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@
"default": "./dist/initializeInpageProvider.cjs"
}
},
"./dist/initializeInpageProvider.cjs": {
"types": "./dist/initializeInpageProvider.d.cts",
"default": "./dist/initializeInpageProvider.cjs"
"./initializeInpageProvider": {
"import": {
"types": "./dist/initializeInpageProvider.d.mts",
"default": "./dist/initializeInpageProvider.mjs"
},
"require": {
"types": "./dist/initializeInpageProvider.d.cts",
"default": "./dist/initializeInpageProvider.cjs"
}
},
"./stream-provider": {
"import": {
Expand All @@ -70,6 +76,8 @@
"types": "./dist/index.d.cts",
"files": [
"dist",
"initializeInpageProvider.d.ts",
"initializeInpageProvider.js",
"stream-provider.js"
],
"scripts": {
Expand Down

0 comments on commit 8d85f6b

Please sign in to comment.