Skip to content

Commit

Permalink
better meta url polyfill (#5738)
Browse files Browse the repository at this point in the history
* better meta url polyfill

* Create quick-experts-shave.md

* update
  • Loading branch information
Feiyang1 committed Nov 17, 2021
1 parent 6f0049e commit ce39a1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/quick-experts-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/firestore": patch
---

better meta url polyfill
19 changes: 18 additions & 1 deletion packages/firestore/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ import { generateBuildTargetReplaceConfig } from '../../scripts/build/rollup_rep

const util = require('./rollup.shared');

// Customize how import.meta.url is polyfilled in cjs nodejs build. We use it to be able to use require() in esm.
// It only generates the nodejs version of the polyfill, as opposed to the default polyfill which
// supports both browser and nodejs. The browser support is unnecessary and doesn't work well with Jest. See https://github.com/firebase/firebase-js-sdk/issues/5687
function importMetaUrlPolyfillPlugin() {
return {
name: 'import-meta-url-current-module',
resolveImportMeta(property, { moduleId }) {
if (property === 'url') {
// copied from rollup output
return `new (require('url').URL)('file:' + __filename).href`;
}
return null;
}
};
}

const nodePlugins = function () {
return [
typescriptPlugin({
Expand Down Expand Up @@ -105,7 +121,8 @@ const allBuilds = [
},
plugins: [
...util.es2017ToEs5Plugins(/* mangled= */ false),
replace(generateBuildTargetReplaceConfig('cjs', 2017))
replace(generateBuildTargetReplaceConfig('cjs', 2017)),
importMetaUrlPolyfillPlugin()
],
external: util.resolveNodeExterns,
treeshake: {
Expand Down

0 comments on commit ce39a1a

Please sign in to comment.