/** * @license * Copyright 2026 Qwen Team * SPDX-License-Identifier: Apache-2.0 */ import { spawnSync } from 'node:child_process'; // Release workflow jobs set this when they run explicit build/bundle steps after // npm ci. Workflows that rely on prepare-during-install should leave it unset. const skipPrepare = ['1', 'true'].includes( (process.env.QWEN_SKIP_PREPARE ?? '').toLowerCase(), ); if (skipPrepare) { // The heavy build/bundle/husky are skipped, but git-commit.ts (gitignored, // imported by e.g. cli's systemInfo) is still required to build or typecheck // the packages that import it. Generate it here so a later per-workspace // build/typecheck — such as the review tooling's — doesn't fail on the // missing module. The non-skip path generates it via `npm run build`. run('npm', ['run', 'generate']); console.log( 'Skipping prepare build/bundle/husky because QWEN_SKIP_PREPARE is set.', ); process.exit(0); } run('husky'); run('npm', ['run', 'build']); run('npm', ['run', 'bundle']); function run(command, args = []) { const result = spawnSync(command, args, { shell: process.platform === 'win32', stdio: 'inherit', }); const label = args.length ? `${command} ${args.join(' ')}` : command; if (result.error) { console.error(`prepare: ${label} failed: ${result.error.message}`); process.exit(1); } if (result.signal) { console.error(`prepare: ${label} killed by signal ${result.signal}`); process.exit(1); } if (result.status !== 0) { console.error(`prepare: ${label} exited with status ${result.status}`); process.exit(result.status ?? 1); } }