Skip to content

Commit b091b02

Browse files
authored
Add a Node ESM build to RUT (#6360)
1 parent 8f82660 commit b091b02

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/rules-unit-testing': patch
3+
---
4+
5+
Add Node ESM build to rules-unit-testing.

packages/rules-unit-testing/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
"description": "",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.cjs.js",
7+
"exports": {
8+
".": {
9+
"types": "./dist/index.d.ts",
10+
"node": {
11+
"import": "./dist/esm/index.esm.js",
12+
"require": "./dist/index.cjs.js"
13+
},
14+
"default": "./dist/index.cjs.js"
15+
},
16+
"./package.json": "./package.json"
17+
},
718
"engines": {
819
"node": ">=10.10.0"
920
},

packages/rules-unit-testing/rollup.config.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,42 @@
1818
import typescriptPlugin from 'rollup-plugin-typescript2';
1919
import pkg from './package.json';
2020
import typescript from 'typescript';
21+
import { emitModulePackageFile } from '../../scripts/build/rollup_emit_module_package_file';
2122

2223
const plugins = [
2324
typescriptPlugin({
2425
typescript
2526
})
2627
];
2728

29+
const es2017BuildPlugins = [
30+
typescriptPlugin({
31+
typescript,
32+
tsconfigOverride: {
33+
compilerOptions: {
34+
target: 'es2017'
35+
}
36+
}
37+
})
38+
];
39+
2840
const deps = Object.keys(
2941
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
3042
);
3143

32-
export default {
33-
input: 'index.ts',
34-
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
35-
plugins: [...plugins],
36-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
37-
};
44+
export default [
45+
{
46+
input: 'index.ts',
47+
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
48+
plugins: [...plugins],
49+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
50+
},
51+
{
52+
input: 'index.ts',
53+
output: [
54+
{ file: pkg.exports['.'].node.import, format: 'es', sourcemap: true }
55+
],
56+
plugins: [...es2017BuildPlugins, emitModulePackageFile()],
57+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
58+
}
59+
];

0 commit comments

Comments
 (0)