diff --git a/package.json b/package.json index 060b4ea..251ac33 100644 --- a/package.json +++ b/package.json @@ -4,31 +4,36 @@ "description": "A framework agnostic library for editable commands", "author": "@skyra", "license": "MIT", - "main": "dist/index.js", - "module": "dist/index.mjs", - "types": "dist/index.d.ts", + "type": "module", + "main": "dist/cjs/index.cjs", + "module": "dist/esm/index.mjs", + "types": "dist/cjs/index.d.cts", "exports": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.js" + "import": { + "types": "./dist/esm/index.d.mts", + "default": "./dist/esm/index.mjs" + }, + "require": { + "types": "./dist/cjs/index.d.cts", + "default": "./dist/cjs/index.cjs" + } }, "sideEffects": false, "homepage": "https://skyra-project.github.io/editable-commands", - "files": [ - "dist/**/*.js*", - "dist/**/*.mjs*", - "dist/**/*.d*" - ], "scripts": { "lint": "eslint src --ext ts --fix", "format": "prettier --write \"src/**/*.ts\"", "docs": "typedoc", - "build": "tsup", + "build": "tsup && yarn build:rename-mjs-index", + "build:rename-mjs-index": "node scripts/rename-mjs-index.mjs", "typecheck": "tsc -p tsconfig.eslint.json", "bump": "cliff-jumper", "check-update": "cliff-jumper --dry-run", "prepack": "yarn build" }, + "files": [ + "dist/" + ], "devDependencies": { "@commitlint/cli": "^19.3.0", "@commitlint/config-conventional": "^19.2.2", diff --git a/scripts/rename-mjs-index.mjs b/scripts/rename-mjs-index.mjs new file mode 100644 index 0000000..4d59d2e --- /dev/null +++ b/scripts/rename-mjs-index.mjs @@ -0,0 +1,13 @@ +import { green } from 'colorette'; +import { rename } from 'node:fs/promises'; +import { join } from 'node:path'; + +const inputPath = 'dist/esm/index.d.ts'; +const outputPath = 'dist/esm/index.d.mts'; + +const fullInputPathUrl = join(process.cwd(), inputPath); +const fullOutputPathUrl = join(process.cwd(), outputPath); + +await rename(fullInputPathUrl, fullOutputPathUrl); + +console.log(green(`✅ Renamed index.d.ts to index.d.mts`)); diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 3ad4f46..b1ab953 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig.base.json", - "include": ["src", "tsup.config.ts"] + "include": ["src", "scripts", "tsup.config.ts"] } diff --git a/tsup.config.ts b/tsup.config.ts index 6e6a0da..ff51061 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,14 +1,19 @@ -import { defineConfig } from 'tsup'; +import { Options, defineConfig } from 'tsup'; -export default defineConfig({ +const baseOptions: Options = { clean: true, dts: true, entry: ['src/index.ts'], - format: ['esm', 'cjs'], minify: false, skipNodeModulesBundle: true, sourcemap: true, target: 'es2020', tsconfig: 'src/tsconfig.json', - keepNames: true -}); + keepNames: true, + treeshake: true +}; + +export default [ + defineConfig({ ...baseOptions, outDir: 'dist/cjs', format: 'cjs' }), + defineConfig({ ...baseOptions, outDir: 'dist/esm', format: 'esm', outExtension: () => ({ js: '.mjs' }) }) +];