Skip to content

Commit 5e5c412

Browse files
authored
Provide ESM modules from webchannel-wrapper (#7228)
1 parent 1d6771e commit 5e5c412

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

.changeset/strong-ghosts-compare.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/webchannel-wrapper': patch
3+
---
4+
5+
Make webchannel-wrapper exports Node-ESM-friendly.

packages/webchannel-wrapper/gulpfile.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ const commonjs = require('@rollup/plugin-commonjs');
2626
const rollupSourcemaps = require('rollup-plugin-sourcemaps');
2727
const typescriptPlugin = require('rollup-plugin-typescript2');
2828
const typescript = require('typescript');
29+
const pkg = require('./package.json');
30+
31+
// Copied from "../../scripts/build/rollup_emit_module_package_file" which is ESM
32+
// and would require converting this file to MJS to use
33+
function emitModulePackageFile() {
34+
return {
35+
generateBundle() {
36+
this.emitFile({
37+
fileName: 'package.json',
38+
source: `{"type":"module"}`,
39+
type: 'asset'
40+
});
41+
},
42+
name: 'emit-module-package-file'
43+
};
44+
}
2945

3046
// The optimization level for the JS compiler.
3147
// Valid levels: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS.
@@ -114,13 +130,29 @@ function createRollupTask({
114130
})
115131
);
116132
}
133+
if (format === 'es') {
134+
plugins.push(emitModulePackageFile());
135+
}
117136
const inputOptions = {
118137
input: inputPath,
119138
plugins
120139
};
121140

141+
let outputFilename;
142+
if (format === 'es') {
143+
if (compileToES5) {
144+
// ESM5
145+
outputFilename = pkg.esm5;
146+
} else {
147+
// ESM2017
148+
outputFilename = pkg.module;
149+
}
150+
} else {
151+
// CJS
152+
outputFilename = pkg.main;
153+
}
122154
const outputOptions = {
123-
file: `dist/index${outputExtension ? '.' : ''}${outputExtension}.js`,
155+
file: outputFilename,
124156
format,
125157
sourcemap: true,
126158
// Prevents warning when compiling CJS that there are named and default exports together.

packages/webchannel-wrapper/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"description": "A wrapper of the webchannel packages from closure-library for use outside of a closure compiled application",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.js",
7-
"module": "dist/index.esm2017.js",
8-
"esm5": "dist/index.esm.js",
7+
"module": "dist/esm/index.esm2017.js",
8+
"esm5": "dist/esm/index.esm.js",
99
"exports": {
1010
".": {
1111
"types": "./src/index.d.ts",
1212
"require": "./dist/index.js",
13-
"esm5": "./dist/index.esm.js",
14-
"default": "./dist/index.esm2017.js"
13+
"esm5": "./dist/esm/index.esm.js",
14+
"default": "./dist/esm/index.esm2017.js"
1515
},
1616
"./package.json": "./package.json"
1717
},

0 commit comments

Comments
 (0)