diff --git a/.gitignore b/.gitignore index a2f9a256..0e75fe55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ node_modules dist -dist-cjs coverage diff --git a/commonjs.js b/commonjs.js deleted file mode 100644 index 73fd6b72..00000000 --- a/commonjs.js +++ /dev/null @@ -1,39 +0,0 @@ -import fs from 'fs'; -import path from 'path'; - -function convertToCommonJs(filePath) { - // update imports - const content = fs.readFileSync(filePath, 'utf-8'); - const updatedContent = content.replace(/(require\(['"])(.*)(\.js)(['"]\))/g, '$1$2.cjs$4'); - fs.writeFileSync(filePath, updatedContent, 'utf-8'); - - // update file extension - const commonJsPath = filePath.replace(/\.js$/, '.cjs'); - 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); - if (fs.lstatSync(fullPath).isDirectory()) { - walk(fullPath); - } else if (file.endsWith('.js')) { - convertToCommonJs(fullPath); - } else if (file.endsWith('.d.ts')) { - convertToCommonJsDeclaration(fullPath); - } - }); -} - -walk('./dist-cjs'); diff --git a/package.json b/package.json index 349f0d56..890df89f 100644 --- a/package.json +++ b/package.json @@ -2,23 +2,19 @@ "version": "2.2.5", "license": "MIT", "type": "module", - "typings": "dist/index.d.cts", + "typings": "dist/index.d.ts", "main": "./dist/index.js", "exports": { - "import": "./dist/index.js", - "require": "./dist-cjs/index.cjs" + ".": "./dist/index.js" }, "files": [ - "dist", - "dist-cjs" + "dist" ], "engines": { "node": ">=16" }, "scripts": { - "build": "yarn run build:esm && yarn run build:cjs", - "build:esm": "tsc -p tsconfig.json", - "build:cjs": "tsc -p tsconfig.cjs.json && node commonjs.js", + "build": "tsc", "test": "vitest run", "lint": "tsdx lint", "prepack": "yarn build", diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json deleted file mode 100644 index 67774dfa..00000000 --- a/tsconfig.cjs.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "CommonJS", - "outDir": "dist-cjs" - } -}