From f372b2f403e546e88673a8d7f4d98b776c0eafbf Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 20 Jun 2025 01:59:55 +0800 Subject: [PATCH] refactor: migrate from tsup to tsdown for build process - Replaced `tsup` with `tsdown` in multiple package configurations to streamline the build process. - Updated build scripts in `package.json` files across various applications and packages. - Introduced new `tsdown.config.ts` files for configuration in the `ssr` and `readability` packages. - Removed obsolete `tsup.config.ts` files to clean up the project structure. Signed-off-by: Innei Signed-off-by: Innei --- apps/ssr/package.json | 4 +- apps/ssr/src/lib/dev-vite.ts | 3 +- apps/ssr/src/lib/env.ts | 2 +- apps/ssr/tsconfig.json | 2 +- apps/ssr/tsdown.config.ts | 65 ++++++++ apps/ssr/tsup.config.ts | 43 ----- packages/readability/package.json | 4 +- .../{tsup.config.ts => tsdown.config.ts} | 3 +- pnpm-lock.yaml | 148 +++--------------- 9 files changed, 92 insertions(+), 182 deletions(-) create mode 100644 apps/ssr/tsdown.config.ts delete mode 100644 apps/ssr/tsup.config.ts rename packages/readability/{tsup.config.ts => tsdown.config.ts} (73%) diff --git a/apps/ssr/package.json b/apps/ssr/package.json index 3f03e4c0c..87922e9bc 100644 --- a/apps/ssr/package.json +++ b/apps/ssr/package.json @@ -2,7 +2,7 @@ "name": "@follow/ssr", "private": true, "scripts": { - "build": "cross-env NODE_ENV=production vite build && tsx scripts/prepare-vercel-build.ts && tsup && tsx scripts/cleanup-vercel-build.ts", + "build": "cross-env NODE_ENV=production vite build && tsx scripts/prepare-vercel-build.ts && tsdown && tsx scripts/cleanup-vercel-build.ts", "dev": "cross-env NODE_ENV=development tsx watch --include \"src/**/*.ts\" --exclude \"./*.ts\" --exclude \"./*.mjs\" index.ts", "meta": "tsx helper/meta-map.ts --watch", "start": "tsx index.ts", @@ -66,7 +66,7 @@ "nanoid": "5.1.5", "path-to-regexp": "8.2.0", "tailwindcss-uikit-colors": "0.6.2", - "tsup": "8.5.0", + "tsdown": "0.12.8", "tsx": "4.19.4", "typescript": "catalog:", "vite": "6.3.5" diff --git a/apps/ssr/src/lib/dev-vite.ts b/apps/ssr/src/lib/dev-vite.ts index 53108a603..84fa90c83 100644 --- a/apps/ssr/src/lib/dev-vite.ts +++ b/apps/ssr/src/lib/dev-vite.ts @@ -2,12 +2,13 @@ import { resolve } from "node:path" import type { FastifyInstance } from "fastify" import type { ViteDevServer } from "vite" -import { createServer as createViteServer } from "vite" const root = resolve(__dirname, "../..") let globalVite: ViteDevServer export const registerDevViteServer = async (app: FastifyInstance) => { + const createViteServer = await import("vite").then((m) => m.createServer) + const vite = await createViteServer({ server: { middlewareMode: true }, appType: "custom", diff --git a/apps/ssr/src/lib/env.ts b/apps/ssr/src/lib/env.ts index 2dd9d4a4b..56f4a2872 100644 --- a/apps/ssr/src/lib/env.ts +++ b/apps/ssr/src/lib/env.ts @@ -1 +1 @@ -export const isDev = process.env.NODE_ENV === "development" +export const isDev = false diff --git a/apps/ssr/tsconfig.json b/apps/ssr/tsconfig.json index 3bf98ac2f..5f128ee76 100644 --- a/apps/ssr/tsconfig.json +++ b/apps/ssr/tsconfig.json @@ -33,7 +33,7 @@ "./index.ts", "./api/index.ts", "./scripts/**/*.ts", - "./tsup.config.ts", + "tsdown.config.ts", "./client/**/*.ts", "./client/**/*.tsx", "vite.config.mts", diff --git a/apps/ssr/tsdown.config.ts b/apps/ssr/tsdown.config.ts new file mode 100644 index 000000000..d641ac0a8 --- /dev/null +++ b/apps/ssr/tsdown.config.ts @@ -0,0 +1,65 @@ +import { createReadStream, createWriteStream, readdirSync, renameSync } from "node:fs" +import { createRequire } from "node:module" +import { resolve } from "node:path" + +import { defineConfig } from "tsdown" + +export default defineConfig({ + entry: ["./index.ts"], + outDir: "dist/server", + + clean: true, + format: ["cjs"], + external: ["lightningcss", "vite"], + treeshake: true, + define: { + __DEV__: JSON.stringify(process.env.NODE_ENV === "development"), + }, + hooks(hooks) { + hooks.hook("build:done", async () => { + if (process.env.VERCEL !== "1") return + + const outputFile = "dist/server/index.js" + const tempFile = `${outputFile}.tmp` + + try { + const insertCode = `try { +require.resolve("@fontsource/sn-pro") +require.resolve('kose-font') +require.resolve('kose-font/fonts/KosefontP-JP.ttf') +require.resolve('kose-font/fonts/Kosefont-JP.ttf') +${(() => { + const require = createRequire(import.meta.url) + const fontDepsPath = require.resolve("@fontsource/sn-pro") + const fontsDirPath = resolve(fontDepsPath, "../files") + return readdirSync(fontsDirPath) + .map((file) => `require.resolve("@fontsource/sn-pro/files/${file}")`) + .join("\n") +})()} +} catch {} + ` + + const writeStream = createWriteStream(tempFile) + + if (insertCode) { + writeStream.write(insertCode) + } + + const readStream = createReadStream(outputFile) + + await new Promise((resolve, reject) => { + readStream.pipe(writeStream) + writeStream.on("finish", () => resolve()) + writeStream.on("error", reject) + readStream.on("error", reject) + }) + + renameSync(tempFile, outputFile) + + console.info("Successfully inserted font dependencies into", outputFile) + } catch (error) { + console.error("Failed to modify output file:", error) + } + }) + }, +}) diff --git a/apps/ssr/tsup.config.ts b/apps/ssr/tsup.config.ts deleted file mode 100644 index bab5d123d..000000000 --- a/apps/ssr/tsup.config.ts +++ /dev/null @@ -1,43 +0,0 @@ -import fs from "node:fs" -import { createRequire } from "node:module" -import path, { resolve } from "node:path" - -import { defineConfig } from "tsup" - -export default defineConfig(() => { - return { - entry: ["index.ts"], - outDir: "dist/server", - splitting: false, - clean: true, - format: ["cjs"], - external: ["lightningcss"], - treeshake: true, - define: { - __DEV__: JSON.stringify(process.env.NODE_ENV === "development"), - }, - banner: { - // A trick to get vercel to recognize fonts as such and then keep the node_modules - js: - process.env.VERCEL === "1" - ? ` - try { - require.resolve("@fontsource/sn-pro") - require.resolve('kose-font') - require.resolve('kose-font/fonts/KosefontP-JP.ttf') - require.resolve('kose-font/fonts/Kosefont-JP.ttf') - ${(() => { - const require = createRequire(import.meta.url) - const fontDepsPath = require.resolve("@fontsource/sn-pro") - const fontsDirPath = resolve(fontDepsPath, "../files") - return fs - .readdirSync(path.join(fontsDirPath)) - .map((file) => `require.resolve("@fontsource/sn-pro/files/${file}")`) - .join("\n") - })()} - } catch {} - ` - : ``, - }, - } -}) diff --git a/packages/readability/package.json b/packages/readability/package.json index 11e39f45f..5cf8a5611 100644 --- a/packages/readability/package.json +++ b/packages/readability/package.json @@ -8,7 +8,7 @@ "main": "./src/index.ts", "types": "./src/index.ts", "scripts": { - "build": "tsup" + "build": "tsdown" }, "dependencies": { "@mozilla/readability": "0.6.0", @@ -19,7 +19,7 @@ "devDependencies": { "@follow/configs": "workspace:*", "nbump": "2.1.2", - "tsup": "8.5.0" + "tsdown": "0.12.8" }, "publishConfig": { "exports": { diff --git a/packages/readability/tsup.config.ts b/packages/readability/tsdown.config.ts similarity index 73% rename from packages/readability/tsup.config.ts rename to packages/readability/tsdown.config.ts index 423cdce60..201861eaa 100644 --- a/packages/readability/tsup.config.ts +++ b/packages/readability/tsdown.config.ts @@ -1,9 +1,8 @@ -import { defineConfig } from "tsup" +import { defineConfig } from "tsdown" export default defineConfig({ entry: ["src/index.ts"], outDir: "dist", - splitting: false, dts: true, clean: true, format: ["cjs", "esm"], diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4e42acf86..d303d8ed8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1281,9 +1281,9 @@ importers: tailwindcss-uikit-colors: specifier: 0.6.2 version: 0.6.2 - tsup: - specifier: 8.5.0 - version: 8.5.0(jiti@2.4.2)(postcss@8.5.3)(tsx@4.19.4)(typescript@5.8.3)(yaml@2.8.0) + tsdown: + specifier: 0.12.8 + version: 0.12.8(typescript@5.8.3) tsx: specifier: 4.19.4 version: 4.19.4 @@ -1814,9 +1814,9 @@ importers: nbump: specifier: 2.1.2 version: 2.1.2(conventional-commits-filter@5.0.0) - tsup: - specifier: 8.5.0 - version: 8.5.0(jiti@2.4.2)(postcss@8.5.3)(tsx@4.19.4)(typescript@5.8.3)(yaml@2.8.0) + tsdown: + specifier: 0.12.8 + version: 0.12.8(typescript@5.8.3) packages/vite-plugin-route-builder: devDependencies: @@ -7309,12 +7309,6 @@ packages: resolution: {integrity: sha512-bkXY9WsVpY7CvMhKSR6pZilZu9Ln5WDrKVBUXf2S443etkmEO4V58heTecXcUIsNsi4Rx8JUO4NfX1IcQl4deg==} engines: {node: '>=18.20'} - bundle-require@5.1.0: - resolution: {integrity: sha512-3WrrOuZiyaaZPWiEt4G3+IffISVC9HYlWueJEBWED4ZH4aIAC2PnkdnuRrR94M+w6yGWn4AglWtJtBI8YqvgoA==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - peerDependencies: - esbuild: '>=0.18' - bunyan@1.8.15: resolution: {integrity: sha512-0tECWShh6wUysgucJcBAoYegf3JJoZWibxdqhTm7OHPeT42qdjkZ29QCMcKwbgU1kiH+auSIasNRXMLWXafXig==} engines: {'0': node >=0.10.0} @@ -9619,9 +9613,6 @@ packages: firebase@11.8.1: resolution: {integrity: sha512-oetXhPCvJZM4DVL/n/06442emMU+KzM0JLZjszpwlU6mqdFZqBwumBxn6hQkLukJyU5wsjihZHUY8HEAE2micg==} - fix-dts-default-cjs-exports@1.0.1: - resolution: {integrity: sha512-pVIECanWFC61Hzl2+oOCtoJ3F17kglZC/6N94eRWycFgBH35hHx0Li604ZIzhseh97mf2p0cv7vVrOZGoqhlEg==} - flat-cache@4.0.1: resolution: {integrity: sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==} engines: {node: '>=16'} @@ -10697,10 +10688,6 @@ packages: react: optional: true - joycon@3.1.1: - resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} - engines: {node: '>=10'} - jpeg-js@0.4.4: resolution: {integrity: sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==} @@ -11038,10 +11025,6 @@ packages: resolution: {integrity: sha512-3p6ZOGNbiX4CdvEd1VcE6yi78UrGNpjHO33noGwHCnT/o2fyllJDepsm8+mFFv/DvtwFHht5HIHSyOy5a+ChVQ==} engines: {node: '>=4'} - load-tsconfig@0.2.5: - resolution: {integrity: sha512-IXO6OCs9yg8tMKzfPZ1YmheJbZCiEsnBdcB03l0OcfK9prKnJb96siuHCr5Fl37/yo9DnKU+TLpxzTUspw9shg==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - local-pkg@0.5.1: resolution: {integrity: sha512-9rrA30MRRP3gBD3HTGnC6cDFpaE1kVDWxWgqWJUN0RvDNAo+Nz/9GxB+nHOH0ifbVFy0hSA1V6vFDvnx54lTEQ==} engines: {node: '>=14'} @@ -12438,24 +12421,6 @@ packages: ts-node: optional: true - postcss-load-config@6.0.1: - resolution: {integrity: sha512-oPtTM4oerL+UXmx+93ytZVN82RrlY/wPUV8IeDxFrzIjXOLF1pN+EmKPLbubvKHT2HC20xXsCAH2Z+CKV6Oz/g==} - engines: {node: '>= 18'} - peerDependencies: - jiti: '>=1.21.0' - postcss: '>=8.0.9' - tsx: ^4.8.1 - yaml: ^2.4.2 - peerDependenciesMeta: - jiti: - optional: true - postcss: - optional: true - tsx: - optional: true - yaml: - optional: true - postcss-merge-longhand@7.0.5: resolution: {integrity: sha512-Kpu5v4Ys6QI59FxmxtNB/iHUVDn9Y9sYw66D6+SZoIk4QTz1prC4aYkhIESu+ieG1iylod1f8MILMs1Em3mmIw==} engines: {node: ^18.12.0 || ^20.9.0 || >=22.0} @@ -14402,10 +14367,6 @@ packages: tr46@1.0.1: resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==} - tree-kill@1.2.2: - resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==} - hasBin: true - trie-memoize@1.2.0: resolution: {integrity: sha512-hEDLVEP1FCgaRtt0oZDJdz2lK9uK7WlB7ASswt9U9cqruSNueVigtRGxI97hevKlViqhAcRgNgzuY/m8FCCMcg==} @@ -14529,25 +14490,6 @@ packages: tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} - tsup@8.5.0: - resolution: {integrity: sha512-VmBp77lWNQq6PfuMqCHD3xWl22vEoWsKajkF8t+yMBawlUS8JzEI+vOVMeuNZIuMML8qXRizFKi9oD5glKQVcQ==} - engines: {node: '>=18'} - hasBin: true - peerDependencies: - '@microsoft/api-extractor': ^7.36.0 - '@swc/core': ^1 - postcss: ^8.4.12 - typescript: '>=4.5.0' - peerDependenciesMeta: - '@microsoft/api-extractor': - optional: true - '@swc/core': - optional: true - postcss: - optional: true - typescript: - optional: true - tsx@4.19.4: resolution: {integrity: sha512-gK5GVzDkJK1SI1zwHf32Mqxf2tSJkNx+eYcNly5+nHvWqXUJYUkWBQtKauoESz3ymezAI++ZwT855x5p5eop+Q==} engines: {node: '>=18.0.0'} @@ -15675,7 +15617,7 @@ snapshots: '@babel/helper-member-expression-to-functions@7.27.1': dependencies: '@babel/traverse': 7.27.3 - '@babel/types': 7.27.3 + '@babel/types': 7.27.6 transitivePeerDependencies: - supports-color @@ -15715,7 +15657,7 @@ snapshots: '@babel/helper-optimise-call-expression@7.27.1': dependencies: - '@babel/types': 7.27.3 + '@babel/types': 7.27.6 '@babel/helper-plugin-utils@7.27.1': {} @@ -15772,7 +15714,7 @@ snapshots: dependencies: '@babel/template': 7.27.2 '@babel/traverse': 7.27.3 - '@babel/types': 7.27.3 + '@babel/types': 7.27.6 transitivePeerDependencies: - supports-color @@ -23014,7 +22956,7 @@ snapshots: babel-plugin-jest-hoist@29.6.3: dependencies: '@babel/template': 7.27.2 - '@babel/types': 7.27.3 + '@babel/types': 7.27.6 '@types/babel__core': 7.20.5 '@types/babel__traverse': 7.20.7 @@ -23452,11 +23394,6 @@ snapshots: builtin-modules@5.0.0: {} - bundle-require@5.1.0(esbuild@0.25.5): - dependencies: - esbuild: 0.25.5 - load-tsconfig: 0.2.5 - bunyan@1.8.15: optionalDependencies: dtrace-provider: 0.8.8 @@ -26416,12 +26353,6 @@ snapshots: transitivePeerDependencies: - '@react-native-async-storage/async-storage' - fix-dts-default-cjs-exports@1.0.1: - dependencies: - magic-string: 0.30.17 - mlly: 1.7.4 - rollup: 4.41.1 - flat-cache@4.0.1: dependencies: flatted: 3.3.3 @@ -27564,7 +27495,7 @@ snapshots: istanbul-lib-instrument@5.2.1: dependencies: '@babel/core': 7.27.3 - '@babel/parser': 7.27.3 + '@babel/parser': 7.27.5 '@istanbuljs/schema': 0.1.3 istanbul-lib-coverage: 3.2.2 semver: 6.3.1 @@ -27697,8 +27628,6 @@ snapshots: '@types/react': 19.1.6 react: 19.0.0 - joycon@3.1.1: {} - jpeg-js@0.4.4: {} js-tokens@4.0.0: {} @@ -28039,8 +27968,6 @@ snapshots: pify: 2.3.0 strip-bom: 3.0.0 - load-tsconfig@0.2.5: {} - local-pkg@0.5.1: dependencies: mlly: 1.7.4 @@ -28576,7 +28503,7 @@ snapshots: metro-transform-plugins@0.82.4: dependencies: '@babel/core': 7.27.3 - '@babel/generator': 7.27.3 + '@babel/generator': 7.27.5 '@babel/template': 7.27.2 '@babel/traverse': 7.27.3 flow-enums-runtime: 0.0.6 @@ -28587,9 +28514,9 @@ snapshots: metro-transform-worker@0.82.4(bufferutil@4.0.9): dependencies: '@babel/core': 7.27.3 - '@babel/generator': 7.27.3 - '@babel/parser': 7.27.3 - '@babel/types': 7.27.3 + '@babel/generator': 7.27.5 + '@babel/parser': 7.27.5 + '@babel/types': 7.27.6 flow-enums-runtime: 0.0.6 metro: 0.82.4(bufferutil@4.0.9) metro-babel-transformer: 0.82.4 @@ -28607,9 +28534,9 @@ snapshots: metro-transform-worker@0.82.4(bufferutil@4.0.9)(utf-8-validate@6.0.5): dependencies: '@babel/core': 7.27.3 - '@babel/generator': 7.27.3 - '@babel/parser': 7.27.3 - '@babel/types': 7.27.3 + '@babel/generator': 7.27.5 + '@babel/parser': 7.27.5 + '@babel/types': 7.27.6 flow-enums-runtime: 0.0.6 metro: 0.82.4(bufferutil@4.0.9)(utf-8-validate@6.0.5) metro-babel-transformer: 0.82.4 @@ -29827,15 +29754,6 @@ snapshots: postcss: 8.5.3 ts-node: 10.9.2(@types/node@22.15.23)(typescript@5.8.3) - postcss-load-config@6.0.1(jiti@2.4.2)(postcss@8.5.3)(tsx@4.19.4)(yaml@2.8.0): - dependencies: - lilconfig: 3.1.3 - optionalDependencies: - jiti: 2.4.2 - postcss: 8.5.3 - tsx: 4.19.4 - yaml: 2.8.0 - postcss-merge-longhand@7.0.5(postcss@8.5.3): dependencies: postcss: 8.5.3 @@ -32062,8 +31980,6 @@ snapshots: dependencies: punycode: 2.3.1 - tree-kill@1.2.2: {} - trie-memoize@1.2.0: {} trigram-utils@2.0.1: @@ -32181,34 +32097,6 @@ snapshots: tslib@2.8.1: {} - tsup@8.5.0(jiti@2.4.2)(postcss@8.5.3)(tsx@4.19.4)(typescript@5.8.3)(yaml@2.8.0): - dependencies: - bundle-require: 5.1.0(esbuild@0.25.5) - cac: 6.7.14 - chokidar: 4.0.3 - consola: 3.4.2 - debug: 4.4.1(supports-color@8.1.1) - esbuild: 0.25.5 - fix-dts-default-cjs-exports: 1.0.1 - joycon: 3.1.1 - picocolors: 1.1.1 - postcss-load-config: 6.0.1(jiti@2.4.2)(postcss@8.5.3)(tsx@4.19.4)(yaml@2.8.0) - resolve-from: 5.0.0 - rollup: 4.41.1 - source-map: 0.8.0-beta.0 - sucrase: 3.35.0 - tinyexec: 0.3.2 - tinyglobby: 0.2.14 - tree-kill: 1.2.2 - optionalDependencies: - postcss: 8.5.3 - typescript: 5.8.3 - transitivePeerDependencies: - - jiti - - supports-color - - tsx - - yaml - tsx@4.19.4: dependencies: esbuild: 0.25.5