From 0bab0b7a786d1563bf665904c7097d1fe06efce5 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Tue, 31 Jan 2023 12:02:30 -0800 Subject: [PATCH] Add CJS browser entry points for all packages (#6981) --- .changeset/ninety-taxis-study.md | 19 +++ packages/auth-compat/package.json | 6 +- packages/auth-compat/rollup.config.js | 13 ++ packages/auth/package.json | 12 +- packages/auth/rollup.config.js | 12 ++ packages/database-compat/package.json | 8 +- packages/database/package.json | 6 +- packages/database/rollup.config.js | 19 +++ packages/firebase/package.json | 170 +++++++++++++++++---- packages/firestore-compat/package.json | 6 +- packages/firestore-compat/rollup.config.js | 12 ++ packages/firestore/package.json | 12 +- packages/firestore/rollup.config.js | 24 ++- packages/firestore/rollup.config.lite.js | 16 ++ packages/functions-compat/package.json | 6 +- packages/functions-compat/rollup.config.js | 10 ++ packages/functions/package.json | 6 +- packages/functions/rollup.config.js | 13 ++ packages/messaging-compat/package.json | 2 +- packages/messaging/package.json | 11 +- packages/messaging/sw/package.json | 2 +- packages/rules-unit-testing/package.json | 6 +- packages/storage/package.json | 6 +- packages/storage/rollup.config.js | 20 +++ packages/template/package.json | 6 +- packages/template/rollup.config.js | 10 ++ packages/util/package.json | 6 +- packages/util/rollup.config.js | 10 ++ 28 files changed, 393 insertions(+), 56 deletions(-) create mode 100644 .changeset/ninety-taxis-study.md diff --git a/.changeset/ninety-taxis-study.md b/.changeset/ninety-taxis-study.md new file mode 100644 index 00000000000..05a7cf02cf6 --- /dev/null +++ b/.changeset/ninety-taxis-study.md @@ -0,0 +1,19 @@ +--- +'@firebase/auth': patch +'@firebase/auth-compat': patch +'@firebase/database': patch +'@firebase/database-compat': patch +'firebase': patch +'@firebase/firestore': patch +'@firebase/firestore-compat': patch +'@firebase/functions': patch +'@firebase/functions-compat': patch +'@firebase/messaging': patch +'@firebase/messaging-compat': patch +'@firebase/rules-unit-testing': patch +'@firebase/storage': patch +'@firebase/template': patch +'@firebase/util': patch +--- + +Added browser CJS entry points (expected by Jest when using JSDOM mode). diff --git a/packages/auth-compat/package.json b/packages/auth-compat/package.json index da5829e7e0a..507b6f1dbb0 100644 --- a/packages/auth-compat/package.json +++ b/packages/auth-compat/package.json @@ -16,7 +16,11 @@ "require": "./dist/index.node.cjs.js" }, "esm5": "./dist/index.esm.js", - "default": "./dist/index.esm2017.js" + "default": "./dist/index.esm2017.js", + "browser": { + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm2017.js" + } }, "./package.json": "./package.json" }, diff --git a/packages/auth-compat/rollup.config.js b/packages/auth-compat/rollup.config.js index 5b767355657..cb3491541c4 100644 --- a/packages/auth-compat/rollup.config.js +++ b/packages/auth-compat/rollup.config.js @@ -73,6 +73,19 @@ const browserBuilds = [ treeshake: { moduleSideEffects: false } + }, + { + input: 'index.ts', + output: { + file: 'dist/index.cjs.js', + format: 'cjs', + sourcemap: true + }, + plugins: es2017BuildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + treeshake: { + moduleSideEffects: false + } } ]; diff --git a/packages/auth/package.json b/packages/auth/package.json index b3b7d5c537f..70900487fdd 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -31,7 +31,11 @@ "default": "./dist/index.webworker.esm5.js" }, "esm5": "./dist/esm5/index.js", - "default": "./dist/esm2017/index.js" + "default": "./dist/esm2017/index.js", + "browser": { + "require": "./dist/browser-cjs/index.js", + "import": "./dist/esm2017/index.js" + } }, "./cordova": { "types": "./dist/cordova/index.cordova.d.ts", @@ -57,7 +61,11 @@ "default": "./dist/cordova/internal.js" }, "esm5": "./dist/esm5/internal.js", - "default": "./dist/esm2017/internal.js" + "default": "./dist/esm2017/internal.js", + "browser": { + "require": "./dist/browser-cjs/internal.js", + "import": "./dist/esm2017/internal.js" + } }, "./package.json": "./package.json" }, diff --git a/packages/auth/rollup.config.js b/packages/auth/rollup.config.js index bea0d0d7135..01e358a9aff 100644 --- a/packages/auth/rollup.config.js +++ b/packages/auth/rollup.config.js @@ -97,6 +97,18 @@ const browserBuilds = [ replace(generateBuildTargetReplaceConfig('esm', 2017)) ], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + }, + { + input: { + index: 'index.ts', + internal: 'internal/index.ts' + }, + output: [{ dir: 'dist/browser-cjs', format: 'cjs', sourcemap: true }], + plugins: [ + ...es2017BuildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 2017)) + ], + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; diff --git a/packages/database-compat/package.json b/packages/database-compat/package.json index 9262c1a2ced..6850d3581bf 100644 --- a/packages/database-compat/package.json +++ b/packages/database-compat/package.json @@ -22,7 +22,11 @@ "require": "./dist/index.js" }, "esm5": "./dist/index.esm5.js", - "default": "./dist/index.esm2017.js" + "default": "./dist/index.esm2017.js", + "browser": { + "require": "./dist/index.js", + "import": "./dist/index.esm2017.js" + } }, "./standalone": { "types": "./dist/database-compat/src/index.standalone.d.ts", @@ -64,4 +68,4 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" } -} \ No newline at end of file +} diff --git a/packages/database/package.json b/packages/database/package.json index af93208a9e5..d8cc37c497e 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -17,7 +17,11 @@ }, "esm5": "./dist/index.esm5.js", "standalone": "./dist/index.standalone.js", - "default": "./dist/index.esm2017.js" + "default": "./dist/index.esm2017.js", + "browser": { + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm2017.js" + } }, "./package.json": "./package.json" }, diff --git a/packages/database/rollup.config.js b/packages/database/rollup.config.js index d1ba71f14da..886a177e4d9 100644 --- a/packages/database/rollup.config.js +++ b/packages/database/rollup.config.js @@ -94,6 +94,25 @@ const browserBuilds = [ }, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), onwarn: onWarn + }, + { + input: 'src/index.ts', + output: [ + { + file: 'dist/index.cjs.js', + format: 'cjs', + sourcemap: true + } + ], + plugins: [ + ...es2017BuildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 2017)) + ], + treeshake: { + moduleSideEffects: false + }, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + onwarn: onWarn } ]; diff --git a/packages/firebase/package.json b/packages/firebase/package.json index 00bda033db5..6d982103ad8 100644 --- a/packages/firebase/package.json +++ b/packages/firebase/package.json @@ -29,7 +29,11 @@ "require": "./analytics/dist/index.cjs.js", "import": "./analytics/dist/index.mjs" }, - "default": "./analytics/dist/esm/index.esm.js" + "default": "./analytics/dist/esm/index.esm.js", + "browser": { + "require": "./analytics/dist/index.cjs.js", + "import": "./analytics/dist/esm/index.esm.js" + } }, "./app": { "types": "./app/dist/app/index.d.ts", @@ -37,7 +41,11 @@ "require": "./app/dist/index.cjs.js", "import": "./app/dist/index.mjs" }, - "default": "./app/dist/esm/index.esm.js" + "default": "./app/dist/esm/index.esm.js", + "browser": { + "require": "./app/dist/index.cjs.js", + "import": "./app/dist/esm/index.esm.js" + } }, "./app-check": { "types": "./app-check/dist/app-check/index.d.ts", @@ -45,7 +53,11 @@ "require": "./app-check/dist/index.cjs.js", "import": "./app-check/dist/index.mjs" }, - "default": "./app-check/dist/esm/index.esm.js" + "default": "./app-check/dist/esm/index.esm.js", + "browser": { + "require": "./app-check/dist/index.cjs.js", + "import": "./app-check/dist/esm/index.esm.js" + } }, "./auth": { "types": "./auth/dist/auth/index.d.ts", @@ -53,7 +65,11 @@ "require": "./auth/dist/index.cjs.js", "import": "./auth/dist/index.mjs" }, - "default": "./auth/dist/esm/index.esm.js" + "default": "./auth/dist/esm/index.esm.js", + "browser": { + "require": "./auth/dist/index.cjs.js", + "import": "./auth/dist/esm/index.esm.js" + } }, "./auth/cordova": { "types": "./auth/cordova/dist/auth/cordova/index.d.ts", @@ -61,7 +77,11 @@ "require": "./auth/cordova/dist/index.cjs.js", "import": "./auth/cordova/dist/index.mjs" }, - "default": "./auth/cordova/dist/esm/index.esm.js" + "default": "./auth/cordova/dist/esm/index.esm.js", + "browser": { + "require": "./auth/cordova/dist/index.cjs.js", + "import": "./auth/cordova/dist/esm/index.esm.js" + } }, "./auth/react-native": { "types": "./auth/react-native/dist/auth/react-native/index.d.ts", @@ -69,7 +89,11 @@ "require": "./auth/react-native/dist/index.cjs.js", "import": "./auth/react-native/dist/index.mjs" }, - "default": "./auth/react-native/dist/esm/index.esm.js" + "default": "./auth/react-native/dist/esm/index.esm.js", + "browser": { + "require": "./auth/react-native/dist/index.cjs.js", + "import": "./auth/react-native/dist/esm/index.esm.js" + } }, "./database": { "types": "./database/dist/database/index.d.ts", @@ -77,7 +101,11 @@ "require": "./database/dist/index.cjs.js", "import": "./database/dist/index.mjs" }, - "default": "./database/dist/esm/index.esm.js" + "default": "./database/dist/esm/index.esm.js", + "browser": { + "require": "./database/dist/index.cjs.js", + "import": "./database/dist/esm/index.esm.js" + } }, "./firestore": { "types": "./firestore/dist/firestore/index.d.ts", @@ -85,7 +113,11 @@ "require": "./firestore/dist/index.cjs.js", "import": "./firestore/dist/index.mjs" }, - "default": "./firestore/dist/esm/index.esm.js" + "default": "./firestore/dist/esm/index.esm.js", + "browser": { + "require": "./firestore/dist/index.cjs.js", + "import": "./firestore/dist/esm/index.esm.js" + } }, "./firestore/lite": { "types": "./firestore/lite/dist/firestore/lite/index.d.ts", @@ -93,7 +125,11 @@ "require": "./firestore/lite/dist/index.cjs.js", "import": "./firestore/lite/dist/index.mjs" }, - "default": "./firestore/lite/dist/esm/index.esm.js" + "default": "./firestore/lite/dist/esm/index.esm.js", + "browser": { + "require": "./firestore/lite/dist/index.cjs.js", + "import": "./firestore/lite/dist/esm/index.esm.js" + } }, "./functions": { "types": "./functions/dist/functions/index.d.ts", @@ -101,7 +137,11 @@ "require": "./functions/dist/index.cjs.js", "import": "./functions/dist/index.mjs" }, - "default": "./functions/dist/esm/index.esm.js" + "default": "./functions/dist/esm/index.esm.js", + "browser": { + "require": "./functions/dist/index.cjs.js", + "import": "./functions/dist/esm/index.esm.js" + } }, "./installations": { "types": "./installations/dist/installations/index.d.ts", @@ -109,7 +149,11 @@ "require": "./installations/dist/index.cjs.js", "import": "./installations/dist/index.mjs" }, - "default": "./installations/dist/esm/index.esm.js" + "default": "./installations/dist/esm/index.esm.js", + "browser": { + "require": "./installations/dist/index.cjs.js", + "import": "./installations/dist/esm/index.esm.js" + } }, "./messaging": { "types": "./messaging/dist/messaging/index.d.ts", @@ -117,7 +161,11 @@ "require": "./messaging/dist/index.cjs.js", "import": "./messaging/dist/index.mjs" }, - "default": "./messaging/dist/esm/index.esm.js" + "default": "./messaging/dist/esm/index.esm.js", + "browser": { + "require": "./messaging/dist/index.cjs.js", + "import": "./messaging/dist/esm/index.esm.js" + } }, "./messaging/sw": { "types": "./messaging/sw/dist/messaging/sw/index.d.ts", @@ -125,7 +173,11 @@ "require": "./messaging/sw/dist/index.cjs.js", "import": "./messaging/sw/dist/index.mjs" }, - "default": "./messaging/sw/dist/esm/index.esm.js" + "default": "./messaging/sw/dist/esm/index.esm.js", + "browser": { + "require": "./messaging/sw/dist/index.cjs.js", + "import": "./messaging/sw/dist/esm/index.esm.js" + } }, "./performance": { "types": "./performance/dist/performance/index.d.ts", @@ -133,7 +185,11 @@ "require": "./performance/dist/index.cjs.js", "import": "./performance/dist/index.mjs" }, - "default": "./performance/dist/esm/index.esm.js" + "default": "./performance/dist/esm/index.esm.js", + "browser": { + "require": "./performance/dist/index.cjs.js", + "import": "./performance/dist/esm/index.esm.js" + } }, "./remote-config": { "types": "./remote-config/dist/remote-config/index.d.ts", @@ -141,7 +197,11 @@ "require": "./remote-config/dist/index.cjs.js", "import": "./remote-config/dist/index.mjs" }, - "default": "./remote-config/dist/esm/index.esm.js" + "default": "./remote-config/dist/esm/index.esm.js", + "browser": { + "require": "./remote-config/dist/index.cjs.js", + "import": "./remote-config/dist/esm/index.esm.js" + } }, "./storage": { "types": "./storage/dist/storage/index.d.ts", @@ -149,7 +209,11 @@ "require": "./storage/dist/index.cjs.js", "import": "./storage/dist/index.mjs" }, - "default": "./storage/dist/esm/index.esm.js" + "default": "./storage/dist/esm/index.esm.js", + "browser": { + "require": "./storage/dist/index.cjs.js", + "import": "./storage/dist/esm/index.esm.js" + } }, "./compat/analytics": { "types": "./compat/analytics/dist/compat/analytics/index.d.ts", @@ -157,7 +221,11 @@ "require": "./compat/analytics/dist/index.cjs.js", "import": "./compat/analytics/dist/index.mjs" }, - "default": "./compat/analytics/dist/esm/index.esm.js" + "default": "./compat/analytics/dist/esm/index.esm.js", + "browser": { + "require": "./compat/analytics/dist/index.cjs.js", + "import": "./compat/analytics/dist/esm/index.esm.js" + } }, "./compat/app": { "types": "./compat/app/dist/compat/app/index.d.ts", @@ -165,7 +233,11 @@ "require": "./compat/app/dist/index.cjs.js", "import": "./compat/app/dist/index.mjs" }, - "default": "./compat/app/dist/esm/index.esm.js" + "default": "./compat/app/dist/esm/index.esm.js", + "browser": { + "require": "./compat/app/dist/index.cjs.js", + "import": "./compat/app/dist/esm/index.esm.js" + } }, "./compat/app-check": { "types": "./compat/app-check/dist/compat/app-check/index.d.ts", @@ -173,7 +245,11 @@ "require": "./compat/app-check/dist/index.cjs.js", "import": "./compat/app-check/dist/index.mjs" }, - "default": "./compat/app-check/dist/esm/index.esm.js" + "default": "./compat/app-check/dist/esm/index.esm.js", + "browser": { + "require": "./compat/app-check/dist/index.cjs.js", + "import": "./compat/app-check/dist/esm/index.esm.js" + } }, "./compat/auth": { "types": "./compat/auth/dist/compat/auth/index.d.ts", @@ -181,7 +257,11 @@ "require": "./compat/auth/dist/index.cjs.js", "import": "./compat/auth/dist/index.mjs" }, - "default": "./compat/auth/dist/esm/index.esm.js" + "default": "./compat/auth/dist/esm/index.esm.js", + "browser": { + "require": "./compat/auth/dist/index.cjs.js", + "import": "./compat/auth/dist/esm/index.esm.js" + } }, "./compat/database": { "types": "./compat/database/dist/compat/database/index.d.ts", @@ -189,7 +269,11 @@ "require": "./compat/database/dist/index.cjs.js", "import": "./compat/database/dist/index.mjs" }, - "default": "./compat/database/dist/esm/index.esm.js" + "default": "./compat/database/dist/esm/index.esm.js", + "browser": { + "require": "./compat/database/dist/index.cjs.js", + "import": "./compat/database/dist/esm/index.esm.js" + } }, "./compat/firestore": { "types": "./compat/firestore/dist/compat/firestore/index.d.ts", @@ -197,7 +281,11 @@ "require": "./compat/firestore/dist/index.cjs.js", "import": "./compat/firestore/dist/index.mjs" }, - "default": "./compat/firestore/dist/esm/index.esm.js" + "default": "./compat/firestore/dist/esm/index.esm.js", + "browser": { + "require": "./compat/firestore/dist/index.cjs.js", + "import": "./compat/firestore/dist/esm/index.esm.js" + } }, "./compat/functions": { "types": "./compat/functions/dist/compat/functions/index.d.ts", @@ -205,7 +293,11 @@ "require": "./compat/functions/dist/index.cjs.js", "import": "./compat/functions/dist/index.mjs" }, - "default": "./compat/functions/dist/esm/index.esm.js" + "default": "./compat/functions/dist/esm/index.esm.js", + "browser": { + "require": "./compat/functions/dist/index.cjs.js", + "import": "./compat/functions/dist/esm/index.esm.js" + } }, "./compat/installations": { "types": "./compat/installations/dist/compat/installations/index.d.ts", @@ -213,7 +305,11 @@ "require": "./compat/installations/dist/index.cjs.js", "import": "./compat/installations/dist/index.mjs" }, - "default": "./compat/installations/dist/esm/index.esm.js" + "default": "./compat/installations/dist/esm/index.esm.js", + "browser": { + "require": "./compat/installations/dist/index.cjs.js", + "import": "./compat/installations/dist/esm/index.esm.js" + } }, "./compat/messaging": { "types": "./compat/messaging/dist/compat/messaging/index.d.ts", @@ -221,7 +317,11 @@ "require": "./compat/messaging/dist/index.cjs.js", "import": "./compat/messaging/dist/index.mjs" }, - "default": "./compat/messaging/dist/esm/index.esm.js" + "default": "./compat/messaging/dist/esm/index.esm.js", + "browser": { + "require": "./compat/messaging/dist/index.cjs.js", + "import": "./compat/messaging/dist/esm/index.esm.js" + } }, "./compat/performance": { "types": "./compat/performance/dist/compat/performance/index.d.ts", @@ -229,7 +329,11 @@ "require": "./compat/performance/dist/index.cjs.js", "import": "./compat/performance/dist/index.mjs" }, - "default": "./compat/performance/dist/esm/index.esm.js" + "default": "./compat/performance/dist/esm/index.esm.js", + "browser": { + "require": "./compat/performance/dist/index.cjs.js", + "import": "./compat/performance/dist/esm/index.esm.js" + } }, "./compat/remote-config": { "types": "./compat/remote-config/dist/compat/remote-config/index.d.ts", @@ -237,7 +341,11 @@ "require": "./compat/remote-config/dist/index.cjs.js", "import": "./compat/remote-config/dist/index.mjs" }, - "default": "./compat/remote-config/dist/esm/index.esm.js" + "default": "./compat/remote-config/dist/esm/index.esm.js", + "browser": { + "require": "./compat/remote-config/dist/index.cjs.js", + "import": "./compat/remote-config/dist/esm/index.esm.js" + } }, "./compat/storage": { "types": "./compat/storage/dist/compat/storage/index.d.ts", @@ -245,7 +353,11 @@ "require": "./compat/storage/dist/index.cjs.js", "import": "./compat/storage/dist/index.mjs" }, - "default": "./compat/storage/dist/esm/index.esm.js" + "default": "./compat/storage/dist/esm/index.esm.js", + "browser": { + "require": "./compat/storage/dist/index.cjs.js", + "import": "./compat/storage/dist/esm/index.esm.js" + } }, "./package.json": "./package.json" }, @@ -321,4 +433,4 @@ "database" ], "typings": "empty.d.ts" -} \ No newline at end of file +} diff --git a/packages/firestore-compat/package.json b/packages/firestore-compat/package.json index 483a7e557c7..2321b49048b 100644 --- a/packages/firestore-compat/package.json +++ b/packages/firestore-compat/package.json @@ -17,7 +17,11 @@ }, "react-native": "./dist/index.rn.js", "esm5": "./dist/index.esm5.js", - "default": "./dist/index.esm2017.js" + "default": "./dist/index.esm2017.js", + "browser": { + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm2017.js" + } }, "./package.json": "./package.json" }, diff --git a/packages/firestore-compat/rollup.config.js b/packages/firestore-compat/rollup.config.js index ebf87c79e15..ecf6d42ca91 100644 --- a/packages/firestore-compat/rollup.config.js +++ b/packages/firestore-compat/rollup.config.js @@ -68,6 +68,18 @@ const browserBuilds = [ ], plugins: es5Plugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + }, + { + input: './src/index.ts', + output: [ + { + file: 'dist/index.cjs.js', + format: 'cjs', + sourcemap: true + } + ], + plugins: es2017Plugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; diff --git a/packages/firestore/package.json b/packages/firestore/package.json index 800ecf7db6b..b3931e38840 100644 --- a/packages/firestore/package.json +++ b/packages/firestore/package.json @@ -56,7 +56,11 @@ }, "react-native": "./dist/index.rn.js", "esm5": "./dist/index.esm5.js", - "default": "./dist/index.esm2017.js" + "default": "./dist/index.esm2017.js", + "browser": { + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm2017.js" + } }, "./lite": { "types": "./dist/lite/index.d.ts", @@ -66,7 +70,11 @@ }, "react-native": "./dist/lite/index.rn.esm2017.js", "esm5": "./dist/lite/index.browser.esm5.js", - "default": "./dist/lite/index.browser.esm2017.js" + "default": "./dist/lite/index.browser.esm2017.js", + "browser": { + "require": "./dist/lite/index.cjs.js", + "import": "./dist/lite/index.browser.esm2017.js" + } }, "./package.json": "./package.json" }, diff --git a/packages/firestore/rollup.config.js b/packages/firestore/rollup.config.js index cdde1fd83ab..21b984ab929 100644 --- a/packages/firestore/rollup.config.js +++ b/packages/firestore/rollup.config.js @@ -69,8 +69,8 @@ const browserPlugins = function () { }; const allBuilds = [ - // Intermidiate Node ESM build without build target reporting - // this is an intermidiate build used to generate the actual esm and cjs builds + // Intermediate Node ESM build without build target reporting + // this is an intermediate build used to generate the actual esm and cjs builds // which add build target reporting { input: './src/index.node.ts', @@ -117,8 +117,8 @@ const allBuilds = [ moduleSideEffects: false } }, - // Intermidiate browser build without build target reporting - // this is an intermidiate build used to generate the actual esm and cjs builds + // Intermediate browser build without build target reporting + // this is an intermediate build used to generate the actual esm and cjs builds // which add build target reporting { input: './src/index.ts', @@ -152,6 +152,22 @@ const allBuilds = [ moduleSideEffects: false } }, + // Convert es2017 build to cjs + { + input: pkg['browser'], + output: [ + { + file: './dist/index.cjs.js', + format: 'cjs', + sourcemap: true + } + ], + plugins: [replace(generateBuildTargetReplaceConfig('cjs', 2017))], + external: util.resolveBrowserExterns, + treeshake: { + moduleSideEffects: false + } + }, // es2017 build with build target reporting { input: pkg['browser'], diff --git a/packages/firestore/rollup.config.lite.js b/packages/firestore/rollup.config.lite.js index af2f510838f..ed11e40f6b8 100644 --- a/packages/firestore/rollup.config.lite.js +++ b/packages/firestore/rollup.config.lite.js @@ -171,6 +171,22 @@ const allBuilds = [ moduleSideEffects: false } }, + // Convert es2017 build to CJS + { + input: path.resolve('./lite', pkg.browser), + output: [ + { + file: './dist/lite/index.cjs.js', + format: 'es', + sourcemap: true + } + ], + plugins: [replace(generateBuildTargetReplaceConfig('cjs', 2017))], + external: util.resolveBrowserExterns, + treeshake: { + moduleSideEffects: false + } + }, // Browser es2017 build { input: path.resolve('./lite', pkg.browser), diff --git a/packages/functions-compat/package.json b/packages/functions-compat/package.json index 85ac2bed069..7aef9212356 100644 --- a/packages/functions-compat/package.json +++ b/packages/functions-compat/package.json @@ -15,7 +15,11 @@ "require": "./dist/index.node.cjs.js" }, "esm5": "./dist/index.esm5.js", - "default": "./dist/index.esm2017.js" + "default": "./dist/index.esm2017.js", + "browser": { + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm2017.js" + } }, "./package.json": "./package.json" }, diff --git a/packages/functions-compat/rollup.config.js b/packages/functions-compat/rollup.config.js index 74a738a1c92..949aeebd513 100644 --- a/packages/functions-compat/rollup.config.js +++ b/packages/functions-compat/rollup.config.js @@ -60,6 +60,16 @@ const browserBuilds = [ }, plugins: es2017BuildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + }, + { + input: 'src/index.ts', + output: { + file: './dist/index.cjs.js', + format: 'cjs', + sourcemap: true + }, + plugins: es2017BuildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; diff --git a/packages/functions/package.json b/packages/functions/package.json index ab044778319..111c399cd5d 100644 --- a/packages/functions/package.json +++ b/packages/functions/package.json @@ -15,7 +15,11 @@ "require": "./dist/index.node.cjs.js" }, "esm5": "./dist/index.esm.js", - "default": "./dist/index.esm2017.js" + "default": "./dist/index.esm2017.js", + "browser": { + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm2017.js" + } }, "./package.json": "./package.json" }, diff --git a/packages/functions/rollup.config.js b/packages/functions/rollup.config.js index f535171ee9e..bb5506ea9b5 100644 --- a/packages/functions/rollup.config.js +++ b/packages/functions/rollup.config.js @@ -68,6 +68,19 @@ const browserBuilds = [ ...es2017BuildPlugins, replace(generateBuildTargetReplaceConfig('esm', 2017)) ] + }, + { + input: 'src/index.ts', + output: { + file: './dist/index.cjs.js', + format: 'cjs', + sourcemap: true + }, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: [ + ...es2017BuildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 2017)) + ] } ]; diff --git a/packages/messaging-compat/package.json b/packages/messaging-compat/package.json index 68a6ec867be..d7e16e813fd 100644 --- a/packages/messaging-compat/package.json +++ b/packages/messaging-compat/package.json @@ -11,7 +11,7 @@ "exports": { ".": { "types": "./dist/src/index.d.ts", - "node": "./dist/index.cjs.js", + "require": "./dist/index.cjs.js", "esm5": "./dist/esm/index.esm.js", "default": "./dist/esm/index.esm2017.js" }, diff --git a/packages/messaging/package.json b/packages/messaging/package.json index 5f09f0d1f78..aeee75a58fb 100644 --- a/packages/messaging/package.json +++ b/packages/messaging/package.json @@ -6,22 +6,21 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "sw": "dist/index.sw.esm2017.js", + "sw": "dist/esm/index.sw.esm2017.js", "sw-main": "dist/index.sw.cjs", "esm5": "dist/esm/index.esm.js", "exports": { ".": { "types": "./dist/index-public.d.ts", - "node": "./dist/index.cjs.js", - "browser": "./dist/esm/index.esm2017.js", + "require": "./dist/index.cjs.js", "module": "./dist/esm/index.esm2017.js", "esm5": "./dist/esm/index.esm.js", - "default": "./dist/index.cjs.js" + "default": "./dist/esm/index.esm2017.js" }, "./sw": { "types": "./dist/sw/index-public.d.ts", - "node": "./dist/index.sw.cjs", - "default": "./dist/index.sw.esm2017.js" + "require": "./dist/index.sw.cjs", + "default": "./dist/esm/index.sw.esm2017.js" }, "./package.json": "./package.json" }, diff --git a/packages/messaging/sw/package.json b/packages/messaging/sw/package.json index 98f4f9711b6..472e37684bc 100644 --- a/packages/messaging/sw/package.json +++ b/packages/messaging/sw/package.json @@ -3,6 +3,6 @@ "description": "", "author": "Firebase (https://firebase.google.com/)", "main": "../dist/index.sw.cjs", - "module": "../dist/index.sw.esm2017.js", + "module": "../dist/esm/index.sw.esm2017.js", "typings": "../dist/src/index.sw.d.ts" } diff --git a/packages/rules-unit-testing/package.json b/packages/rules-unit-testing/package.json index c796541fa3c..f2a838736b2 100644 --- a/packages/rules-unit-testing/package.json +++ b/packages/rules-unit-testing/package.json @@ -11,7 +11,11 @@ "import": "./dist/esm/index.esm.js", "require": "./dist/index.cjs.js" }, - "default": "./dist/index.cjs.js" + "default": "./dist/index.cjs.js", + "browser": { + "require": "./dist/index.cjs.js", + "import": "./dist/esm/index.esm.js" + } }, "./package.json": "./package.json" }, diff --git a/packages/storage/package.json b/packages/storage/package.json index 6ecf2e42a0c..cb77dbc746a 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -15,7 +15,11 @@ "default": "./dist/index.node.cjs.js" }, "esm5": "./dist/index.esm5.js", - "default": "./dist/index.esm2017.js" + "default": "./dist/index.esm2017.js", + "browser": { + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm2017.js" + } }, "./package.json": "./package.json" }, diff --git a/packages/storage/rollup.config.js b/packages/storage/rollup.config.js index 4bcb603de3a..73c9d7561aa 100644 --- a/packages/storage/rollup.config.js +++ b/packages/storage/rollup.config.js @@ -99,6 +99,26 @@ const browserBuilds = [ moduleSideEffects: false } }, + { + input: './src/index.ts', + output: { + file: './dist/index.cjs.js', + format: 'cjs', + sourcemap: true + }, + plugins: [ + alias(generateAliasConfig('browser')), + ...es2017Plugins, + replace({ + ...generateBuildTargetReplaceConfig('cjs', 2017), + '__RUNTIME_ENV__': '' + }) + ], + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + treeshake: { + moduleSideEffects: false + } + }, { // needed by Emulator UI input: './src/index.ts', diff --git a/packages/template/package.json b/packages/template/package.json index 892332529a4..1bab48a2749 100644 --- a/packages/template/package.json +++ b/packages/template/package.json @@ -16,7 +16,11 @@ "require": "./dist/index.node.cjs.js" }, "esm5": "./dist/index.esm5.js", - "default": "./dist/index.esm2017.js" + "default": "./dist/index.esm2017.js", + "browser": { + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm2017.js" + } }, "./package.json": "./package.json" }, diff --git a/packages/template/rollup.config.js b/packages/template/rollup.config.js index 5c95031f734..0417ac2a28d 100644 --- a/packages/template/rollup.config.js +++ b/packages/template/rollup.config.js @@ -57,6 +57,16 @@ const browserBuilds = [ }, plugins: es2017BuildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + }, + { + input: 'index.ts', + output: { + file: './dist/index.cjs.js', + format: 'cjs', + sourcemap: true + }, + plugins: es2017BuildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; diff --git a/packages/util/package.json b/packages/util/package.json index 518b71c6cd3..42b766c8513 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -15,7 +15,11 @@ "require": "./dist/index.node.cjs.js" }, "esm5": "./dist/index.esm5.js", - "default": "./dist/index.esm2017.js" + "default": "./dist/index.esm2017.js", + "browser": { + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm2017.js" + } }, "./package.json": "./package.json" }, diff --git a/packages/util/rollup.config.js b/packages/util/rollup.config.js index 4bd11731821..8f0d1312bfa 100644 --- a/packages/util/rollup.config.js +++ b/packages/util/rollup.config.js @@ -57,6 +57,16 @@ const browserBuilds = [ }, plugins: es2017BuildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + }, + { + input: 'index.ts', + output: { + file: './dist/index.cjs.js', + format: 'cjs', + sourcemap: true + }, + plugins: es2017BuildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ];