mirror of
https://github.com/lobehub/lobehub.git
synced 2026-09-20 04:56:13 +08:00
9dfe9242ec
The desktop app builds `apps/cli` from the workspace it installs at `apps/desktop`. pnpm 12 writes those out-of-root member links with two extra `../` segments, so `apps/cli/node_modules/@lobechat/device-control` and `@lobechat/device-identity` dangle. Rolldown only warns, marks both imports external and reports a successful build, so canary 2.2.17-canary.18 onwards shipped a `lobe-cli.js` that dies at startup with `ERR_MODULE_NOT_FOUND: @lobechat/device-control`, even for `--version`. Repair the dangling links before bundling, and turn an unresolved import into a build failure so a broken bundle can never ship silently again. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
import config from './tsdown.config';
|
|
|
|
const resolveInputOptions = async () => {
|
|
const { inputOptions } = config as {
|
|
inputOptions: (options: Record<string, any>, ...rest: any[]) => Promise<any> | any;
|
|
};
|
|
|
|
const options: Record<string, any> = {};
|
|
await inputOptions(options, 'esm', { cjsDts: false });
|
|
|
|
return options;
|
|
};
|
|
|
|
describe('CLI build configuration', () => {
|
|
it('bundles ws so the desktop-embedded CLI runs without node_modules', () => {
|
|
expect(config).toEqual(
|
|
expect.objectContaining({
|
|
deps: expect.objectContaining({ alwaysBundle: expect.arrayContaining(['ws']) }),
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('fails the build instead of externalizing an unresolved import', async () => {
|
|
const { onLog } = await resolveInputOptions();
|
|
|
|
expect(() =>
|
|
onLog(
|
|
'warn',
|
|
{
|
|
code: 'UNRESOLVED_IMPORT',
|
|
message: `Could not resolve '@lobechat/device-control' in src/commands/connect.ts`,
|
|
},
|
|
vi.fn(),
|
|
),
|
|
).toThrow('@lobechat/device-control');
|
|
});
|
|
|
|
it('forwards every other log to the default handler', async () => {
|
|
const { onLog } = await resolveInputOptions();
|
|
const defaultHandler = vi.fn();
|
|
const log = { code: 'INEFFECTIVE_DYNAMIC_IMPORT', message: 'dynamic import will not move' };
|
|
|
|
onLog('warn', log, defaultHandler);
|
|
|
|
expect(defaultHandler).toHaveBeenCalledWith('warn', log);
|
|
});
|
|
});
|