Skip to content

Commit d3a61fd

Browse files
os-zhuangclaude
andcommitted
perf(build): gate .d.ts emission on OS_SKIP_DTS; fix optional AI plugin skip
Part 1 — OS_SKIP_DTS build-time gating (default behavior unchanged): - 12 tsup configs: dts: true → dts: !process.env.OS_SKIP_DTS - packages/spec/package.json: skip the separate BUILD_DTS=true tsup pass when OS_SKIP_DTS is set (the ~80–90s DTS pass) - packages/cli/package.json: when OS_SKIP_DTS is set, deps have no .d.ts, so build with --noCheck --declaration false to still emit runnable JS (full typecheck preserved by default) - turbo.json: declare OS_SKIP_DTS in globalEnv (Turbo 2.x strict env mode otherwise filters it out; also part of the cache key) Image build (OS_SKIP_DTS=1): framework turbo run build ~5m03s → ~1m12s. Part 2 — fix optional AI plugin "failed to start" false alarm: serve.ts loads @objectstack/service-ai and optional @objectstack/service-ai-studio via importFromHost() and is meant to silently skip when absent. ESM throws "Cannot find package '...'" (code on err.code, not in message), which the old guard didn't match, so control-plane hosts logged a scary error on every boot. Detect missing module via err.code === 'ERR_MODULE_NOT_FOUND' and also match "Cannot find package". Applied to both the AIService and AIStudio guards. Refs objectstack-ai/cloud#107 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e1478fe commit d3a61fd

16 files changed

Lines changed: 25 additions & 16 deletions

File tree

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"os": "./bin/run.js"
1010
},
1111
"scripts": {
12-
"build": "tsc -p tsconfig.build.json",
12+
"build": "if [ -n \"$OS_SKIP_DTS\" ]; then tsc -p tsconfig.build.json --noCheck --declaration false --declarationMap false; else tsc -p tsconfig.build.json; fi",
1313
"dev": "tsc -p tsconfig.build.json --watch",
1414
"test": "vitest run",
1515
"lint": "eslint src"

packages/cli/src/commands/serve.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,11 @@ export default class Serve extends Command {
13771377
trackPlugin('AIService');
13781378
} catch (err: unknown) {
13791379
const msg = err instanceof Error ? err.message : String(err);
1380-
if (!msg.includes('Cannot find module') && !msg.includes('ERR_MODULE_NOT_FOUND')) {
1380+
const code = (err as { code?: string })?.code;
1381+
const missing = code === 'ERR_MODULE_NOT_FOUND'
1382+
|| msg.includes('Cannot find module')
1383+
|| msg.includes('Cannot find package');
1384+
if (!missing) {
13811385
console.error('[AI] AIServicePlugin failed to start:', msg);
13821386
}
13831387
// @objectstack/service-ai not installed — AI features unavailable
@@ -1401,7 +1405,11 @@ export default class Serve extends Command {
14011405
trackPlugin('AIStudio');
14021406
} catch (err: unknown) {
14031407
const msg = err instanceof Error ? err.message : String(err);
1404-
if (!msg.includes('Cannot find module') && !msg.includes('ERR_MODULE_NOT_FOUND')) {
1408+
const code = (err as { code?: string })?.code;
1409+
const missing = code === 'ERR_MODULE_NOT_FOUND'
1410+
|| msg.includes('Cannot find module')
1411+
|| msg.includes('Cannot find package');
1412+
if (!missing) {
14051413
console.error('[AI Studio] AIStudioPlugin failed to start:', msg);
14061414
}
14071415
// @objectstack/service-ai-studio not installed — AI authoring unavailable

packages/cli/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default defineConfig([
1717
{
1818
entry: ['src/index.ts'],
1919
format: ['esm'],
20-
dts: true,
20+
dts: !process.env.OS_SKIP_DTS,
2121
shims: true,
2222
},
2323
]);

packages/core/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default defineConfig({
1313
splitting: false,
1414
sourcemap: true,
1515
clean: true,
16-
dts: true,
16+
dts: !process.env.OS_SKIP_DTS,
1717
format: ['esm', 'cjs'],
1818
target: 'es2020',
1919
});

packages/metadata-core/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default defineConfig({
77
splitting: true,
88
sourcemap: true,
99
clean: true,
10-
dts: true,
10+
dts: !process.env.OS_SKIP_DTS,
1111
format: ['esm', 'cjs'],
1212
target: 'es2020',
1313
external: ['vitest'],

packages/metadata-fs/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default defineConfig({
77
splitting: false,
88
sourcemap: true,
99
clean: true,
10-
dts: true,
10+
dts: !process.env.OS_SKIP_DTS,
1111
format: ['esm', 'cjs'],
1212
target: 'es2020',
1313
external: ['chokidar', '@objectstack/metadata-core'],

packages/metadata/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default defineConfig({
1111
splitting: false,
1212
sourcemap: true,
1313
clean: true,
14-
dts: true,
14+
dts: !process.env.OS_SKIP_DTS,
1515
format: ['esm', 'cjs'],
1616
target: 'es2020',
1717
});

packages/platform-objects/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default defineConfig({
1717
plugin: 'src/plugin.ts',
1818
},
1919
format: ['cjs', 'esm'],
20-
dts: true,
20+
dts: !process.env.OS_SKIP_DTS,
2121
clean: true,
2222
sourcemap: true,
2323
splitting: false,

packages/plugins/plugin-webhooks/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default defineConfig({
77
splitting: true,
88
sourcemap: true,
99
clean: true,
10-
dts: true,
10+
dts: !process.env.OS_SKIP_DTS,
1111
format: ['esm', 'cjs'],
1212
target: 'es2020',
1313
external: ['vitest'],

packages/runtime/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default defineConfig({
77
splitting: false,
88
sourcemap: true,
99
clean: true,
10-
dts: true,
10+
dts: !process.env.OS_SKIP_DTS,
1111
format: ['esm', 'cjs'],
1212
target: 'es2020',
1313
// Mark driver packages as external so they are resolved at runtime, not bundled

0 commit comments

Comments
 (0)