























@@ -8,7 +8,8 @@ export type PluginInstallSourceWarning =
88| "default-choice-missing-source"
99| "npm-integrity-without-source"
1010| "npm-spec-floating"
11-| "npm-spec-missing-integrity";
11+| "npm-spec-missing-integrity"
12+| "npm-spec-package-name-mismatch";
12131314export type PluginInstallNpmPinState =
1415| "exact-with-integrity"
@@ -19,6 +20,7 @@ export type PluginInstallNpmPinState =
1920export type PluginInstallNpmSourceInfo = {
2021spec: string;
2122packageName: string;
23+expectedPackageName?: string;
2224selector?: string;
2325selectorKind: ParsedRegistryNpmSpec["selectorKind"];
2426exactVersion: boolean;
@@ -37,6 +39,10 @@ export type PluginInstallSourceInfo = {
3739warnings: readonly PluginInstallSourceWarning[];
3840};
394142+export type DescribePluginInstallSourceOptions = {
43+expectedPackageName?: string | null;
44+};
45+4046function resolveNpmPinState(params: {
4147exactVersion: boolean;
4248hasIntegrity: boolean;
@@ -51,13 +57,23 @@ function resolveDefaultChoice(value: unknown): PluginPackageInstall["defaultChoi
5157return value === "npm" || value === "local" ? value : undefined;
5258}
535960+function normalizeExpectedPackageName(value: string | null | undefined): string | undefined {
61+const expected = normalizeOptionalString(value);
62+if (!expected) {
63+return undefined;
64+}
65+return parseRegistryNpmSpec(expected)?.name ?? expected;
66+}
67+5468export function describePluginInstallSource(
5569install: PluginPackageInstall,
70+options?: DescribePluginInstallSourceOptions,
5671): PluginInstallSourceInfo {
5772const npmSpec = normalizeOptionalString(install.npmSpec);
5873const localPath = normalizeOptionalString(install.localPath);
5974const defaultChoice = resolveDefaultChoice(install.defaultChoice);
6075const expectedIntegrity = normalizeOptionalString(install.expectedIntegrity);
76+const expectedPackageName = normalizeExpectedPackageName(options?.expectedPackageName);
6177const warnings: PluginInstallSourceWarning[] = [];
6278let npm: PluginInstallNpmSourceInfo | undefined;
6379@@ -76,9 +92,15 @@ export function describePluginInstallSource(
7692if (!hasIntegrity) {
7793warnings.push("npm-spec-missing-integrity");
7894}
95+if (expectedPackageName && parsed.name !== expectedPackageName) {
96+warnings.push("npm-spec-package-name-mismatch");
97+}
7998npm = {
8099spec: parsed.raw,
81100packageName: parsed.name,
101+ ...(expectedPackageName && parsed.name !== expectedPackageName
102+ ? { expectedPackageName }
103+ : {}),
82104selectorKind: parsed.selectorKind,
83105 exactVersion,
84106pinState: resolveNpmPinState({ exactVersion, hasIntegrity }),
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。