mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
perf(setup): speed up conductor setup and make it rerun-safe (#107)
Drop the duplicate `pnpm run build` (artifacts:build already builds every package). Run package builds in parallel topology via one recursive pnpm invocation. Enable incremental tsc and keep the cli's tsbuildinfo outside its dist (moved the dist wipe into a separate `clean` script). Run the final `ktx status` doctor from a temp dir so it stops walking up into a parent ktx.yaml and failing the script. Conductor setup drops from ~26s to ~9.8s cold and ~4.4s warm.
This commit is contained in:
parent
b759a4a286
commit
2de4dd2c1b
7 changed files with 38 additions and 59 deletions
|
|
@ -41,12 +41,6 @@ export const NPM_ARTIFACT_PACKAGES = [{ name: PUBLIC_NPM_PACKAGE_NAME, packageRo
|
|||
|
||||
export const CLI_PYTHON_ASSET_MANIFEST = 'manifest.json';
|
||||
|
||||
const CONNECTOR_PACKAGE_NAMES = INTERNAL_NPM_WORKSPACE_PACKAGES
|
||||
.map((packageInfo) => packageInfo.name)
|
||||
.filter((packageName) => packageName.startsWith('@ktx/connector-'));
|
||||
|
||||
const NPM_ARTIFACT_BUILD_ORDER = ['@ktx/llm', '@ktx/context', ...CONNECTOR_PACKAGE_NAMES, '@ktx/cli'];
|
||||
|
||||
function scriptRootDir() {
|
||||
return resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
}
|
||||
|
|
@ -84,18 +78,19 @@ export function packageArtifactLayout(rootDir = scriptRootDir()) {
|
|||
}
|
||||
|
||||
export function buildArtifactCommands(layout) {
|
||||
const packagesByName = new Map(INTERNAL_NPM_WORKSPACE_PACKAGES.map((packageInfo) => [packageInfo.name, packageInfo]));
|
||||
const npmBuildCommands = NPM_ARTIFACT_BUILD_ORDER.map((packageName) => {
|
||||
const packageInfo = packagesByName.get(packageName);
|
||||
if (!packageInfo) {
|
||||
throw new Error(`Unknown npm artifact build package: ${packageName}`);
|
||||
}
|
||||
return {
|
||||
command: 'pnpm',
|
||||
args: ['--filter', packageInfo.name, 'run', 'build'],
|
||||
cwd: layout.rootDir,
|
||||
};
|
||||
});
|
||||
// One recursive pnpm invocation; topology comes from workspace deps in
|
||||
// each package.json, parallelism from --workspace-concurrency.
|
||||
const npmBuildCommand = {
|
||||
command: 'pnpm',
|
||||
args: [
|
||||
'--filter',
|
||||
'./packages/*',
|
||||
'--workspace-concurrency=10',
|
||||
'run',
|
||||
'build',
|
||||
],
|
||||
cwd: layout.rootDir,
|
||||
};
|
||||
const publicPackageCommand = {
|
||||
command: process.execPath,
|
||||
args: ['scripts/build-public-npm-package.mjs'],
|
||||
|
|
@ -103,7 +98,7 @@ export function buildArtifactCommands(layout) {
|
|||
};
|
||||
|
||||
return [
|
||||
...npmBuildCommands,
|
||||
npmBuildCommand,
|
||||
{
|
||||
command: process.execPath,
|
||||
args: ['scripts/build-python-runtime-wheel.mjs'],
|
||||
|
|
@ -929,21 +924,13 @@ async function buildArtifacts(layout) {
|
|||
await mkdir(layout.npmDir, { recursive: true });
|
||||
await mkdir(layout.pythonDir, { recursive: true });
|
||||
|
||||
const commands = buildArtifactCommands(layout);
|
||||
const npmBuildCount = NPM_ARTIFACT_BUILD_ORDER.length;
|
||||
const npmPackStart = commands.length - 1;
|
||||
const [npmBuildCommand, wheelCommand, publicPackageCommand] = buildArtifactCommands(layout);
|
||||
|
||||
for (const command of commands.slice(0, npmBuildCount)) {
|
||||
await runCommand(command.command, command.args, { cwd: command.cwd });
|
||||
}
|
||||
for (const command of commands.slice(npmBuildCount, npmPackStart)) {
|
||||
await runCommand(command.command, command.args, { cwd: command.cwd });
|
||||
}
|
||||
await runCommand(npmBuildCommand.command, npmBuildCommand.args, { cwd: npmBuildCommand.cwd });
|
||||
await runCommand(wheelCommand.command, wheelCommand.args, { cwd: wheelCommand.cwd });
|
||||
const pythonArtifacts = await findPythonArtifacts(layout.pythonDir);
|
||||
await copyRuntimeWheelAssets(layout, pythonArtifacts);
|
||||
for (const command of commands.slice(npmPackStart)) {
|
||||
await runCommand(command.command, command.args, { cwd: command.cwd });
|
||||
}
|
||||
await runCommand(publicPackageCommand.command, publicPackageCommand.args, { cwd: publicPackageCommand.cwd });
|
||||
|
||||
for (const packageInfo of NPM_ARTIFACT_PACKAGES) {
|
||||
await assertPathExists(layout.npmTarballs[packageInfo.name], `${packageInfo.name} tarball`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue