From ce7f80447f9b55f98d931bbf5029d02d0bff599f Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Wed, 30 Jul 2025 16:48:00 -0400 Subject: [PATCH 1/2] switches cli to be built with bun instead of node and allows for cli to be run via bun and agent compiled with bun.build instead of ncc --- package-lock.json | 2 +- packages/cli/package.json | 7 +- packages/cli/src/x/actions/deploy.action.ts | 88 +++++++++++++++++---- 3 files changed, 77 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 027adf8f..a03226d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36169,7 +36169,7 @@ }, "packages/cli": { "name": "flatfile", - "version": "3.11.0", + "version": "3.11.1", "dependencies": { "@flatfile/cross-env-config": "^0.0.6", "@flatfile/listener": "^1.1.2", diff --git a/packages/cli/package.json b/packages/cli/package.json index d7760d8e..a328494f 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,18 +1,19 @@ { "name": "flatfile", - "version": "3.11.1", + "version": "4.0.0", "description": "", "main": "./dist/index.js", "bin": { "flatfile": "./dist/index.js" }, + "type": "module", "files": [ "dist", "templates" ], "scripts": { - "build": "tsup src/index.ts --format esm,cjs --dts", - "dev": "tsup src/index.ts --format esm,cjs --dts --watch", + "build": "bun build src/index.ts --target node --outdir dist", + "dev": "bun run src/index.ts --target node --watch", "lint": "TIMING=1 eslint \"src/**/*.{ts,tsx,js,jsx}\" --fix", "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist", "test": "jest --runInBand --forceExit --passWithNoTests" diff --git a/packages/cli/src/x/actions/deploy.action.ts b/packages/cli/src/x/actions/deploy.action.ts index c1106a1d..cff888c4 100644 --- a/packages/cli/src/x/actions/deploy.action.ts +++ b/packages/cli/src/x/actions/deploy.action.ts @@ -223,7 +223,7 @@ export async function deployAction( try { const data = fs.readFileSync( - path.join(__dirname, '..', 'templates', 'entry.js'), + path.join(__dirname, '../../../', 'templates', 'entry.js'), 'utf8' ) const result = data.replace( @@ -303,21 +303,17 @@ export async function deployAction( }).start() try { - const { - err, - code, - map: sourceMapBase, - } = await ncc(path.join(outDir, '_entry.js'), { - minify: liteMode, - target: 'es2020', - sourceMap: true, - sourceMapIncludeSources: true, - sourceMapRegister: false, - cache: false, - // TODO: add debug flag to add this and other debug options - quiet: true, - // debugLog: false - }) + let code: string + let err: any + let sourceMapBase: string + + if (process.versions.bun) { + // Runtime is bun, so we can use Bun.build + ;({ code, sourceMapBase, err } = await bundleWithBun(outDir, liteMode)); + } else { + // Runtime is node, so we can use ncc + ;({ code, sourceMapBase, err } = await bundleWithNcc(outDir, liteMode)); + } const deployFile = path.join(outDir, 'deploy.js') fs.writeFileSync(deployFile, code, 'utf8') @@ -362,3 +358,63 @@ export async function deployAction( return program.error(messages.error(e)) } } + +async function bundleWithBun(outDir: string, liteMode: boolean) { + // Kick off the build + // @ts-expect-error Bun is not defined in the global scope + // eslint-disable-next-line no-undef + const result = await Bun.build({ + entrypoints: [path.join(outDir, "_entry.js")], + outdir: outDir, // write files to disk + bundle: true, // bundle dependencies + minify: liteMode, // equivalent to ncc’s `minify` + target: "node", // same as ncc’s `target` + sourcemap: "linked", // generate source maps + format: "esm", // or "cjs" if you need CommonJS + // note: Bun.build doesn’t support sourceMapIncludeSources, + // sourceMapRegister, cache or quiet flags––you can control + // logs via `result.logs` below. + }); + + // Check for build errors + let err: any + if (!result.success) { + err = 'Build failed:' + for (const msg of result.logs) { + err += `\n${msg}` + } + } + + // Extract code and source map from the outputs + let code = ""; + let sourceMapBase = ""; + for (const artifact of result.outputs) { + if (artifact.kind === "entry-point") { + code = await artifact.text(); + } else if (artifact.kind === "sourcemap") { + sourceMapBase = await artifact.text(); + } + } + + return { code, sourceMapBase, err }; +} + +async function bundleWithNcc(outDir: string, liteMode: boolean) { + const { + err, + code, + map: sourceMapBase, + } = await ncc(path.join(outDir, '_entry.js'), { + minify: liteMode, + target: 'es2020', + sourceMap: true, + sourceMapIncludeSources: true, + sourceMapRegister: false, + cache: false, + // TODO: add debug flag to add this and other debug options + quiet: true, + // debugLog: false + }) + + return { code, sourceMapBase, err }; +} \ No newline at end of file From 5ab9c46f994c660ef11f2cc82f1cc6c141f79760 Mon Sep 17 00:00:00 2001 From: Carl Brugger Date: Fri, 1 Aug 2025 13:06:18 -0500 Subject: [PATCH 2/2] add changeset --- .changeset/dry-pots-shake.md | 5 +++++ package-lock.json | 2 +- packages/cli/package.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/dry-pots-shake.md diff --git a/.changeset/dry-pots-shake.md b/.changeset/dry-pots-shake.md new file mode 100644 index 00000000..e1ed4f47 --- /dev/null +++ b/.changeset/dry-pots-shake.md @@ -0,0 +1,5 @@ +--- +'flatfile': major +--- + +This release adds bun build support to the flatfile cli diff --git a/package-lock.json b/package-lock.json index a03226d9..c06e3a64 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36169,7 +36169,7 @@ }, "packages/cli": { "name": "flatfile", - "version": "3.11.1", + "version": "4.0.0-rc.0", "dependencies": { "@flatfile/cross-env-config": "^0.0.6", "@flatfile/listener": "^1.1.2", diff --git a/packages/cli/package.json b/packages/cli/package.json index a328494f..6764e234 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "flatfile", - "version": "4.0.0", + "version": "3.11.1", "description": "", "main": "./dist/index.js", "bin": {