Skip to content

Commit 79a5351

Browse files
script to build esm
1 parent 647db35 commit 79a5351

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,29 @@
55
"repository": "journeyapps/https-proxy-socket",
66
"license": "MIT",
77
"type": "module",
8-
"main": "./lib/cjs/index.js",
9-
"module": "./lib/esm/index.js",
8+
"main": "./lib/cjs/index.cjs",
9+
"module": "./lib/esm/index.mjs",
1010
"exports": {
1111
".": {
1212
"import": {
13-
"default": "./lib/esm/index.js",
13+
"default": "./lib/esm/index.mjs",
1414
"types": "./lib/esm/index.d.ts"
1515
},
1616
"require": {
17-
"default": "./lib/cjs/index.js",
17+
"default": "./lib/cjs/index.cjs",
1818
"types": "./lib/cjs/index.d.ts"
1919
}
2020
}
2121
},
2222
"bin": {
23-
"mongo-replicas": "lib/esm/bin/mongoReplicas.js"
23+
"mongo-replicas": "lib/esm/bin/mongoReplicas.mjs"
2424
},
2525
"scripts": {
2626
"ci:publish": "changeset publish && git push --follow-tags",
2727
"ci:version": "changeset version && pnpm install --no-frozen-lockfile",
2828
"clean": "rm -rf ./lib && tsc -b --clean",
2929
"clean:modules": "rm -rf node_modules",
30-
"build:esm": "tsc -p tsconfig.esm.json",
31-
"build:cjs": "tsc -p tsconfig.cjs.json",
32-
"build": "pnpm build:esm && pnpm build:cjs",
30+
"build": "node scripts/build.js",
3331
"test": "vitest run"
3432
},
3533
"devDependencies": {

scripts/build.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { execSync } from 'child_process';
2+
import { readdirSync, renameSync } from 'fs';
3+
import { join } from 'path';
4+
5+
// Compile ESM
6+
execSync('tsc -p tsconfig.esm.json', { stdio: 'inherit' });
7+
8+
// Compile CJS
9+
execSync('tsc -p tsconfig.cjs.json', { stdio: 'inherit' });
10+
11+
// Rename .js -> .cjs in CJS folder
12+
const cjsDir = join(process.cwd(), 'lib/cjs');
13+
readdirSync(cjsDir).forEach((file) => {
14+
if (file.endsWith('.js')) {
15+
const oldPath = join(cjsDir, file);
16+
const newPath = join(cjsDir, file.replace(/\.js$/, '.cjs'));
17+
renameSync(oldPath, newPath);
18+
}
19+
});
20+
21+
// Rename .js -> .mjs in ESM folder
22+
const esmDir = join(process.cwd(), 'lib/esm');
23+
readdirSync(esmDir).forEach((file) => {
24+
if (file.endsWith('.js')) {
25+
const oldPath = join(esmDir, file);
26+
const newPath = join(esmDir, file.replace(/\.js$/, '.mjs'));
27+
renameSync(oldPath, newPath);
28+
}
29+
});
30+
31+
console.log('✅ Build complete: ESM (.js) + CJS (.cjs)');

0 commit comments

Comments
 (0)