Files
SnowLuma/.pnpm-store/v11/files/dd/1ea039d371fe3d51bfe240d7b3b687b1cf83648f6de27cb46515e3fc1bda7f9d9c98464ce1293cbde2a23100c3b04687afbe274baa77deae03f86e4fde15e0
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

56 lines
1.8 KiB
Plaintext

import fs from 'node:fs/promises';
import { i as internalFixDefaultCJSExports } from './utils-DwzdDEfz.mjs';
import 'magic-string';
import 'mlly';
function transformDtsDefaultCJSExports(code, fileName, options = {}) {
return internalFixDefaultCJSExports(code, {
fileName,
// we don't need the imports (used only for exporting types optimization)
imports: []
}, options);
}
async function fixDtsFileDefaultCJSExports(dtsPath, options = {}) {
const result = transformDtsDefaultCJSExports(
await fs.readFile(dtsPath, "utf-8"),
dtsPath,
options
);
if (result) {
await fs.writeFile(dtsPath, result, "utf8");
}
return !!result;
}
async function transformESMDtsToCJSDts(dtsPath, dtsDestPath, options = {}) {
if (dtsPath === dtsDestPath) {
throw new Error(`dtsPath and dtsDestPath should be different: ${dtsPath}`);
}
const code = await fs.readFile(dtsPath, "utf-8");
const result = transformDtsDefaultCJSExports(
code,
dtsPath,
options
) ?? code;
const { transformLocalImports = defaultLocalImportsTransformer } = options;
await fs.writeFile(
dtsDestPath,
transformLocalImports(result, dtsPath, dtsDestPath),
"utf8"
);
}
function defaultLocalImportsTransformer(code, dtsPath, dtsDestPath) {
const from = dtsPath.endsWith(".d.mts") ? /\s+(from\s+["'].\.?\/.*(\.mjs)["'];?)\s+/g : /\s+(from\s+["'].\.?\/.*(\.js)["'];?)\s+/g;
let matcher = from.exec(code);
if (!matcher) {
return code;
}
const extension = dtsDestPath.endsWith("d.ts") ? ".js" : ".cjs";
while (matcher) {
code = code.replaceAll(matcher[1], matcher[1].replace(matcher[2], extension));
matcher = from.exec(code);
}
return code;
}
export { defaultLocalImportsTransformer, fixDtsFileDefaultCJSExports, transformDtsDefaultCJSExports, transformESMDtsToCJSDts };