Skip to content

Commit

Permalink
feat: use @rollup/plugin-typescript, closes #59
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

removed flags --minify, --target because we replaced rollup-plugin-esbuild with @rollup/plugin-typescript
  • Loading branch information
egoist committed Jul 10, 2020
1 parent 048e19f commit fe5c6d2
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 83 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
# tsup

Rollup + [esbuild](https://github.com/evanw/esbuild).
Rollup your TypeScript library with no config.

This library is intentionally kept simple, if you want customizations please use Rollup directly.

## Why Rollup?

> Rollup is at least an order of magnitude slower than esbuild, why not use esbuild directly?
Because esbuild isn't mature enough, here we use Rollup to bundle `.d.ts` files, add code splitting support, import non-js assets etc. tsup uses esbuild to compile TypeScript/ESNext code to ES2015.

## What can it bundle?

Anything that's supported by Node.js natively, namely `.js`, `.json`, `.mjs`. Plus `.ts`, `.vue` (soon), `.css` (soon).
Anything that's supported by Node.js natively, namely `.js`, `.json`, `.mjs`. And TypeScript `.ts`, `.tsx`

## Install

Expand Down Expand Up @@ -54,8 +48,6 @@ tsup [...files] --bundle

`dependencies` in your `packages.json` are always excluded, you can also use `--external <module>` flag to mark specific package as external.

When you're bundling a lot files, this can be 10x~200x slower than esbuild.

### Run a program

```bash
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@
],
"author": "EGOIST",
"license": "MIT",
"repository": {
"url": "https://github.com/egoist/tsup.git"
},
"scripts": {
"build": "rm -rf dist && tsup src/cli.ts src/index.ts --external typescript --bundle --dts",
"prepublishOnly": "npm run build",
"test": "npm run build && jest"
},
"dependencies": {
"@rollup/plugin-typescript": "^5.0.1",
"joycon": "^2.2.5",
"rollup": "^2.20.0",
"rollup-plugin-dts": "^1.4.7",
"rollup-plugin-esbuild": "^2.1.0"
"tslib": "^2.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"@types/fs-extra": "^8.1.0",
"@types/jest": "^26.0.4",
"@types/node": "^14.0.18",
"@types/node": "^14.0.21",
"@types/resolve": "^1.17.1",
"cac": "^6.5.10",
"colorette": "^1.2.0",
Expand All @@ -37,8 +41,8 @@
"pretty-bytes": "^5.3.0",
"resolve": "^1.17.0",
"rollup-plugin-hashbang": "^2.2.2",
"ts-jest": "^25.5.1",
"tsup": "^1.4.4",
"ts-jest": "^26.1.1",
"tsup": "^1.5.1",
"typescript": "^3.9.6"
}
}
5 changes: 0 additions & 5 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ async function main() {
.option('--format <format>', 'Bundle format, "cjs", "iife", "umd", "esm"', {
default: 'cjs',
})
.option('--minify', 'Minify bundle')
.option('--target <target>', 'Bundle target, "es20XX" or "esnext"', {
default: 'es2017',
})
.option('--bundle', 'Bundle node_modules')
.option('--dts', 'Generate declaration file')
.option('--dts-bundle', 'Bundle types from node_modules')
Expand Down Expand Up @@ -93,7 +89,6 @@ async function main() {
define: options.define,
outDir: 'dist',
format: 'cjs',
target: 'es2017',
})
const bundle = await rollup(rollupConfig.inputConfig)
const { output } = await bundle.write(rollupConfig.outputConfig)
Expand Down
23 changes: 11 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { ModuleFormat, InputOptions, OutputOptions } from 'rollup'
import { Target as EsbuildTarget } from 'esbuild'
import prettyBytes from 'pretty-bytes'
import colors from 'colorette'
import hashbangPlugin from 'rollup-plugin-hashbang'
import esbuildPlugin from 'rollup-plugin-esbuild'
import tsPlugin from '@rollup/plugin-typescript'
import commonjsPlugin from '@rollup/plugin-commonjs'
import jsonPlugin from '@rollup/plugin-json'
import { sizePlugin, caches } from './size-plugin'
import { resolvePlugin } from './resolve-plugin'
import { isExternal } from './utils'
import { isExternal, resolveTsConfig } from './utils'

type Options = {
// Bundle packages in node_modules
Expand All @@ -17,9 +16,7 @@ type Options = {
dts?: boolean
// Bundle .d.ts files in node_modules
dtsBundle?: boolean
target?: EsbuildTarget
watch?: boolean
minify?: boolean
jsxFactory?: string
jsxFragment?: string
outDir: string
Expand All @@ -38,6 +35,12 @@ export async function createRollupConfigs(files: string[], options: Options) {
options.dts = true
}

const tsconfig = resolveTsConfig(process.cwd()) || false

if (tsconfig) {
console.log(`Using tsconfig: ${tsconfig}`)
}

const getRollupConfig = async ({
dts,
dtsBundle,
Expand Down Expand Up @@ -68,13 +71,9 @@ export async function createRollupConfigs(files: string[], options: Options) {
hashbangPlugin(),
jsonPlugin(),
!dts &&
esbuildPlugin({
target: options.target,
watch: options.watch,
minify: options.minify,
jsxFactory: options.jsxFactory,
jsxFragment: options.jsxFragment,
define: options.define,
tsPlugin({
module: 'esnext',
tsconfig,
}),
(!dts || dtsBundle) &&
resolvePlugin({
Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import JoyCon from 'joycon'

// No backslash in path
function slash(input: string) {
return input.replace(/\\/g, '/')
Expand Down Expand Up @@ -36,4 +38,9 @@ export function isExternal(
}

return false
}

export function resolveTsConfig(cwd: string) {
const joycon = new JoyCon()
return joycon.resolveSync(['tsconfig.build.json', 'tsconfig.json'], cwd)
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
"outDir": "./dist", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
Expand Down Expand Up @@ -50,6 +50,7 @@
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

"skipLibCheck": true,
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
Expand Down
113 changes: 62 additions & 51 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,15 @@
is-module "^1.0.0"
resolve "^1.14.2"

"@rollup/pluginutils@^3.0.10", "@rollup/pluginutils@^3.0.8":
version "3.0.10"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.0.10.tgz#a659b9025920378494cd8f8c59fbf9b3a50d5f12"
integrity sha512-d44M7t+PjmMrASHbhgpSbVgtL6EFyX7J4mYxwQ/c5eoaE6N2VgCgEcWVzNnwycIloti+/MpwFr8qfw+nRw00sw==
"@rollup/plugin-typescript@^5.0.1":
version "5.0.1"
resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-5.0.1.tgz#af1cb238e4821e9e371cb00b10a7f61f282fca5b"
integrity sha512-r2rfyh7dFfqHwxkITM/I9sW+rkx66/ycr12msvZliU6AX1plIcRq4lU9crcQbcSjMr7T9ONWM6pAwsBiNAYW8g==
dependencies:
"@types/estree" "0.0.39"
estree-walker "^1.0.1"
picomatch "^2.2.2"
"@rollup/pluginutils" "^3.0.1"
resolve "^1.14.1"

"@rollup/pluginutils@^3.1.0":
"@rollup/pluginutils@^3.0.1", "@rollup/pluginutils@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b"
integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==
Expand All @@ -505,6 +504,15 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"

"@rollup/pluginutils@^3.0.8":
version "3.0.10"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.0.10.tgz#a659b9025920378494cd8f8c59fbf9b3a50d5f12"
integrity sha512-d44M7t+PjmMrASHbhgpSbVgtL6EFyX7J4mYxwQ/c5eoaE6N2VgCgEcWVzNnwycIloti+/MpwFr8qfw+nRw00sw==
dependencies:
"@types/estree" "0.0.39"
estree-walker "^1.0.1"
picomatch "^2.2.2"

"@sinonjs/commons@^1.7.0":
version "1.7.2"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.7.2.tgz#505f55c74e0272b43f6c52d81946bed7058fc0e2"
Expand Down Expand Up @@ -615,11 +623,16 @@
jest-diff "^25.2.1"
pretty-format "^25.2.1"

"@types/node@*", "@types/node@^14.0.18":
"@types/node@*":
version "14.0.18"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.18.tgz#5111b2285659442f9f95697386a2b42b875bd7e9"
integrity sha512-0Z3nS5acM0cIV4JPzrj9g/GH0Et5vmADWtip3YOXOp1NpOLU8V3KoZDc8ny9c1pe/YSYYzQkAWob6dyV/EWg4g==

"@types/node@^14.0.21":
version "14.0.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.21.tgz#c84005e3f43b7e19a7374d47d5c411039da59231"
integrity sha512-kmfWRnh81BrOfQ2Bn3xXCkoB6PLNsJlHhliYvkPa5UL6nmMHkANm358zVpO7TW6CDe9i267pkS/Id65OKL8+Ug==

"@types/normalize-package-data@^2.4.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
Expand Down Expand Up @@ -1305,15 +1318,10 @@ error-ex@^1.3.1:
dependencies:
is-arrayish "^0.2.1"

esbuild@^0.3.0:
version "0.3.2"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.3.2.tgz#3f6bdfbf51b2e776bb57952691930097b3770705"
integrity sha512-sm5o2D/nHhXSrs2D4UySNeyjSxJlgxQ6Ze2Cy6OOIJqbuDd/u6sMtiSn243bAEiyyYzlazueeryrrWJJCkv8lA==

esbuild@^0.5.3:
version "0.5.14"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.5.14.tgz#c7c900f728304136556db036840e638318e81cf1"
integrity sha512-0vVlkpR7XOsqzhUA6xgKzZ/vIXCi+sZZI7t/HG4vJ+nUqo77iEyg1KfIKuqk2kBJQ9/Ts7NXuK5/mfL2J0ZVzA==
version "0.5.26"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.5.26.tgz#0868e8f3e0938c6cb9a8c93e74f85900eff1a071"
integrity sha512-OopLmIbQNOWBWMBoOtHjDEaIiTI2okEpRkbiKccfatnXJtsGazwWhR0dmvY8ynjLx/BOPS9mQ6QFl7J1BQCcaQ==

escape-string-regexp@^1.0.5:
version "1.0.5"
Expand Down Expand Up @@ -2646,12 +2654,10 @@ mixin-deep@^1.2.0:
for-in "^1.0.2"
is-extendable "^1.0.1"

[email protected]:
version "0.5.5"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def"
integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==
dependencies:
minimist "^1.2.5"
[email protected]:
version "1.0.4"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

[email protected]:
version "2.0.0"
Expand Down Expand Up @@ -3092,7 +3098,7 @@ resolve-url@^0.2.1:
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=

resolve@^1.10.0, resolve@^1.11.0, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.3.2:
resolve@^1.10.0, resolve@^1.11.0, resolve@^1.14.1, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.3.2:
version "1.17.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444"
integrity sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==
Expand All @@ -3118,14 +3124,6 @@ rollup-plugin-dts@^1.4.7:
optionalDependencies:
"@babel/code-frame" "^7.8.3"

rollup-plugin-esbuild@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-esbuild/-/rollup-plugin-esbuild-1.4.1.tgz#b388ebd4cda1198208d7746feea7656d485019b0"
integrity sha512-gTzKtVo/OiOOe6pwRFHQCyCtEeYxcxLmjpqMiT4TnwXtPdF8RNP9c5wh/NZPztQydcMdEe1W+TO7poXwbLQekw==
dependencies:
"@rollup/pluginutils" "^3.0.10"
esbuild "^0.3.0"

rollup-plugin-esbuild@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-esbuild/-/rollup-plugin-esbuild-2.1.0.tgz#8e12337c63a5b1144e0c5e8adf2f1568ad4d7d69"
Expand All @@ -3141,7 +3139,14 @@ rollup-plugin-hashbang@^2.2.2:
dependencies:
magic-string "^0.22.4"

rollup@^2.10.0, rollup@^2.20.0:
rollup@^2.18.0:
version "2.21.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.21.0.tgz#d2e114533812043d5c9b7b0a83f1b2a242e4e1d6"
integrity sha512-BEGgy+wSzux7Ycq58pRiWEOBZaXRXTuvzl1gsm7gqmsAHxkWf9nyA5V2LN9fGSHhhDQd0/C13iRzSh4bbIpWZQ==
optionalDependencies:
fsevents "~2.1.2"

rollup@^2.20.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.20.0.tgz#7456fed8424a5247954958751642e9fdd0ad7485"
integrity sha512-hkbp//ne1om8+PQRpd81zk0KDvbJxkLZdZJh1ZNxjd1EkI0H1TmYuHqqXx88yciS+5YnMom3geubQjTeeUnNNw==
Expand Down Expand Up @@ -3202,16 +3207,16 @@ saxes@^5.0.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==

[email protected], semver@^6.0.0, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@^7.2.1, semver@^7.3.2:
[email protected], semver@^7.2.1, semver@^7.3.2:
version "7.3.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==

semver@^6.0.0, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

set-blocking@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
Expand Down Expand Up @@ -3572,10 +3577,10 @@ tr46@^2.0.2:
dependencies:
punycode "^2.1.1"

ts-jest@^25.5.1:
version "25.5.1"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-25.5.1.tgz#2913afd08f28385d54f2f4e828be4d261f4337c7"
integrity sha512-kHEUlZMK8fn8vkxDjwbHlxXRB9dHYpyzqKIGDNxbzs+Rz+ssNDSDNusEK8Fk/sDd4xE6iKoQLfFkFVaskmTJyw==
ts-jest@^26.1.1:
version "26.1.1"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.1.1.tgz#b98569b8a4d4025d966b3d40c81986dd1c510f8d"
integrity sha512-Lk/357quLg5jJFyBQLnSbhycnB3FPe+e9i7ahxokyXxAYoB0q1pPmqxxRPYr4smJic1Rjcf7MXDBhZWgxlli0A==
dependencies:
bs-logger "0.x"
buffer-from "1.x"
Expand All @@ -3584,18 +3589,24 @@ ts-jest@^25.5.1:
lodash.memoize "4.x"
make-error "1.x"
micromatch "4.x"
mkdirp "0.x"
semver "6.x"
mkdirp "1.x"
semver "7.x"
yargs-parser "18.x"

tsup@^1.4.4:
version "1.4.4"
resolved "https://registry.yarnpkg.com/tsup/-/tsup-1.4.4.tgz#014d34eafa58b418224c38ce1773e1e96c6a9cfc"
integrity sha512-x9AKi9iHgflC4IOGSnbyze9a8WF9ef6vxFJWhSp7ZACxtLdubautGxNLuXxEBZOtnFvXm0X0yZjVelKeqqLJ4A==
tslib@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.0.tgz#18d13fc2dce04051e20f074cc8387fd8089ce4f3"
integrity sha512-lTqkx847PI7xEDYJntxZH89L2/aXInsyF2luSafe/+0fHOMjlBNXdH6th7f70qxLDhul7KZK0zC8V5ZIyHl0/g==

tsup@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/tsup/-/tsup-1.5.1.tgz#34022d3e7a2e6dc0f3d6b6399c12ac54f9182c73"
integrity sha512-H4CpUz5GAiS36HhJSrCTbNPOl1V0FT1WkMb1mnygmU67l7f4fpG9MsxeH7dHzT7Q3pyCZapBscnG5h7DuUnU7g==
dependencies:
joycon "^2.2.5"
rollup "^2.10.0"
rollup-plugin-esbuild "^1.4.1"
rollup "^2.18.0"
rollup-plugin-dts "^1.4.7"
rollup-plugin-esbuild "^2.1.0"

tunnel-agent@^0.6.0:
version "0.6.0"
Expand Down

0 comments on commit fe5c6d2

Please sign in to comment.