Skip to content

Commit 26051f0

Browse files
authored
Merge 3ef41c0 into df8ec42
2 parents df8ec42 + 3ef41c0 commit 26051f0

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

packages/firestore/rollup.config.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,30 @@ const util = require('./rollup.shared');
3535
// Customize how import.meta.url is polyfilled in cjs nodejs build. We use it to
3636
// be able to use require() in esm. It only generates the nodejs version of the
3737
// polyfill, as opposed to the default polyfill which supports both browser and
38-
// nodejs. The browser support is unnecessary and doesn't work well with Jest.
38+
// nodejs. The browser support doesn't work well with Jest.
3939
// See https://github.com/firebase/firebase-js-sdk/issues/5687
40+
// Although this is a cjs Node build and shouldn't require the browser option,
41+
// Vercel apps using this break on deployment, but work in local development.
42+
// See https://github.com/firebase/firebase-js-sdk/issues/5823
4043
function importMetaUrlPolyfillPlugin(filename) {
4144
return {
4245
name: 'import-meta-url-current-module',
4346
resolveImportMeta(property, { moduleId }) {
4447
if (property === 'url') {
45-
// copied from rollup output
48+
// Added a check for Jest (see issue 5687 linked above)
49+
// See https://jestjs.io/docs/environment-variables - apparently
50+
// these are not always both set.
51+
const JEST_CHECK =
52+
`typeof process !== 'undefined' && process.env !== undefined` +
53+
` && (process.env.JEST_WORKER_ID !== undefined || ` +
54+
`process.env.NODE_ENV === 'test')`;
55+
// Copied from rollup output
4656
return (
47-
"(typeof document === 'undefined' ? new (require('url').URL)" +
48-
"('file:' + __filename).href : (document.currentScript && " +
57+
`((typeof document === 'undefined' || (${JEST_CHECK})) ?` +
58+
` new (require('url').URL)` +
59+
`('file:' + __filename).href : (document.currentScript && ` +
4960
`document.currentScript.src || new URL('${filename}', ` +
50-
'document.baseURI).href))'
61+
`document.baseURI).href))`
5162
);
5263
}
5364
return null;

0 commit comments

Comments
 (0)