fix: double-.js extension in @/ alias resolution (fix-imports.mjs)

The fix-imports.mjs script blindly appended '.js' to every @/ alias
import, even when the source specifier already carried a .js
extension (e.g. '@/shared/config/index.js'). This produced
'index.js.js' in the emitted dist/, causing ERR_MODULE_NOT_FOUND
at startup.

This was latent: only triggered once digestScheduler.ts (which
uses @/shared/config/index.js with explicit extension) was built.
The user-reputation removal (2a8f6d9) was also blocked by this
bug — stale binary kept crashing with 'user_reputations' query
errors because it was never redeployed.

Fix: only append .js when the @/ specifier has no existing
extension. Applied to both gateway and backend scripts.
This commit is contained in:
mytheclipsebotreview
2026-08-20 18:08:30 +07:00
committed by asepharyana
parent 0aa893ab7d
commit f5d5690401
2 changed files with 20 additions and 2 deletions
+10 -1
View File
@@ -25,7 +25,16 @@ function walk(dir) {
const pat = /from\s+['"]([^'"]+)['"]/g; const pat = /from\s+['"]([^'"]+)['"]/g;
const n = c.replace(pat, (m, spec) => { const n = c.replace(pat, (m, spec) => {
if (spec.startsWith("@/")) { if (spec.startsWith("@/")) {
const target = join("dist", spec.slice(2)) + ".js"; // Source may already carry an extension (e.g. "@/shared/config/index.js");
// only append ".js" when the specifier has none — otherwise we'd
// produce "index.js.js".
const core = spec.slice(2);
let target;
if (/\.(js|json|node|mjs|cjs)$/.test(core)) {
target = join("dist", core);
} else {
target = join("dist", core) + ".js";
}
let rel = relative(dirname(p), target); let rel = relative(dirname(p), target);
if (!rel.startsWith(".")) rel = "./" + rel; if (!rel.startsWith(".")) rel = "./" + rel;
return `from "${rel}"`; return `from "${rel}"`;
@@ -25,7 +25,16 @@ function walk(dir) {
const pat = /from\s+['"]([^'"]+)['"]/g; const pat = /from\s+['"]([^'"]+)['"]/g;
const n = c.replace(pat, (m, spec) => { const n = c.replace(pat, (m, spec) => {
if (spec.startsWith("@/")) { if (spec.startsWith("@/")) {
const target = join("dist", spec.slice(2)) + ".js"; // Source may already carry an extension (e.g. "@/shared/config/index.js");
// only append ".js" when the specifier has none — otherwise we'd
// produce "index.js.js".
const core = spec.slice(2);
let target;
if (/\.(js|json|node|mjs|cjs)$/.test(core)) {
target = join("dist", core);
} else {
target = join("dist", core) + ".js";
}
let rel = relative(dirname(p), target); let rel = relative(dirname(p), target);
if (!rel.startsWith(".")) rel = "./" + rel; if (!rel.startsWith(".")) rel = "./" + rel;
return `from "${rel}"`; return `from "${rel}"`;