@dexto/image-bundler 1.5.0
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/.turbo/turbo-build.log +20 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +44 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +540 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +473 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
- package/src/bundler.ts +361 -0
- package/src/cli.ts +93 -0
- package/src/generator.ts +331 -0
- package/src/index.ts +9 -0
- package/src/types.ts +30 -0
- package/tsconfig.json +19 -0
- package/tsup.config.ts +13 -0
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/bundler.ts","../src/generator.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * CLI for bundling Dexto base images\n */\n\n// Suppress experimental warnings (e.g., Type Stripping)\nprocess.removeAllListeners('warning');\nprocess.on('warning', (warning) => {\n if (warning.name !== 'ExperimentalWarning') {\n console.warn(warning);\n }\n});\n\nimport { Command } from 'commander';\nimport { bundle } from './bundler.js';\nimport { readFileSync } from 'node:fs';\nimport { join, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport pc from 'picocolors';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\n// Read version from package.json\nconst packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));\n\nconst program = new Command();\n\nprogram.name('dexto-bundle').description('Bundle Dexto base images').version(packageJson.version);\n\nprogram\n .command('build')\n .description('Build a base image from dexto.image.ts')\n .option('-i, --image <path>', 'Path to dexto.image.ts file', 'dexto.image.ts')\n .option('-o, --out <dir>', 'Output directory', 'dist')\n .option('--sourcemap', 'Generate source maps', false)\n .option('--minify', 'Minify output', false)\n .action(async (options) => {\n try {\n console.log(pc.cyan('š Dexto Image Bundler\\n'));\n\n const result = await bundle({\n imagePath: options.image,\n outDir: options.out,\n sourcemap: options.sourcemap,\n minify: options.minify,\n });\n\n console.log(pc.green('\\n⨠Build successful!\\n'));\n console.log(pc.bold('Image Details:'));\n console.log(` Name: ${result.metadata.name}`);\n console.log(` Version: ${result.metadata.version}`);\n console.log(` Target: ${result.metadata.target}`);\n console.log(` Built at: ${result.metadata.builtAt}`);\n console.log(` Core: v${result.metadata.coreVersion}`);\n\n if (result.metadata.constraints.length > 0) {\n console.log(` Constraints: ${result.metadata.constraints.join(', ')}`);\n }\n\n if (result.warnings.length > 0) {\n console.log(pc.yellow('\\nā ļø Warnings:'));\n result.warnings.forEach((w) => console.log(` - ${w}`));\n }\n\n // Read package.json to get the actual package name\n const packageJsonPath = join(process.cwd(), 'package.json');\n let packageName = result.metadata.name;\n try {\n if (readFileSync) {\n const pkgJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\n packageName = pkgJson.name || result.metadata.name;\n }\n } catch {\n // Use metadata name as fallback\n }\n\n console.log(pc.green('\\nā
Image is ready to use!'));\n console.log(' To use this image in an app:');\n console.log(\n pc.dim(\n ` 1. Install it: pnpm add ${packageName}@file:../${packageName.split('/').pop()}`\n )\n );\n console.log(pc.dim(` 2. Import it: import { createAgent } from '${packageName}';`));\n console.log(pc.dim(`\\n Or publish to npm and install normally.`));\n } catch (error) {\n console.error(pc.red('\\nā Build failed:'), error);\n process.exit(1);\n }\n });\n\nprogram.parse();\n","/**\n * Main bundler logic\n */\n\nimport { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, statSync } from 'node:fs';\nimport { dirname, join, resolve, relative, extname } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { validateImageDefinition } from '@dexto/core';\nimport type { ImageDefinition } from '@dexto/core';\nimport type { BundleOptions, BundleResult } from './types.js';\nimport { generateEntryPoint } from './generator.js';\nimport ts from 'typescript';\n\n/**\n * Bundle a Dexto base image\n */\nexport async function bundle(options: BundleOptions): Promise<BundleResult> {\n const warnings: string[] = [];\n\n // 1. Load and validate image definition\n console.log(`š¦ Loading image definition from ${options.imagePath}`);\n const definition = await loadImageDefinition(options.imagePath);\n\n console.log(`ā
Loaded image: ${definition.name} v${definition.version}`);\n\n // 2. Validate definition\n console.log(`š Validating image definition...`);\n try {\n validateImageDefinition(definition);\n console.log(`ā
Image definition is valid`);\n } catch (error) {\n throw new Error(`Image validation failed: ${error}`);\n }\n\n // 3. Get core version (from package.json)\n const coreVersion = getCoreVersion();\n\n // 3.5. Discover providers from convention-based folders\n console.log(`š Discovering providers from folders...`);\n const imageDir = dirname(options.imagePath);\n const discoveredProviders = discoverProviders(imageDir);\n console.log(`ā
Discovered ${discoveredProviders.totalCount} provider(s)`);\n\n // 4. Generate code\n console.log(`šØ Generating entry point...`);\n const generated = generateEntryPoint(definition, coreVersion, discoveredProviders);\n\n // 5. Ensure output directory exists\n const outDir = resolve(options.outDir);\n if (!existsSync(outDir)) {\n mkdirSync(outDir, { recursive: true });\n }\n\n // 5.5. Compile provider category folders\n console.log(`šØ Compiling provider source files...`);\n const categories = ['blob-store', 'tools', 'compaction', 'plugins'];\n let compiledCount = 0;\n\n for (const category of categories) {\n const categoryDir = join(imageDir, category);\n if (existsSync(categoryDir)) {\n compileSourceFiles(categoryDir, join(outDir, category));\n compiledCount++;\n }\n }\n\n if (compiledCount > 0) {\n console.log(\n `ā
Compiled ${compiledCount} provider categor${compiledCount === 1 ? 'y' : 'ies'}`\n );\n }\n\n // 6. Write generated files\n const entryFile = join(outDir, 'index.js');\n const typesFile = join(outDir, 'index.d.ts');\n\n console.log(`š Writing ${entryFile}...`);\n writeFileSync(entryFile, generated.js, 'utf-8');\n\n console.log(`š Writing ${typesFile}...`);\n writeFileSync(typesFile, generated.dts, 'utf-8');\n\n // 7. Generate package.json exports\n updatePackageJson(dirname(options.imagePath), outDir);\n\n console.log(`⨠Build complete!`);\n console.log(` Entry: ${entryFile}`);\n console.log(` Types: ${typesFile}`);\n\n const metadata = {\n name: definition.name,\n version: definition.version,\n description: definition.description,\n target: definition.target || 'custom',\n constraints: definition.constraints || [],\n builtAt: new Date().toISOString(),\n coreVersion,\n };\n\n return {\n entryFile,\n typesFile,\n metadata,\n warnings,\n };\n}\n\n/**\n * Load image definition from file\n */\nasync function loadImageDefinition(imagePath: string): Promise<ImageDefinition> {\n const absolutePath = resolve(imagePath);\n\n if (!existsSync(absolutePath)) {\n throw new Error(`Image file not found: ${absolutePath}`);\n }\n\n try {\n // Convert to file:// URL for ESM import\n const fileUrl = pathToFileURL(absolutePath).href;\n\n // Dynamic import\n const module = await import(fileUrl);\n\n // Get default export\n const definition = module.default as ImageDefinition;\n\n if (!definition) {\n throw new Error('Image file must have a default export');\n }\n\n return definition;\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Failed to load image definition: ${error.message}`);\n }\n throw error;\n }\n}\n\n/**\n * Get @dexto/core version\n */\nfunction getCoreVersion(): string {\n try {\n // Try to read from node_modules\n const corePackageJson = join(process.cwd(), 'node_modules/@dexto/core/package.json');\n if (existsSync(corePackageJson)) {\n const pkg = JSON.parse(readFileSync(corePackageJson, 'utf-8'));\n return pkg.version;\n }\n\n // Fallback to workspace version\n return '1.0.0';\n } catch {\n return '1.0.0';\n }\n}\n\n/**\n * Update or create package.json with proper exports\n */\nfunction updatePackageJson(imageDir: string, outDir: string): void {\n const packageJsonPath = join(imageDir, 'package.json');\n\n if (!existsSync(packageJsonPath)) {\n console.log(`ā ļø No package.json found, skipping exports update`);\n return;\n }\n\n try {\n const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\n\n // Update exports\n pkg.exports = {\n '.': {\n types: './dist/index.d.ts',\n import: './dist/index.js',\n },\n };\n\n // Update main and types fields\n pkg.main = './dist/index.js';\n pkg.types = './dist/index.d.ts';\n\n writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2), 'utf-8');\n console.log(`ā
Updated package.json exports`);\n } catch (error) {\n console.warn(`ā ļø Failed to update package.json: ${error}`);\n }\n}\n\n/**\n * Compile TypeScript source files to JavaScript\n */\nfunction compileSourceFiles(srcDir: string, outDir: string): void {\n // Find all .ts files\n const tsFiles = findTypeScriptFiles(srcDir);\n\n if (tsFiles.length === 0) {\n console.log(` No TypeScript files found in ${srcDir}`);\n return;\n }\n\n console.log(` Found ${tsFiles.length} TypeScript file(s) to compile`);\n\n // TypeScript compiler options\n const compilerOptions: ts.CompilerOptions = {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.ESNext,\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n outDir: outDir,\n rootDir: srcDir, // Use srcDir as root\n declaration: true,\n esModuleInterop: true,\n skipLibCheck: true,\n strict: true,\n resolveJsonModule: true,\n };\n\n // Create program\n const program = ts.createProgram(tsFiles, compilerOptions);\n\n // Emit compiled files\n const emitResult = program.emit();\n\n // Check for errors\n const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);\n\n if (allDiagnostics.length > 0) {\n allDiagnostics.forEach((diagnostic) => {\n if (diagnostic.file) {\n const { line, character } = ts.getLineAndCharacterOfPosition(\n diagnostic.file,\n diagnostic.start!\n );\n const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\\n');\n console.error(\n ` ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`\n );\n } else {\n console.error(\n ` ${ts.flattenDiagnosticMessageText(diagnostic.messageText, '\\n')}`\n );\n }\n });\n\n if (emitResult.emitSkipped) {\n throw new Error('TypeScript compilation failed');\n }\n }\n}\n\n/**\n * Recursively find all TypeScript files in a directory\n */\nfunction findTypeScriptFiles(dir: string): string[] {\n const files: string[] = [];\n\n function walk(currentDir: string) {\n const entries = readdirSync(currentDir);\n\n for (const entry of entries) {\n const fullPath = join(currentDir, entry);\n const stat = statSync(fullPath);\n\n if (stat.isDirectory()) {\n walk(fullPath);\n } else if (stat.isFile() && extname(entry) === '.ts') {\n files.push(fullPath);\n }\n }\n }\n\n walk(dir);\n return files;\n}\n\n/**\n * Provider discovery result for a single category\n */\nexport interface DiscoveredProviders {\n blobStore: string[];\n customTools: string[];\n compaction: string[];\n plugins: string[];\n totalCount: number;\n}\n\n/**\n * Discover providers from convention-based folder structure\n *\n * Convention (folder-based with index.ts):\n * tools/ - CustomToolProvider folders\n * weather/ - Provider folder\n * index.ts - Provider implementation (auto-discovered)\n * helpers.ts - Optional helper files\n * types.ts - Optional type definitions\n * blob-store/ - BlobStoreProvider folders\n * compaction/ - CompactionProvider folders\n * plugins/ - PluginProvider folders\n *\n * Naming Convention (Node.js standard):\n * <folder>/index.ts - Auto-discovered and registered\n * <folder>/other.ts - Ignored unless imported by index.ts\n */\nfunction discoverProviders(imageDir: string): DiscoveredProviders {\n const result: DiscoveredProviders = {\n blobStore: [],\n customTools: [],\n compaction: [],\n plugins: [],\n totalCount: 0,\n };\n\n // Category mapping: folder name -> property name\n const categories = {\n 'blob-store': 'blobStore',\n tools: 'customTools',\n compaction: 'compaction',\n plugins: 'plugins',\n } as const;\n\n for (const [folderName, propName] of Object.entries(categories)) {\n const categoryDir = join(imageDir, folderName);\n\n if (!existsSync(categoryDir)) {\n continue;\n }\n\n // Find all provider folders (those with index.ts)\n const providerFolders = readdirSync(categoryDir)\n .filter((entry) => {\n const entryPath = join(categoryDir, entry);\n const stat = statSync(entryPath);\n\n // Must be a directory\n if (!stat.isDirectory()) {\n return false;\n }\n\n // Must contain index.ts\n const indexPath = join(entryPath, 'index.ts');\n return existsSync(indexPath);\n })\n .map((folder) => {\n // Return relative path for imports\n return `./${folderName}/${folder}/index.js`;\n });\n\n if (providerFolders.length > 0) {\n result[propName as keyof Omit<DiscoveredProviders, 'totalCount'>].push(\n ...providerFolders\n );\n result.totalCount += providerFolders.length;\n console.log(` Found ${providerFolders.length} provider(s) in ${folderName}/`);\n }\n }\n\n return result;\n}\n","/**\n * Code generator for base images\n *\n * Transforms image definitions into importable packages with:\n * - Side-effect provider registration\n * - createAgent() factory\n * - Utility exports\n * - Metadata exports\n */\n\nimport type { ImageDefinition } from '@dexto/core';\nimport type { GeneratedCode } from './types.js';\nimport type { DiscoveredProviders } from './bundler.js';\n\n/**\n * Generate JavaScript entry point for an image\n */\nexport function generateEntryPoint(\n definition: ImageDefinition,\n coreVersion: string,\n discoveredProviders?: DiscoveredProviders\n): GeneratedCode {\n // Generate imports section\n const imports = generateImports(definition, discoveredProviders);\n\n // Generate provider registration section\n const registrations = generateProviderRegistrations(definition, discoveredProviders);\n\n // Generate factory function\n const factory = generateFactory();\n\n // Generate utility exports\n const utilityExports = generateUtilityExports(definition);\n\n // Generate metadata export\n const metadata = generateMetadata(definition, coreVersion);\n\n // Combine all sections\n const js = `// AUTO-GENERATED by @dexto/bundler\n// Do not edit this file directly. Edit dexto.image.ts instead.\n\n${imports}\n\n${registrations}\n\n${factory}\n\n${utilityExports}\n\n${metadata}\n`;\n\n // Generate TypeScript definitions\n const dts = generateTypeDefinitions(definition);\n\n return { js, dts };\n}\n\nfunction generateImports(\n definition: ImageDefinition,\n discoveredProviders?: DiscoveredProviders\n): string {\n const imports: string[] = [];\n\n // Import base image first (if extending) - triggers side-effect provider registration\n if (definition.extends) {\n imports.push(`// Import base image for provider registration (side effect)`);\n imports.push(`import '${definition.extends}';`);\n imports.push(``);\n }\n\n // Core imports\n imports.push(`import { DextoAgent } from '@dexto/core';`);\n\n // Always import all registries since we re-export them in generateFactory()\n // This ensures the re-exports don't reference unimported identifiers\n imports.push(\n `import { customToolRegistry, pluginRegistry, compactionRegistry, blobStoreRegistry } from '@dexto/core';`\n );\n\n // Import discovered providers\n if (discoveredProviders) {\n const categories = [\n { key: 'blobStore', label: 'Blob Storage' },\n { key: 'customTools', label: 'Custom Tools' },\n { key: 'compaction', label: 'Compaction' },\n { key: 'plugins', label: 'Plugins' },\n ] as const;\n\n for (const { key, label } of categories) {\n const providers = discoveredProviders[key];\n if (providers.length > 0) {\n imports.push(``);\n imports.push(`// ${label} providers (auto-discovered)`);\n providers.forEach((path, index) => {\n const varName = `${key}Provider${index}`;\n imports.push(`import * as ${varName} from '${path}';`);\n });\n }\n }\n }\n\n return imports.join('\\n');\n}\n\nfunction generateProviderRegistrations(\n definition: ImageDefinition,\n discoveredProviders?: DiscoveredProviders\n): string {\n const registrations: string[] = [];\n\n if (definition.extends) {\n registrations.push(\n `// Base image providers already registered via import of '${definition.extends}'`\n );\n registrations.push('');\n }\n\n registrations.push('// SIDE EFFECT: Register providers on import');\n registrations.push('');\n\n // Auto-register discovered providers\n if (discoveredProviders) {\n const categoryMap = [\n { key: 'blobStore', registry: 'blobStoreRegistry', label: 'Blob Storage' },\n { key: 'customTools', registry: 'customToolRegistry', label: 'Custom Tools' },\n { key: 'compaction', registry: 'compactionRegistry', label: 'Compaction' },\n { key: 'plugins', registry: 'pluginRegistry', label: 'Plugins' },\n ] as const;\n\n for (const { key, registry, label } of categoryMap) {\n const providers = discoveredProviders[key];\n if (providers.length === 0) continue;\n\n registrations.push(`// Auto-register ${label} providers`);\n providers.forEach((path, index) => {\n const varName = `${key}Provider${index}`;\n registrations.push(`// From ${path}`);\n registrations.push(`for (const exported of Object.values(${varName})) {`);\n registrations.push(\n ` if (exported && typeof exported === 'object' && 'type' in exported && 'create' in exported) {`\n );\n registrations.push(` try {`);\n registrations.push(` ${registry}.register(exported);`);\n registrations.push(\n ` console.log(\\`ā Registered ${key}: \\${exported.type}\\`);`\n );\n registrations.push(` } catch (err) {`);\n registrations.push(` // Ignore duplicate registration errors`);\n registrations.push(\n ` if (!err.message?.includes('already registered')) throw err;`\n );\n registrations.push(` }`);\n registrations.push(` }`);\n registrations.push(`}`);\n });\n registrations.push('');\n }\n }\n\n // Handle manual registration functions (backwards compatibility)\n for (const [category, config] of Object.entries(definition.providers)) {\n if (!config) continue;\n\n if (config.register) {\n // Async registration function with duplicate prevention\n registrations.push(`// Register ${category} via custom function (from dexto.image.ts)`);\n registrations.push(`await (async () => {`);\n registrations.push(` try {`);\n registrations.push(\n ` ${config.register\n .toString()\n .replace(/^async\\s*\\(\\)\\s*=>\\s*{/, '')\n .replace(/}$/, '')}`\n );\n registrations.push(` } catch (err) {`);\n registrations.push(` // Ignore duplicate registration errors`);\n registrations.push(` if (!err.message?.includes('already registered')) {`);\n registrations.push(` throw err;`);\n registrations.push(` }`);\n registrations.push(` }`);\n registrations.push(`})();`);\n registrations.push('');\n }\n }\n\n return registrations.join('\\n');\n}\n\nfunction generateFactory(): string {\n return `/**\n * Create a Dexto agent using this image's registered providers.\n *\n * @param config - Agent configuration\n * @param configPath - Optional path to config file\n * @returns DextoAgent instance with providers already registered\n */\nexport function createAgent(config, configPath) {\n return new DextoAgent(config, configPath);\n}\n\n/**\n * Re-export registries for runtime customization.\n * This allows apps to add custom providers without depending on @dexto/core directly.\n */\nexport {\n customToolRegistry,\n pluginRegistry,\n compactionRegistry,\n blobStoreRegistry,\n} from '@dexto/core';`;\n}\n\nfunction generateUtilityExports(definition: ImageDefinition): string {\n const sections: string[] = [];\n\n // Generate wildcard utility exports\n if (definition.utils && Object.keys(definition.utils).length > 0) {\n sections.push('// Utility exports');\n for (const [name, path] of Object.entries(definition.utils)) {\n sections.push(`export * from '${path}';`);\n }\n }\n\n // Generate selective named exports (filter out type-only exports for runtime JS)\n if (definition.exports && Object.keys(definition.exports).length > 0) {\n if (sections.length > 0) sections.push('');\n sections.push('// Selective package re-exports');\n for (const [packageName, exports] of Object.entries(definition.exports)) {\n // Check for wildcard re-export\n if (exports.length === 1 && exports[0] === '*') {\n sections.push(`export * from '${packageName}';`);\n continue;\n }\n\n // Filter out type-only exports (those starting with 'type ')\n const runtimeExports = exports.filter((exp) => !exp.startsWith('type '));\n if (runtimeExports.length > 0) {\n sections.push(`export {`);\n sections.push(` ${runtimeExports.join(',\\n ')}`);\n sections.push(`} from '${packageName}';`);\n }\n }\n }\n\n if (sections.length === 0) {\n return '// No utilities or exports defined for this image';\n }\n\n return sections.join('\\n');\n}\n\nfunction generateMetadata(definition: ImageDefinition, coreVersion: string): string {\n const metadata: Record<string, any> = {\n name: definition.name,\n version: definition.version,\n description: definition.description,\n target: definition.target || 'custom',\n constraints: definition.constraints || [],\n builtAt: new Date().toISOString(),\n coreVersion: coreVersion,\n };\n\n // Include extends information if present\n if (definition.extends) {\n metadata.extends = definition.extends;\n }\n\n return `/**\n * Image metadata\n * Generated at build time\n */\nexport const imageMetadata = ${JSON.stringify(metadata, null, 4)};`;\n}\n\nfunction generateTypeDefinitions(definition: ImageDefinition): string {\n const sections: string[] = [];\n\n // Wildcard utility exports\n if (definition.utils && Object.keys(definition.utils).length > 0) {\n sections.push('// Utility re-exports');\n for (const path of Object.values(definition.utils)) {\n sections.push(`export * from '${path}';`);\n }\n }\n\n // Selective named exports\n if (definition.exports && Object.keys(definition.exports).length > 0) {\n if (sections.length > 0) sections.push('');\n sections.push('// Selective package re-exports');\n for (const [packageName, exports] of Object.entries(definition.exports)) {\n // Check for wildcard re-export\n if (exports.length === 1 && exports[0] === '*') {\n sections.push(`export * from '${packageName}';`);\n continue;\n }\n\n sections.push(`export {`);\n sections.push(` ${exports.join(',\\n ')}`);\n sections.push(`} from '${packageName}';`);\n }\n }\n\n const utilityExports = sections.length > 0 ? '\\n\\n' + sections.join('\\n') : '';\n\n return `// AUTO-GENERATED TypeScript definitions\n// Do not edit this file directly\n\nimport type { DextoAgent, AgentConfig, ImageMetadata } from '@dexto/core';\n\n/**\n * Create a Dexto agent using this image's registered providers.\n */\nexport declare function createAgent(config: AgentConfig, configPath?: string): DextoAgent;\n\n/**\n * Image metadata\n */\nexport declare const imageMetadata: ImageMetadata;\n\n/**\n * Re-exported registries for runtime customization\n */\nexport {\n customToolRegistry,\n pluginRegistry,\n compactionRegistry,\n blobStoreRegistry,\n} from '@dexto/core';${utilityExports}\n`;\n}\n"],"mappings":";;;AAaA,SAAS,eAAe;;;ACTxB,SAAS,cAAc,eAAe,WAAW,YAAY,aAAa,gBAAgB;AAC1F,SAAS,SAAS,MAAM,SAAmB,eAAe;AAC1D,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B;;;ACUjC,SAAS,mBACZ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AAAA,EAClB;AACJ,CAAC;AAEL,QAAQ,MAAM;","names":["program","readFileSync","join","dirname","__filename","__dirname"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ImageMetadata } from '@dexto/core';
|
|
2
|
+
|
|
3
|
+
interface BundleOptions {
|
|
4
|
+
/** Path to dexto.image.ts file */
|
|
5
|
+
imagePath: string;
|
|
6
|
+
/** Output directory for built image */
|
|
7
|
+
outDir: string;
|
|
8
|
+
/** Whether to generate source maps */
|
|
9
|
+
sourcemap?: boolean;
|
|
10
|
+
/** Whether to minify output */
|
|
11
|
+
minify?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface BundleResult {
|
|
14
|
+
/** Path to generated entry file */
|
|
15
|
+
entryFile: string;
|
|
16
|
+
/** Path to generated types file */
|
|
17
|
+
typesFile: string;
|
|
18
|
+
/** Image metadata */
|
|
19
|
+
metadata: ImageMetadata;
|
|
20
|
+
/** Warnings encountered during build */
|
|
21
|
+
warnings: string[];
|
|
22
|
+
}
|
|
23
|
+
interface GeneratedCode {
|
|
24
|
+
/** Generated JavaScript code */
|
|
25
|
+
js: string;
|
|
26
|
+
/** Generated TypeScript definitions */
|
|
27
|
+
dts: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Main bundler logic
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Bundle a Dexto base image
|
|
36
|
+
*/
|
|
37
|
+
declare function bundle(options: BundleOptions): Promise<BundleResult>;
|
|
38
|
+
|
|
39
|
+
export { type BundleOptions, type BundleResult, type GeneratedCode, bundle };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
// src/bundler.ts
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, statSync } from "fs";
|
|
3
|
+
import { dirname, join, resolve, extname } from "path";
|
|
4
|
+
import { pathToFileURL } from "url";
|
|
5
|
+
import { validateImageDefinition } from "@dexto/core";
|
|
6
|
+
|
|
7
|
+
// src/generator.ts
|
|
8
|
+
function generateEntryPoint(definition, coreVersion, discoveredProviders) {
|
|
9
|
+
const imports = generateImports(definition, discoveredProviders);
|
|
10
|
+
const registrations = generateProviderRegistrations(definition, discoveredProviders);
|
|
11
|
+
const factory = generateFactory();
|
|
12
|
+
const utilityExports = generateUtilityExports(definition);
|
|
13
|
+
const metadata = generateMetadata(definition, coreVersion);
|
|
14
|
+
const js = `// AUTO-GENERATED by @dexto/bundler
|
|
15
|
+
// Do not edit this file directly. Edit dexto.image.ts instead.
|
|
16
|
+
|
|
17
|
+
${imports}
|
|
18
|
+
|
|
19
|
+
${registrations}
|
|
20
|
+
|
|
21
|
+
${factory}
|
|
22
|
+
|
|
23
|
+
${utilityExports}
|
|
24
|
+
|
|
25
|
+
${metadata}
|
|
26
|
+
`;
|
|
27
|
+
const dts = generateTypeDefinitions(definition);
|
|
28
|
+
return { js, dts };
|
|
29
|
+
}
|
|
30
|
+
function generateImports(definition, discoveredProviders) {
|
|
31
|
+
const imports = [];
|
|
32
|
+
if (definition.extends) {
|
|
33
|
+
imports.push(`// Import base image for provider registration (side effect)`);
|
|
34
|
+
imports.push(`import '${definition.extends}';`);
|
|
35
|
+
imports.push(``);
|
|
36
|
+
}
|
|
37
|
+
imports.push(`import { DextoAgent } from '@dexto/core';`);
|
|
38
|
+
imports.push(
|
|
39
|
+
`import { customToolRegistry, pluginRegistry, compactionRegistry, blobStoreRegistry } from '@dexto/core';`
|
|
40
|
+
);
|
|
41
|
+
if (discoveredProviders) {
|
|
42
|
+
const categories = [
|
|
43
|
+
{ key: "blobStore", label: "Blob Storage" },
|
|
44
|
+
{ key: "customTools", label: "Custom Tools" },
|
|
45
|
+
{ key: "compaction", label: "Compaction" },
|
|
46
|
+
{ key: "plugins", label: "Plugins" }
|
|
47
|
+
];
|
|
48
|
+
for (const { key, label } of categories) {
|
|
49
|
+
const providers = discoveredProviders[key];
|
|
50
|
+
if (providers.length > 0) {
|
|
51
|
+
imports.push(``);
|
|
52
|
+
imports.push(`// ${label} providers (auto-discovered)`);
|
|
53
|
+
providers.forEach((path, index) => {
|
|
54
|
+
const varName = `${key}Provider${index}`;
|
|
55
|
+
imports.push(`import * as ${varName} from '${path}';`);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return imports.join("\n");
|
|
61
|
+
}
|
|
62
|
+
function generateProviderRegistrations(definition, discoveredProviders) {
|
|
63
|
+
const registrations = [];
|
|
64
|
+
if (definition.extends) {
|
|
65
|
+
registrations.push(
|
|
66
|
+
`// Base image providers already registered via import of '${definition.extends}'`
|
|
67
|
+
);
|
|
68
|
+
registrations.push("");
|
|
69
|
+
}
|
|
70
|
+
registrations.push("// SIDE EFFECT: Register providers on import");
|
|
71
|
+
registrations.push("");
|
|
72
|
+
if (discoveredProviders) {
|
|
73
|
+
const categoryMap = [
|
|
74
|
+
{ key: "blobStore", registry: "blobStoreRegistry", label: "Blob Storage" },
|
|
75
|
+
{ key: "customTools", registry: "customToolRegistry", label: "Custom Tools" },
|
|
76
|
+
{ key: "compaction", registry: "compactionRegistry", label: "Compaction" },
|
|
77
|
+
{ key: "plugins", registry: "pluginRegistry", label: "Plugins" }
|
|
78
|
+
];
|
|
79
|
+
for (const { key, registry, label } of categoryMap) {
|
|
80
|
+
const providers = discoveredProviders[key];
|
|
81
|
+
if (providers.length === 0) continue;
|
|
82
|
+
registrations.push(`// Auto-register ${label} providers`);
|
|
83
|
+
providers.forEach((path, index) => {
|
|
84
|
+
const varName = `${key}Provider${index}`;
|
|
85
|
+
registrations.push(`// From ${path}`);
|
|
86
|
+
registrations.push(`for (const exported of Object.values(${varName})) {`);
|
|
87
|
+
registrations.push(
|
|
88
|
+
` if (exported && typeof exported === 'object' && 'type' in exported && 'create' in exported) {`
|
|
89
|
+
);
|
|
90
|
+
registrations.push(` try {`);
|
|
91
|
+
registrations.push(` ${registry}.register(exported);`);
|
|
92
|
+
registrations.push(
|
|
93
|
+
` console.log(\`\u2713 Registered ${key}: \${exported.type}\`);`
|
|
94
|
+
);
|
|
95
|
+
registrations.push(` } catch (err) {`);
|
|
96
|
+
registrations.push(` // Ignore duplicate registration errors`);
|
|
97
|
+
registrations.push(
|
|
98
|
+
` if (!err.message?.includes('already registered')) throw err;`
|
|
99
|
+
);
|
|
100
|
+
registrations.push(` }`);
|
|
101
|
+
registrations.push(` }`);
|
|
102
|
+
registrations.push(`}`);
|
|
103
|
+
});
|
|
104
|
+
registrations.push("");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const [category, config] of Object.entries(definition.providers)) {
|
|
108
|
+
if (!config) continue;
|
|
109
|
+
if (config.register) {
|
|
110
|
+
registrations.push(`// Register ${category} via custom function (from dexto.image.ts)`);
|
|
111
|
+
registrations.push(`await (async () => {`);
|
|
112
|
+
registrations.push(` try {`);
|
|
113
|
+
registrations.push(
|
|
114
|
+
` ${config.register.toString().replace(/^async\s*\(\)\s*=>\s*{/, "").replace(/}$/, "")}`
|
|
115
|
+
);
|
|
116
|
+
registrations.push(` } catch (err) {`);
|
|
117
|
+
registrations.push(` // Ignore duplicate registration errors`);
|
|
118
|
+
registrations.push(` if (!err.message?.includes('already registered')) {`);
|
|
119
|
+
registrations.push(` throw err;`);
|
|
120
|
+
registrations.push(` }`);
|
|
121
|
+
registrations.push(` }`);
|
|
122
|
+
registrations.push(`})();`);
|
|
123
|
+
registrations.push("");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return registrations.join("\n");
|
|
127
|
+
}
|
|
128
|
+
function generateFactory() {
|
|
129
|
+
return `/**
|
|
130
|
+
* Create a Dexto agent using this image's registered providers.
|
|
131
|
+
*
|
|
132
|
+
* @param config - Agent configuration
|
|
133
|
+
* @param configPath - Optional path to config file
|
|
134
|
+
* @returns DextoAgent instance with providers already registered
|
|
135
|
+
*/
|
|
136
|
+
export function createAgent(config, configPath) {
|
|
137
|
+
return new DextoAgent(config, configPath);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Re-export registries for runtime customization.
|
|
142
|
+
* This allows apps to add custom providers without depending on @dexto/core directly.
|
|
143
|
+
*/
|
|
144
|
+
export {
|
|
145
|
+
customToolRegistry,
|
|
146
|
+
pluginRegistry,
|
|
147
|
+
compactionRegistry,
|
|
148
|
+
blobStoreRegistry,
|
|
149
|
+
} from '@dexto/core';`;
|
|
150
|
+
}
|
|
151
|
+
function generateUtilityExports(definition) {
|
|
152
|
+
const sections = [];
|
|
153
|
+
if (definition.utils && Object.keys(definition.utils).length > 0) {
|
|
154
|
+
sections.push("// Utility exports");
|
|
155
|
+
for (const [name, path] of Object.entries(definition.utils)) {
|
|
156
|
+
sections.push(`export * from '${path}';`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (definition.exports && Object.keys(definition.exports).length > 0) {
|
|
160
|
+
if (sections.length > 0) sections.push("");
|
|
161
|
+
sections.push("// Selective package re-exports");
|
|
162
|
+
for (const [packageName, exports] of Object.entries(definition.exports)) {
|
|
163
|
+
if (exports.length === 1 && exports[0] === "*") {
|
|
164
|
+
sections.push(`export * from '${packageName}';`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const runtimeExports = exports.filter((exp) => !exp.startsWith("type "));
|
|
168
|
+
if (runtimeExports.length > 0) {
|
|
169
|
+
sections.push(`export {`);
|
|
170
|
+
sections.push(` ${runtimeExports.join(",\n ")}`);
|
|
171
|
+
sections.push(`} from '${packageName}';`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (sections.length === 0) {
|
|
176
|
+
return "// No utilities or exports defined for this image";
|
|
177
|
+
}
|
|
178
|
+
return sections.join("\n");
|
|
179
|
+
}
|
|
180
|
+
function generateMetadata(definition, coreVersion) {
|
|
181
|
+
const metadata = {
|
|
182
|
+
name: definition.name,
|
|
183
|
+
version: definition.version,
|
|
184
|
+
description: definition.description,
|
|
185
|
+
target: definition.target || "custom",
|
|
186
|
+
constraints: definition.constraints || [],
|
|
187
|
+
builtAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
188
|
+
coreVersion
|
|
189
|
+
};
|
|
190
|
+
if (definition.extends) {
|
|
191
|
+
metadata.extends = definition.extends;
|
|
192
|
+
}
|
|
193
|
+
return `/**
|
|
194
|
+
* Image metadata
|
|
195
|
+
* Generated at build time
|
|
196
|
+
*/
|
|
197
|
+
export const imageMetadata = ${JSON.stringify(metadata, null, 4)};`;
|
|
198
|
+
}
|
|
199
|
+
function generateTypeDefinitions(definition) {
|
|
200
|
+
const sections = [];
|
|
201
|
+
if (definition.utils && Object.keys(definition.utils).length > 0) {
|
|
202
|
+
sections.push("// Utility re-exports");
|
|
203
|
+
for (const path of Object.values(definition.utils)) {
|
|
204
|
+
sections.push(`export * from '${path}';`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (definition.exports && Object.keys(definition.exports).length > 0) {
|
|
208
|
+
if (sections.length > 0) sections.push("");
|
|
209
|
+
sections.push("// Selective package re-exports");
|
|
210
|
+
for (const [packageName, exports] of Object.entries(definition.exports)) {
|
|
211
|
+
if (exports.length === 1 && exports[0] === "*") {
|
|
212
|
+
sections.push(`export * from '${packageName}';`);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
sections.push(`export {`);
|
|
216
|
+
sections.push(` ${exports.join(",\n ")}`);
|
|
217
|
+
sections.push(`} from '${packageName}';`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const utilityExports = sections.length > 0 ? "\n\n" + sections.join("\n") : "";
|
|
221
|
+
return `// AUTO-GENERATED TypeScript definitions
|
|
222
|
+
// Do not edit this file directly
|
|
223
|
+
|
|
224
|
+
import type { DextoAgent, AgentConfig, ImageMetadata } from '@dexto/core';
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Create a Dexto agent using this image's registered providers.
|
|
228
|
+
*/
|
|
229
|
+
export declare function createAgent(config: AgentConfig, configPath?: string): DextoAgent;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Image metadata
|
|
233
|
+
*/
|
|
234
|
+
export declare const imageMetadata: ImageMetadata;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Re-exported registries for runtime customization
|
|
238
|
+
*/
|
|
239
|
+
export {
|
|
240
|
+
customToolRegistry,
|
|
241
|
+
pluginRegistry,
|
|
242
|
+
compactionRegistry,
|
|
243
|
+
blobStoreRegistry,
|
|
244
|
+
} from '@dexto/core';${utilityExports}
|
|
245
|
+
`;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/bundler.ts
|
|
249
|
+
import ts from "typescript";
|
|
250
|
+
async function bundle(options) {
|
|
251
|
+
const warnings = [];
|
|
252
|
+
console.log(`\u{1F4E6} Loading image definition from ${options.imagePath}`);
|
|
253
|
+
const definition = await loadImageDefinition(options.imagePath);
|
|
254
|
+
console.log(`\u2705 Loaded image: ${definition.name} v${definition.version}`);
|
|
255
|
+
console.log(`\u{1F50D} Validating image definition...`);
|
|
256
|
+
try {
|
|
257
|
+
validateImageDefinition(definition);
|
|
258
|
+
console.log(`\u2705 Image definition is valid`);
|
|
259
|
+
} catch (error) {
|
|
260
|
+
throw new Error(`Image validation failed: ${error}`);
|
|
261
|
+
}
|
|
262
|
+
const coreVersion = getCoreVersion();
|
|
263
|
+
console.log(`\u{1F50D} Discovering providers from folders...`);
|
|
264
|
+
const imageDir = dirname(options.imagePath);
|
|
265
|
+
const discoveredProviders = discoverProviders(imageDir);
|
|
266
|
+
console.log(`\u2705 Discovered ${discoveredProviders.totalCount} provider(s)`);
|
|
267
|
+
console.log(`\u{1F528} Generating entry point...`);
|
|
268
|
+
const generated = generateEntryPoint(definition, coreVersion, discoveredProviders);
|
|
269
|
+
const outDir = resolve(options.outDir);
|
|
270
|
+
if (!existsSync(outDir)) {
|
|
271
|
+
mkdirSync(outDir, { recursive: true });
|
|
272
|
+
}
|
|
273
|
+
console.log(`\u{1F528} Compiling provider source files...`);
|
|
274
|
+
const categories = ["blob-store", "tools", "compaction", "plugins"];
|
|
275
|
+
let compiledCount = 0;
|
|
276
|
+
for (const category of categories) {
|
|
277
|
+
const categoryDir = join(imageDir, category);
|
|
278
|
+
if (existsSync(categoryDir)) {
|
|
279
|
+
compileSourceFiles(categoryDir, join(outDir, category));
|
|
280
|
+
compiledCount++;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (compiledCount > 0) {
|
|
284
|
+
console.log(
|
|
285
|
+
`\u2705 Compiled ${compiledCount} provider categor${compiledCount === 1 ? "y" : "ies"}`
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
const entryFile = join(outDir, "index.js");
|
|
289
|
+
const typesFile = join(outDir, "index.d.ts");
|
|
290
|
+
console.log(`\u{1F4DD} Writing ${entryFile}...`);
|
|
291
|
+
writeFileSync(entryFile, generated.js, "utf-8");
|
|
292
|
+
console.log(`\u{1F4DD} Writing ${typesFile}...`);
|
|
293
|
+
writeFileSync(typesFile, generated.dts, "utf-8");
|
|
294
|
+
updatePackageJson(dirname(options.imagePath), outDir);
|
|
295
|
+
console.log(`\u2728 Build complete!`);
|
|
296
|
+
console.log(` Entry: ${entryFile}`);
|
|
297
|
+
console.log(` Types: ${typesFile}`);
|
|
298
|
+
const metadata = {
|
|
299
|
+
name: definition.name,
|
|
300
|
+
version: definition.version,
|
|
301
|
+
description: definition.description,
|
|
302
|
+
target: definition.target || "custom",
|
|
303
|
+
constraints: definition.constraints || [],
|
|
304
|
+
builtAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
305
|
+
coreVersion
|
|
306
|
+
};
|
|
307
|
+
return {
|
|
308
|
+
entryFile,
|
|
309
|
+
typesFile,
|
|
310
|
+
metadata,
|
|
311
|
+
warnings
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
async function loadImageDefinition(imagePath) {
|
|
315
|
+
const absolutePath = resolve(imagePath);
|
|
316
|
+
if (!existsSync(absolutePath)) {
|
|
317
|
+
throw new Error(`Image file not found: ${absolutePath}`);
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
const fileUrl = pathToFileURL(absolutePath).href;
|
|
321
|
+
const module = await import(fileUrl);
|
|
322
|
+
const definition = module.default;
|
|
323
|
+
if (!definition) {
|
|
324
|
+
throw new Error("Image file must have a default export");
|
|
325
|
+
}
|
|
326
|
+
return definition;
|
|
327
|
+
} catch (error) {
|
|
328
|
+
if (error instanceof Error) {
|
|
329
|
+
throw new Error(`Failed to load image definition: ${error.message}`);
|
|
330
|
+
}
|
|
331
|
+
throw error;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function getCoreVersion() {
|
|
335
|
+
try {
|
|
336
|
+
const corePackageJson = join(process.cwd(), "node_modules/@dexto/core/package.json");
|
|
337
|
+
if (existsSync(corePackageJson)) {
|
|
338
|
+
const pkg = JSON.parse(readFileSync(corePackageJson, "utf-8"));
|
|
339
|
+
return pkg.version;
|
|
340
|
+
}
|
|
341
|
+
return "1.0.0";
|
|
342
|
+
} catch {
|
|
343
|
+
return "1.0.0";
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function updatePackageJson(imageDir, outDir) {
|
|
347
|
+
const packageJsonPath = join(imageDir, "package.json");
|
|
348
|
+
if (!existsSync(packageJsonPath)) {
|
|
349
|
+
console.log(`\u26A0\uFE0F No package.json found, skipping exports update`);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
try {
|
|
353
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
354
|
+
pkg.exports = {
|
|
355
|
+
".": {
|
|
356
|
+
types: "./dist/index.d.ts",
|
|
357
|
+
import: "./dist/index.js"
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
pkg.main = "./dist/index.js";
|
|
361
|
+
pkg.types = "./dist/index.d.ts";
|
|
362
|
+
writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2), "utf-8");
|
|
363
|
+
console.log(`\u2705 Updated package.json exports`);
|
|
364
|
+
} catch (error) {
|
|
365
|
+
console.warn(`\u26A0\uFE0F Failed to update package.json: ${error}`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function compileSourceFiles(srcDir, outDir) {
|
|
369
|
+
const tsFiles = findTypeScriptFiles(srcDir);
|
|
370
|
+
if (tsFiles.length === 0) {
|
|
371
|
+
console.log(` No TypeScript files found in ${srcDir}`);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
console.log(` Found ${tsFiles.length} TypeScript file(s) to compile`);
|
|
375
|
+
const compilerOptions = {
|
|
376
|
+
target: ts.ScriptTarget.ES2022,
|
|
377
|
+
module: ts.ModuleKind.ESNext,
|
|
378
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
379
|
+
outDir,
|
|
380
|
+
rootDir: srcDir,
|
|
381
|
+
// Use srcDir as root
|
|
382
|
+
declaration: true,
|
|
383
|
+
esModuleInterop: true,
|
|
384
|
+
skipLibCheck: true,
|
|
385
|
+
strict: true,
|
|
386
|
+
resolveJsonModule: true
|
|
387
|
+
};
|
|
388
|
+
const program = ts.createProgram(tsFiles, compilerOptions);
|
|
389
|
+
const emitResult = program.emit();
|
|
390
|
+
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
391
|
+
if (allDiagnostics.length > 0) {
|
|
392
|
+
allDiagnostics.forEach((diagnostic) => {
|
|
393
|
+
if (diagnostic.file) {
|
|
394
|
+
const { line, character } = ts.getLineAndCharacterOfPosition(
|
|
395
|
+
diagnostic.file,
|
|
396
|
+
diagnostic.start
|
|
397
|
+
);
|
|
398
|
+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
399
|
+
console.error(
|
|
400
|
+
` ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`
|
|
401
|
+
);
|
|
402
|
+
} else {
|
|
403
|
+
console.error(
|
|
404
|
+
` ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
if (emitResult.emitSkipped) {
|
|
409
|
+
throw new Error("TypeScript compilation failed");
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function findTypeScriptFiles(dir) {
|
|
414
|
+
const files = [];
|
|
415
|
+
function walk(currentDir) {
|
|
416
|
+
const entries = readdirSync(currentDir);
|
|
417
|
+
for (const entry of entries) {
|
|
418
|
+
const fullPath = join(currentDir, entry);
|
|
419
|
+
const stat = statSync(fullPath);
|
|
420
|
+
if (stat.isDirectory()) {
|
|
421
|
+
walk(fullPath);
|
|
422
|
+
} else if (stat.isFile() && extname(entry) === ".ts") {
|
|
423
|
+
files.push(fullPath);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
walk(dir);
|
|
428
|
+
return files;
|
|
429
|
+
}
|
|
430
|
+
function discoverProviders(imageDir) {
|
|
431
|
+
const result = {
|
|
432
|
+
blobStore: [],
|
|
433
|
+
customTools: [],
|
|
434
|
+
compaction: [],
|
|
435
|
+
plugins: [],
|
|
436
|
+
totalCount: 0
|
|
437
|
+
};
|
|
438
|
+
const categories = {
|
|
439
|
+
"blob-store": "blobStore",
|
|
440
|
+
tools: "customTools",
|
|
441
|
+
compaction: "compaction",
|
|
442
|
+
plugins: "plugins"
|
|
443
|
+
};
|
|
444
|
+
for (const [folderName, propName] of Object.entries(categories)) {
|
|
445
|
+
const categoryDir = join(imageDir, folderName);
|
|
446
|
+
if (!existsSync(categoryDir)) {
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const providerFolders = readdirSync(categoryDir).filter((entry) => {
|
|
450
|
+
const entryPath = join(categoryDir, entry);
|
|
451
|
+
const stat = statSync(entryPath);
|
|
452
|
+
if (!stat.isDirectory()) {
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
const indexPath = join(entryPath, "index.ts");
|
|
456
|
+
return existsSync(indexPath);
|
|
457
|
+
}).map((folder) => {
|
|
458
|
+
return `./${folderName}/${folder}/index.js`;
|
|
459
|
+
});
|
|
460
|
+
if (providerFolders.length > 0) {
|
|
461
|
+
result[propName].push(
|
|
462
|
+
...providerFolders
|
|
463
|
+
);
|
|
464
|
+
result.totalCount += providerFolders.length;
|
|
465
|
+
console.log(` Found ${providerFolders.length} provider(s) in ${folderName}/`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return result;
|
|
469
|
+
}
|
|
470
|
+
export {
|
|
471
|
+
bundle
|
|
472
|
+
};
|
|
473
|
+
//# sourceMappingURL=index.js.map
|