Skip to content

Commit

Permalink
refactor: switch to split cjs and esm builds and fully build with tsup (
Browse files Browse the repository at this point in the history
#697)

* refactor: switch to split cjs and esm builds and fully build with tsup

* chore: revert to master version

* refactor: use a single tsup config
  • Loading branch information
favna authored Dec 2, 2023
1 parent 34751a6 commit 2502abb
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 147 deletions.
4 changes: 4 additions & 0 deletions .rollup-type-bundlerrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
external:
- node:url
- node:events
onlyBundle: true
30 changes: 18 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
"name": "@sapphire/framework",
"version": "4.8.2",
"description": "Discord bot framework built for advanced and amazing bots.",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"types": "dist/cjs/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
"import": {
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.cjs"
}
},
"author": "@sapphire",
"license": "MIT",
Expand All @@ -20,12 +25,12 @@
"test:watch": "vitest",
"update": "yarn upgrade-interactive",
"typecheck": "tsc -p tsconfig.eslint.json",
"build": "tsup && yarn build:esm && yarn build:types",
"build:esm": "gen-esm-wrapper dist/index.js dist/index.mjs",
"build:types": "tsc -b src",
"build": "tsup",
"bump": "cliff-jumper",
"check-update": "cliff-jumper --dry-run",
"prepack": "rollup-type-bundler -v -e node:url node:events"
"prepack": "yarn build && concurrently \"yarn:prepack:*\"",
"prepack:cjs": "rollup-type-bundler -d dist/cjs",
"prepack:esm": "rollup-type-bundler -d dist/esm -t .mts"
},
"dependencies": {
"@discordjs/builders": "^1.7.0",
Expand All @@ -43,7 +48,7 @@
"@commitlint/config-conventional": "^18.4.3",
"@favware/cliff-jumper": "^2.2.3",
"@favware/npm-deprecate": "^1.0.7",
"@favware/rollup-type-bundler": "^2.0.0",
"@favware/rollup-type-bundler": "^3.1.0",
"@sapphire/eslint-config": "^5.0.2",
"@sapphire/prettier-config": "^2.0.0",
"@sapphire/ts-config": "^5.0.0",
Expand All @@ -52,6 +57,7 @@
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"@vitest/coverage-v8": "^0.34.6",
"concurrently": "^8.2.2",
"cz-conventional-changelog": "^3.3.0",
"discord.js": "^14.14.1",
"esbuild-plugin-file-path-extensions": "^1.0.0",
Expand All @@ -63,7 +69,7 @@
"gen-esm-wrapper": "^1.1.3",
"lint-staged": "^15.1.0",
"prettier": "^3.1.0",
"tsup": "^7.3.0",
"tsup": "^8.0.1",
"typedoc": "^0.25.4",
"typedoc-json-parser": "^9.0.1",
"typescript": "^5.3.2",
Expand Down
28 changes: 20 additions & 8 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import { esbuildPluginFilePathExtensions } from 'esbuild-plugin-file-path-extensions';
import { esbuildPluginVersionInjector } from 'esbuild-plugin-version-injector';
import { defineConfig } from 'tsup';
import { defineConfig, type Options } from 'tsup';

export default defineConfig({
const baseOptions: Options = {
clean: true,
entry: ['src/**/*.ts'],
format: ['cjs'],
dts: true,
minify: false,
skipNodeModulesBundle: true,
sourcemap: true,
target: 'es2020',
target: 'es2021',
tsconfig: 'src/tsconfig.json',
keepNames: true,
esbuildPlugins: [esbuildPluginVersionInjector(), esbuildPluginFilePathExtensions()],
treeshake: true,
bundle: true,
splitting: false
});
treeshake: true
};

export default [
defineConfig({
...baseOptions,
outDir: 'dist/cjs',
format: 'cjs',
outExtension: () => ({ js: '.cjs' })
}),
defineConfig({
...baseOptions,
outDir: 'dist/esm',
format: 'esm'
})
];
Loading

0 comments on commit 2502abb

Please sign in to comment.