@agentuity/cli 0.0.94 ā 0.0.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +54 -0
- package/dist/auth.d.ts +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +8 -5
- package/dist/auth.js.map +1 -1
- package/dist/banner.js +1 -1
- package/dist/banner.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +190 -27
- package/dist/cli.js.map +1 -1
- package/dist/cmd/auth/signup.js +1 -1
- package/dist/cmd/auth/signup.js.map +1 -1
- package/dist/cmd/build/ast.d.ts.map +1 -1
- package/dist/cmd/build/ast.js +7 -0
- package/dist/cmd/build/ast.js.map +1 -1
- package/dist/cmd/build/entry-generator.d.ts +20 -0
- package/dist/cmd/build/entry-generator.d.ts.map +1 -0
- package/dist/cmd/build/entry-generator.js +366 -0
- package/dist/cmd/build/entry-generator.js.map +1 -0
- package/dist/cmd/build/index.d.ts.map +1 -1
- package/dist/cmd/build/index.js +5 -23
- package/dist/cmd/build/index.js.map +1 -1
- package/dist/cmd/build/vite/agent-discovery.d.ts +33 -0
- package/dist/cmd/build/vite/agent-discovery.d.ts.map +1 -0
- package/dist/cmd/build/vite/agent-discovery.js +297 -0
- package/dist/cmd/build/vite/agent-discovery.js.map +1 -0
- package/dist/cmd/build/vite/browser-env-plugin.d.ts +9 -0
- package/dist/cmd/build/vite/browser-env-plugin.d.ts.map +1 -0
- package/dist/cmd/build/vite/browser-env-plugin.js +28 -0
- package/dist/cmd/build/vite/browser-env-plugin.js.map +1 -0
- package/dist/cmd/build/vite/bun-dev-server.d.ts +29 -0
- package/dist/cmd/build/vite/bun-dev-server.d.ts.map +1 -0
- package/dist/cmd/build/vite/bun-dev-server.js +54 -0
- package/dist/cmd/build/vite/bun-dev-server.js.map +1 -0
- package/dist/cmd/build/vite/config-loader.d.ts +23 -0
- package/dist/cmd/build/vite/config-loader.d.ts.map +1 -0
- package/dist/cmd/build/vite/config-loader.js +50 -0
- package/dist/cmd/build/vite/config-loader.js.map +1 -0
- package/dist/cmd/build/vite/index.d.ts +26 -0
- package/dist/cmd/build/vite/index.d.ts.map +1 -0
- package/dist/cmd/build/vite/index.js +127 -0
- package/dist/cmd/build/vite/index.js.map +1 -0
- package/dist/cmd/build/vite/lifecycle-generator.d.ts +11 -0
- package/dist/cmd/build/vite/lifecycle-generator.d.ts.map +1 -0
- package/dist/cmd/build/vite/lifecycle-generator.js +35 -0
- package/dist/cmd/build/vite/lifecycle-generator.js.map +1 -0
- package/dist/cmd/build/vite/metadata-generator.d.ts +32 -0
- package/dist/cmd/build/vite/metadata-generator.d.ts.map +1 -0
- package/dist/cmd/build/vite/metadata-generator.js +489 -0
- package/dist/cmd/build/vite/metadata-generator.js.map +1 -0
- package/dist/cmd/build/vite/patch-plugin.d.ts +21 -0
- package/dist/cmd/build/vite/patch-plugin.d.ts.map +1 -0
- package/dist/cmd/build/vite/patch-plugin.js +70 -0
- package/dist/cmd/build/vite/patch-plugin.js.map +1 -0
- package/dist/cmd/build/vite/registry-generator.d.ts +19 -0
- package/dist/cmd/build/vite/registry-generator.d.ts.map +1 -0
- package/dist/cmd/build/{route-registry.js ā vite/registry-generator.js} +126 -48
- package/dist/cmd/build/vite/registry-generator.js.map +1 -0
- package/dist/cmd/build/vite/route-discovery.d.ts +58 -0
- package/dist/cmd/build/vite/route-discovery.d.ts.map +1 -0
- package/dist/cmd/build/vite/route-discovery.js +125 -0
- package/dist/cmd/build/vite/route-discovery.js.map +1 -0
- package/dist/cmd/build/vite/server-bundler.d.ts +16 -0
- package/dist/cmd/build/vite/server-bundler.d.ts.map +1 -0
- package/dist/cmd/build/vite/server-bundler.js +194 -0
- package/dist/cmd/build/vite/server-bundler.js.map +1 -0
- package/dist/cmd/build/vite/vite-asset-server-config.d.ts +19 -0
- package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +1 -0
- package/dist/cmd/build/vite/vite-asset-server-config.js +105 -0
- package/dist/cmd/build/vite/vite-asset-server-config.js.map +1 -0
- package/dist/cmd/build/vite/vite-asset-server.d.ts +23 -0
- package/dist/cmd/build/vite/vite-asset-server.d.ts.map +1 -0
- package/dist/cmd/build/vite/vite-asset-server.js +40 -0
- package/dist/cmd/build/vite/vite-asset-server.js.map +1 -0
- package/dist/cmd/build/vite/vite-builder.d.ts +44 -0
- package/dist/cmd/build/vite/vite-builder.d.ts.map +1 -0
- package/dist/cmd/build/vite/vite-builder.js +232 -0
- package/dist/cmd/build/vite/vite-builder.js.map +1 -0
- package/dist/cmd/build/vite/workbench-generator.d.ts +10 -0
- package/dist/cmd/build/vite/workbench-generator.d.ts.map +1 -0
- package/dist/cmd/build/vite/workbench-generator.js +135 -0
- package/dist/cmd/build/vite/workbench-generator.js.map +1 -0
- package/dist/cmd/build/vite-bundler.d.ts +23 -0
- package/dist/cmd/build/vite-bundler.d.ts.map +1 -0
- package/dist/cmd/build/vite-bundler.js +79 -0
- package/dist/cmd/build/vite-bundler.js.map +1 -0
- package/dist/cmd/cloud/agent/get.d.ts.map +1 -1
- package/dist/cmd/cloud/agent/get.js +1 -0
- package/dist/cmd/cloud/agent/get.js.map +1 -1
- package/dist/cmd/cloud/agent/list.d.ts.map +1 -1
- package/dist/cmd/cloud/agent/list.js +1 -0
- package/dist/cmd/cloud/agent/list.js.map +1 -1
- package/dist/cmd/cloud/db/get.d.ts.map +1 -1
- package/dist/cmd/cloud/db/get.js +1 -0
- package/dist/cmd/cloud/db/get.js.map +1 -1
- package/dist/cmd/cloud/db/list.d.ts.map +1 -1
- package/dist/cmd/cloud/db/list.js +1 -0
- package/dist/cmd/cloud/db/list.js.map +1 -1
- package/dist/cmd/cloud/deploy.d.ts.map +1 -1
- package/dist/cmd/cloud/deploy.js +152 -128
- package/dist/cmd/cloud/deploy.js.map +1 -1
- package/dist/cmd/cloud/deployment/list.d.ts.map +1 -1
- package/dist/cmd/cloud/deployment/list.js +4 -0
- package/dist/cmd/cloud/deployment/list.js.map +1 -1
- package/dist/cmd/cloud/env/list.d.ts.map +1 -1
- package/dist/cmd/cloud/env/list.js +1 -0
- package/dist/cmd/cloud/env/list.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/get.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/get.js +1 -0
- package/dist/cmd/cloud/keyvalue/get.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/keys.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/keys.js +1 -0
- package/dist/cmd/cloud/keyvalue/keys.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/list-namespaces.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/list-namespaces.js +1 -0
- package/dist/cmd/cloud/keyvalue/list-namespaces.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/stats.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/stats.js +1 -0
- package/dist/cmd/cloud/keyvalue/stats.js.map +1 -1
- package/dist/cmd/cloud/secret/list.d.ts.map +1 -1
- package/dist/cmd/cloud/secret/list.js +1 -0
- package/dist/cmd/cloud/secret/list.js.map +1 -1
- package/dist/cmd/cloud/session/list.d.ts.map +1 -1
- package/dist/cmd/cloud/session/list.js +4 -0
- package/dist/cmd/cloud/session/list.js.map +1 -1
- package/dist/cmd/cloud/storage/get.d.ts.map +1 -1
- package/dist/cmd/cloud/storage/get.js +1 -0
- package/dist/cmd/cloud/storage/get.js.map +1 -1
- package/dist/cmd/cloud/storage/list.d.ts.map +1 -1
- package/dist/cmd/cloud/storage/list.js +3 -0
- package/dist/cmd/cloud/storage/list.js.map +1 -1
- package/dist/cmd/cloud/stream/get.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/get.js +1 -0
- package/dist/cmd/cloud/stream/get.js.map +1 -1
- package/dist/cmd/cloud/stream/list.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/list.js +1 -0
- package/dist/cmd/cloud/stream/list.js.map +1 -1
- package/dist/cmd/cloud/vector/get.d.ts.map +1 -1
- package/dist/cmd/cloud/vector/get.js +1 -0
- package/dist/cmd/cloud/vector/get.js.map +1 -1
- package/dist/cmd/cloud/vector/search.d.ts.map +1 -1
- package/dist/cmd/cloud/vector/search.js +1 -0
- package/dist/cmd/cloud/vector/search.js.map +1 -1
- package/dist/cmd/dev/index.d.ts.map +1 -1
- package/dist/cmd/dev/index.js +291 -751
- package/dist/cmd/dev/index.js.map +1 -1
- package/dist/cmd/dev/sync.d.ts +1 -1
- package/dist/cmd/dev/sync.d.ts.map +1 -1
- package/dist/cmd/dev/sync.js +3 -0
- package/dist/cmd/dev/sync.js.map +1 -1
- package/dist/cmd/profile/show.d.ts.map +1 -1
- package/dist/cmd/profile/show.js +3 -4
- package/dist/cmd/profile/show.js.map +1 -1
- package/dist/cmd/project/create.d.ts.map +1 -1
- package/dist/cmd/project/create.js +3 -4
- package/dist/cmd/project/create.js.map +1 -1
- package/dist/cmd/project/list.d.ts.map +1 -1
- package/dist/cmd/project/list.js +1 -0
- package/dist/cmd/project/list.js.map +1 -1
- package/dist/cmd/project/show.d.ts.map +1 -1
- package/dist/cmd/project/show.js +1 -0
- package/dist/cmd/project/show.js.map +1 -1
- package/dist/cmd/upgrade/index.d.ts.map +1 -1
- package/dist/cmd/upgrade/index.js +5 -3
- package/dist/cmd/upgrade/index.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +29 -11
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime-bootstrap.d.ts +3 -2
- package/dist/runtime-bootstrap.d.ts.map +1 -1
- package/dist/runtime-bootstrap.js +7 -2
- package/dist/runtime-bootstrap.js.map +1 -1
- package/dist/schemas/deploy.d.ts +1 -1
- package/dist/types.d.ts +40 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/bun-version-checker.d.ts +11 -0
- package/dist/utils/bun-version-checker.d.ts.map +1 -0
- package/dist/utils/bun-version-checker.js +56 -0
- package/dist/utils/bun-version-checker.js.map +1 -0
- package/dist/version-check.d.ts.map +1 -1
- package/dist/version-check.js +5 -2
- package/dist/version-check.js.map +1 -1
- package/package.json +10 -3
- package/src/auth.ts +9 -5
- package/src/banner.ts +1 -1
- package/src/cli.ts +228 -29
- package/src/cmd/auth/signup.ts +1 -1
- package/src/cmd/build/ast.ts +7 -0
- package/src/cmd/build/entry-generator.ts +404 -0
- package/src/cmd/build/index.ts +7 -28
- package/src/cmd/build/vite/agent-discovery.ts +467 -0
- package/src/cmd/build/vite/browser-env-plugin.ts +34 -0
- package/src/cmd/build/vite/bun-dev-server.ts +78 -0
- package/src/cmd/build/vite/config-loader.ts +70 -0
- package/src/cmd/build/vite/index.ts +166 -0
- package/src/cmd/build/vite/lifecycle-generator.ts +43 -0
- package/src/cmd/build/vite/metadata-generator.ts +602 -0
- package/src/cmd/build/vite/patch-plugin.ts +88 -0
- package/src/cmd/build/vite/registry-generator.ts +288 -0
- package/src/cmd/build/vite/route-discovery.ts +186 -0
- package/src/cmd/build/vite/server-bundler.ts +258 -0
- package/src/cmd/build/vite/vite-asset-server-config.ts +134 -0
- package/src/cmd/build/vite/vite-asset-server.ts +63 -0
- package/src/cmd/build/vite/vite-builder.ts +284 -0
- package/src/cmd/build/vite/workbench-generator.ts +152 -0
- package/src/cmd/build/vite-bundler.ts +110 -0
- package/src/cmd/cloud/agent/get.ts +2 -0
- package/src/cmd/cloud/agent/list.ts +1 -0
- package/src/cmd/cloud/db/get.ts +1 -0
- package/src/cmd/cloud/db/list.ts +1 -0
- package/src/cmd/cloud/deploy.ts +175 -144
- package/src/cmd/cloud/deployment/list.ts +4 -0
- package/src/cmd/cloud/env/list.ts +1 -0
- package/src/cmd/cloud/keyvalue/get.ts +1 -0
- package/src/cmd/cloud/keyvalue/keys.ts +1 -0
- package/src/cmd/cloud/keyvalue/list-namespaces.ts +1 -0
- package/src/cmd/cloud/keyvalue/stats.ts +2 -0
- package/src/cmd/cloud/secret/list.ts +1 -0
- package/src/cmd/cloud/session/list.ts +4 -0
- package/src/cmd/cloud/storage/get.ts +1 -0
- package/src/cmd/cloud/storage/list.ts +4 -0
- package/src/cmd/cloud/stream/get.ts +1 -0
- package/src/cmd/cloud/stream/list.ts +1 -0
- package/src/cmd/cloud/vector/get.ts +1 -0
- package/src/cmd/cloud/vector/search.ts +1 -0
- package/src/cmd/dev/index.ts +323 -914
- package/src/cmd/dev/sync.ts +5 -1
- package/src/cmd/profile/show.ts +3 -4
- package/src/cmd/project/create.ts +3 -4
- package/src/cmd/project/list.ts +1 -0
- package/src/cmd/project/show.ts +1 -0
- package/src/cmd/upgrade/index.ts +6 -3
- package/src/config.ts +31 -11
- package/src/index.ts +2 -0
- package/src/runtime-bootstrap.ts +8 -2
- package/src/types.ts +48 -1
- package/src/utils/bun-version-checker.ts +70 -0
- package/src/version-check.ts +6 -2
- package/dist/cmd/build/bundler.d.ts +0 -22
- package/dist/cmd/build/bundler.d.ts.map +0 -1
- package/dist/cmd/build/bundler.js +0 -766
- package/dist/cmd/build/bundler.js.map +0 -1
- package/dist/cmd/build/config-loader.d.ts +0 -16
- package/dist/cmd/build/config-loader.d.ts.map +0 -1
- package/dist/cmd/build/config-loader.js +0 -227
- package/dist/cmd/build/config-loader.js.map +0 -1
- package/dist/cmd/build/file.d.ts +0 -2
- package/dist/cmd/build/file.d.ts.map +0 -1
- package/dist/cmd/build/file.js +0 -10
- package/dist/cmd/build/file.js.map +0 -1
- package/dist/cmd/build/fix-duplicate-exports.d.ts +0 -2
- package/dist/cmd/build/fix-duplicate-exports.d.ts.map +0 -1
- package/dist/cmd/build/fix-duplicate-exports.js +0 -170
- package/dist/cmd/build/fix-duplicate-exports.js.map +0 -1
- package/dist/cmd/build/plugin.d.ts +0 -6
- package/dist/cmd/build/plugin.d.ts.map +0 -1
- package/dist/cmd/build/plugin.js +0 -645
- package/dist/cmd/build/plugin.js.map +0 -1
- package/dist/cmd/build/route-discovery.d.ts +0 -54
- package/dist/cmd/build/route-discovery.d.ts.map +0 -1
- package/dist/cmd/build/route-discovery.js +0 -148
- package/dist/cmd/build/route-discovery.js.map +0 -1
- package/dist/cmd/build/route-registry.d.ts +0 -38
- package/dist/cmd/build/route-registry.d.ts.map +0 -1
- package/dist/cmd/build/route-registry.js.map +0 -1
- package/src/cmd/build/bundler.ts +0 -927
- package/src/cmd/build/config-loader.ts +0 -268
- package/src/cmd/build/file.ts +0 -10
- package/src/cmd/build/fix-duplicate-exports.ts +0 -207
- package/src/cmd/build/plugin.ts +0 -782
- package/src/cmd/build/route-discovery.ts +0 -202
- package/src/cmd/build/route-registry.ts +0 -222
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import { rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { StructuredError } from '@agentuity/core';
|
|
4
|
-
import type { BuildConfigFunction, BuildPhase, BuildContext, BuildConfig } from '../../types';
|
|
5
|
-
|
|
6
|
-
const BuildConfigLoadError = StructuredError('BuildConfigLoadError');
|
|
7
|
-
const BuildConfigValidationError = StructuredError('BuildConfigValidationError');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Reserved define keys that cannot be overridden by user config
|
|
11
|
-
*/
|
|
12
|
-
const RESERVED_DEFINE_PREFIXES = ['process.env.AGENTUITY_', 'process.env.NODE_ENV'];
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Load and validate agentuity.config.ts from the project root
|
|
16
|
-
*/
|
|
17
|
-
export async function loadBuildConfig(rootDir: string): Promise<BuildConfigFunction | null> {
|
|
18
|
-
const configPath = join(rootDir, 'agentuity.config.ts');
|
|
19
|
-
|
|
20
|
-
// Check if config file exists
|
|
21
|
-
const configFile = Bun.file(configPath);
|
|
22
|
-
if (!(await configFile.exists())) {
|
|
23
|
-
return null; // No config file is OK - it's optional
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
// Create wrapper script in project root so imports resolve correctly
|
|
28
|
-
// Using a hidden temp file to avoid conflicts with user files
|
|
29
|
-
const wrapperPath = join(rootDir, `.agentuity-config-loader-${Date.now()}.mts`);
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
// Create a wrapper script that imports the config and outputs it as JSON
|
|
33
|
-
// Using relative import so Bun can resolve dependencies from project's node_modules
|
|
34
|
-
const wrapperCode = `
|
|
35
|
-
import configFunction from './agentuity.config.ts';
|
|
36
|
-
|
|
37
|
-
// Validate it's a function
|
|
38
|
-
if (typeof configFunction !== 'function') {
|
|
39
|
-
console.error(JSON.stringify({
|
|
40
|
-
error: 'BuildConfigValidationError',
|
|
41
|
-
message: \`agentuity.config.ts must export a default function, got \${typeof configFunction}\`
|
|
42
|
-
}));
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Output success marker
|
|
47
|
-
console.log('__CONFIG_LOADED__');
|
|
48
|
-
`;
|
|
49
|
-
|
|
50
|
-
writeFileSync(wrapperPath, wrapperCode);
|
|
51
|
-
|
|
52
|
-
// Run the wrapper script with Bun
|
|
53
|
-
// Note: stdout/stderr are piped (not inherited) to suppress output from user's screen
|
|
54
|
-
const proc = Bun.spawn(['bun', wrapperPath], {
|
|
55
|
-
cwd: rootDir,
|
|
56
|
-
stdout: 'pipe', // Capture stdout to prevent output to user's terminal
|
|
57
|
-
stderr: 'pipe', // Capture stderr to prevent output to user's terminal
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const output = await new Response(proc.stdout).text();
|
|
61
|
-
const errorOutput = await new Response(proc.stderr).text();
|
|
62
|
-
const exitCode = await proc.exited;
|
|
63
|
-
|
|
64
|
-
if (exitCode !== 0) {
|
|
65
|
-
// Try to parse error as JSON
|
|
66
|
-
let errorData = null;
|
|
67
|
-
try {
|
|
68
|
-
errorData = JSON.parse(errorOutput);
|
|
69
|
-
} catch (_parseError) {
|
|
70
|
-
// Not JSON, will treat as regular error below
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// If we successfully parsed a BuildConfigValidationError, throw it
|
|
74
|
-
if (errorData?.error === 'BuildConfigValidationError') {
|
|
75
|
-
throw new BuildConfigValidationError({
|
|
76
|
-
message: errorData.message,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Otherwise, throw a generic load error with the raw error output
|
|
81
|
-
throw new BuildConfigLoadError({
|
|
82
|
-
message: `Failed to load agentuity.config.ts:\n${errorOutput}`,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Verify the success marker
|
|
87
|
-
if (!output.includes('__CONFIG_LOADED__')) {
|
|
88
|
-
throw new BuildConfigLoadError({
|
|
89
|
-
message: 'Config file loaded but did not output expected marker',
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Now import the config file directly - it's been validated
|
|
94
|
-
const configModule = await import(configPath);
|
|
95
|
-
const configFunction = configModule.default;
|
|
96
|
-
|
|
97
|
-
// Double-check it's a function (should always pass if wrapper succeeded)
|
|
98
|
-
if (typeof configFunction !== 'function') {
|
|
99
|
-
throw new BuildConfigValidationError({
|
|
100
|
-
message: `agentuity.config.ts must export a default function, got ${typeof configFunction}`,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return configFunction as BuildConfigFunction;
|
|
105
|
-
} finally {
|
|
106
|
-
// Clean up temp wrapper file
|
|
107
|
-
rmSync(wrapperPath, { force: true });
|
|
108
|
-
}
|
|
109
|
-
} catch (error) {
|
|
110
|
-
// If it's already our error, re-throw
|
|
111
|
-
if (error instanceof BuildConfigValidationError || error instanceof BuildConfigLoadError) {
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Wrap other errors
|
|
116
|
-
throw new BuildConfigLoadError({
|
|
117
|
-
message: `Failed to load agentuity.config.ts: ${error instanceof Error ? error.message : String(error)}`,
|
|
118
|
-
cause: error instanceof Error ? error : undefined,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Execute the build config function for a specific phase and validate the result
|
|
125
|
-
*/
|
|
126
|
-
export async function executeBuildConfig(
|
|
127
|
-
configFunction: BuildConfigFunction,
|
|
128
|
-
phase: BuildPhase,
|
|
129
|
-
context: BuildContext
|
|
130
|
-
): Promise<BuildConfig> {
|
|
131
|
-
try {
|
|
132
|
-
// Execute the config function (may be async)
|
|
133
|
-
const config = await configFunction(phase, context);
|
|
134
|
-
|
|
135
|
-
// Validate the result is an object
|
|
136
|
-
if (!config || typeof config !== 'object') {
|
|
137
|
-
throw new BuildConfigValidationError({
|
|
138
|
-
message: `Build config for phase "${phase}" must return an object, got ${typeof config}`,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Validate plugins array if provided
|
|
143
|
-
if (config.plugins !== undefined) {
|
|
144
|
-
if (!Array.isArray(config.plugins)) {
|
|
145
|
-
throw new BuildConfigValidationError({
|
|
146
|
-
message: `Build config plugins for phase "${phase}" must be an array, got ${typeof config.plugins}`,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
// Validate each plugin has a name property (basic BunPlugin check)
|
|
150
|
-
for (const plugin of config.plugins) {
|
|
151
|
-
if (!plugin || typeof plugin !== 'object' || !('name' in plugin)) {
|
|
152
|
-
throw new BuildConfigValidationError({
|
|
153
|
-
message: `Invalid plugin in phase "${phase}": plugins must be BunPlugin objects with a name property`,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Validate external array if provided
|
|
160
|
-
if (config.external !== undefined) {
|
|
161
|
-
if (!Array.isArray(config.external)) {
|
|
162
|
-
throw new BuildConfigValidationError({
|
|
163
|
-
message: `Build config external for phase "${phase}" must be an array, got ${typeof config.external}`,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
// Validate each external is a string
|
|
167
|
-
for (const ext of config.external) {
|
|
168
|
-
if (typeof ext !== 'string') {
|
|
169
|
-
throw new BuildConfigValidationError({
|
|
170
|
-
message: `Invalid external in phase "${phase}": all externals must be strings, got ${typeof ext}`,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Validate and filter define object if provided
|
|
177
|
-
if (config.define !== undefined) {
|
|
178
|
-
if (typeof config.define !== 'object' || config.define === null) {
|
|
179
|
-
throw new BuildConfigValidationError({
|
|
180
|
-
message: `Build config define for phase "${phase}" must be an object, got ${typeof config.define}`,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Check for reserved keys and filter them out
|
|
185
|
-
const filteredDefine: Record<string, string> = {};
|
|
186
|
-
const blockedKeys: string[] = [];
|
|
187
|
-
|
|
188
|
-
for (const [key, value] of Object.entries(config.define)) {
|
|
189
|
-
// Check if this key starts with any reserved prefix
|
|
190
|
-
const isReserved = RESERVED_DEFINE_PREFIXES.some((prefix) => key.startsWith(prefix));
|
|
191
|
-
|
|
192
|
-
if (isReserved) {
|
|
193
|
-
blockedKeys.push(key);
|
|
194
|
-
continue; // Skip reserved keys
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// Validate value is a string
|
|
198
|
-
if (typeof value !== 'string') {
|
|
199
|
-
throw new BuildConfigValidationError({
|
|
200
|
-
message: `Build config define values for phase "${phase}" must be strings, got ${typeof value} for key "${key}"`,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
filteredDefine[key] = value;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Warn if we blocked any keys
|
|
208
|
-
if (blockedKeys.length > 0) {
|
|
209
|
-
context.logger.warn(
|
|
210
|
-
`Build config for phase "${phase}" attempted to override reserved define keys (ignored): ${blockedKeys.join(', ')}`
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Replace with filtered version
|
|
215
|
-
config.define = filteredDefine;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return config;
|
|
219
|
-
} catch (error) {
|
|
220
|
-
// If it's already our error, re-throw
|
|
221
|
-
if (error instanceof BuildConfigValidationError) {
|
|
222
|
-
throw error;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Wrap other errors
|
|
226
|
-
throw new BuildConfigLoadError({
|
|
227
|
-
message: `Failed to execute build config for phase "${phase}": ${error instanceof Error ? error.message : String(error)}`,
|
|
228
|
-
cause: error instanceof Error ? error : undefined,
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Merge user build config with base Bun.BuildConfig
|
|
235
|
-
* User config is applied AFTER base config with safeguards
|
|
236
|
-
* Returns a complete Bun.BuildConfig with user overrides applied
|
|
237
|
-
*/
|
|
238
|
-
export function mergeBuildConfig(
|
|
239
|
-
baseConfig: import('bun').BuildConfig,
|
|
240
|
-
userConfig: BuildConfig
|
|
241
|
-
): import('bun').BuildConfig {
|
|
242
|
-
const merged = { ...baseConfig };
|
|
243
|
-
|
|
244
|
-
// Merge plugins (user plugins come AFTER Agentuity plugin)
|
|
245
|
-
if (userConfig.plugins && userConfig.plugins.length > 0) {
|
|
246
|
-
merged.plugins = [...(baseConfig.plugins ?? []), ...userConfig.plugins];
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Merge external (combine arrays, dedupe)
|
|
250
|
-
if (userConfig.external && userConfig.external.length > 0) {
|
|
251
|
-
const existingExternal = Array.isArray(baseConfig.external)
|
|
252
|
-
? baseConfig.external
|
|
253
|
-
: baseConfig.external
|
|
254
|
-
? [baseConfig.external]
|
|
255
|
-
: [];
|
|
256
|
-
merged.external = [...new Set([...existingExternal, ...userConfig.external])];
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Merge define (user defines come last, but reserved keys already filtered)
|
|
260
|
-
if (userConfig.define && Object.keys(userConfig.define).length > 0) {
|
|
261
|
-
merged.define = {
|
|
262
|
-
...baseConfig.define,
|
|
263
|
-
...userConfig.define,
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return merged;
|
|
268
|
-
}
|
package/src/cmd/build/file.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
2
|
-
|
|
3
|
-
export async function getFilesRecursively(dir: string): Promise<string[]> {
|
|
4
|
-
const glob = new Bun.Glob('**/*');
|
|
5
|
-
const files: string[] = [];
|
|
6
|
-
for await (const file of glob.scan({ cwd: dir, onlyFiles: true, absolute: false, dot: true })) {
|
|
7
|
-
files.push(resolve(dir, file));
|
|
8
|
-
}
|
|
9
|
-
return files;
|
|
10
|
-
}
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
export async function fixDuplicateExportsInDirectory(dir: string, verbose = false) {
|
|
4
|
-
if (verbose) {
|
|
5
|
-
console.log(`Scanning for .js files in: ${dir}`);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const jsFiles = await getAllJsFiles(dir);
|
|
9
|
-
if (verbose) {
|
|
10
|
-
console.log(`Found ${jsFiles.length} .js files`);
|
|
11
|
-
for (const js of jsFiles) {
|
|
12
|
-
console.log(` + Processing ${js}`);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (jsFiles.length === 0) {
|
|
17
|
-
if (verbose) {
|
|
18
|
-
console.log('No .js files found');
|
|
19
|
-
}
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Process all files in parallel
|
|
24
|
-
const results = await Promise.all(
|
|
25
|
-
jsFiles.map(async (filePath) => {
|
|
26
|
-
try {
|
|
27
|
-
const wasFixed = await fixDuplicateExportsInFile(filePath, verbose);
|
|
28
|
-
return { filePath, wasFixed, error: null };
|
|
29
|
-
} catch (error) {
|
|
30
|
-
return { filePath, wasFixed: false, error };
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
// Report results
|
|
36
|
-
const fixed = results.filter((r) => r.wasFixed);
|
|
37
|
-
const errors = results.filter((r) => r.error);
|
|
38
|
-
|
|
39
|
-
if (verbose) {
|
|
40
|
-
console.log(`\nResults:`);
|
|
41
|
-
console.log(`- Total files: ${jsFiles.length}`);
|
|
42
|
-
console.log(`- Files fixed: ${fixed.length}`);
|
|
43
|
-
console.log(`- Errors: ${errors.length}`);
|
|
44
|
-
|
|
45
|
-
if (fixed.length > 0) {
|
|
46
|
-
console.log('\nFixed files:');
|
|
47
|
-
fixed.forEach(({ filePath }) => {
|
|
48
|
-
console.log(` - ${filePath}`);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (errors.length > 0) {
|
|
53
|
-
console.log('\nErrors:');
|
|
54
|
-
errors.forEach(({ filePath, error }) => {
|
|
55
|
-
console.log(` - ${filePath}: ${error}`);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function fixDuplicateExportsInFile(filePath: string, verbose = false): Promise<boolean> {
|
|
62
|
-
const originalCode = await Bun.file(filePath).text();
|
|
63
|
-
|
|
64
|
-
// Only fix __INVALID__REF__ - remove it from imports and exports
|
|
65
|
-
let code = originalCode;
|
|
66
|
-
|
|
67
|
-
// Pattern 1: __INVALID__REF__ at start with comma after: "__INVALID__REF__, foo" -> "foo"
|
|
68
|
-
code = code.replace(/\b__INVALID__REF__\s*,\s*/g, '');
|
|
69
|
-
|
|
70
|
-
// Pattern 2: __INVALID__REF__ at end with comma before: "foo, __INVALID__REF__" -> "foo"
|
|
71
|
-
code = code.replace(/,\s*__INVALID__REF__\b/g, '');
|
|
72
|
-
|
|
73
|
-
// Pattern 3: __INVALID__REF__ alone (shouldn't happen but handle it)
|
|
74
|
-
code = code.replace(/\b__INVALID__REF__\b/g, '');
|
|
75
|
-
|
|
76
|
-
// Remove duplicate export statements
|
|
77
|
-
// Find all export { ... } statements (allow leading whitespace)
|
|
78
|
-
const exportPattern = /^\s*export\s*\{([^}]+)\}\s*;?\s*$/gm;
|
|
79
|
-
const exports: Array<{
|
|
80
|
-
match: string;
|
|
81
|
-
names: Set<string>;
|
|
82
|
-
nameToSyntax: Map<string, string>;
|
|
83
|
-
start: number;
|
|
84
|
-
end: number;
|
|
85
|
-
}> = [];
|
|
86
|
-
let match;
|
|
87
|
-
|
|
88
|
-
while ((match = exportPattern.exec(code)) !== null) {
|
|
89
|
-
const nameToSyntax = new Map<string, string>();
|
|
90
|
-
const names: string[] = [];
|
|
91
|
-
|
|
92
|
-
match[1].split(',').forEach((n) => {
|
|
93
|
-
const fullSyntax = n.trim();
|
|
94
|
-
const parts = fullSyntax.split(/\s+as\s+/);
|
|
95
|
-
const exportedName = parts.length > 1 ? parts[1].trim() : parts[0].trim();
|
|
96
|
-
if (exportedName) {
|
|
97
|
-
names.push(exportedName);
|
|
98
|
-
nameToSyntax.set(exportedName, fullSyntax);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
exports.push({
|
|
103
|
-
match: match[0],
|
|
104
|
-
names: new Set(names),
|
|
105
|
-
nameToSyntax,
|
|
106
|
-
start: match.index,
|
|
107
|
-
end: match.index + match[0].length,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Track which names we've seen and which export statements to remove/modify
|
|
112
|
-
const seenNames = new Set<string>();
|
|
113
|
-
const indicesToRemove: number[] = [];
|
|
114
|
-
const modificationsNeeded = new Map<number, Set<string>>(); // index -> names to keep
|
|
115
|
-
|
|
116
|
-
for (let i = 0; i < exports.length; i++) {
|
|
117
|
-
const exp = exports[i];
|
|
118
|
-
const duplicateNames = [...exp.names].filter((name) => seenNames.has(name));
|
|
119
|
-
const newNames = [...exp.names].filter((name) => !seenNames.has(name));
|
|
120
|
-
const allDuplicates = duplicateNames.length === exp.names.size;
|
|
121
|
-
|
|
122
|
-
if (verbose && duplicateNames.length > 0) {
|
|
123
|
-
console.log(` Duplicate exports found in statement ${i}: ${duplicateNames.join(', ')}`);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (allDuplicates && exp.names.size > 0) {
|
|
127
|
-
// This entire export statement is a duplicate - remove it
|
|
128
|
-
indicesToRemove.push(i);
|
|
129
|
-
if (verbose) {
|
|
130
|
-
console.log(` -> Will remove entire statement`);
|
|
131
|
-
}
|
|
132
|
-
} else if (duplicateNames.length > 0) {
|
|
133
|
-
// Partial duplicates - need to remove just the duplicate names
|
|
134
|
-
modificationsNeeded.set(i, new Set(newNames));
|
|
135
|
-
if (verbose) {
|
|
136
|
-
console.log(` -> Will keep only: ${newNames.join(', ')}`);
|
|
137
|
-
}
|
|
138
|
-
// Mark the new names as seen
|
|
139
|
-
newNames.forEach((name) => seenNames.add(name));
|
|
140
|
-
} else {
|
|
141
|
-
// No duplicates - mark these names as seen
|
|
142
|
-
exp.names.forEach((name) => seenNames.add(name));
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Build patches for modifications and removals, then apply from end to preserve indices
|
|
147
|
-
const patches: Array<{ start: number; end: number; replacement: string }> = [];
|
|
148
|
-
|
|
149
|
-
// Partial duplicates: replace the export statement with only the kept names
|
|
150
|
-
for (const [i, namesToKeep] of modificationsNeeded.entries()) {
|
|
151
|
-
const exp = exports[i];
|
|
152
|
-
const syntaxToKeep = [...namesToKeep].map((name) => exp.nameToSyntax.get(name)!);
|
|
153
|
-
const newExport = `export { ${syntaxToKeep.join(', ')} };`;
|
|
154
|
-
patches.push({ start: exp.start, end: exp.end, replacement: newExport });
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Full duplicates: remove the entire export statement
|
|
158
|
-
for (const idx of indicesToRemove) {
|
|
159
|
-
const exp = exports[idx];
|
|
160
|
-
patches.push({ start: exp.start, end: exp.end, replacement: '' });
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Apply all patches from right to left so earlier indices remain valid
|
|
164
|
-
patches.sort((a, b) => b.start - a.start);
|
|
165
|
-
for (const { start, end, replacement } of patches) {
|
|
166
|
-
code = code.slice(0, start) + replacement + code.slice(end);
|
|
167
|
-
}
|
|
168
|
-
// Nothing changed
|
|
169
|
-
if (code === originalCode) {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Write the fixed content back to the file
|
|
174
|
-
await Bun.write(filePath, code);
|
|
175
|
-
|
|
176
|
-
if (verbose) {
|
|
177
|
-
console.log(`\nš§ Fixed exports in: ${filePath}`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
async function getAllJsFiles(dir: string): Promise<string[]> {
|
|
184
|
-
const glob = new Bun.Glob('**/*.js');
|
|
185
|
-
const files = await Array.fromAsync(glob.scan({ cwd: dir, dot: true }));
|
|
186
|
-
return files.map((file) => path.join(dir, file));
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
async function main() {
|
|
190
|
-
const dir = process.argv[2];
|
|
191
|
-
if (!dir) {
|
|
192
|
-
console.error('Usage: bun fix-duplicate-exports.ts <directory>');
|
|
193
|
-
process.exit(1);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const { existsSync } = await import('node:fs');
|
|
197
|
-
if (!existsSync(dir)) {
|
|
198
|
-
console.error(`Error: Directory does not exist: ${dir}`);
|
|
199
|
-
process.exit(1);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
await fixDuplicateExportsInDirectory(dir, true);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (import.meta.main) {
|
|
206
|
-
await main();
|
|
207
|
-
}
|