diff --git a/.changeset/kind-waves-impress.md b/.changeset/kind-waves-impress.md new file mode 100644 index 0000000000..da2f6da405 --- /dev/null +++ b/.changeset/kind-waves-impress.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Fixed the package prepack command so that it no longer produces unnecessary `index` entries in the `typesVersions` map, which could cause `/index` to be added when automatically adding imports. diff --git a/packages/cli/src/modules/build/lib/packager/productionPack.ts b/packages/cli/src/modules/build/lib/packager/productionPack.ts index ee96b87849..b201d24d0c 100644 --- a/packages/cli/src/modules/build/lib/packager/productionPack.ts +++ b/packages/cli/src/modules/build/lib/packager/productionPack.ts @@ -143,7 +143,7 @@ async function rewriteEntryPoints( // Clear to ensure a clean slate before adding entries back in further down if (pkg.typesVersions) { - pkg.typesVersions = { '*': {} }; + pkg.typesVersions = undefined; } for (const entryPoint of entryPoints) { @@ -166,9 +166,8 @@ async function rewriteEntryPoints( if (!pkg.typesVersions) { pkg.typesVersions = { '*': {} }; } - pkg.typesVersions['*'][entryPoint.name] = [ - `dist/${entryPoint.name}.d.ts`, - ]; + const mount = entryPoint.name === 'index' ? '*' : entryPoint.name; + pkg.typesVersions['*'][mount] = [`dist/${entryPoint.name}.d.ts`]; } exp.default = exp.require ?? exp.import; @@ -218,6 +217,14 @@ async function rewriteEntryPoints( } } + // Clean up the typesVersions field if it only contains a wildcard + if (pkg.typesVersions?.['*']) { + const keys = Object.keys(pkg.typesVersions['*']); + if (keys.length === 1 && keys[0] === '*') { + delete pkg.typesVersions; + } + } + if (pkg.exports) { pkg.exports = outputExports; // We treat package.json as a fixed export that is always available in the published package