Skip to content

Commit 6a70bbe

Browse files
committed
fix: add backwards compatibility
1 parent 384a3be commit 6a70bbe

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
"scripts": {
3131
"prepare": "npm run build",
3232
"build:clean": "rm -rf dist",
33-
"build:update-package-info": "tsx scripts/update-package-info.ts",
33+
"build:update-package-version": "tsx scripts/updatePackageVersion.ts",
3434
"build:esm": "tsc --project tsconfig.esm.json",
3535
"build:cjs": "tsc --project tsconfig.cjs.json",
36-
"build:package-json": "tsx scripts/write-package-json.ts",
36+
"build:universal-package": "tsx scripts/createUniversalPackage.ts",
3737
"build:chmod": "chmod +x dist/esm/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:esm && npm run build:cjs && npm run build:universal-package && npm run build:chmod",
3939
"inspect": "npm run build && mcp-inspector -- dist/esm/index.js",
4040
"prettier": "prettier",
4141
"check": "npm run build && npm run check:types && npm run check:lint && npm run check:format",

scripts/write-package-json.ts renamed to scripts/createUniversalPackage.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { resolve } from "path";
55

66
const distDir = resolve("dist");
77

8+
/**
9+
* Node uses the package.json to know whether files with a .js extensions
10+
* should be interpreted as CommonJS or ESM.
11+
*/
812
// ESM package.json
913
const esmPath = resolve(distDir, "esm", "package.json");
1014
mkdirSync(resolve(distDir, "esm"), { recursive: true });
@@ -14,3 +18,8 @@ writeFileSync(esmPath, JSON.stringify({ type: "module" }));
1418
const cjsPath = resolve(distDir, "cjs", "package.json");
1519
mkdirSync(resolve(distDir, "cjs"), { recursive: true });
1620
writeFileSync(cjsPath, JSON.stringify({ type: "commonjs" }));
21+
22+
// Create a dist/index.js file that imports the ESM index.js file
23+
// To minimize breaking changes from pre-universal package time.
24+
const indexPath = resolve(distDir, "index.js");
25+
writeFileSync(indexPath, `import "./esm/index.js";`);

scripts/update-package-info.ts renamed to scripts/updatePackageVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as {
1010
};
1111

1212
// Define the packageInfo.ts content
13-
const packageInfoContent = `// This file was generated by scripts/update-package-info.ts - Do not edit it manually.
13+
const packageInfoContent = `// This file was generated by scripts/updatePackageVersion.ts - Do not edit it manually.
1414
export const packageInfo = {
1515
version: "${packageJson.version}",
1616
mcpServerName: "MongoDB MCP Server",

src/common/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by scripts/update-package-info.ts - Do not edit it manually.
1+
// This file was generated by scripts/updatePackageVersion.ts - Do not edit it manually.
22
export const packageInfo = {
33
version: "0.1.3",
44
mcpServerName: "MongoDB MCP Server",

0 commit comments

Comments
 (0)