fix: handle cold dev startup and versioned dependency removal

This commit is contained in:
whyour committed 2026-11-21 13:33:39 +08:00
1 parent a65d56a980
commit 0841e4e134
6 files changed
+211 -17

No files matched your search

+8 -4
View File
@@ -42,11 +42,15 @@ class Application {
}
private startMasterProcess() {
// Source transpilation competes with the frontend's cold compilation in
// development. Keep a bounded wait without applying that budget to normal
// production startup.
const readyTimeout =
process.arch === 'arm' &&
Number(
(process.config.variables as { arm_version?: string | number }).arm_version,
) === 6
process.env.NODE_ENV === 'development' ||
(process.arch === 'arm' &&
Number(
(process.config.variables as { arm_version?: string | number }).arm_version,
) === 6)
? 120000
: 30000;
// Fork gRPC worker first and wait for it to be ready
+25 -6
View File
@@ -861,7 +861,22 @@ export function getInstallCommand(type: DependenceTypes, name: string): string {
export function getUninstallCommand(
type: DependenceTypes,
name: string,
linuxOsType?: 'Debian' | 'Ubuntu' | 'Alpine',
): string {
if (type === DependenceTypes.nodejs) {
// pnpm remove expects the installed name, not an install specifier. Start
// after the first character so a scoped name keeps its leading '@'.
const specifier = name.trim();
const versionIndex = specifier.indexOf('@', 1);
const packageName =
versionIndex === -1 ? specifier : specifier.slice(0, versionIndex);
// Keep ordinary names identical to the process argv used by cancel's PID
// lookup, while passing unusual input literally to the shell.
const argument = /^(?:@[a-z0-9._~-]+\/)?[a-z0-9._~-]+$/i.test(packageName)
? packageName
: shellQuote(packageName);
return `pnpm remove -g -- ${argument}`;
}
if (type === DependenceTypes.python3) {
name = name.trim();
if (isRequirementsFile(name)) {
@@ -899,12 +914,16 @@ export function getUninstallCommand(
PYTHON_VENV_DIR ? '' : ' --root-user-action=ignore'
} -y -- ${shellQuote(packageName)}`;
}
const baseCommands = {
[DependenceTypes.nodejs]: 'pnpm remove -g',
[DependenceTypes.linux]:
getOsTypeSync() === 'Alpine' ? 'apk del' : maybeSudo('apt-get remove -y'),
};
return `${baseCommands[type]} ${name.trim()}`;
if ((linuxOsType || getOsTypeSync()) === 'Alpine') {
// apk del accepts package names, not the version constraints or repository
// tags accepted by apk add. Keep apt's version/architecture selectors intact.
const packageName = name.trim().split(/[<>=~@]/, 1)[0].trim();
const argument = /^[a-z0-9][a-z0-9+_.-]*$/i.test(packageName)
? packageName
: shellQuote(packageName);
return `apk del -- ${argument}`;
}
return `${maybeSudo('apt-get remove -y')} ${name.trim()}`;
}
export function isDemoEnv() {
+2 -2
View File
@@ -315,7 +315,7 @@ export default class DependenceService {
}
const linuxCommand = LINUX_DEPENDENCE_COMMAND[osType];
depInstallCommand = `${linuxCommand.install} ${doc.name.trim()}`;
depUnInstallCommand = `${linuxCommand.uninstall} ${doc.name.trim()}`;
depUnInstallCommand = getUninstallCommand(doc.type, doc.name, osType);
}
const pids = await Promise.all([
getPid(depInstallCommand),
@@ -442,7 +442,7 @@ export default class DependenceService {
if (isLinuxDependence) {
command = isInstall
? `${linuxCommand.install} ${depName.trim()}`
: `${linuxCommand.uninstall} ${depName.trim()}`;
: getUninstallCommand(dependency.type, depName, osType);
}
const startTime = dayjs();