Skip to content

Commit

Permalink
Add a Node ESM build to RUT (#6360)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 committed Jun 14, 2022
1 parent 8f82660 commit b091b02
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-starfishes-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/rules-unit-testing': patch
---

Add Node ESM build to rules-unit-testing.
11 changes: 11 additions & 0 deletions packages/rules-unit-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
"description": "",
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
"main": "dist/index.cjs.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"node": {
"import": "./dist/esm/index.esm.js",
"require": "./dist/index.cjs.js"
},
"default": "./dist/index.cjs.js"
},
"./package.json": "./package.json"
},
"engines": {
"node": ">=10.10.0"
},
Expand Down
34 changes: 28 additions & 6 deletions packages/rules-unit-testing/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,42 @@
import typescriptPlugin from 'rollup-plugin-typescript2';
import pkg from './package.json';
import typescript from 'typescript';
import { emitModulePackageFile } from '../../scripts/build/rollup_emit_module_package_file';

const plugins = [
typescriptPlugin({
typescript
})
];

const es2017BuildPlugins = [
typescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
}
})
];

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);

export default {
input: 'index.ts',
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
plugins: [...plugins],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
};
export default [
{
input: 'index.ts',
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
plugins: [...plugins],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
{
input: 'index.ts',
output: [
{ file: pkg.exports['.'].node.import, format: 'es', sourcemap: true }
],
plugins: [...es2017BuildPlugins, emitModulePackageFile()],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

0 comments on commit b091b02

Please sign in to comment.