From 461f83bb7ab86f9decb90deb2c42ece52d633531 Mon Sep 17 00:00:00 2001 From: Swasthik K Date: Tue, 17 Feb 2026 00:29:35 +0530 Subject: [PATCH] feat: add dual ESM + CommonJS build support --- .gitignore | 1 + package.json | 14 +++++++++----- tsconfig.cjs.json | 8 ++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 tsconfig.cjs.json diff --git a/.gitignore b/.gitignore index c5c127f..2134439 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules/ dist/ +dist-cjs/ *.log .DS_Store *.tsbuildinfo diff --git a/package.json b/package.json index 3802486..fc6fae2 100644 --- a/package.json +++ b/package.json @@ -2,25 +2,29 @@ "name": "@fly/sprites", "version": "0.0.1-dev", "description": "JavaScript/TypeScript SDK for Sprites - remote command execution", - "main": "dist/index.js", + "main": "dist/index.cjs", "types": "dist/index.d.ts", "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs", + "default": "./dist/index.js" } }, "engines": { "node": ">=24.0.0" }, "scripts": { - "build": "tsc", + "build:esm": "tsc", + "build:cjs": "tsc -p tsconfig.cjs.json", + "build": "npm run clean && npm run build:esm && npm run build:cjs && cp dist-cjs/index.js dist/index.cjs", "watch": "tsc --watch", "test": "npm run build && node --test dist/**/*.test.js", "test:unit": "npm run build && node --test dist/exec.test.js", "test:integration": "npm run build && node --test dist/integration.test.js", - "clean": "rm -rf dist", + "clean": "rm -rf dist dist-cjs", "prepublishOnly": "npm run clean && npm run build" }, "keywords": [ @@ -43,6 +47,7 @@ }, "files": [ "dist/**/*.js", + "dist/**/*.cjs", "dist/**/*.d.ts", "dist/**/*.d.ts.map", "!dist/**/*.test.*", @@ -54,4 +59,3 @@ "typescript": "^5.6.0" } } - diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..8d8d34a --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "moduleResolution": "Node", + "outDir": "dist-cjs", + } +}