Skip to content

Commit f054321

Browse files
committed
chore: enable esModuleInterop
- Enable esModuleInterop in tsconfig.release.json for better CJS/ESM interop. - Update unit tests and source code to use default imports for CJS modules (fs, nock, jsonwebtoken, etc.) to align with new compiler settings.
1 parent dece9a9 commit f054321

File tree

8 files changed

+16
-26
lines changed

8 files changed

+16
-26
lines changed

mocha/setup.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
import * as chai from "chai";
2-
import * as chaiAsPromisedModule from "chai-as-promised";
3-
import * as nockModule from "nock";
4-
5-
// Normalize CommonJS exports so ts-node (Node.js 20) and Node.js 22's strip-only loader
6-
// both receive callable modules without relying on esModuleInterop.
7-
type ChaiPlugin = Parameters<typeof chai.use>[0];
8-
type NockModule = typeof nockModule;
9-
10-
const chaiAsPromisedExport = chaiAsPromisedModule as ChaiPlugin & { default?: ChaiPlugin };
11-
const chaiAsPromised = chaiAsPromisedExport.default ?? chaiAsPromisedExport;
12-
const nockExport = nockModule as NockModule & { default?: NockModule };
13-
const nock = nockExport.default ?? nockExport;
1+
import chai from "chai";
2+
import chaiAsPromised from "chai-as-promised";
3+
import nock from "nock";
144

155
chai.use(chaiAsPromised);
16-
17-
nock.disableNetConnect();
6+
nock.disableNetConnect();

spec/common/config.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
// SOFTWARE.
2222

2323
import { expect } from "chai";
24-
import * as fs from "fs";
25-
import * as process from "process";
24+
import fs from "fs";
2625
import * as sinon from "sinon";
2726

2827
import { firebaseConfig, resetCache } from "../../src/common/config";

spec/fixtures/mockrequest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { EventEmitter } from 'node:stream';
22

3-
import * as jwt from 'jsonwebtoken';
4-
import * as jwkToPem from 'jwk-to-pem';
5-
import * as nock from 'nock';
3+
import jwt from 'jsonwebtoken';
4+
import jwkToPem from 'jwk-to-pem';
5+
import nock from 'nock';
66
import * as mockJWK from '../fixtures/credential/jwk.json';
77
import * as mockKey from '../fixtures/credential/key.json';
88

src/bin/firebase-functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// SOFTWARE.
2424

2525
import * as http from "http";
26-
import * as express from "express";
26+
import express from "express";
2727
import * as fs from "fs/promises";
2828
import * as path from "path";
2929
import { loadStack } from "../runtime/loader";

src/common/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppOptions } from "firebase-admin/app";
2-
import { readFileSync } from "fs";
2+
import fs from "fs";
33
import * as path from "path";
44

55
import * as logger from "../logger";
@@ -29,7 +29,7 @@ export function firebaseConfig(): AppOptions | null {
2929
// explicitly state that the user can set the env to a file:
3030
// https://firebase.google.com/docs/admin/setup#initialize-without-parameters
3131
if (!env.startsWith("{")) {
32-
env = readFileSync(path.join(process.env.PWD, env)).toString("utf8");
32+
env = fs.readFileSync(path.join(process.env.PWD, env)).toString("utf8");
3333
}
3434

3535
cache = JSON.parse(env);

src/common/providers/https.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
import * as cors from "cors";
23+
import cors from "cors";
2424
import * as express from "express";
2525
import { DecodedAppCheckToken } from "firebase-admin/app-check";
2626

src/v2/providers/https.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @packageDocumentation
2626
*/
2727

28-
import * as cors from "cors";
28+
import cors from "cors";
2929
import * as express from "express";
3030
import { convertIfPresent, convertInvoker, copyIfPresent } from "../../common/encoding";
3131
import { wrapTraceContext } from "../trace";
@@ -48,7 +48,8 @@ import * as options from "../options";
4848
import { withInit } from "../../common/onInit";
4949
import * as logger from "../../logger";
5050

51-
export { Request, CallableRequest, CallableResponse, FunctionsErrorCode, HttpsError };
51+
export { HttpsError };
52+
export type { Request, CallableRequest, CallableResponse, FunctionsErrorCode };
5253

5354
/**
5455
* Options that can be set on an onRequest HTTPS function.

tsconfig.release.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"stripInternal": true,
1010
"target": "es2022",
1111
"useDefineForClassFields": false,
12+
"esModuleInterop": true,
1213
"typeRoots": ["./node_modules/@types"]
1314
},
1415
"files": [

0 commit comments

Comments
 (0)