Fix: prevent double ./cjs/ prefix in main field

When package.json already has main: './cjs/index.js', the build script
was incorrectly adding another ./cjs/ prefix resulting in './cjs/cjs/index.js'

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-18 07:07:02 +03:00
parent 5822ced63c
commit 4fbef2fcd2
@@ -792,7 +792,8 @@ function buildExports () {
? pkg.main
: `./${pkg.main}`;
pkg.main = main.replace(/^\.\//, './cjs/');
// Only add ./cjs/ prefix if main doesn't already start with ./cjs/
pkg.main = main.startsWith('./cjs/') ? main : main.replace(/^\.\//, './cjs/');
pkg.module = main;
pkg.types = main.replace('.js', '.d.ts');
}
@@ -806,7 +807,8 @@ function buildExports () {
? value
: `./${value}`;
pkg[k] = entry.replace(/^\.\//, './cjs/');
// Only add ./cjs/ prefix if entry doesn't already start with ./cjs/
pkg[k] = entry.startsWith('./cjs/') ? entry : entry.replace(/^\.\//, './cjs/');
}
});