Skip to content

Commit 2cf1b06

Browse files
authored
chore: make the @packages/types an independent bundle without needed ts-node to register entrypoint. Both ESM and CJS distributions are built and types are used as source to be compatible with older styles of commonjs bundling. Types are not shipped with the package. (#32608)
1 parent 504b153 commit 2cf1b06

File tree

8 files changed

+44
-21
lines changed

8 files changed

+44
-21
lines changed

guides/esm-migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
- [x] packages/stderr-filtering ✅ **COMPLETED**
6464
- [ ] packages/telemetry **PARTIAL** - entry point is JS
6565
- [ ] packages/ts **PARTIAL** - ultimate goal is removal and likely not worth the effort to convert
66-
- [ ] packages/types **PARTIAL** - entry point is JS
66+
- [x] packages/types **COMPLETED**
6767
- [x] packages/v8-snapshot-require
6868
- [x] packages/web-config
6969

packages/types/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
src/**/*.js
1+
esm/
2+
cjs/

packages/types/index.js

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

packages/types/package.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,39 @@
22
"name": "@packages/types",
33
"version": "0.0.0-development",
44
"private": true,
5-
"main": "index.js",
6-
"browser": "src/index.ts",
5+
"main": "cjs/index.js",
6+
"browser": "esm/index.js",
77
"scripts": {
8-
"build-prod": "tsc || echo 'built, with type errors'",
9-
"check-ts": "tsc --noEmit",
10-
"clean": "rimraf --glob 'src/*.js' 'src/**/*.js'",
8+
"build": "yarn build:esm && yarn build:cjs",
9+
"build-prod": "yarn build",
10+
"build:cjs": "rimraf cjs && tsc -p tsconfig.cjs.json",
11+
"build:esm": "rimraf esm && tsc -p tsconfig.esm.json",
12+
"check-ts": "tsc -p tsconfig.cjs.json --noEmit",
13+
"clean": "rimraf cjs esm",
1114
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json, .",
1215
"test": "vitest run"
1316
},
1417
"dependencies": {
1518
"semver": "^7.7.1"
1619
},
1720
"devDependencies": {
21+
"@packages/root": "0.0.0-development",
1822
"@types/node": "22.18.0",
1923
"axios": "^1.8.3",
2024
"better-sqlite3": "11.10.0",
2125
"devtools-protocol": "0.0.1459876",
2226
"express": "4.21.0",
27+
"rimraf": "^6.0.1",
2328
"socket.io": "4.0.1",
2429
"typescript": "~5.4.5",
2530
"vitest": "^3.2.4"
2631
},
2732
"files": [
28-
"src/*"
33+
"cjs/*",
34+
"esm/*"
2935
],
3036
"types": "src/index.ts",
37+
"module": "esm/index.js",
3138
"workspaces": {
3239
"nohoist": [
3340
"devtools-protocol"

packages/types/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import semverMajor from 'semver/functions/major'
2-
import packageInfo from '../../../package.json'
2+
import packageInfo from '@packages/root'
33

44
import type { SpecFile } from './spec'
55

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"extends": "../ts/tsconfig.json",
32
"include": [
43
"src/*.ts",
54
"src/**/*.ts"
@@ -11,13 +10,14 @@
1110
"noUnusedLocals": false,
1211
"noUnusedParameters": false,
1312
"allowJs": true,
14-
"types": [],
1513
"noUncheckedIndexedAccess": true,
1614
"ignoreDeprecations": "5.0",
17-
/*
18-
* TODO: remove importsNotUsedAsValues after typescript 5.5 and up as it will no longer work. If we want the same behavior
19-
* as importsNotUsedAsValues, we need to use "verbatimModuleSyntax", which will require this package to be an ES Module.
20-
*/
2115
"importsNotUsedAsValues": "error",
22-
},
16+
"skipLibCheck": true,
17+
"resolveJsonModule": true,
18+
"types": [
19+
"mocha",
20+
"node"
21+
]
22+
}
2323
}

packages/types/tsconfig.cjs.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": "./src",
5+
"outDir": "./cjs",
6+
"target": "ES2022",
7+
"module": "CommonJS",
8+
"moduleResolution": "node"
9+
}
10+
}

packages/types/tsconfig.esm.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": "./src",
5+
"outDir": "./esm",
6+
"target": "ES2022",
7+
"module": "ES2022",
8+
"moduleResolution": "node"
9+
}
10+
}

0 commit comments

Comments
 (0)