mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
build: stamp public npm package version
This commit is contained in:
parent
64f7349c43
commit
34f5a544e3
5 changed files with 39 additions and 28 deletions
|
|
@ -9,8 +9,11 @@ import { promisify } from 'node:util';
|
|||
const execFileAsync = promisify(execFile);
|
||||
|
||||
export const PUBLIC_NPM_PACKAGE_NAME = '@kaelio/ktx';
|
||||
export const PUBLIC_NPM_PACKAGE_VERSION = '0.0.0-private';
|
||||
export const PUBLIC_NPM_PACKAGE_TARBALL = 'kaelio-ktx-0.0.0-private.tgz';
|
||||
export const PUBLIC_NPM_PACKAGE_VERSION = '0.1.0';
|
||||
|
||||
export function publicNpmPackageTarballName(version = PUBLIC_NPM_PACKAGE_VERSION) {
|
||||
return `kaelio-ktx-${version}.tgz`;
|
||||
}
|
||||
|
||||
export const PUBLIC_BUNDLED_WORKSPACE_PACKAGES = [
|
||||
'@ktx/llm',
|
||||
|
|
@ -42,13 +45,14 @@ function scriptRootDir() {
|
|||
return resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
}
|
||||
|
||||
export function publicNpmPackageLayout(rootDir = scriptRootDir()) {
|
||||
export function publicNpmPackageLayout(rootDir = scriptRootDir(), version = PUBLIC_NPM_PACKAGE_VERSION) {
|
||||
return {
|
||||
rootDir,
|
||||
packageVersion: version,
|
||||
cliPackageRoot: join(rootDir, 'packages', 'cli'),
|
||||
packRoot: join(rootDir, 'dist', 'public-npm-package'),
|
||||
npmDir: join(rootDir, 'dist', 'artifacts', 'npm'),
|
||||
tarballPath: join(rootDir, 'dist', 'artifacts', 'npm', PUBLIC_NPM_PACKAGE_TARBALL),
|
||||
tarballPath: join(rootDir, 'dist', 'artifacts', 'npm', publicNpmPackageTarballName(version)),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -114,10 +118,10 @@ export function collectPublicDependencies(packageJsons) {
|
|||
return sortedObject(dependencies);
|
||||
}
|
||||
|
||||
export function publicNpmPackageJson(cliPackageJson, dependencies) {
|
||||
export function publicNpmPackageJson(cliPackageJson, dependencies, version = PUBLIC_NPM_PACKAGE_VERSION) {
|
||||
return {
|
||||
name: PUBLIC_NPM_PACKAGE_NAME,
|
||||
version: cliPackageJson.version ?? PUBLIC_NPM_PACKAGE_VERSION,
|
||||
version,
|
||||
description: 'Standalone KTX context layer for database agents',
|
||||
private: false,
|
||||
type: 'module',
|
||||
|
|
@ -178,7 +182,10 @@ async function copyPackageFileEntries(sourceRoot, targetRoot, packageJson) {
|
|||
|
||||
async function copyCliPackage(layout, cliPackageJson, dependencies) {
|
||||
await copyPackageFileEntries(layout.cliPackageRoot, layout.packRoot, cliPackageJson);
|
||||
await writeJson(join(layout.packRoot, 'package.json'), publicNpmPackageJson(cliPackageJson, dependencies));
|
||||
await writeJson(
|
||||
join(layout.packRoot, 'package.json'),
|
||||
publicNpmPackageJson(cliPackageJson, dependencies, layout.packageVersion),
|
||||
);
|
||||
}
|
||||
|
||||
async function copyBundledWorkspacePackage(rootDir, packageName, packageJson) {
|
||||
|
|
@ -219,7 +226,7 @@ export async function createPublicNpmPackageTree(layout = publicNpmPackageLayout
|
|||
|
||||
return {
|
||||
layout,
|
||||
packageJson: publicNpmPackageJson(cliPackageJson, dependencies),
|
||||
packageJson: publicNpmPackageJson(cliPackageJson, dependencies, layout.packageVersion),
|
||||
bundledPackages: PUBLIC_BUNDLED_WORKSPACE_PACKAGES,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@ import { describe, it } from 'node:test';
|
|||
import {
|
||||
PUBLIC_BUNDLED_WORKSPACE_PACKAGES,
|
||||
PUBLIC_NPM_PACKAGE_NAME,
|
||||
PUBLIC_NPM_PACKAGE_VERSION,
|
||||
collectPublicDependencies,
|
||||
createPublicNpmPackageTree,
|
||||
publicNpmPackageJson,
|
||||
publicNpmPackageLayout,
|
||||
publicNpmPackageTarballName,
|
||||
publicNpmPackCommand,
|
||||
} from './build-public-npm-package.mjs';
|
||||
|
||||
|
|
@ -137,13 +139,12 @@ async function writeWorkspaceFixture(root) {
|
|||
}
|
||||
|
||||
describe('publicNpmPackageLayout', () => {
|
||||
it('uses stable public package build and tarball paths', () => {
|
||||
it('uses the first public npm release version for the tarball name', () => {
|
||||
const layout = publicNpmPackageLayout('/repo/ktx');
|
||||
|
||||
assert.equal(layout.rootDir, '/repo/ktx');
|
||||
assert.equal(layout.packRoot, '/repo/ktx/dist/public-npm-package');
|
||||
assert.equal(layout.npmDir, '/repo/ktx/dist/artifacts/npm');
|
||||
assert.equal(layout.tarballPath, '/repo/ktx/dist/artifacts/npm/kaelio-ktx-0.0.0-private.tgz');
|
||||
assert.equal(PUBLIC_NPM_PACKAGE_VERSION, '0.1.0');
|
||||
assert.equal(publicNpmPackageTarballName(), 'kaelio-ktx-0.1.0.tgz');
|
||||
assert.equal(layout.tarballPath, '/repo/ktx/dist/artifacts/npm/kaelio-ktx-0.1.0.tgz');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -206,6 +207,7 @@ describe('publicNpmPackageJson', () => {
|
|||
);
|
||||
|
||||
assert.equal(packageJson.name, PUBLIC_NPM_PACKAGE_NAME);
|
||||
assert.equal(packageJson.version, '0.1.0');
|
||||
assert.equal(packageJson.private, false);
|
||||
assert.deepEqual(packageJson.bin, { ktx: './dist/bin.js' });
|
||||
assert.deepEqual(packageJson.dependencies, { commander: '14.0.3' });
|
||||
|
|
@ -261,7 +263,7 @@ describe('publicNpmPackCommand', () => {
|
|||
'--config.node-linker=hoisted',
|
||||
'pack',
|
||||
'--out',
|
||||
'/repo/ktx/dist/artifacts/npm/kaelio-ktx-0.0.0-private.tgz',
|
||||
'/repo/ktx/dist/artifacts/npm/kaelio-ktx-0.1.0.tgz',
|
||||
],
|
||||
cwd: '/repo/ktx/dist/public-npm-package',
|
||||
});
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ describe('localEmbeddingsSmokeOptIn', () => {
|
|||
describe('publicKtxTarballName', () => {
|
||||
it('selects the public @kaelio/ktx tarball name', () => {
|
||||
assert.equal(
|
||||
publicKtxTarballName(['kaelio-ktx-0.0.0-private.tgz', 'ignore-me.tgz']),
|
||||
'kaelio-ktx-0.0.0-private.tgz',
|
||||
publicKtxTarballName(['kaelio-ktx-0.1.0.tgz', 'ignore-me.tgz']),
|
||||
'kaelio-ktx-0.1.0.tgz',
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ import {
|
|||
} from './build-python-runtime-wheel.mjs';
|
||||
import {
|
||||
PUBLIC_NPM_PACKAGE_NAME,
|
||||
PUBLIC_NPM_PACKAGE_TARBALL,
|
||||
PUBLIC_NPM_PACKAGE_VERSION,
|
||||
publicNpmPackageTarballName,
|
||||
} from './build-public-npm-package.mjs';
|
||||
|
||||
const PACKAGE_VERSION = '0.0.0-private';
|
||||
|
|
@ -69,7 +70,7 @@ function scriptRootDir() {
|
|||
|
||||
function npmPackageTarballName(packageName) {
|
||||
if (packageName === PUBLIC_NPM_PACKAGE_NAME) {
|
||||
return PUBLIC_NPM_PACKAGE_TARBALL;
|
||||
return publicNpmPackageTarballName(PUBLIC_NPM_PACKAGE_VERSION);
|
||||
}
|
||||
return `${packageName.replace('@ktx/', 'ktx-')}-${PACKAGE_VERSION}.tgz`;
|
||||
}
|
||||
|
|
@ -254,12 +255,13 @@ async function readNpmPackageMetadata(rootDir, packageInfo) {
|
|||
`Unexpected package name in ${packageInfo.packageRoot}/package.json: expected ${expectedSourceName}, got ${packageJson.name}`,
|
||||
);
|
||||
}
|
||||
const isPublicKtxPackage = packageInfo.name === PUBLIC_NPM_PACKAGE_NAME;
|
||||
return releaseMetadataEntry({
|
||||
ecosystem: 'npm',
|
||||
packageName: packageInfo.name,
|
||||
packageRoot: packageInfo.packageRoot,
|
||||
packageVersion: packageJson.version,
|
||||
privatePackage: packageInfo.name === PUBLIC_NPM_PACKAGE_NAME ? false : packageJson.private === true,
|
||||
packageVersion: isPublicKtxPackage ? PUBLIC_NPM_PACKAGE_VERSION : packageJson.version,
|
||||
privatePackage: isPublicKtxPackage ? false : packageJson.private === true,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -692,7 +694,7 @@ try {
|
|||
|
||||
const version = await run('pnpm', ['exec', 'ktx', '--version']);
|
||||
requireSuccess('ktx public package version', version);
|
||||
requireOutput('ktx public package version', version, /@kaelio\\/ktx 0\\.0\\.0-private/);
|
||||
requireOutput('ktx public package version', version, /@kaelio\\/ktx 0\\.1\\.0/);
|
||||
|
||||
const runtimeStatusBefore = parseJsonResult(
|
||||
'ktx runtime status missing',
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ describe('packageArtifactLayout', () => {
|
|||
assert.equal(layout.artifactDir, '/repo/ktx/dist/artifacts');
|
||||
assert.equal(layout.npmDir, '/repo/ktx/dist/artifacts/npm');
|
||||
assert.equal(layout.pythonDir, '/repo/ktx/dist/artifacts/python');
|
||||
assert.equal(layout.cliTarball, '/repo/ktx/dist/artifacts/npm/kaelio-ktx-0.0.0-private.tgz');
|
||||
assert.equal(layout.cliTarball, '/repo/ktx/dist/artifacts/npm/kaelio-ktx-0.1.0.tgz');
|
||||
assert.deepEqual(Object.keys(layout.npmTarballs), ['@kaelio/ktx']);
|
||||
});
|
||||
});
|
||||
|
|
@ -136,7 +136,7 @@ describe('packageReleaseMetadata', () => {
|
|||
ecosystem: 'npm',
|
||||
packageName: '@kaelio/ktx',
|
||||
packageRoot: 'packages/cli',
|
||||
packageVersion: '0.0.0-private',
|
||||
packageVersion: '0.1.0',
|
||||
private: false,
|
||||
releaseMode: 'ci-artifact-only',
|
||||
},
|
||||
|
|
@ -226,7 +226,7 @@ describe('artifact manifest', () => {
|
|||
ecosystem: 'npm',
|
||||
packageName: '@kaelio/ktx',
|
||||
packageRoot: 'packages/cli',
|
||||
packageVersion: '0.0.0-private',
|
||||
packageVersion: '0.1.0',
|
||||
private: false,
|
||||
releaseMode: 'ci-artifact-only',
|
||||
},
|
||||
|
|
@ -277,8 +277,8 @@ describe('artifact manifest', () => {
|
|||
artifactKind: 'tarball',
|
||||
ecosystem: 'npm',
|
||||
packageName: '@kaelio/ktx',
|
||||
packageVersion: '0.0.0-private',
|
||||
path: 'npm/kaelio-ktx-0.0.0-private.tgz',
|
||||
packageVersion: '0.1.0',
|
||||
path: 'npm/kaelio-ktx-0.1.0.tgz',
|
||||
},
|
||||
],
|
||||
);
|
||||
|
|
@ -331,7 +331,7 @@ describe('artifact manifest', () => {
|
|||
],
|
||||
);
|
||||
|
||||
const npmEntry = manifest.files.find((file) => file.path === 'npm/kaelio-ktx-0.0.0-private.tgz');
|
||||
const npmEntry = manifest.files.find((file) => file.path === 'npm/kaelio-ktx-0.1.0.tgz');
|
||||
assert.ok(npmEntry);
|
||||
assert.equal(npmEntry.bytes, Buffer.byteLength('@kaelio/ktx-tarball'));
|
||||
assert.equal(npmEntry.sha256, createHash('sha256').update('@kaelio/ktx-tarball').digest('hex'));
|
||||
|
|
@ -547,7 +547,7 @@ describe('verification snippets', () => {
|
|||
const source = npmRuntimeSmokeSource();
|
||||
|
||||
assert.match(source, /ktx public package version/);
|
||||
assert.match(source, /@kaelio\\\/ktx 0\\\.0\\\.0-private/);
|
||||
assert.match(source, /@kaelio\\\/ktx 0\\\.1\\\.0/);
|
||||
assert.match(source, /'ktx', 'sl', 'query'/);
|
||||
assert.doesNotMatch(source, /@ktx\/context/);
|
||||
assert.doesNotMatch(source, /@modelcontextprotocol/);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue