Fixed module resolution errors
All checks were successful
armco-org/analytics/pipeline/head This commit looks good

This commit is contained in:
2025-12-23 00:46:30 +05:30
parent 8ca9dead46
commit ab88ce6e04
2 changed files with 34 additions and 1 deletions

View File

@@ -4,8 +4,37 @@
import fs from "fs-extra";
import childProcess from "child_process";
import path from "path";
import pkg from "./package.json" with { type: "json" };
/**
* Add .js extensions to relative imports in compiled JS files
* Required for Node.js ESM module resolution
*/
function addJsExtensions(dir) {
const files = fs.readdirSync(dir);
for (const file of files) {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
addJsExtensions(filePath);
} else if (file.endsWith('.js')) {
let content = fs.readFileSync(filePath, 'utf8');
// Match: from "./something" or from '../something' (without .js extension)
content = content.replace(
/(from\s+['"])(\.\.?\/[^'"]+)(?<!\.js)(['"])/g,
'$1$2.js$3'
);
// Match: export * from "./something" or export { x } from '../something'
content = content.replace(
/(export\s+(?:\*|{[^}]*})\s+from\s+['"])(\.\.?\/[^'"]+)(?<!\.js)(['"])/g,
'$1$2.js$3'
);
fs.writeFileSync(filePath, content);
}
}
}
/**
* Start
*/
@@ -16,6 +45,10 @@ import pkg from "./package.json" with { type: "json" };
await remove("./dist/");
await exec("tsc --build tsconfig.prod.json", "./");
// Add .js extensions to relative imports for Node.js ESM compatibility
console.log("Adding .js extensions to imports...");
addJsExtensions("./dist");
// Prepare a clean package.json for the published artifact
const publishPkg = { ...pkg };

View File

@@ -1,6 +1,6 @@
{
"name": "@armco/analytics",
"version": "0.3.3",
"version": "0.3.4",
"description": "Universal Analytics Library for Browser and Node.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",