diff --git a/dts.snapshot.json b/dts.snapshot.json index 136b52d..c9dd07f 100644 --- a/dts.snapshot.json +++ b/dts.snapshot.json @@ -1,6 +1,6 @@ { "api.d.mts": { - "snapshot": "declare function snapshot(_: string, _: string): Record", + "snapshot": "declare function snapshot(_: string, _: string, _: { applyExportRename?: boolean }): Record", "#exports": [ "snapshot" ] diff --git a/src/api.ts b/src/api.ts index daaba54..350d740 100644 --- a/src/api.ts +++ b/src/api.ts @@ -10,6 +10,7 @@ const singlelineCommentsRE = /\/\/.*$/gm export function snapshot( code: string, fileName: string = 'dummy.d.ts', + { applyExportRename = true }: { applyExportRename?: boolean } = {}, ): Record { code = code .replaceAll(multilineCommentsRE, '') @@ -81,21 +82,22 @@ export function snapshot( } } - for (const stmt of program.body) { - if ( - stmt.type === 'ExportNamedDeclaration' && - stmt.declaration === null && - stmt.specifiers.length - ) { - for (const specifier of stmt.specifiers) { - const exported = nodeToString(specifier.exported) - const local = nodeToString(specifier.local) - if (local !== exported) { - result[exported] = result[local] + if (applyExportRename) + for (const stmt of program.body) { + if ( + stmt.type === 'ExportNamedDeclaration' && + stmt.declaration === null && + stmt.specifiers.length + ) { + for (const specifier of stmt.specifiers) { + const exported = nodeToString(specifier.exported) + const local = nodeToString(specifier.local) + if (local !== exported) { + result[exported] = result[local] + } } } } - } return result diff --git a/src/index.ts b/src/index.ts index 8f72d2c..70ba6d2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,8 +43,10 @@ export function DtsSnapshot({ if (chunk.type === 'asset' || !filter(chunk.fileName)) continue const map: Record = (result[ - chunk.fileName - ] = snapshot(chunk.code, chunk.fileName)) + chunk.preliminaryFileName + ] = snapshot(chunk.code, chunk.fileName, { + applyExportRename: chunk.isEntry, + })) if (chunk.isEntry) { if (excludeNonExport) { @@ -54,6 +56,7 @@ export function DtsSnapshot({ } } } + map['#exports'] = chunk.exports } }