From 8d85f6be94cdcc33c49a6f5c71e80233fbb5b1ae Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Wed, 27 Nov 2024 16:40:58 -0330 Subject: [PATCH] Use alternative strategy that works better for ESM builds 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. --- constraints.pro | 2 +- initializeInpageProvider.d.ts | 5 +++++ initializeInpageProvider.js | 5 +++++ package.json | 14 +++++++++++--- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 initializeInpageProvider.d.ts create mode 100644 initializeInpageProvider.js diff --git a/constraints.pro b/constraints.pro index 8474011e..9b7b06c1 100644 --- a/constraints.pro +++ b/constraints.pro @@ -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". diff --git a/initializeInpageProvider.d.ts b/initializeInpageProvider.d.ts new file mode 100644 index 00000000..3cf80c10 --- /dev/null +++ b/initializeInpageProvider.d.ts @@ -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'; diff --git a/initializeInpageProvider.js b/initializeInpageProvider.js new file mode 100644 index 00000000..76b53ff4 --- /dev/null +++ b/initializeInpageProvider.js @@ -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'); diff --git a/package.json b/package.json index 3de8ccfc..0d24043b 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -70,6 +76,8 @@ "types": "./dist/index.d.cts", "files": [ "dist", + "initializeInpageProvider.d.ts", + "initializeInpageProvider.js", "stream-provider.js" ], "scripts": {