fix: add CJS build for NestJS CommonJS compatibility
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

NestJS compiles to CommonJS, but the package only exported ESM.
Node throws ERR_PACKAGE_PATH_NOT_EXPORTED when CJS code requires
an ESM-only package. Added dual ESM/CJS build with proper exports
conditions.

- ESM output in dist/esm/, CJS output in dist/cjs/
- package.json exports now includes import, require, and default
- Bumped to 0.1.1

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 15:07:23 -06:00
parent 20f56edb49
commit bf001813b8
3 changed files with 21 additions and 6 deletions

View File

@@ -1,14 +1,17 @@
{
"name": "@mosaicstack/telemetry-client",
"version": "0.1.0",
"version": "0.1.1",
"description": "TypeScript client SDK for Mosaic Stack Telemetry",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
"types": "./dist/esm/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
}
},
"engines": {
@@ -19,7 +22,7 @@
],
"license": "MPL-2.0",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"build": "tsc -p tsconfig.build.json && tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",

View File

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

9
tsconfig.cjs.json Normal file
View File

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