Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "@robotixai/calculator-engine",
"version": "0.3.0",
"version": "0.4.0",
"description": "Financial retirement projection engine with Monte Carlo simulation, multi-jurisdiction tax, and withdrawal strategies",
"private": false,
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand All @@ -14,8 +15,9 @@
},
"files": ["dist", "README.md", "LICENSE"],
"scripts": {
"build": "tsc",
"lint": "tsc --noEmit"
"build": "tsc && node scripts/fix-esm-extensions.mjs",
"lint": "tsc --noEmit",
"test": "node src/__tests__/smoke.test.mjs"
},
"dependencies": {},
"devDependencies": {
Expand Down
38 changes: 38 additions & 0 deletions scripts/fix-esm-extensions.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Post-build script: adds .js extensions to relative imports in dist/ so that
* Node's native ESM loader can resolve them without --experimental-specifier-resolution.
*/
import { readdir, readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

const DIST = new URL('../dist', import.meta.url).pathname;

// Match: from './foo' or from '../foo' (no extension)
const RE = /(from\s+['"])(\.\.?\/[^'"]+?)(['"])/g;

async function walk(dir) {
const entries = await readdir(dir, { withFileTypes: true });
const files = [];
for (const e of entries) {
const full = join(dir, e.name);
if (e.isDirectory()) files.push(...(await walk(full)));
else if (e.name.endsWith('.js')) files.push(full);
}
return files;
}

const files = await walk(DIST);
let patched = 0;

for (const f of files) {
const src = await readFile(f, 'utf8');
const out = src.replace(RE, (match, pre, path, post) => {
// Skip if already has an extension
if (/\.\w+$/.test(path)) return match;
patched++;
return `${pre}${path}.js${post}`;
});
if (out !== src) await writeFile(f, out);
}

console.log(`fix-esm-extensions: patched ${patched} imports in ${files.length} files`);
Loading
Loading