Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: split CJS and ESM builds correctly #295

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions scripts/rename-mjs-index.mjs
Original file line number Diff line number Diff line change
@@ -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`));
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.base.json",
"include": ["src", "tsup.config.ts"]
"include": ["src", "scripts", "tsup.config.ts"]
}
15 changes: 10 additions & 5 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -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' }) })
];
Loading