Skip to content

perf(build): ⚡ migrate from tsup to faster tsdown #2160

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"node": ">=18.0.0"
},
"scripts": {
"build": "pnpm -r --filter=./packages/** run build",
"build": "pnpm -r --filter=./packages/** --parallel run build",
"ci:publish": "zx scripts/publish.mjs",
"cy": "cypress open",
"cy:fixture": "pnpm -C cypress/fixtures/basic run dev",
Expand Down Expand Up @@ -64,7 +64,7 @@
"simple-git-hooks": "catalog:dev",
"taze": "catalog:dev",
"tinyexec": "catalog:prod",
"tsup": "catalog:dev",
"tsdown": "catalog:dev",
"tsx": "catalog:dev",
"typescript": "catalog:dev",
"vite": "catalog:prod",
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"node": ">=18.0.0"
},
"scripts": {
"build": "rimraf dist && tsup src/index.ts src/core.ts src/fs.ts src/utils.ts",
"build": "tsdown src/index.ts src/core.ts src/fs.ts src/utils.ts",
"dev": "nr build --watch",
"prepublishOnly": "npm run build"
},
Expand Down
1 change: 1 addition & 0 deletions packages/parser/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '../../tsdown.config.ts'
1 change: 0 additions & 1 deletion packages/parser/tsup.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/slidev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"node": ">=18.0.0"
},
"scripts": {
"build": "rimraf dist && tsup node/index.ts node/cli.ts",
"build": "tsdown node/index.ts node/cli.ts",
"dev": "nr build --watch",
"prepublishOnly": "npm run build",
"start": "tsx node/cli.ts"
Expand Down
1 change: 1 addition & 0 deletions packages/slidev/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '../../tsdown.config.ts'
1 change: 0 additions & 1 deletion packages/slidev/tsup.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"node": ">=18.0.0"
},
"scripts": {
"build": "tsup src/index.ts",
"build": "tsdown src/index.ts",
"dev": "nr build --watch",
"prepublishOnly": "npm run build"
},
Expand Down
1 change: 1 addition & 0 deletions packages/types/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '../../tsdown.config.ts'
1 change: 0 additions & 1 deletion packages/types/tsup.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/vscode/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ node_modules/**
language-server/**
scripts/**
src/**
tsup.config.ts
tsdown.config.ts
*.map
4 changes: 2 additions & 2 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@
"publish": "tsx scripts/publish.ts",
"pack": "vsce package --no-dependencies",
"prepare": "tsx scripts/schema.ts",
"build": "tsup --env.NODE_ENV production --treeshake",
"dev": "nr prepare && tsup --watch ./src --watch ./language-server --env.NODE_ENV development",
"build": "tsdown --env.NODE_ENV production --treeshake",
"dev": "nr prepare && tsdown --watch ./src --watch ./language-server --env.NODE_ENV development",
"vscode:prepublish": "nr build"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/syntaxes/codeblock-patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs'
import { join } from 'node:path'

const Markdown = JSON.parse(
readFileSync(join(__dirname, '../node_modules/tm-grammars/grammars/markdown.json'), 'utf8'),
readFileSync(join(import.meta.dirname, '../node_modules/tm-grammars/grammars/markdown.json'), 'utf8'),
)

const base = {
Expand Down
3 changes: 3 additions & 0 deletions packages/vscode/syntaxes/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"compilerOptions": {
"module": "Preserve"
},
"include": [
"*.ts",
"*.vue",
Expand Down
21 changes: 11 additions & 10 deletions packages/vscode/tsup.config.ts → packages/vscode/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@ import { copyFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import process from 'node:process'
import { resolvePath } from 'mlly'
import { defineConfig } from 'tsup'
import { generateCodeblockPatch } from './syntaxes/codeblock-patch'
import { defineConfig } from 'tsdown'
import { generateCodeblockPatch } from './syntaxes/codeblock-patch.ts'

export default defineConfig({
// @ts-expect-error `entry` is valid option
entry: {
'index': 'src/index.ts',
'language-server': 'language-server/bin.ts',
},
format: ['cjs'],
format: 'cjs',
target: 'node18',
clean: true,
minify: process.env.NODE_ENV === 'production',
sourcemap: true,
external: [
'vscode',
],
inject: ['./language-server/import-meta-url.ts'],
shims: ['./language-server/import-meta-url.ts'],
define: {
'import.meta.url': 'import_meta_url',
},
esbuildPlugins: [{
plugins: [{
name: 'umd2esm',
setup(build) {
build.onResolve({ filter: /^(vscode-.*-languageservice|jsonc-parser)/ }, async (args) => {
setup(build: any) {
build.onResolve({ filter: /^(vscode-.*-languageservice|jsonc-parser)/ }, async (args: any) => {
const pathUmdMay = await resolvePath(args.path, { url: args.resolveDir })
// Call twice the replace is to solve the problem of the path in Windows
const pathEsm = pathUmdMay.replace('/umd/', '/esm/').replace('\\umd\\', '\\esm\\')
Expand All @@ -34,8 +35,8 @@ export default defineConfig({
},
}],
async onSuccess() {
const assetsDir = join(__dirname, '../../assets')
const resDir = join(__dirname, './dist/res')
const assetsDir = join(import.meta.dirname, '../../assets')
const resDir = join(import.meta.dirname, './dist/res')

if (!existsSync(resDir))
mkdirSync(resDir, { recursive: true })
Expand All @@ -44,7 +45,7 @@ export default defineConfig({
copyFileSync(join(assetsDir, file), join(resDir, file))

writeFileSync(
join(__dirname, 'syntaxes/codeblock-patch.json'),
join(import.meta.dirname, 'syntaxes/codeblock-patch.json'),
JSON.stringify(generateCodeblockPatch(), null, 2),
)
},
Expand Down
Loading
Loading