From dfc04e70aa417d0e7212f81d8959cf93892dd5e3 Mon Sep 17 00:00:00 2001 From: Diogo Mendes Matsubara Date: Fri, 26 Jun 2026 14:24:08 +0200 Subject: [PATCH 1/2] chore: simplify action builds with tsup Replace the custom build.cjs wrapper with a single tsup invocation. - move entrypoint discovery into tsup.config.ts - change npm build script to run tsup directly - remove build.cjs - regenerate dist bundles with the new build path This keeps the output behavior the same while making the build configuration the single source of truth. --- build.cjs | 22 ---------------------- package.json | 2 +- tsup.config.ts | 48 ++++++++++++++++++++++++++---------------------- 3 files changed, 27 insertions(+), 45 deletions(-) delete mode 100755 build.cjs diff --git a/build.cjs b/build.cjs deleted file mode 100755 index cbf72597..00000000 --- a/build.cjs +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env node - -const fs = require("fs/promises"); -const child_process = require("child_process"); - -async function main() { - const dir = await fs.opendir("src"); - for await (const dirent of dir) { - if (["-pre.ts", "-main.ts", "-post.ts"].some(x => dirent.name.endsWith(x))) { - child_process.exec(`tsup-node src/${dirent.name} --out-dir dist --format esm`, (error, stdout, stderr) => { - if (error) { - console.error(`exec error: ${error}`); - return; - } - console.log(`stdout: ${stdout}`); - console.error(`stderr: ${stderr}`); - }); - } - } -} - -main().then(); diff --git a/package.json b/package.json index bcf23d32..4958c762 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "format:write": "prettier --write **/*.ts", "format:check": "prettier --check **/*.ts", "lint": "npx eslint . -c eslint.config.mjs", - "build": "./build.cjs", + "build": "tsup", "build:watch": "npm run package -- --watch", "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --detectOpenHandles", "all": "npm run format:write && npm run lint && npm run test && npm run build", diff --git a/tsup.config.ts b/tsup.config.ts index 5d5657b5..839b4349 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,24 +1,28 @@ -import { defineConfig } from 'tsup' +import { readdirSync } from "fs"; +import { defineConfig } from "tsup"; + +const entry = readdirSync("src") + .filter(name => ["-pre.ts", "-main.ts", "-post.ts"].some(suffix => name.endsWith(suffix))) + .map(name => `src/${name}`); export default defineConfig({ - noExternal: [ - /(.*)/ - ], - dts: false, - splitting: false, - clean: false, - skipNodeModulesBundle: true, - shims: true, - cjsInterop: false, - target: "es2022", - format: 'esm', - outDir: "dist/", - banner: { - js: `import { createRequire as __createRequire } from 'module'; const require = __createRequire(import.meta.url);`, - }, - outExtension({ format }) { - return { - js: `.mjs`, - } - }, -}) \ No newline at end of file + entry, + noExternal: [/(.*)/], + dts: false, + splitting: false, + clean: false, + skipNodeModulesBundle: true, + shims: true, + cjsInterop: false, + target: "es2022", + format: ["esm"], + outDir: "dist/", + banner: { + js: `import { createRequire as __createRequire } from 'module'; const require = __createRequire(import.meta.url);`, + }, + outExtension() { + return { + js: ".mjs", + }; + }, +}); From 037af668c0ef2c3cc23e1eed463c213a1f7ef95e Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Thu, 2 Jul 2026 15:42:31 +0200 Subject: [PATCH 2/2] Sort output of `readdirSync` and filter out directories Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- tsup.config.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tsup.config.ts b/tsup.config.ts index 839b4349..6011320d 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,9 +1,12 @@ import { readdirSync } from "fs"; import { defineConfig } from "tsup"; -const entry = readdirSync("src") - .filter(name => ["-pre.ts", "-main.ts", "-post.ts"].some(suffix => name.endsWith(suffix))) - .map(name => `src/${name}`); +const entry = readdirSync("src", { withFileTypes: true }) + .filter((dirent) => dirent.isFile()) + .map((dirent) => dirent.name) + .filter((name) => ["-pre.ts", "-main.ts", "-post.ts"].some((suffix) => name.endsWith(suffix))) + .sort() + .map((name) => `src/${name}`); export default defineConfig({ entry,