qwen-code/scripts/build-standalone-release.js
易良 64dd058c9c
ci(pnpm): install with pnpm everywhere and retire package-lock.json (#11859)
* ci(pnpm): install dependencies with pnpm in CI and release

CI tests the graph release ships only if both install it the same way, so
this moves both, keeping every `npm run` script and `npm publish` as they are.

- ci.yml (7), release.yml (3) and release-vscode-companion.yml (2) install
  with `corepack pnpm install --frozen-lockfile`; release keeps
  --ignore-scripts plus its explicit postinstall and generate steps.
- setup-node drops the npm cache and sets package-manager-cache: false,
  which setup-node v5+ needs once package.json declares a pnpm
  packageManager.
- A composite action caches the pnpm store on the three always-hosted jobs;
  the ECS pool keeps its store on local disk.
- version.js no longer lets npm reify node_modules: --no-workspaces-update on
  both `npm version` calls, and a package-lock-only refresh in step 9.
- The notices generator, prepare-package's sharp pin and the standalone
  release's native package specs read the installed tree or pnpm-lock.yaml
  instead of package-lock.json keys.
- New size baselines for the three workflows, which were already over them.

* chore(vscode): regenerate NOTICES from the pnpm-installed tree

Generated in CI (pnpm Worktree Smoke on ubuntu-latest) by the ported
generator. Same entry set as before except the five packages npm and pnpm
resolve differently: fdir 6.5.0, picomatch 4.0.5, mdurl 2.1.0,
@types/node 22.20.1 and mime-db 1.52.0 (form-data's pinned copy). No entry
lacks a license text or repository.

* fix(pnpm): resolve undeclared zod peers to the repo's zod, as npm does

The first CI run on this branch failed the export renderer's size budget:
1,930,015 bytes against 1,930,000, where the same commit built on npm's
tree comes to 1,858,186. Comparing both trees' esbuild metafiles and
prebuilt bundles put the whole difference in web-shell's transcript.js
(+100,903 bytes pre-minify), and the added code is zod 4 plus the
@modelcontextprotocol/ext-apps schemas; the sdk daemon bundle is identical.

web-shell bundles ext-apps, whose zod and MCP SDK are peers, and declares
no zod itself, so pnpm filled the peer with the highest locked zod (4.4.3)
while npm serves the hoisted 3.25.76. Declaring zod 3.25.76 as a root
devDependency makes pnpm resolve every such peer to it
(resolve-peers-from-workspace-root is on by default), which is npm's
hoisting behaviour. mobile-mcp keeps its own zod 4.4.3, as under npm; the
npm tree does not change.

* fix(pnpm): keep npm's root @types/node so root-level typechecks match

The no-AK integration gate typechecks integration-tests/, which takes
Node's types from the root node_modules. npm hoists @types/node 20.19.1
there, because acp-bridge and core pin it; pnpm, with no root declaration,
hoisted 22.20.1, whose spawnSync overloads type process-registry.ts's
stdout as string | NonSharedBuffer and fail TS2322. The same code passes on
every npm-installed PR.

Declaring 20.19.1 as a root devDependency puts npm's copy back where a
root-level tsconfig looks. The npm tree does not change.

* ci(pnpm): install with pnpm in the remaining workflows

The follow-up to switching CI and release: every other workflow that
installs the root workspace now uses the pinned pnpm with
--frozen-lockfile, so no job tests a graph that release does not ship.

- e2e, tui-parity, repo-hygiene, web-shell-visuals, serve-ab, sdk-java,
  windows-runner-smoke, qwen-autofix, the SDK releases, finalize-release,
  sync-release-to-oss, the root install in desktop-release and
  cd-cua-driver, and the sandbox Dockerfile.
- setup-node drops the root npm cache (package-manager-cache: false); hosted
  jobs restore the pnpm store through the shared composite action, and
  qwen-autofix keeps af-012's rule that the persistent pool restores no
  remote cache.
- serve-ab and web-shell-visuals install a separate base checkout that can
  predate pnpm-lock.yaml, so those installs fall back to npm ci there.
- Out of scope, unchanged: packages with their own lockfile (cua-driver's
  TypeScript SDK, desktop-shell, live-host, mobile-mcp), and the triage
  lanes with npm-cache.yml and the npm audit gate, which move with the
  package-lock.json retirement.
- New size baselines for the touched workflows; qwen-autofix stays under
  the 470000-byte gate.

* fix(pnpm): link the workspace packages that root-level code imports

npm links every workspace package into the root node_modules, so
integration-tests/ and scripts/, which are not workspace packages
themselves, can import @qwen-code/* by name. pnpm links a workspace
package only where it is a declared dependency, and the root declared
none, so the no-AK integration gate could not find
@qwen-code/qwen-code-core.

The root now declares the seven packages that root-level code imports at
runtime as file: devDependencies: acp-bridge, channel-base, the CLI,
core, sdk, web-shell and web-templates. npm already links them, so its
tree does not change (letting npm re-resolve the lock reproduces the
same root entry); .pnpmfile.mjs rewrites them to workspace:*, which pnpm
links at the root.

* ci(pnpm): move triage, the store producer and the root audit to pnpm

- qwen-triage's verify and tmux-testing lanes install the PR with
  `corepack pnpm install --frozen-lockfile` from a restored pnpm store.
  The one retry clears node_modules first, because pnpm install, unlike
  npm ci, keeps it.
- npm-cache.yml becomes pnpm-store.yml, keyed on pnpm-lock.yaml.
- security-checks audits the root workspace with `pnpm audit`, which reads
  the lockfile, so the root install step goes. The vendored lockfiles keep
  npm, and the retry recognises pnpm's endpoint error too.
- qwen-autofix drops the hosted-only store cache: its heavy jobs forbid
  local `uses: './...'` actions, and the file sits at the size gate.
- cd-cua-driver: setup-node@v4 has no package-manager-cache input.
- package-assets fixtures install sharp rather than listing it in
  package-lock.json, matching how prepare-package now resolves it.
- AGENTS.md, CONTRIBUTING.md and the npm workspace guide install with pnpm.

* feat(review): install pnpm repos in qwen review's build/test

qwen review installed dependencies only for a repo with package-lock.json
and reported a pnpm repo as unsupported, so reviews of qwen-code would
lose their build and test once its npm lockfile goes.

- lockfileInstaller() picks npm or pnpm from the committed lockfile. With
  both, `packageManager: pnpm@...` chooses pnpm; anything else keeps npm.
- A pnpm repo installs with `corepack pnpm install --frozen-lockfile`
  through the same disk, budget and sandbox path as `npm ci`, and counts
  as installed once node_modules/.modules.yaml exists.
- Scripts still run through `npm run`, and the npm path is unchanged.

* ci(pnpm): retire the root package-lock.json

pnpm-lock.yaml is now the only root lockfile.

- check-lockfile keeps the pnpm integrity check and Playwright parity,
  which now reads pnpm importers and snapshots. The npm-vs-pnpm agreement
  and build-approval checks go: pnpm 11's strictDepBuilds and every CI
  install's --frozen-lockfile enforce what they covered.
- pnpm-lock-freshness.yml goes; it regenerated pnpm-lock.yaml from
  package-lock.json.
- Release: version.js drops its package-lock refresh, the release commit
  stages pnpm-lock.yaml and the SDK release stages no lockfile, so neither
  `git add` fails on the missing file. `npm version` in the SDK and
  mobile-mcp releases passes --no-workspaces-update so it cannot reinstall
  the root with npm.
- cd-mobile-mcp installs from the root pnpm lockfile. setup-node in
  cd-mobile-mcp, qwen-code-pr-review and desktop-release no longer keys an
  npm cache on the root lockfile.
- check-desktop-isolation reads pnpm importers; build.js, build_sandbox.js
  and preflight install with pnpm.
- pnpm-lock.yaml, pnpm-workspace.yaml and .pnpmfile.mjs join the autofix
  supply-chain class and repo-hygiene's deny list; pnpm-lock.yaml joins
  autofix's generated-diff exclusions, sdk-java's path filter and the
  platform-sensitivity manifests.
- .gitignore lists /package-lock.json so an npm install cannot commit it
  back. Tests and docs follow.

* fix(standalone): read the node-pty versions from the pnpm lockfile

* chore(vscode-ide-companion): regenerate NOTICES.txt after the lockfile swap

* chore(vscode-ide-companion): regenerate NOTICES.txt from the pnpm dependency tree

The committed NOTICES.txt was generated from an npm install and does not
match the tree produced by the pnpm install the release pipeline now uses
(659 resolved dependencies, differing @types/node and mime-db versions).
Regenerating with the pinned pnpm install makes the freshness check
reproducible.

* fix(ci): drop the npm cache from the daily dependency audit

actions/setup-node's npm cache keys off the root package-lock.json, which this branch retires, so the scheduled job would fail at Set up Node before the audit ran. No pull_request run reaches this workflow to catch it. The root tree is never installed here either: pnpm audit reads pnpm-lock.yaml directly.

Matches the sibling workflows that already set package-manager-cache: false; scripts/tests/security-workflows.test.js now pins it.

* chore(ci): stop banking main-side drift in the workflow size ratchet

The ratchet exists to turn a workflow's growth into one reviewed line. This branch re-recorded entries for 17 workflows it never touches, several upward by 0.4-2.8 KB - drift that happened on main, banked into the manifest without review.

Restore those to their merge-base values, so .size-baseline changes only for the 22 workflows this branch actually edits. The entries were not needed to go green: ci.yml passes the PR's base commit, so a file that drifted on main and is otherwise untouched earns a warning, not a failure.

* fix(release): initialize standalone state before main

* test(browser-use): read Playwright pin from pnpm lock

* fix(ci): address pnpm migration review blockers

* fix(desktop): stop reading the retired root lockfile

---------

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-09-20 02:11:25 +00:00

564 lines
17 KiB
JavaScript

#!/usr/bin/env node
/**
* @license
* Copyright 2025 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/
import { execFileSync } from 'node:child_process';
import crypto from 'node:crypto';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';
import { fileURLToPath } from 'node:url';
import { parse as parseYaml } from 'yaml';
import {
TARGET_CLIPBOARD_PACKAGE,
standaloneArchiveName,
writeSha256Sums,
} from './create-standalone-package.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = path.resolve(__dirname, '..');
const RELEASE_TARGETS = [
{
qwenTarget: 'darwin-arm64',
nodeTarget: 'darwin-arm64',
nodeArchiveExtension: 'tar.gz',
bunAsset: 'bun-darwin-aarch64',
},
{
qwenTarget: 'darwin-x64',
nodeTarget: 'darwin-x64',
nodeArchiveExtension: 'tar.gz',
bunAsset: 'bun-darwin-x64',
},
{
qwenTarget: 'linux-arm64',
nodeTarget: 'linux-arm64',
nodeArchiveExtension: 'tar.xz',
bunAsset: 'bun-linux-aarch64',
},
{
qwenTarget: 'linux-x64',
nodeTarget: 'linux-x64',
nodeArchiveExtension: 'tar.xz',
bunAsset: 'bun-linux-x64',
},
{
qwenTarget: 'win-x64',
nodeTarget: 'win-x64',
nodeArchiveExtension: 'zip',
bunAsset: 'bun-windows-x64',
},
];
// Classic Node.js packaging stays the default. --runtime=bun opts into the
// temporary OpenTUI preview (the renderer needs bun:ffi; Node without FFI
// falls back to ink). --include-opentui-preview adds the bun flavor's
// archives (suffixed -opentui-preview) to the same release directory.
const DEFAULT_RUNTIME = 'node';
const DEFAULT_BUN_VERSION = '1.3.14';
const BUN_RELEASE_BASE_URL = 'https://github.com/oven-sh/bun/releases/download';
// Temporary OpenTUI preview: the bundled OpenTUI backend resolves its native
// render library at runtime via `import('@opentui/core-<platform>-<arch>')`,
// so each standalone archive must ship the matching platform package(s).
// Stage every platform variant (like the clipboard addons) because release
// packaging cross-builds all targets from a single host. Linux is glibc-only
// on purpose: RELEASE_TARGETS bundles glibc-linked Bun binaries that cannot
// start on musl hosts, so the -musl render packages would be dead weight
// claiming support the archive cannot deliver.
const OPENTUI_PLATFORM_PACKAGES = [
'@opentui/core-darwin-arm64',
'@opentui/core-darwin-x64',
'@opentui/core-linux-arm64',
'@opentui/core-linux-x64',
'@opentui/core-win32-arm64',
'@opentui/core-win32-x64',
];
async function main() {
const args = parseArgs(process.argv.slice(2));
if (args.help) {
printUsage();
return;
}
const runtime = args.runtime || DEFAULT_RUNTIME;
if (runtime !== 'node' && runtime !== 'bun') {
fail('--runtime must be either "node" or "bun"');
}
// The bun flavor is additive: with --include-opentui-preview the release
// directory carries both the classic Node.js archives and the bun/OpenTUI
// preview archives; every downstream check derives its expected set from
// this list.
const flavors =
args.includeOpentuiPreview && runtime !== 'bun'
? ['node', 'bun']
: [runtime];
const nodeVersion = args.nodeVersion || process.versions.node;
const bunVersion = args.bunVersion || DEFAULT_BUN_VERSION;
const outDir = path.resolve(
args.outDir || path.join(rootDir, 'dist', 'standalone'),
);
const runtimeParent = path.resolve(
args.runtimeDir || process.env.RUNNER_TEMP || os.tmpdir(),
);
fs.mkdirSync(runtimeParent, { recursive: true });
const runtimeDir = fs.mkdtempSync(
path.join(runtimeParent, `qwen-${runtime}-runtime-`),
);
const nodeDistUrl = `https://nodejs.org/dist/v${nodeVersion}`;
const bunDistUrl = `${BUN_RELEASE_BASE_URL}/bun-v${bunVersion}`;
try {
fs.mkdirSync(outDir, { recursive: true });
// Each flavor verifies its runtime archive against its own publisher's
// checksum list (Node.js SHASUMS256.txt vs Bun's), so fetch one per flavor.
const checksums = {};
for (const flavor of flavors) {
const checksumsPath = path.join(runtimeDir, `${flavor}-SHASUMS256.txt`);
await downloadFile(
`${flavor === 'bun' ? bunDistUrl : nodeDistUrl}/SHASUMS256.txt`,
checksumsPath,
);
checksums[flavor] = parseChecksums(
fs.readFileSync(checksumsPath, 'utf8'),
);
}
const nativeModulesDir = stageNativeModules(runtimeDir);
// Only the bun runtime consumes the staged OpenTUI packages; the classic
// Node packaging must not install them (nor fail on a missing lockfile
// entry) at all.
const opentuiModulesDir = flavors.includes('bun')
? stageOpenTuiPackages(runtimeDir)
: undefined;
for (const flavor of flavors) {
for (const target of RELEASE_TARGETS) {
await packageTarget({
...target,
runtime: flavor,
bunDistUrl,
nodeDistUrl,
nodeVersion,
outDir,
releaseVersion: args.version,
runtimeDir,
checksums: checksums[flavor],
nativeModulesDir,
opentuiModulesDir,
});
}
}
await writeSha256Sums(outDir);
assertStandaloneOutput(outDir, flavors);
} finally {
fs.rmSync(runtimeDir, { recursive: true, force: true });
}
}
function isMainModule() {
return process.argv[1] && path.resolve(process.argv[1]) === __filename;
}
async function packageTarget({
qwenTarget,
nodeTarget,
nodeArchiveExtension,
bunAsset,
runtime,
bunDistUrl,
nodeDistUrl,
nodeVersion,
outDir,
releaseVersion,
runtimeDir,
checksums,
nativeModulesDir,
opentuiModulesDir,
}) {
let archiveName;
let archiveUrlBase;
if (runtime === 'bun') {
archiveName = `${bunAsset}.zip`;
archiveUrlBase = bunDistUrl;
} else {
archiveName = `node-v${nodeVersion}-${nodeTarget}.${nodeArchiveExtension}`;
archiveUrlBase = nodeDistUrl;
}
const archivePath = path.join(runtimeDir, archiveName);
await downloadFile(`${archiveUrlBase}/${archiveName}`, archivePath);
await verifyNodeArchive(
archivePath,
archiveName,
checksums,
runtime === 'bun' ? 'Bun' : 'Node.js',
);
const args = [
'scripts/create-standalone-package.js',
'--target',
qwenTarget,
'--node-archive',
archivePath,
'--native-modules-dir',
nativeModulesDir,
'--out-dir',
outDir,
'--skip-checksums',
];
if (runtime === 'bun') {
args.push('--runtime', 'bun');
args.push('--opentui-modules-dir', opentuiModulesDir);
}
if (releaseVersion) {
args.push('--version', releaseVersion);
}
execFileSync(process.execPath, args, {
cwd: rootDir,
stdio: 'inherit',
});
}
// The release installs from pnpm-lock.yaml, so that is where every target's
// native package version comes from. Only the build host's own platform
// package is installed, so the installed tree cannot answer for the others.
let pnpmLockedKeys;
function readPnpmLockedVersion(packageName) {
pnpmLockedKeys ??= Object.keys(
parseYaml(fs.readFileSync(path.join(rootDir, 'pnpm-lock.yaml'), 'utf8'))
?.packages ?? {},
);
const versions = pnpmLockedKeys
.filter((key) => key.startsWith(`${packageName}@`))
.map((key) => key.slice(packageName.length + 1));
// Two locked versions would leave the staged one ambiguous; fail instead.
return versions.length === 1 ? versions[0] : undefined;
}
function readClipboardPackageSpecs() {
const cliPackage = JSON.parse(
fs.readFileSync(
path.join(rootDir, 'packages', 'cli', 'package.json'),
'utf8',
),
);
const packageNames = [
'@teddyzhu/clipboard',
...new Set(TARGET_CLIPBOARD_PACKAGE.values()),
];
return packageNames.map((packageName) => {
const version = readPnpmLockedVersion(packageName);
const declaredVersion = cliPackage.optionalDependencies?.[packageName];
if (!version || ![version, `^${version}`].includes(declaredVersion)) {
fail(`Clipboard package version is not locked for ${packageName}`);
}
return `${packageName}@${version}`;
});
}
// node-pty pins live in the root package.json optionalDependencies (mirrored
// in packages/core). The wrapper plus every pinned platform package must be
// staged because release packaging cross-builds all targets from a single
// host — the host's own node_modules only ever carries one platform's
// prebuild, and getPty() resolves the platform package from node_modules at
// runtime (#11872). Deriving the list from the root manifest keeps it in sync
// when a platform pin is added (e.g. linux-arm64).
function readNodePtyPackageSpecs() {
const rootPackage = JSON.parse(
fs.readFileSync(path.join(rootDir, 'package.json'), 'utf8'),
);
const packageNames = Object.keys(
rootPackage.optionalDependencies ?? {},
).filter((packageName) => packageName.startsWith('@lydell/node-pty'));
return packageNames.map((packageName) => {
const version = readPnpmLockedVersion(packageName);
if (!version) {
fail(`node-pty package version is not locked for ${packageName}`);
}
return `${packageName}@${version}`;
});
}
function stageNativeModules(runtimeDir) {
const installDir = path.join(runtimeDir, 'clipboard-modules');
fs.mkdirSync(installDir, { recursive: true });
console.log('Staging standalone native packages (clipboard, node-pty)');
const npmExecPath = process.env.npm_execpath;
if (!npmExecPath) {
fail('npm_execpath is unavailable; run package:standalone:release via npm');
}
execFileSync(
process.execPath,
[
npmExecPath,
'install',
'--prefix',
installDir,
'--package-lock=false',
'--no-save',
'--ignore-scripts',
'--force',
'--no-audit',
'--no-fund',
...readClipboardPackageSpecs(),
...readNodePtyPackageSpecs(),
],
{
cwd: rootDir,
stdio: 'inherit',
},
);
return path.join(installDir, 'node_modules');
}
// Temporary OpenTUI preview: the bundled OpenTUI backend resolves its native
// render library at runtime via `import('@opentui/core-<platform>-<arch>')`,
// so each standalone archive must ship the matching platform package(s).
function readOpenTuiPackageSpecs() {
return OPENTUI_PLATFORM_PACKAGES.map((packageName) => {
const version = readPnpmLockedVersion(packageName);
if (!version) {
fail(`OpenTUI platform package version is not locked for ${packageName}`);
}
return `${packageName}@${version}`;
});
}
function stageOpenTuiPackages(runtimeDir) {
const installDir = path.join(runtimeDir, 'opentui-modules');
fs.mkdirSync(installDir, { recursive: true });
console.log('Staging standalone OpenTUI native packages');
const npmExecPath = process.env.npm_execpath;
if (!npmExecPath) {
fail('npm_execpath is unavailable; run package:standalone:release via npm');
}
execFileSync(
process.execPath,
[
npmExecPath,
'install',
'--prefix',
installDir,
'--package-lock=false',
'--no-save',
'--ignore-scripts',
'--force',
'--no-audit',
'--no-fund',
...readOpenTuiPackageSpecs(),
],
{
cwd: rootDir,
stdio: 'inherit',
},
);
return path.join(installDir, 'node_modules');
}
async function downloadFile(url, destination) {
console.log(`Downloading ${url}`);
const response = await fetch(url);
if (!response.ok) {
fail(
`Failed to download ${url}: ${response.status} ${response.statusText}`,
);
}
if (!response.body) {
fail(`Failed to download ${url}: response body was empty`);
}
await pipeline(
Readable.fromWeb(response.body),
fs.createWriteStream(destination),
);
}
function parseChecksums(content) {
const checksums = new Map();
for (const line of content.split(/\r?\n/)) {
const [hash, fileName] = line.trim().split(/\s+/, 2);
if (hash && fileName) {
checksums.set(fileName.replace(/^\*/, ''), hash);
}
}
return checksums;
}
async function verifyNodeArchive(archivePath, archiveName, checksums, label) {
const runtimeLabel = label || 'Node.js';
const expected = checksums.get(archiveName);
if (!expected) {
fail(`${runtimeLabel} SHASUMS256.txt does not list ${archiveName}`);
}
const actual = await sha256File(archivePath);
if (actual !== expected) {
fail(`Checksum verification failed for ${archiveName}`);
}
console.log(`Verified ${runtimeLabel} runtime checksum for ${archiveName}`);
}
async function sha256File(filePath) {
const hash = crypto.createHash('sha256');
await pipeline(fs.createReadStream(filePath), hash);
return hash.digest('hex');
}
function assertStandaloneOutput(outDir, runtimes = ['node']) {
const checksumPath = path.join(outDir, 'SHA256SUMS');
if (!fs.existsSync(checksumPath)) {
fail(`Standalone SHA256SUMS was not created at ${checksumPath}`);
}
const expectedArchiveNames = RELEASE_TARGETS.flatMap(({ qwenTarget }) =>
runtimes.map((runtime) => standaloneArchiveName(qwenTarget, runtime)),
).sort();
const archiveNames = fs
.readFileSync(checksumPath, 'utf8')
.split(/\r?\n/)
.filter((line) => /^[0-9a-f]{64}\s+/.test(line))
.map((line) => line.trim().split(/\s+/, 2)[1]?.replace(/^\*/, ''))
.filter(Boolean)
.sort();
const missing = expectedArchiveNames.filter(
(archiveName) => !archiveNames.includes(archiveName),
);
const extra = archiveNames.filter(
(archiveName) => !expectedArchiveNames.includes(archiveName),
);
if (
archiveNames.length !== expectedArchiveNames.length ||
missing.length > 0 ||
extra.length > 0
) {
fail(
[
`Expected standalone checksums for ${expectedArchiveNames.join(', ')}`,
`found ${archiveNames.join(', ') || 'none'}.`,
missing.length > 0 ? `Missing: ${missing.join(', ')}.` : '',
extra.length > 0 ? `Extra: ${extra.join(', ')}.` : '',
]
.filter(Boolean)
.join(' '),
);
}
console.log(`Verified ${archiveNames.length} standalone release checksums.`);
}
function parseArgs(argv) {
const args = {
help: false,
includeOpentuiPreview: false,
nodeVersion: undefined,
bunVersion: undefined,
runtime: undefined,
outDir: undefined,
runtimeDir: undefined,
version: undefined,
};
for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index];
switch (arg) {
case '--help':
case '-h':
args.help = true;
break;
case '--include-opentui-preview':
args.includeOpentuiPreview = true;
break;
case '--node-version':
args.nodeVersion = readOptionValue(argv, index, arg);
index += 1;
break;
case '--bun-version':
args.bunVersion = readOptionValue(argv, index, arg);
index += 1;
break;
case '--runtime':
args.runtime = readOptionValue(argv, index, arg);
index += 1;
break;
case '--out-dir':
args.outDir = readOptionValue(argv, index, arg);
index += 1;
break;
case '--runtime-dir':
args.runtimeDir = readOptionValue(argv, index, arg);
index += 1;
break;
case '--version':
args.version = readOptionValue(argv, index, arg);
index += 1;
break;
default:
fail(`Unknown option: ${arg}`);
}
}
return args;
}
function readOptionValue(argv, index, optionName) {
const value = argv[index + 1];
if (!value || value.startsWith('-')) {
fail(`${optionName} requires a value`);
}
return value;
}
function printUsage() {
console.log(`
Usage:
npm run package:standalone:release -- [OPTIONS]
Options:
--version VERSION Release version written to standalone manifests.
--out-dir PATH Output directory. Defaults to dist/standalone.
--runtime-dir PATH Temporary Node.js runtime download directory.
--node-version VERSION Node.js version to download. Defaults to current Node.
--runtime RUNTIME Runtime to bundle: "node" (classic packaging) or
"bun" (temporary OpenTUI preview).
--include-opentui-preview
Also build the bun/OpenTUI preview archives
(qwen-code-*-opentui-preview.*) into the same output
directory, alongside the classic archives.
--bun-version VERSION Bun version to download. Defaults to ${DEFAULT_BUN_VERSION}.
`);
}
function fail(message) {
throw new Error(`ERROR: ${message}`);
}
export {
assertStandaloneOutput,
parseChecksums,
readClipboardPackageSpecs,
readNodePtyPackageSpecs,
RELEASE_TARGETS,
};
if (isMainModule()) {
try {
await main();
} catch (error) {
console.error(error instanceof Error ? error.message : error);
process.exitCode = 1;
}
}