feat(cli): refactor embedded assets with Bun-specific and stub implementations

Split embedded assets loading into runtime-specific variants using package.json imports field. Bun-compiled binaries use the full implementation with file assets, while stub fallback provides clear error for non-Bun runtimes.
This commit is contained in:
weishu
2025-12-20 23:46:02 +08:00
parent be655f9fcf
commit cf04937355
6 changed files with 21 additions and 4 deletions
+2
View File
@@ -2,3 +2,5 @@
process.env.DEV = 'false';
await import('./index');
export {};
+2 -2
View File
@@ -3,7 +3,7 @@ import { dirname, join } from 'node:path';
import { arch, platform } from 'node:os';
import * as tar from 'tar';
import packageJson from '../../package.json';
import type { EmbeddedAsset } from './embeddedAssets';
import type { EmbeddedAsset } from '#embedded-assets';
import { isBunCompiled, runtimePath } from '@/projectPath';
const RUNTIME_MARKER = '.runtime-version';
@@ -131,7 +131,7 @@ export async function ensureRuntimeAssets(): Promise<void> {
return;
}
const { loadEmbeddedAssets } = await import('./embeddedAssets');
const { loadEmbeddedAssets } = await import('#embedded-assets');
const runtimeRoot = runtimePath();
const markerPath = join(runtimeRoot, RUNTIME_MARKER);
if (existsSync(markerPath)) {
@@ -10,7 +10,6 @@ import ripgrepArchiveLicense from '../../tools/archives/ripgrep-LICENSE' assert
import difftasticLicense from '../../tools/licenses/difftastic-LICENSE' assert { type: 'file' };
import ripgrepLicense from '../../tools/licenses/ripgrep-LICENSE' assert { type: 'file' };
export interface EmbeddedAsset {
relativePath: string;
sourcePath: string;
+8
View File
@@ -0,0 +1,8 @@
export interface EmbeddedAsset {
relativePath: string;
sourcePath: string;
}
export async function loadEmbeddedAssets(): Promise<EmbeddedAsset[]> {
throw new Error('Embedded assets are only available in Bun-compiled binaries.');
}
+2
View File
@@ -8,4 +8,6 @@ declare module 'bun:bundle' {
| 'HAPI_TARGET_WIN32_X64'
| 'HAPI_TARGET_WIN32_ARM64';
}
export function feature(name: Registry['features']): boolean;
}