Skip to content

Provide ESM modules from webchannel-wrapper #7228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strong-ghosts-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/webchannel-wrapper': patch
---

Make webchannel-wrapper exports Node-ESM-friendly.
34 changes: 33 additions & 1 deletion packages/webchannel-wrapper/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ const commonjs = require('@rollup/plugin-commonjs');
const rollupSourcemaps = require('rollup-plugin-sourcemaps');
const typescriptPlugin = require('rollup-plugin-typescript2');
const typescript = require('typescript');
const pkg = require('./package.json');

// Copied from "../../scripts/build/rollup_emit_module_package_file" which is ESM
// and would require converting this file to MJS to use
function emitModulePackageFile() {
return {
generateBundle() {
this.emitFile({
fileName: 'package.json',
source: `{"type":"module"}`,
type: 'asset'
});
},
name: 'emit-module-package-file'
};
}

// The optimization level for the JS compiler.
// Valid levels: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS.
Expand Down Expand Up @@ -114,13 +130,29 @@ function createRollupTask({
})
);
}
if (format === 'es') {
plugins.push(emitModulePackageFile());
}
const inputOptions = {
input: inputPath,
plugins
};

let outputFilename;
if (format === 'es') {
if (compileToES5) {
// ESM5
outputFilename = pkg.esm5;
} else {
// ESM2017
outputFilename = pkg.module;
}
} else {
// CJS
outputFilename = pkg.main;
}
const outputOptions = {
file: `dist/index${outputExtension ? '.' : ''}${outputExtension}.js`,
file: outputFilename,
format,
sourcemap: true,
// Prevents warning when compiling CJS that there are named and default exports together.
Expand Down
8 changes: 4 additions & 4 deletions packages/webchannel-wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"description": "A wrapper of the webchannel packages from closure-library for use outside of a closure compiled application",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"main": "dist/index.js",
"module": "dist/index.esm2017.js",
"esm5": "dist/index.esm.js",
"module": "dist/esm/index.esm2017.js",
"esm5": "dist/esm/index.esm.js",
"exports": {
".": {
"types": "./src/index.d.ts",
"require": "./dist/index.js",
"esm5": "./dist/index.esm.js",
"default": "./dist/index.esm2017.js"
"esm5": "./dist/esm/index.esm.js",
"default": "./dist/esm/index.esm2017.js"
},
"./package.json": "./package.json"
},
Expand Down