Skip to content

Commit 49dccbe

Browse files
committed
fix: add test, keep backwards compatibility
1 parent 2e76d9a commit 49dccbe

File tree

6 files changed

+59
-70
lines changed

6 files changed

+59
-70
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"exports": {
77
".": {
88
"import": {
9-
"types": "./dist/esm/index.d.ts",
10-
"default": "./dist/esm/index.js"
9+
"types": "./dist/lib.d.ts",
10+
"default": "./dist/lib.js"
1111
},
1212
"require": {
13-
"types": "./dist/cjs/index.d.ts",
14-
"default": "./dist/cjs/index.js"
13+
"types": "./dist/cjs/lib.d.ts",
14+
"default": "./dist/cjs/lib.js"
1515
}
1616
}
1717
},
@@ -22,7 +22,7 @@
2222
"url": "https://github.com/mongodb-js/mongodb-mcp-server.git"
2323
},
2424
"bin": {
25-
"mongodb-mcp-server": "dist/cjs/index.js"
25+
"mongodb-mcp-server": "dist/index.js"
2626
},
2727
"publishConfig": {
2828
"access": "public"
@@ -33,10 +33,10 @@
3333
"build:update-package-info": "tsx scripts/update-package-info.ts",
3434
"build:esm": "tsc --project tsconfig.esm.json",
3535
"build:cjs": "tsc --project tsconfig.cjs.json",
36-
"build:package-json": "echo '{\"type\":\"module\"}' > dist/esm/package.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
37-
"build:chmod": "chmod +x dist/cjs/index.js",
36+
"build:package-json": "echo '{\"type\":\"module\"}' > dist/package.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
37+
"build:chmod": "chmod +x dist/index.js",
3838
"build": "npm run build:clean && npm run build:update-package-info && npm run build:esm && npm run build:cjs && npm run build:package-json && npm run build:chmod",
39-
"inspect": "npm run build && mcp-inspector -- dist/cjs/index.js",
39+
"inspect": "npm run build && mcp-inspector -- dist/index.js",
4040
"prettier": "prettier",
4141
"check": "npm run build && npm run check:types && npm run check:lint && npm run check:format",
4242
"check:lint": "eslint .",

src/lib.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { Server, type ServerOptions } from "./server.js";
2+
export { Telemetry } from "./telemetry/telemetry.js";
3+
export { Session, type SessionOptions } from "./common/session.js";
4+
export type { UserConfig, ConnectOptions } from "./common/config.js";

test-dual-modules.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/build/test-dual-modules.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/integration/build.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { createRequire } from "module";
2+
import path from "path";
3+
import { fileURLToPath } from "url";
4+
import { describe, it, expect } from "vitest";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
describe("Build Test", () => {
10+
it("should successfully require CommonJS module", () => {
11+
const require = createRequire(__filename);
12+
const cjsPath = path.resolve(__dirname, "../../dist/cjs/lib.js");
13+
14+
const cjsModule = require(cjsPath) as Record<string, unknown>;
15+
16+
expect(cjsModule).toBeDefined();
17+
expect(typeof cjsModule).toBe("object");
18+
});
19+
20+
it("should successfully import ESM module", async () => {
21+
const esmPath = path.resolve(__dirname, "../../dist/lib.js");
22+
23+
const esmModule = (await import(esmPath)) as Record<string, unknown>;
24+
25+
expect(esmModule).toBeDefined();
26+
expect(typeof esmModule).toBe("object");
27+
});
28+
29+
it("should have matching exports between CommonJS and ESM modules", async () => {
30+
// Import CommonJS module
31+
const require = createRequire(__filename);
32+
const cjsPath = path.resolve(__dirname, "../../dist/cjs/lib.js");
33+
const cjsModule = require(cjsPath) as Record<string, unknown>;
34+
35+
// Import ESM module
36+
const esmPath = path.resolve(__dirname, "../../dist/lib.js");
37+
const esmModule = (await import(esmPath)) as Record<string, unknown>;
38+
39+
// Compare exports
40+
const cjsKeys = Object.keys(cjsModule).sort();
41+
const esmKeys = Object.keys(esmModule).sort();
42+
43+
expect(cjsKeys).toEqual(esmKeys);
44+
expect(cjsKeys).toEqual(["Server", "Session", "Telemetry"]);
45+
});
46+
});

tsconfig.esm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"compilerOptions": {
44
"module": "esnext",
55
"moduleResolution": "bundler",
6-
"outDir": "./dist/esm",
6+
"outDir": "./dist",
77
"declaration": true,
88
"declarationMap": true
99
}

0 commit comments

Comments
 (0)