From 678ca76e26a303fced935a4ca136d8d319a7cf6a Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Fri, 14 Apr 2023 10:51:35 -0700 Subject: [PATCH 1/2] Provide modules from webchannel-wrapper --- packages/webchannel-wrapper/gulpfile.js | 36 +++++++++++++++++++++++- packages/webchannel-wrapper/package.json | 8 +++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/webchannel-wrapper/gulpfile.js b/packages/webchannel-wrapper/gulpfile.js index de51bc0ded1..2f1055a0b50 100644 --- a/packages/webchannel-wrapper/gulpfile.js +++ b/packages/webchannel-wrapper/gulpfile.js @@ -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. @@ -114,13 +130,31 @@ 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. diff --git a/packages/webchannel-wrapper/package.json b/packages/webchannel-wrapper/package.json index 35217bc539f..8da5215f8da 100644 --- a/packages/webchannel-wrapper/package.json +++ b/packages/webchannel-wrapper/package.json @@ -4,14 +4,14 @@ "description": "A wrapper of the webchannel packages from closure-library for use outside of a closure compiled application", "author": "Firebase (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" }, From f6f286af1b8dab7326f24c9ed029ae1e10b23e3f Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Fri, 14 Apr 2023 11:52:01 -0700 Subject: [PATCH 2/2] format, changeset --- .changeset/strong-ghosts-compare.md | 5 +++++ packages/webchannel-wrapper/gulpfile.js | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 .changeset/strong-ghosts-compare.md diff --git a/.changeset/strong-ghosts-compare.md b/.changeset/strong-ghosts-compare.md new file mode 100644 index 00000000000..348ce8ddb0b --- /dev/null +++ b/.changeset/strong-ghosts-compare.md @@ -0,0 +1,5 @@ +--- +'@firebase/webchannel-wrapper': patch +--- + +Make webchannel-wrapper exports Node-ESM-friendly. diff --git a/packages/webchannel-wrapper/gulpfile.js b/packages/webchannel-wrapper/gulpfile.js index 2f1055a0b50..820f7ea537e 100644 --- a/packages/webchannel-wrapper/gulpfile.js +++ b/packages/webchannel-wrapper/gulpfile.js @@ -131,9 +131,7 @@ function createRollupTask({ ); } if (format === 'es') { - plugins.push( - emitModulePackageFile() - ); + plugins.push(emitModulePackageFile()); } const inputOptions = { input: inputPath,