mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
feat: read CLI package metadata dynamically
This commit is contained in:
parent
994bc23147
commit
271c05ac99
3 changed files with 38 additions and 4 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import { createRequire } from 'node:module';
|
||||
|
||||
import type { KtxConnectionMetabaseSetupArgs } from './commands/connection-metabase-setup.js';
|
||||
import type { KtxConnectionNotionArgs } from './commands/connection-notion.js';
|
||||
import type { KtxAgentArgs } from './agent.js';
|
||||
|
|
@ -16,9 +18,11 @@ import { profileMark, profileSpan } from './startup-profile.js';
|
|||
|
||||
profileMark('module:cli-runtime');
|
||||
|
||||
const requirePackageJson = createRequire(import.meta.url);
|
||||
|
||||
export interface KtxCliPackageInfo {
|
||||
name: '@ktx/cli';
|
||||
version: '0.0.0-private';
|
||||
name: string;
|
||||
version: string;
|
||||
contextPackageName: '@ktx/context';
|
||||
}
|
||||
|
||||
|
|
@ -45,9 +49,24 @@ export interface KtxCliDeps {
|
|||
}
|
||||
|
||||
export function getKtxCliPackageInfo(): KtxCliPackageInfo {
|
||||
return packageInfoFromJson(requirePackageJson('../package.json'));
|
||||
}
|
||||
|
||||
export function packageInfoFromJson(packageJson: unknown): KtxCliPackageInfo {
|
||||
if (
|
||||
typeof packageJson !== 'object' ||
|
||||
packageJson === null ||
|
||||
!('name' in packageJson) ||
|
||||
!('version' in packageJson) ||
|
||||
typeof packageJson.name !== 'string' ||
|
||||
typeof packageJson.version !== 'string'
|
||||
) {
|
||||
throw new Error('Invalid KTX CLI package metadata');
|
||||
}
|
||||
|
||||
return {
|
||||
name: '@ktx/cli',
|
||||
version: '0.0.0-private',
|
||||
name: packageJson.name,
|
||||
version: packageJson.version,
|
||||
contextPackageName: '@ktx/context',
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|||
|
||||
import {
|
||||
getKtxCliPackageInfo,
|
||||
packageInfoFromJson,
|
||||
rendererUnavailableVizFallback,
|
||||
renderMemoryFlowTui,
|
||||
resolveVizFallback,
|
||||
|
|
@ -56,6 +57,19 @@ describe('getKtxCliPackageInfo', () => {
|
|||
version: '0.0.0-private',
|
||||
});
|
||||
});
|
||||
|
||||
it('normalizes public package metadata from package.json contents', () => {
|
||||
expect(
|
||||
packageInfoFromJson({
|
||||
name: '@kaelio/ktx',
|
||||
version: '0.1.0',
|
||||
}),
|
||||
).toEqual({
|
||||
name: '@kaelio/ktx',
|
||||
version: '0.1.0',
|
||||
contextPackageName: '@ktx/context',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('memory-flow renderer exports', () => {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { profileMark } from './startup-profile.js';
|
|||
|
||||
export {
|
||||
getKtxCliPackageInfo,
|
||||
packageInfoFromJson,
|
||||
runInitForCommander,
|
||||
runKtxCli,
|
||||
type KtxCliDeps,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue