fix: support cjs

This commit is contained in:
ycjcl868 2025-01-04 00:58:01 +08:00
commit 7d274d3f8e
5 changed files with 120 additions and 1614 deletions

1484
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,7 @@
"author": "Anthropic, PBC (https://anthropic.com)",
"homepage": "https://modelcontextprotocol.io",
"bugs": "https://github.com/modelcontextprotocol/typescript-sdk/issues",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/modelcontextprotocol/typescript-sdk.git"
@ -26,8 +27,7 @@
"typesVersions": {
"*": {
"*": [
"./dist/esm/*",
"./dist/cjs/*"
"./dist/esm/*"
]
}
},
@ -35,8 +35,10 @@
"dist"
],
"scripts": {
"build": "tsup",
"prepack": "tsup",
"build": "npm run build:esm && npm run build:cjs",
"build:esm": "tsc -p tsconfig.prod.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
"prepack": "npm run build:esm && npm run build:cjs",
"lint": "eslint src/",
"test": "jest",
"start": "npm run server",
@ -49,7 +51,6 @@
"zod": "^3.23.8"
},
"devDependencies": {
"tsup": "^8.3.5",
"@eslint/js": "^9.8.0",
"@types/content-type": "^1.1.8",
"@types/eslint__js": "^8.42.3",

9
tsconfig.cjs.json Normal file
View file

@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./dist/cjs"
},
"exclude": ["**/*.test.ts"]
}

View file

@ -1,6 +1,7 @@
{
"extends": "./tsconfig.json",
"exclude": [
"**/*.test.ts",
]
"compilerOptions": {
"outDir": "./dist/esm"
},
"exclude": ["**/*.test.ts"]
}

View file

@ -1,25 +0,0 @@
import { defineConfig, Options } from "tsup";
const commonConfig: Options = {
clean: true,
dts: true,
splitting: false,
tsconfig: "tsconfig.prod.json",
};
export default defineConfig([
{
...commonConfig,
entry: ["src/**/*"],
bundle: false,
outDir: "dist/cjs",
format: ["cjs"],
},
{
...commonConfig,
entry: ["src/**/*"],
bundle: false,
outDir: "dist/esm",
format: ["esm"],
},
]);