From 516f89aca401c4b01219aa4b3a418096897b14fd Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Tue, 28 Oct 2025 14:51:40 +0100 Subject: [PATCH] fix: cjs declaration --- commonjs.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/commonjs.js b/commonjs.js index 7bf5e61..73fd6b7 100644 --- a/commonjs.js +++ b/commonjs.js @@ -12,6 +12,17 @@ function convertToCommonJs(filePath) { fs.renameSync(filePath, commonJsPath); } +function convertToCommonJsDeclaration(filePath) { + // update imports + const content = fs.readFileSync(filePath, 'utf-8'); + const updatedContent = content.replace(/(from ['"])(.*)(\.js)(['"];?)/g, '$1$2.cjs$4'); + fs.writeFileSync(filePath, updatedContent, 'utf-8'); + + // update file extension + const commonJsDeclPath = filePath.replace(/\.d\.ts$/, '.d.cts'); + fs.renameSync(filePath, commonJsDeclPath); +} + function walk(dir) { fs.readdirSync(dir).forEach(file => { const fullPath = path.join(dir, file); @@ -19,6 +30,8 @@ function walk(dir) { walk(fullPath); } else if (file.endsWith('.js')) { convertToCommonJs(fullPath); + } else if (file.endsWith('.d.ts')) { + convertToCommonJsDeclaration(fullPath); } }); }