From 66ab161a55ee8fdd7346f85db1c6acc527d47dad Mon Sep 17 00:00:00 2001 From: Arechi Date: Thu, 30 Apr 2026 13:32:03 +0200 Subject: [PATCH] build: convert TypeScript package to ESM-only Switches the npm package from CommonJS to ESM-only output. - tsconfig.json: module/moduleResolution NodeNext, target ES2022 - package.json: adds "type": "module" and "exports" map; drops "main" - CI Generate: adds esModuleInterop=true and importSuffix=.js so ts-proto emits relative imports with .js extensions for NodeNext Breaking change for CommonJS consumers (require() is blocked by the exports map); a major version bump should accompany this before publishing. Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/ci-typescript.yaml | 4 +++- package.json | 10 ++++++++-- tsconfig.json | 5 +++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-typescript.yaml b/.github/workflows/ci-typescript.yaml index 1c174753..9d382b1a 100644 --- a/.github/workflows/ci-typescript.yaml +++ b/.github/workflows/ci-typescript.yaml @@ -45,7 +45,9 @@ jobs: --ts_proto_out=./out \ --ts_proto_opt=outputIndex=true \ --ts_proto_opt=globalThisPolyfill=true \ - --ts_proto_opt=useExactTypes=false + --ts_proto_opt=useExactTypes=false \ + --ts_proto_opt=esModuleInterop=true \ + --ts_proto_opt=importSuffix=.js - name: Compile run: pnpm run build diff --git a/package.json b/package.json index aa763b88..e5dbd325 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,14 @@ "type": "git", "url": "https://github.com/BluEye-Robotics/ProtocolDefinitions.git" }, - "main": "dist/index.js", - "types": "dist/index.d.ts", + "type": "module", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, + "types": "./dist/index.d.ts", "files": [ "dist" ], diff --git a/tsconfig.json b/tsconfig.json index fc30754e..54339cbc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,8 @@ { "compilerOptions": { - "target": "ES2020", - "module": "CommonJS", + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", "declaration": true, "outDir": "dist", "strict": true,