diff --git a/package.json b/package.json index 489ca64..31f34b1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ ".": { "types": { "import": "./dist/index.d.ts", - "require": "./cjs/index.d.cts" + "require": "./cjs/index.d.ts" }, "import": "./dist/index.js", "require": "./cjs/index.js", diff --git a/scripts/prepare-packages.js b/scripts/prepare-packages.js deleted file mode 100644 index 2190440..0000000 --- a/scripts/prepare-packages.js +++ /dev/null @@ -1,59 +0,0 @@ -import fs from 'node:fs' -import { join } from 'node:path' - -main() - .then(() => { - console.log('Packages Ready') - process.exit(0) - }) - .catch(err => { - console.error(err) - process.exit(1) - }) - -async function main() { - const distFolders = [ - { - path: 'cjs', - type: 'commonjs' - }, - { - path: 'dist', - type: 'module' - } - ] - - for (let folderMeta of distFolders) { - const folderPath = join(process.cwd(), folderMeta.path) - const doesFolderExist = fs.existsSync(folderPath) - if (!doesFolderExist) continue - - await fs.promises.writeFile( - join(folderPath, 'package.json'), - JSON.stringify({ type: folderMeta.type }, null, 2), - 'utf8' - ) - - if (folderMeta.type === 'commonjs') { - const dtsFiles = await collectDTSFiles(folderPath) - for (let typeDefFile of dtsFiles) { - const renamedFile = typeDefFile.replace(/(\.d\.ts)$/, '.d.cts') - await fs.promises.rename(typeDefFile, renamedFile) - } - } - } -} - -async function collectDTSFiles(directory, paths = []) { - const assets = await fs.promises.readdir(directory) - for (let asset of assets) { - const assetPath = join(directory, asset) - const fileStat = await fs.promises.stat(assetPath) - if (fileStat.isFile()) { - paths.push(assetPath) - } else { - paths = paths.concat(await collectDTSFiles(assetPath, [])) - } - } - return paths.filter(x => x.endsWith('.d.ts')) -}