Skip to content

Commit 2502abb

Browse files
authoredDec 2, 2023
refactor: switch to split cjs and esm builds and fully build with tsup (#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
1 parent 34751a6 commit 2502abb

File tree

4 files changed

+208
-147
lines changed

4 files changed

+208
-147
lines changed
 

‎.rollup-type-bundlerrc.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
external:
2+
- node:url
3+
- node:events
4+
onlyBundle: true

‎package.json

+18-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
"name": "@sapphire/framework",
33
"version": "4.8.2",
44
"description": "Discord bot framework built for advanced and amazing bots.",
5-
"main": "dist/index.js",
6-
"module": "dist/index.mjs",
7-
"types": "dist/index.d.ts",
5+
"main": "dist/cjs/index.cjs",
6+
"module": "dist/esm/index.mjs",
7+
"types": "dist/cjs/index.d.ts",
88
"exports": {
9-
"import": "./dist/index.mjs",
10-
"require": "./dist/index.js",
11-
"types": "./dist/index.d.ts"
9+
"import": {
10+
"types": "./dist/esm/index.d.mts",
11+
"default": "./dist/esm/index.mjs"
12+
},
13+
"require": {
14+
"types": "./dist/cjs/index.d.ts",
15+
"default": "./dist/cjs/index.cjs"
16+
}
1217
},
1318
"author": "@sapphire",
1419
"license": "MIT",
@@ -20,12 +25,12 @@
2025
"test:watch": "vitest",
2126
"update": "yarn upgrade-interactive",
2227
"typecheck": "tsc -p tsconfig.eslint.json",
23-
"build": "tsup && yarn build:esm && yarn build:types",
24-
"build:esm": "gen-esm-wrapper dist/index.js dist/index.mjs",
25-
"build:types": "tsc -b src",
28+
"build": "tsup",
2629
"bump": "cliff-jumper",
2730
"check-update": "cliff-jumper --dry-run",
28-
"prepack": "rollup-type-bundler -v -e node:url node:events"
31+
"prepack": "yarn build && concurrently \"yarn:prepack:*\"",
32+
"prepack:cjs": "rollup-type-bundler -d dist/cjs",
33+
"prepack:esm": "rollup-type-bundler -d dist/esm -t .mts"
2934
},
3035
"dependencies": {
3136
"@discordjs/builders": "^1.7.0",
@@ -43,7 +48,7 @@
4348
"@commitlint/config-conventional": "^18.4.3",
4449
"@favware/cliff-jumper": "^2.2.3",
4550
"@favware/npm-deprecate": "^1.0.7",
46-
"@favware/rollup-type-bundler": "^2.0.0",
51+
"@favware/rollup-type-bundler": "^3.1.0",
4752
"@sapphire/eslint-config": "^5.0.2",
4853
"@sapphire/prettier-config": "^2.0.0",
4954
"@sapphire/ts-config": "^5.0.0",
@@ -52,6 +57,7 @@
5257
"@typescript-eslint/eslint-plugin": "^6.13.1",
5358
"@typescript-eslint/parser": "^6.13.1",
5459
"@vitest/coverage-v8": "^0.34.6",
60+
"concurrently": "^8.2.2",
5561
"cz-conventional-changelog": "^3.3.0",
5662
"discord.js": "^14.14.1",
5763
"esbuild-plugin-file-path-extensions": "^1.0.0",
@@ -63,7 +69,7 @@
6369
"gen-esm-wrapper": "^1.1.3",
6470
"lint-staged": "^15.1.0",
6571
"prettier": "^3.1.0",
66-
"tsup": "^7.3.0",
72+
"tsup": "^8.0.1",
6773
"typedoc": "^0.25.4",
6874
"typedoc-json-parser": "^9.0.1",
6975
"typescript": "^5.3.2",

‎tsup.config.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
import { esbuildPluginFilePathExtensions } from 'esbuild-plugin-file-path-extensions';
22
import { esbuildPluginVersionInjector } from 'esbuild-plugin-version-injector';
3-
import { defineConfig } from 'tsup';
3+
import { defineConfig, type Options } from 'tsup';
44

5-
export default defineConfig({
5+
const baseOptions: Options = {
66
clean: true,
77
entry: ['src/**/*.ts'],
8-
format: ['cjs'],
8+
dts: true,
99
minify: false,
1010
skipNodeModulesBundle: true,
1111
sourcemap: true,
12-
target: 'es2020',
12+
target: 'es2021',
1313
tsconfig: 'src/tsconfig.json',
1414
keepNames: true,
1515
esbuildPlugins: [esbuildPluginVersionInjector(), esbuildPluginFilePathExtensions()],
16-
treeshake: true,
17-
bundle: true,
18-
splitting: false
19-
});
16+
treeshake: true
17+
};
18+
19+
export default [
20+
defineConfig({
21+
...baseOptions,
22+
outDir: 'dist/cjs',
23+
format: 'cjs',
24+
outExtension: () => ({ js: '.cjs' })
25+
}),
26+
defineConfig({
27+
...baseOptions,
28+
outDir: 'dist/esm',
29+
format: 'esm'
30+
})
31+
];

0 commit comments

Comments
 (0)
Please sign in to comment.