Skip to content

Commit 2e76d9a

Browse files
committed
wip
1 parent c138c1e commit 2e76d9a

File tree

9 files changed

+106
-42
lines changed

9 files changed

+106
-42
lines changed

.github/workflows/prepare_release.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
id: bump-version
3333
run: |
3434
echo "NEW_VERSION=$(npm version ${{ inputs.version }} --no-git-tag-version)" >> $GITHUB_OUTPUT
35+
npm run build:update-version
3536
- name: Create release PR
3637
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # 7.0.8
3738
id: create-pr

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"name": "mongodb-mcp-server",
33
"description": "MongoDB Model Context Protocol Server",
44
"version": "0.1.3",
5-
"main": "dist/cjs/index.js",
6-
"module": "dist/esm/index.js",
7-
"types": "dist/cjs/index.d.ts",
5+
"type": "module",
86
"exports": {
97
".": {
108
"import": {
@@ -17,6 +15,7 @@
1715
}
1816
}
1917
},
18+
"main": "cjs/index.js",
2019
"author": "MongoDB <[email protected]>",
2120
"homepage": "https://github.com/mongodb-js/mongodb-mcp-server",
2221
"repository": {
@@ -31,11 +30,12 @@
3130
"scripts": {
3231
"prepare": "npm run build",
3332
"build:clean": "rm -rf dist",
33+
"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",
3636
"build:package-json": "echo '{\"type\":\"module\"}' > dist/esm/package.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
3737
"build:chmod": "chmod +x dist/cjs/index.js",
38-
"build": "npm run build:clean && npm run build:esm && npm run build:cjs && npm run build:package-json && npm run build:chmod",
38+
"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",
3939
"inspect": "npm run build && mcp-inspector -- dist/cjs/index.js",
4040
"prettier": "prettier",
4141
"check": "npm run build && npm run check:types && npm run check:lint && npm run check:format",

scripts/update-package-info.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env node
2+
3+
import { readFileSync, writeFileSync } from "fs";
4+
import { join } from "path";
5+
6+
interface PackageJson {
7+
version: string;
8+
name?: string;
9+
description?: string;
10+
}
11+
12+
// Read package.json
13+
const packageJsonPath = join(import.meta.dirname, "..", "package.json");
14+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as PackageJson;
15+
16+
// Define the packageInfo.ts content
17+
const packageInfoContent = `// This file was generated by scripts/update-package-info.ts - Do not edit it manually.
18+
export const packageInfo = {
19+
version: "${packageJson.version}",
20+
mcpServerName: "MongoDB MCP Server",
21+
};
22+
`;
23+
24+
// Write to packageInfo.ts
25+
const packageInfoPath = join(import.meta.dirname, "..", "src", "common", "packageInfo.ts");
26+
writeFileSync(packageInfoPath, packageInfoContent);

scripts/update-version.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env node
2+
3+
import { readFileSync, writeFileSync } from "fs";
4+
import { join } from "path";
5+
6+
interface PackageJson {
7+
version: string;
8+
name?: string;
9+
description?: string;
10+
}
11+
12+
// Read package.json
13+
const packageJsonPath = join(import.meta.dirname, "..", "package.json");
14+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as PackageJson;
15+
16+
// Define the packageInfo.ts content
17+
const packageInfoContent = `// This file was generated by scripts/update-version.ts - Do not edit it manually.
18+
export const packageInfo = {
19+
version: "${packageJson.version}",
20+
mcpServerName: "MongoDB MCP Server",
21+
};
22+
`;
23+
24+
// Write to packageInfo.ts
25+
const packageInfoPath = join(import.meta.dirname, "..", "src", "common", "packageInfo.ts");
26+
writeFileSync(packageInfoPath, packageInfoContent);

src/common/packageInfo.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
import { readFileSync } from "fs";
2-
import { join } from "path";
3-
4-
let packageJson: {
5-
version: string;
6-
} = { version: "unknown" };
7-
8-
try {
9-
packageJson = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8")) as {
10-
version: string;
11-
};
12-
} catch (error) {
13-
console.error("Error getting package info", error);
14-
}
15-
1+
// This file was generated by scripts/update-package-info.ts - Do not edit it manually.
162
export const packageInfo = {
17-
version: packageJson?.version,
3+
version: "0.1.3",
184
mcpServerName: "MongoDB MCP Server",
195
};

tests/build/test-dual-modules.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { test } from "node:test";
2+
import { strict as assert } from "node:assert";
3+
import { createRequire } from "module";
4+
import path from "path";
5+
import { fileURLToPath } from "url";
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
10+
test("CommonJS module import", { timeout: 5000 }, (t) => {
11+
const require = createRequire(__filename);
12+
const cjsPath = path.resolve(__dirname, "../../dist/cjs/index.js");
13+
14+
const cjsModule = require(cjsPath);
15+
16+
assert.equal(typeof cjsModule, "object", "CommonJS module should be an object");
17+
assert.ok(cjsModule, "CommonJS module should be truthy");
18+
});
19+
20+
test("ESM module import", { timeout: 5000 }, async (t) => {
21+
const esmPath = path.resolve(__dirname, "../../dist/esm/d.js");
22+
23+
const esmModule = await import(esmPath);
24+
25+
assert.equal(typeof esmModule, "object", "ESM module should be an object");
26+
assert.ok(esmModule, "ESM module should be truthy");
27+
});
28+
29+
test("module exports comparison", { timeout: 5000 }, async () => {
30+
const require = createRequire(__filename);
31+
const cjsPath = path.resolve(__dirname, "../../dist/cjs/index.js");
32+
const esmPath = path.resolve(__dirname, "../../dist/esm/d.js");
33+
34+
const cjsModule = require(cjsPath);
35+
const esmModule = await import(esmPath);
36+
37+
const cjsKeys = Object.keys(cjsModule).sort();
38+
const esmKeys = Object.keys(esmModule).sort();
39+
40+
assert.deepEqual(
41+
cjsKeys,
42+
esmKeys,
43+
`CommonJS and ESM modules should export the same keys.\nCommonJS: ${JSON.stringify(cjsKeys)}\nESM: ${JSON.stringify(esmKeys)}`
44+
);
45+
});

tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"allowSyntheticDefaultImports": true,
1717
"typeRoots": ["./node_modules/@types", "./src/types"]
1818
},
19-
"include": ["src/**/*.ts", "package.json"]
19+
"include": ["src/**/*.ts"]
2020
}

tsconfig.vscode.json

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

0 commit comments

Comments
 (0)