Skip to content

Commit 436757c

Browse files
haraldschillyclaude
andcommitted
build/esm: add dual CJS+ESM output for comm and api-client (Phase 3)
Phase 3 of incremental CJS→ESM migration: - Add tsconfig-esm.json and conditional exports for @cocalc/comm and @cocalc/api-client packages - Standardize build scripts across all ESM-migrated packages to use `pnpm exec tsc` instead of `../node_modules/.bin/tsc` - Each package now produces both dist/ (CJS) and dist-esm/ (ESM) output Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6a91da5 commit 436757c

File tree

11 files changed

+83
-13
lines changed

11 files changed

+83
-13
lines changed

src/packages/api-client/package.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,30 @@
33
"version": "0.1.2",
44
"description": "CoCalc api client - use cocalc from nodejs",
55
"main": "./dist/index.js",
6+
"exports": {
7+
".": {
8+
"types": "./dist/index.d.ts",
9+
"import": "./dist-esm/index.js",
10+
"default": "./dist/index.js"
11+
},
12+
"./*": {
13+
"types": "./dist/*.d.ts",
14+
"import": "./dist-esm/*.js",
15+
"default": "./dist/*.js"
16+
},
17+
"./src/*": {
18+
"types": "./dist/src/*.d.ts",
19+
"import": "./dist-esm/src/*.js",
20+
"default": "./dist/src/*.js"
21+
}
22+
},
23+
"files": ["dist/**", "dist-esm/**", "bin/**", "README.md", "package.json"],
624
"scripts": {
725
"preinstall": "npx only-allow pnpm",
8-
"build": "../node_modules/.bin/tsc --build",
26+
"build": "pnpm exec tsc --build && pnpm exec tsc -p tsconfig-esm.json && echo '{\"type\":\"module\"}' > dist-esm/package.json",
27+
"clean": "rm -rf node_modules dist dist-esm",
928
"depcheck": "pnpx depcheck --ignores @cocalc/api-client "
1029
},
11-
"files": ["dist/**", "bin/**", "README.md", "package.json"],
1230
"author": "SageMath, Inc.",
1331
"keywords": ["cocalc", "jupyter"],
1432
"license": "SEE LICENSE.md",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "./",
5+
"outDir": "dist-esm",
6+
"module": "ESNext",
7+
"moduleResolution": "bundler",
8+
"declaration": false,
9+
"declarationMap": false,
10+
"composite": false,
11+
"incremental": false,
12+
"sourceMap": true
13+
},
14+
"exclude": ["node_modules", "../node_modules", "dist", "dist-esm", "test"]
15+
}

src/packages/api-client/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"rootDir": "./",
55
"outDir": "dist"
66
},
7-
"exclude": ["node_modules", "dist", "test"],
7+
"exclude": ["node_modules", "dist", "dist-esm", "test"],
88
"references": [{ "path": "../backend" }]
99
}

src/packages/comm/package.json

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,38 @@
33
"version": "0.1.0",
44
"description": "Communication between project and frontend app support",
55
"exports": {
6-
"./*": "./dist/*.js",
7-
"./websocket/*": "./dist/websocket/*.js",
8-
"./project-status/*": "./dist/project-status/*.js",
9-
"./project-info/*": "./dist/project-info/*.js"
6+
"./*": {
7+
"types": "./dist/*.d.ts",
8+
"import": "./dist-esm/*.js",
9+
"default": "./dist/*.js"
10+
},
11+
"./websocket/*": {
12+
"types": "./dist/websocket/*.d.ts",
13+
"import": "./dist-esm/websocket/*.js",
14+
"default": "./dist/websocket/*.js"
15+
},
16+
"./project-status/*": {
17+
"types": "./dist/project-status/*.d.ts",
18+
"import": "./dist-esm/project-status/*.js",
19+
"default": "./dist/project-status/*.js"
20+
},
21+
"./project-info/*": {
22+
"types": "./dist/project-info/*.d.ts",
23+
"import": "./dist-esm/project-info/*.js",
24+
"default": "./dist/project-info/*.js"
25+
}
1026
},
1127
"files": [
1228
"dist/**",
29+
"dist-esm/**",
1330
"README.md",
1431
"package.json",
1532
"tsconfig.json"
1633
],
1734
"scripts": {
1835
"preinstall": "npx only-allow pnpm",
19-
"build": "../node_modules/.bin/tsc --build",
36+
"build": "pnpm exec tsc --build && pnpm exec tsc -p tsconfig-esm.json && echo '{\"type\":\"module\"}' > dist-esm/package.json",
37+
"clean": "rm -rf node_modules dist dist-esm",
2038
"depcheck": "pnpx depcheck --ignores @types/node"
2139
},
2240
"author": "SageMath, Inc.",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "./",
5+
"outDir": "dist-esm",
6+
"module": "ESNext",
7+
"moduleResolution": "bundler",
8+
"declaration": false,
9+
"declarationMap": false,
10+
"composite": false,
11+
"incremental": false,
12+
"sourceMap": true
13+
},
14+
"exclude": ["node_modules", "../node_modules", "dist", "dist-esm", "test"]
15+
}

src/packages/comm/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"rootDir": "./",
55
"outDir": "dist"
66
},
7-
"exclude": ["node_modules", "dist", "test"],
7+
"exclude": ["node_modules", "dist", "dist-esm", "test"],
88
"references": [
99
{ "path": "../sync" },
1010
{ "path": "../jupyter" },

src/packages/pnpm-lock.yaml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/packages/sync-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
],
3030
"scripts": {
3131
"preinstall": "npx only-allow pnpm",
32-
"build": "../node_modules/.bin/tsc --build && ../node_modules/.bin/tsc -p tsconfig-esm.json && echo '{\"type\":\"module\"}' > dist-esm/package.json",
32+
"build": "pnpm exec tsc --build && pnpm exec tsc -p tsconfig-esm.json && echo '{\"type\":\"module\"}' > dist-esm/package.json",
3333
"clean": "rm -rf node_modules dist dist-esm",
3434
"depcheck": "pnpx depcheck"
3535
},

src/packages/sync-fs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
],
3030
"scripts": {
3131
"preinstall": "npx only-allow pnpm",
32-
"build": "../node_modules/.bin/tsc --build && ../node_modules/.bin/tsc -p tsconfig-esm.json && echo '{\"type\":\"module\"}' > dist-esm/package.json",
32+
"build": "pnpm exec tsc --build && pnpm exec tsc -p tsconfig-esm.json && echo '{\"type\":\"module\"}' > dist-esm/package.json",
3333
"clean": "rm -rf node_modules dist dist-esm",
3434
"test": "pnpm exec jest --forceExit --runInBand",
3535
"depcheck": "pnpx depcheck"

src/packages/sync/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"scripts": {
2828
"preinstall": "npx only-allow pnpm",
29-
"build": "../node_modules/.bin/tsc --build && ../node_modules/.bin/tsc -p tsconfig-esm.json && echo '{\"type\":\"module\"}' > dist-esm/package.json",
29+
"build": "pnpm exec tsc --build && pnpm exec tsc -p tsconfig-esm.json && echo '{\"type\":\"module\"}' > dist-esm/package.json",
3030
"test": "pnpm exec jest --forceExit",
3131
"depcheck": "pnpx depcheck --ignores events",
3232
"prepublishOnly": "pnpm test"

0 commit comments

Comments
 (0)