Skip to content

Commit d82f3e5

Browse files
authored
feat: enable ESM support via dual-publishing (#1750)
- Configure tsdown to build both CJS and ESM outputs. - Update package.json exports to support both 'require' and 'import'. - Fix type hygiene issues by using explicit 'export type'. - Update protos/update.sh to generate ESM version of compiledFirestore and fix its imports for Node.js compatibility. - Configure build aliases to handle relative paths to protos correctly in both CJS and ESM builds. - Add packaging integration test to CI. ~Note: I enabled `esModuleInterop` in tsconfig.release.json to support default imports from CommonJS modules (like cors), which is required for proper ESM interop. This caused some chain-effect that required updating several unit tests and source files to use default imports for other CJS dependencies (e.g., fs, nock, jsonwebtoken) to align with the new compiler configuration.~ Fixed in #1751.
1 parent 8bf94c2 commit d82f3e5

24 files changed

+4951
-308
lines changed

.github/workflows/test.yaml

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,36 @@ jobs:
1414
strategy:
1515
matrix:
1616
node-version:
17-
- 24.x
17+
- 20.x
1818
steps:
19-
- uses: actions/checkout@v3
20-
with:
21-
fetch-depth: 0
22-
- uses: actions/setup-node@v3
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-node@v4
2321
with:
2422
node-version: ${{ matrix.node-version }}
2523
cache: npm
2624
- run: npm ci
2725
- run: npm run lint
26+
27+
build:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: actions/setup-node@v4
32+
with:
33+
node-version: 20.x
34+
cache: npm
35+
- run: npm ci
36+
- run: npm run build
37+
- run: npm pack
38+
- uses: actions/upload-artifact@v4
39+
with:
40+
name: lib
41+
path: lib/
42+
- uses: actions/upload-artifact@v4
43+
with:
44+
name: tarball
45+
path: firebase-functions-*.tgz
46+
2847
unit:
2948
runs-on: ubuntu-latest
3049
strategy:
@@ -35,19 +54,16 @@ jobs:
3554
- 22.x
3655
- 24.x
3756
steps:
38-
- uses: actions/checkout@v1
39-
- uses: actions/setup-node@v1
57+
- uses: actions/checkout@v4
58+
- uses: actions/setup-node@v4
4059
with:
4160
node-version: ${{ matrix.node-version }}
42-
- name: Cache npm
43-
uses: actions/cache@v4
44-
with:
45-
path: ~/.npm
46-
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
61+
cache: npm
4762
- run: npm ci
4863
- run: npm run test
64+
4965
integration:
50-
needs: "unit"
66+
needs: build
5167
runs-on: ubuntu-latest
5268
strategy:
5369
matrix:
@@ -57,14 +73,37 @@ jobs:
5773
- 22.x
5874
- 24.x
5975
steps:
60-
- uses: actions/checkout@v1
61-
- uses: actions/setup-node@v1
76+
- uses: actions/checkout@v4
77+
- uses: actions/setup-node@v4
6278
with:
6379
node-version: ${{ matrix.node-version }}
64-
- name: Cache npm
65-
uses: actions/cache@v4
66-
with:
67-
path: ~/.npm
68-
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
80+
cache: npm
6981
- run: npm ci
82+
- uses: actions/download-artifact@v4
83+
with:
84+
name: lib
85+
path: lib
7086
- run: npm run test:bin
87+
env:
88+
SKIP_BUILD: true
89+
90+
packaging:
91+
needs: build
92+
runs-on: ubuntu-latest
93+
strategy:
94+
matrix:
95+
node-version:
96+
- 18.x
97+
- 20.x
98+
- 22.x
99+
- 24.x
100+
steps:
101+
- uses: actions/checkout@v4
102+
- uses: actions/setup-node@v4
103+
with:
104+
node-version: ${{ matrix.node-version }}
105+
- uses: actions/download-artifact@v4
106+
with:
107+
name: tarball
108+
path: .
109+
- run: chmod +x ./scripts/test-packaging.sh && ./scripts/test-packaging.sh firebase-functions-*.tgz

eslint.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ module.exports = [
2222
"dist/",
2323
"spec/fixtures/",
2424
"scripts/**/*.js",
25+
"scripts/**/*.mjs",
2526
"protos/",
2627
".prettierrc.js",
27-
"eslint.config.js",
28+
"eslint.config.*",
29+
"tsdown.config.*",
2830
"scripts/bin-test/sources/esm-ext/index.mjs",
2931
],
3032
},

0 commit comments

Comments
 (0)