Skip to content

Commit 3e8d97b

Browse files
committed
fix(bundle-api): update bundling logic to inline all dependencies and clarify external packages
1 parent b4d0df1 commit 3e8d97b

1 file changed

Lines changed: 23 additions & 18 deletions

File tree

apps/studio/scripts/bundle-api.mjs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,33 @@
55
* which can cause esbuild to resolve to TypeScript source files rather than
66
* compiled dist output — producing ERR_MODULE_NOT_FOUND at runtime.
77
*
8-
* This script bundles api/index.ts with all @objectstack/* workspace packages
9-
* inlined, while keeping third-party npm packages external (they resolve
10-
* normally from node_modules at runtime).
8+
* This script bundles api/index.ts with ALL dependencies inlined (including
9+
* npm packages), so the deployed function is self-contained. Only packages
10+
* with native bindings and optional database drivers are kept external.
1111
*
1212
* Run from the apps/studio directory during the Vercel build step.
1313
*/
1414

1515
import { build } from 'esbuild';
1616
import { unlinkSync } from 'node:fs';
1717

18+
// Packages that cannot be bundled (native bindings / optional drivers)
19+
const EXTERNAL = [
20+
'@libsql/client',
21+
'better-sqlite3',
22+
// Optional knex database drivers — never used at runtime, but knex requires() them
23+
'pg',
24+
'pg-native',
25+
'pg-query-stream',
26+
'mysql',
27+
'mysql2',
28+
'sqlite3',
29+
'oracledb',
30+
'tedious',
31+
// macOS-only native file watcher
32+
'fsevents',
33+
];
34+
1835
await build({
1936
entryPoints: ['api/index.ts'],
2037
bundle: true,
@@ -23,21 +40,9 @@ await build({
2340
target: 'es2020',
2441
outfile: 'api/index.mjs',
2542
sourcemap: true,
26-
// Maintain proper __dirname / import.meta.url behaviour
27-
define: {},
28-
plugins: [{
29-
name: 'externalize-non-workspace',
30-
setup(build) {
31-
build.onResolve({ filter: /.*/ }, (args) => {
32-
// Bundle relative imports (../src/lib/*, ../objectstack.config.js, etc.)
33-
if (args.path.startsWith('.') || args.path.startsWith('/')) return null;
34-
// Bundle @objectstack/* workspace packages inline
35-
if (args.path.startsWith('@objectstack/')) return null;
36-
// Externalize everything else (npm packages, node builtins)
37-
return { path: args.path, external: true };
38-
});
39-
},
40-
}],
43+
external: EXTERNAL,
44+
// Silence warnings about optional/unused require() calls in knex drivers
45+
logOverride: { 'require-resolve-not-external': 'silent' },
4146
});
4247

4348
// Remove the TypeScript source so Vercel only sees the compiled .mjs

0 commit comments

Comments
 (0)