




















@@ -52,27 +52,49 @@ function sameRuntimeDepSpecs(left: readonly string[], right: readonly string[]):
5252);
5353}
545455-function readInstalledRuntimeDepVersion(rootDir: string, depName: string): string | null {
55+function readInstalledRuntimeDepPackage(
56+rootDir: string,
57+depName: string,
58+): { packageDir: string; packageJson: JsonObject } | null {
5659try {
57-const parsed = JSON.parse(
58-fs.readFileSync(resolveDependencySentinelAbsolutePath(rootDir, depName), "utf8"),
59-) as unknown;
60+const packageJsonPath = resolveDependencySentinelAbsolutePath(rootDir, depName);
61+const parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")) as unknown;
6062if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
6163return null;
6264}
63-const version = (parsed as JsonObject).version;
64-return typeof version === "string" && version.trim() ? version.trim() : null;
65+return { packageDir: path.dirname(packageJsonPath), packageJson: parsed as JsonObject };
6566} catch {
6667return null;
6768}
6869}
697071+function hasInstalledRuntimeDepEntryFiles(packageDir: string, packageJson: JsonObject): boolean {
72+const main = packageJson.main;
73+if (typeof main !== "string" || main.trim() === "") {
74+return true;
75+}
76+const mainPath = path.resolve(packageDir, main);
77+if (mainPath !== packageDir && !mainPath.startsWith(`${packageDir}${path.sep}`)) {
78+return false;
79+}
80+return fs.existsSync(mainPath);
81+}
82+7083export function isRuntimeDepSatisfied(
7184rootDir: string,
7285dep: { name: string; version: string },
7386): boolean {
74-const installedVersion = readInstalledRuntimeDepVersion(rootDir, dep.name);
75-return Boolean(installedVersion && satisfies(installedVersion, dep.version));
87+const installed = readInstalledRuntimeDepPackage(rootDir, dep.name);
88+if (!installed) {
89+return false;
90+}
91+const version = installed.packageJson.version;
92+return Boolean(
93+typeof version === "string" &&
94+version.trim() &&
95+satisfies(version.trim(), dep.version) &&
96+hasInstalledRuntimeDepEntryFiles(installed.packageDir, installed.packageJson),
97+);
7698}
779978100export function isRuntimeDepSatisfiedInAnyRoot(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。