qwen-code/scripts/build_package.js
jinye 94982c6a91
fix(build): clean stale outputs before tsc --build to prevent TS5055 (#4453)
* fix(build): clean stale outputs before tsc --build to prevent TS5055

Run `tsc --build --clean` before `tsc --build` in build_package.js so a
stale tsconfig.tsbuildinfo (e.g. after a version bump, branch switch, or
a prior `npm ci` prepare) cannot collide with composite project
references emitting back into packages/core/dist.

Closes #4447

* fix(build): scope clean step to current package only

Replace `tsc --build --clean` with direct `rmSync` of `dist` and
`tsconfig.tsbuildinfo`. `tsc -b --clean` walks project references, so
when scripts/build.js builds packages in dependency order, cleaning
from a downstream package (e.g. cli) would also wipe upstream outputs
(core, acp-bridge, channels) that were just built — a major perf
regression.

Spotted by Copilot review on #4453.
2026-05-23 23:06:31 +08:00

45 lines
1.6 KiB
JavaScript

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { execSync } from 'node:child_process';
import { rmSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
if (!process.cwd().includes('packages')) {
console.error('must be invoked from a package directory');
process.exit(1);
}
// Clean this package's stale outputs first to avoid TS5055 when tsbuildinfo
// is out of sync with sources (e.g. after a version bump or branch switch)
// under composite project references. We delete files directly rather than
// using `tsc --build --clean`, because the latter walks project references
// and would wipe upstream packages already built by scripts/build.js.
rmSync('dist', { recursive: true, force: true });
rmSync('tsconfig.tsbuildinfo', { force: true });
// build typescript files
execSync('tsc --build', { stdio: 'inherit' });
// copy .{md,json} files
execSync('node ../../scripts/copy_files.js', { stdio: 'inherit' });
// touch dist/.last_build
writeFileSync(join(process.cwd(), 'dist', '.last_build'), '');
process.exit(0);