Skip to content

Commit 678ca76

Browse files
committed
Provide modules from webchannel-wrapper
1 parent ecb4454 commit 678ca76

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

packages/webchannel-wrapper/gulpfile.js

+35-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,31 @@ function createRollupTask({
114130
})
115131
);
116132
}
133+
if (format === 'es') {
134+
plugins.push(
135+
emitModulePackageFile()
136+
);
137+
}
117138
const inputOptions = {
118139
input: inputPath,
119140
plugins
120141
};
121142

143+
let outputFilename;
144+
if (format === 'es') {
145+
if (compileToES5) {
146+
// ESM5
147+
outputFilename = pkg.esm5;
148+
} else {
149+
// ESM2017
150+
outputFilename = pkg.module;
151+
}
152+
} else {
153+
// CJS
154+
outputFilename = pkg.main;
155+
}
122156
const outputOptions = {
123-
file: `dist/index${outputExtension ? '.' : ''}${outputExtension}.js`,
157+
file: outputFilename,
124158
format,
125159
sourcemap: true,
126160
// 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)