@uapkg/registry-tools 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aggregator/RegistryToolsAggregator.d.ts +31 -28
- package/dist/aggregator/RegistryToolsAggregator.d.ts.map +1 -1
- package/dist/aggregator/RegistryToolsAggregator.js +71 -73
- package/dist/aggregator/RegistryToolsAggregator.js.map +1 -1
- package/dist/contracts/RegistryToolsTypes.d.ts +101 -98
- package/dist/contracts/RegistryToolsTypes.d.ts.map +1 -1
- package/dist/contracts/RegistryToolsTypes.js +5 -4
- package/dist/contracts/RegistryToolsTypes.js.map +1 -1
- package/dist/index.d.ts +18 -18
- package/dist/index.js +18 -30
- package/dist/io/IntegrityCalculator.d.ts +16 -13
- package/dist/io/IntegrityCalculator.d.ts.map +1 -1
- package/dist/io/IntegrityCalculator.js +96 -92
- package/dist/io/IntegrityCalculator.js.map +1 -1
- package/dist/io/ManifestStore.d.ts +31 -28
- package/dist/io/ManifestStore.d.ts.map +1 -1
- package/dist/io/ManifestStore.js +127 -124
- package/dist/io/ManifestStore.js.map +1 -1
- package/dist/listing/PackageLister.d.ts +18 -15
- package/dist/listing/PackageLister.d.ts.map +1 -1
- package/dist/listing/PackageLister.js +75 -77
- package/dist/listing/PackageLister.js.map +1 -1
- package/dist/mutation/AddPackageVersionPlanner.d.ts +18 -15
- package/dist/mutation/AddPackageVersionPlanner.d.ts.map +1 -1
- package/dist/mutation/AddPackageVersionPlanner.js +110 -117
- package/dist/mutation/AddPackageVersionPlanner.js.map +1 -1
- package/dist/mutation/RemovePackagePlanner.d.ts +15 -12
- package/dist/mutation/RemovePackagePlanner.d.ts.map +1 -1
- package/dist/mutation/RemovePackagePlanner.js +45 -37
- package/dist/mutation/RemovePackagePlanner.js.map +1 -1
- package/dist/mutation/RemovePackageVersionPlanner.d.ts +15 -12
- package/dist/mutation/RemovePackageVersionPlanner.d.ts.map +1 -1
- package/dist/mutation/RemovePackageVersionPlanner.js +60 -52
- package/dist/mutation/RemovePackageVersionPlanner.js.map +1 -1
- package/dist/mutation/VersionSorter.d.ts +4 -1
- package/dist/mutation/VersionSorter.d.ts.map +1 -1
- package/dist/mutation/VersionSorter.js +24 -24
- package/dist/mutation/VersionSorter.js.map +1 -1
- package/dist/paths/RegistryRepoPaths.d.ts +15 -12
- package/dist/paths/RegistryRepoPaths.d.ts.map +1 -1
- package/dist/paths/RegistryRepoPaths.js +38 -33
- package/dist/paths/RegistryRepoPaths.js.map +1 -1
- package/dist/tools/RegistryTools.d.ts +53 -50
- package/dist/tools/RegistryTools.d.ts.map +1 -1
- package/dist/tools/RegistryTools.js +205 -220
- package/dist/tools/RegistryTools.js.map +1 -1
- package/dist/validation/DependencyReachabilityValidator.d.ts +15 -12
- package/dist/validation/DependencyReachabilityValidator.d.ts.map +1 -1
- package/dist/validation/DependencyReachabilityValidator.js +62 -55
- package/dist/validation/DependencyReachabilityValidator.js.map +1 -1
- package/dist/validation/ExternalRegistryPolicyValidator.d.ts +13 -10
- package/dist/validation/ExternalRegistryPolicyValidator.d.ts.map +1 -1
- package/dist/validation/ExternalRegistryPolicyValidator.js +63 -63
- package/dist/validation/ExternalRegistryPolicyValidator.js.map +1 -1
- package/dist/validation/ManifestValidator.d.ts +11 -8
- package/dist/validation/ManifestValidator.d.ts.map +1 -1
- package/dist/validation/ManifestValidator.js +29 -24
- package/dist/validation/ManifestValidator.js.map +1 -1
- package/dist/validation/OfficialRegistryPolicyValidator.d.ts +18 -15
- package/dist/validation/OfficialRegistryPolicyValidator.d.ts.map +1 -1
- package/dist/validation/OfficialRegistryPolicyValidator.js +80 -89
- package/dist/validation/OfficialRegistryPolicyValidator.js.map +1 -1
- package/dist/validation/RegistryValidator.d.ts +25 -22
- package/dist/validation/RegistryValidator.d.ts.map +1 -1
- package/dist/validation/RegistryValidator.js +89 -87
- package/dist/validation/RegistryValidator.js.map +1 -1
- package/dist/validation/ReleaseFileNameValidator.d.ts +12 -9
- package/dist/validation/ReleaseFileNameValidator.d.ts.map +1 -1
- package/dist/validation/ReleaseFileNameValidator.js +36 -29
- package/dist/validation/ReleaseFileNameValidator.js.map +1 -1
- package/package.json +19 -21
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,91 +1,82 @@
|
|
|
1
|
-
import { existsSync } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { BaseManifestSchema } from
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { DiagnosticBag, createRegistryToolsOfficialPolicyViolationDiagnostic } from "@uapkg/diagnostics";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { safeJsonParse } from "@uapkg/common";
|
|
6
|
+
import { BaseManifestSchema } from "@uapkg/package-manifest-schema";
|
|
7
|
+
|
|
8
|
+
//#region src/validation/OfficialRegistryPolicyValidator.ts
|
|
9
|
+
const UAPKG_MANIFEST = "uapkg.json";
|
|
10
|
+
const UAPKG_LOCKFILE = "uapkg.lock";
|
|
9
11
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (dep && typeof dep === 'object' && dep.registry) {
|
|
81
|
-
this.report(bag, 'external-registry-dependency', `dependency "${name}" in ${bucket} targets external registry "${dep.registry}"`, manifestPath);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
report(bag, rule, detail, path) {
|
|
86
|
-
const diag = createRegistryToolsOfficialPolicyViolationDiagnostic(rule, detail, path);
|
|
87
|
-
bag.add(diag);
|
|
88
|
-
this.aggregator.add(diag);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
12
|
+
* Local-only validator for "official registry" rules on an already-extracted
|
|
13
|
+
* package directory.
|
|
14
|
+
*
|
|
15
|
+
* Rules:
|
|
16
|
+
* - `uapkg.json` must exist.
|
|
17
|
+
* - `uapkg.json#name` must match the registry-declared package name.
|
|
18
|
+
* - `uapkg.json#version` must match the registry-declared version.
|
|
19
|
+
* - `uapkg.json#private: true` is rejected.
|
|
20
|
+
* - `uapkg.lock` must not be present.
|
|
21
|
+
* - Dependencies must not target external registries.
|
|
22
|
+
*
|
|
23
|
+
* Never makes network calls. Never checks publish authority.
|
|
24
|
+
*/
|
|
25
|
+
var OfficialRegistryPolicyValidator = class {
|
|
26
|
+
aggregator;
|
|
27
|
+
constructor(aggregator) {
|
|
28
|
+
this.aggregator = aggregator;
|
|
29
|
+
}
|
|
30
|
+
async validate(request) {
|
|
31
|
+
const bag = new DiagnosticBag();
|
|
32
|
+
const dir = request.extractedPackageDir;
|
|
33
|
+
const manifestPath = join(dir, UAPKG_MANIFEST);
|
|
34
|
+
if (!existsSync(manifestPath)) {
|
|
35
|
+
this.report(bag, "manifest-missing", `Missing ${UAPKG_MANIFEST} in extracted package`, manifestPath);
|
|
36
|
+
return bag.toFailure();
|
|
37
|
+
}
|
|
38
|
+
const lockPath = join(dir, UAPKG_LOCKFILE);
|
|
39
|
+
if (existsSync(lockPath)) this.report(bag, "lockfile-forbidden", `${UAPKG_LOCKFILE} must not be packaged`, lockPath);
|
|
40
|
+
let raw;
|
|
41
|
+
try {
|
|
42
|
+
raw = await readFile(manifestPath, "utf-8");
|
|
43
|
+
} catch (err) {
|
|
44
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
45
|
+
this.report(bag, "manifest-unreadable", reason, manifestPath);
|
|
46
|
+
return bag.toFailure();
|
|
47
|
+
}
|
|
48
|
+
const parsed = safeJsonParse(raw, manifestPath);
|
|
49
|
+
if (!parsed.ok) {
|
|
50
|
+
bag.mergeArray(parsed.diagnostics);
|
|
51
|
+
this.aggregator.addMany(parsed.diagnostics);
|
|
52
|
+
return bag.toFailure();
|
|
53
|
+
}
|
|
54
|
+
const validated = BaseManifestSchema.safeParse(parsed.value);
|
|
55
|
+
if (!validated.success) {
|
|
56
|
+
const detail = validated.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
|
|
57
|
+
this.report(bag, "manifest-invalid", detail, manifestPath);
|
|
58
|
+
return bag.toFailure();
|
|
59
|
+
}
|
|
60
|
+
const manifest = validated.data;
|
|
61
|
+
if (manifest.private === true) this.report(bag, "private-package", "`private: true` packages are not publishable", manifestPath);
|
|
62
|
+
if (manifest.name !== request.expectedPackageName) this.report(bag, "name-mismatch", `manifest name "${manifest.name}" does not match registry name "${request.expectedPackageName}"`, manifestPath);
|
|
63
|
+
if (manifest.version !== request.expectedVersion) this.report(bag, "version-mismatch", `manifest version "${manifest.version}" does not match registry version "${request.expectedVersion}"`, manifestPath);
|
|
64
|
+
this.checkExternalDeps(bag, manifest.dependencies, "dependencies", manifestPath);
|
|
65
|
+
this.checkExternalDeps(bag, manifest.devDependencies, "devDependencies", manifestPath);
|
|
66
|
+
this.checkExternalDeps(bag, manifest.peerDependencies, "peerDependencies", manifestPath);
|
|
67
|
+
return bag.toResult({ diagnostics: bag.all() });
|
|
68
|
+
}
|
|
69
|
+
checkExternalDeps(bag, deps, bucket, manifestPath) {
|
|
70
|
+
if (!deps) return;
|
|
71
|
+
for (const [name, dep] of Object.entries(deps)) if (dep && typeof dep === "object" && dep.registry) this.report(bag, "external-registry-dependency", `dependency "${name}" in ${bucket} targets external registry "${dep.registry}"`, manifestPath);
|
|
72
|
+
}
|
|
73
|
+
report(bag, rule, detail, path) {
|
|
74
|
+
const diag = createRegistryToolsOfficialPolicyViolationDiagnostic(rule, detail, path);
|
|
75
|
+
bag.add(diag);
|
|
76
|
+
this.aggregator.add(diag);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { OfficialRegistryPolicyValidator };
|
|
91
82
|
//# sourceMappingURL=OfficialRegistryPolicyValidator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OfficialRegistryPolicyValidator.js","
|
|
1
|
+
{"version":3,"file":"OfficialRegistryPolicyValidator.js","names":[],"sources":["../../src/validation/OfficialRegistryPolicyValidator.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { safeJsonParse } from '@uapkg/common';\nimport type { PackageName, PackageVersion } from '@uapkg/common-schema';\nimport { createRegistryToolsOfficialPolicyViolationDiagnostic, DiagnosticBag, type Result } from '@uapkg/diagnostics';\nimport { BaseManifestSchema } from '@uapkg/package-manifest-schema';\nimport type { RegistryToolsAggregator } from '../aggregator/RegistryToolsAggregator.js';\nimport type { OfficialPackagePolicyReport } from '../contracts/RegistryToolsTypes.js';\n\nconst UAPKG_MANIFEST = 'uapkg.json';\nconst UAPKG_LOCKFILE = 'uapkg.lock';\n\nexport interface OfficialRegistryPolicyRequest {\n /** Absolute path to the extracted package's root directory. */\n readonly extractedPackageDir: string;\n readonly expectedPackageName: PackageName;\n readonly expectedVersion: PackageVersion;\n}\n\n/**\n * Local-only validator for \"official registry\" rules on an already-extracted\n * package directory.\n *\n * Rules:\n * - `uapkg.json` must exist.\n * - `uapkg.json#name` must match the registry-declared package name.\n * - `uapkg.json#version` must match the registry-declared version.\n * - `uapkg.json#private: true` is rejected.\n * - `uapkg.lock` must not be present.\n * - Dependencies must not target external registries.\n *\n * Never makes network calls. Never checks publish authority.\n */\nexport class OfficialRegistryPolicyValidator {\n constructor(private readonly aggregator: RegistryToolsAggregator) {}\n\n async validate(request: OfficialRegistryPolicyRequest): Promise<Result<OfficialPackagePolicyReport>> {\n const bag = new DiagnosticBag();\n const dir = request.extractedPackageDir;\n const manifestPath = join(dir, UAPKG_MANIFEST);\n\n if (!existsSync(manifestPath)) {\n this.report(bag, 'manifest-missing', `Missing ${UAPKG_MANIFEST} in extracted package`, manifestPath);\n return bag.toFailure();\n }\n\n const lockPath = join(dir, UAPKG_LOCKFILE);\n if (existsSync(lockPath)) {\n this.report(bag, 'lockfile-forbidden', `${UAPKG_LOCKFILE} must not be packaged`, lockPath);\n }\n\n let raw: string;\n try {\n raw = await readFile(manifestPath, 'utf-8');\n } catch (err) {\n const reason = err instanceof Error ? err.message : String(err);\n this.report(bag, 'manifest-unreadable', reason, manifestPath);\n return bag.toFailure();\n }\n\n const parsed = safeJsonParse<unknown>(raw, manifestPath);\n if (!parsed.ok) {\n bag.mergeArray(parsed.diagnostics);\n this.aggregator.addMany(parsed.diagnostics);\n return bag.toFailure();\n }\n\n const validated = BaseManifestSchema.safeParse(parsed.value);\n if (!validated.success) {\n const detail = validated.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join('; ');\n this.report(bag, 'manifest-invalid', detail, manifestPath);\n return bag.toFailure();\n }\n\n const manifest = validated.data;\n\n if (manifest.private === true) {\n this.report(bag, 'private-package', '`private: true` packages are not publishable', manifestPath);\n }\n\n if (manifest.name !== request.expectedPackageName) {\n this.report(\n bag,\n 'name-mismatch',\n `manifest name \"${manifest.name}\" does not match registry name \"${request.expectedPackageName}\"`,\n manifestPath,\n );\n }\n\n if (manifest.version !== request.expectedVersion) {\n this.report(\n bag,\n 'version-mismatch',\n `manifest version \"${manifest.version}\" does not match registry version \"${request.expectedVersion}\"`,\n manifestPath,\n );\n }\n\n this.checkExternalDeps(bag, manifest.dependencies, 'dependencies', manifestPath);\n this.checkExternalDeps(bag, manifest.devDependencies, 'devDependencies', manifestPath);\n this.checkExternalDeps(bag, manifest.peerDependencies, 'peerDependencies', manifestPath);\n\n return bag.toResult({ diagnostics: bag.all() });\n }\n\n private checkExternalDeps(\n bag: DiagnosticBag,\n deps: Record<string, { readonly registry?: string }> | undefined,\n bucket: 'dependencies' | 'devDependencies' | 'peerDependencies',\n manifestPath: string,\n ): void {\n if (!deps) return;\n for (const [name, dep] of Object.entries(deps)) {\n if (dep && typeof dep === 'object' && dep.registry) {\n this.report(\n bag,\n 'external-registry-dependency',\n `dependency \"${name}\" in ${bucket} targets external registry \"${dep.registry}\"`,\n manifestPath,\n );\n }\n }\n }\n\n private report(bag: DiagnosticBag, rule: string, detail: string, path?: string): void {\n const diag = createRegistryToolsOfficialPolicyViolationDiagnostic(rule, detail, path);\n bag.add(diag);\n this.aggregator.add(diag);\n }\n}\n"],"mappings":";;;;;;;;AAUA,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;;;;;;;;;;;;;;;AAuBvB,IAAa,kCAAb,MAA6C;CACd;CAA7B,YAAY,AAAiB,YAAqC;EAArC;CAAsC;CAEnE,MAAM,SAAS,SAAsF;EACnG,MAAM,MAAM,IAAI,cAAc;EAC9B,MAAM,MAAM,QAAQ;EACpB,MAAM,eAAe,KAAK,KAAK,cAAc;EAE7C,IAAI,CAAC,WAAW,YAAY,GAAG;GAC7B,KA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BAAgB,YAAY;EAC/E,KAAK,kBAAkB,KAAK,SAAS,iBAAiB,mBAAmB,YAAY;EACrF,KAAK,kBAAkB,KAAK,SAAS,kBAAkB,oBAAoB,YAAY;EAEvF,OAAO,IAAI,SAAS,EAAE,aAAa,IAAI,IAAI,EAAE,CAAC;CAChD;CAEA,AAAQ,kBACN,KACA,MACA,QACA,cACM;EACN,IAAI,CAAC,MAAM;EACX,KAAK,MAAM,CAAC,MAAM,QAAQ,OAAO,QAAQ,IAAI,GAC3C,IAAI,OAAO,OAAO,QAAQ,YAAY,IAAI,UACxC,KAAK,OACH,KACA,gCACA,eAAe,KAAK,OAAO,OAAO,8BAA8B,IAAI,SAAS,IAC7E,YACF;CAGN;CAEA,AAAQ,OAAO,KAAoB,MAAc,QAAgB,MAAqB;EACpF,MAAM,OAAO,qDAAqD,MAAM,QAAQ,IAAI;EACpF,IAAI,IAAI,IAAI;EACZ,KAAK,WAAW,IAAI,IAAI;CAC1B;AACF"}
|
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
1
|
+
import { RegistryToolsAggregator } from "../aggregator/RegistryToolsAggregator.js";
|
|
2
|
+
import { PackageValidationReport, RegistryValidationReport, ResolvedRegistryToolsPolicy } from "../contracts/RegistryToolsTypes.js";
|
|
3
|
+
import { RegistryRepoPaths } from "../paths/RegistryRepoPaths.js";
|
|
4
|
+
import { ManifestStore } from "../io/ManifestStore.js";
|
|
5
|
+
import { PackageLister } from "../listing/PackageLister.js";
|
|
6
|
+
import { DependencyReachabilityValidator } from "./DependencyReachabilityValidator.js";
|
|
7
|
+
import { ExternalRegistryPolicyValidator } from "./ExternalRegistryPolicyValidator.js";
|
|
8
|
+
import { Result } from "@uapkg/diagnostics";
|
|
9
|
+
import { PackageName } from "@uapkg/common-schema";
|
|
10
|
+
//#region src/validation/RegistryValidator.d.ts
|
|
10
11
|
/**
|
|
11
12
|
* High-level validator that runs every cross-cutting check across one or more
|
|
12
13
|
* packages in the registry. Composes per-concern validators rather than doing
|
|
13
14
|
* the work itself (SRP).
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
declare class RegistryValidator {
|
|
17
|
+
private readonly policy;
|
|
18
|
+
private readonly paths;
|
|
19
|
+
private readonly store;
|
|
20
|
+
private readonly lister;
|
|
21
|
+
private readonly externalRegistry;
|
|
22
|
+
private readonly dependencyReachability;
|
|
23
|
+
private readonly aggregator;
|
|
24
|
+
constructor(policy: ResolvedRegistryToolsPolicy, paths: RegistryRepoPaths, store: ManifestStore, lister: PackageLister, externalRegistry: ExternalRegistryPolicyValidator, dependencyReachability: DependencyReachabilityValidator, aggregator: RegistryToolsAggregator);
|
|
25
|
+
validateRegistry(): Promise<Result<RegistryValidationReport>>;
|
|
26
|
+
validatePackages(packageNames: readonly PackageName[]): Promise<Result<RegistryValidationReport>>;
|
|
27
|
+
validateSinglePackage(packageName: PackageName): Promise<PackageValidationReport>;
|
|
28
|
+
private checkVersionsSorted;
|
|
28
29
|
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { RegistryValidator };
|
|
29
32
|
//# sourceMappingURL=RegistryValidator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegistryValidator.d.ts","
|
|
1
|
+
{"version":3,"file":"RegistryValidator.d.ts","names":[],"sources":["../../src/validation/RegistryValidator.ts"],"mappings":";;;;;;;;;;;;;;;cA2Ba;mBAEQ;mBACA;mBACA;mBACA;mBACA;mBACA;mBACA;EAPnB,YACmB,QAAQ,6BACR,OAAO,mBACP,OAAO,eACP,QAAQ,eACR,kBAAkB,iCAClB,wBAAwB,iCACxB,YAAY;EAGzB,oBAAoB,QAAQ,OAAO;EAQnC,iBAAiB,uBAAuB,gBAAgB,QAAQ,OAAO;EAmBvE,sBAAsB,aAAa,cAAc,QAAQ;UAwCvD"}
|
|
@@ -1,89 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { sortVersionsNewestFirst } from "../mutation/VersionSorter.js";
|
|
2
|
+
import { DiagnosticBag, createRegistryToolsPathMismatchDiagnostic, createRegistryToolsVersionsUnsortedDiagnostic, ok } from "@uapkg/diagnostics";
|
|
3
|
+
|
|
4
|
+
//#region src/validation/RegistryValidator.ts
|
|
3
5
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
6
|
+
* High-level validator that runs every cross-cutting check across one or more
|
|
7
|
+
* packages in the registry. Composes per-concern validators rather than doing
|
|
8
|
+
* the work itself (SRP).
|
|
9
|
+
*/
|
|
10
|
+
var RegistryValidator = class {
|
|
11
|
+
policy;
|
|
12
|
+
paths;
|
|
13
|
+
store;
|
|
14
|
+
lister;
|
|
15
|
+
externalRegistry;
|
|
16
|
+
dependencyReachability;
|
|
17
|
+
aggregator;
|
|
18
|
+
constructor(policy, paths, store, lister, externalRegistry, dependencyReachability, aggregator) {
|
|
19
|
+
this.policy = policy;
|
|
20
|
+
this.paths = paths;
|
|
21
|
+
this.store = store;
|
|
22
|
+
this.lister = lister;
|
|
23
|
+
this.externalRegistry = externalRegistry;
|
|
24
|
+
this.dependencyReachability = dependencyReachability;
|
|
25
|
+
this.aggregator = aggregator;
|
|
26
|
+
}
|
|
27
|
+
async validateRegistry() {
|
|
28
|
+
const namesResult = await this.lister.listPackageNames();
|
|
29
|
+
if (!namesResult.ok) return namesResult;
|
|
30
|
+
return this.validatePackages(namesResult.value);
|
|
31
|
+
}
|
|
32
|
+
async validatePackages(packageNames) {
|
|
33
|
+
const reports = [];
|
|
34
|
+
const overall = new DiagnosticBag();
|
|
35
|
+
for (const name of packageNames) {
|
|
36
|
+
const report = await this.validateSinglePackage(name);
|
|
37
|
+
reports.push(report);
|
|
38
|
+
overall.mergeArray(report.diagnostics);
|
|
39
|
+
}
|
|
40
|
+
return ok({
|
|
41
|
+
packageReports: reports,
|
|
42
|
+
diagnostics: overall.all()
|
|
43
|
+
}, overall.all());
|
|
44
|
+
}
|
|
45
|
+
async validateSinglePackage(packageName) {
|
|
46
|
+
const manifestPath = this.store.resolveManifestPath(packageName);
|
|
47
|
+
const bag = new DiagnosticBag();
|
|
48
|
+
const read = await this.store.read(packageName);
|
|
49
|
+
if (!read.ok) {
|
|
50
|
+
bag.mergeArray(read.diagnostics);
|
|
51
|
+
return {
|
|
52
|
+
packageName,
|
|
53
|
+
manifestPath,
|
|
54
|
+
diagnostics: bag.all()
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const manifest = read.value;
|
|
58
|
+
if (manifest.name !== packageName) {
|
|
59
|
+
const expected = this.paths.manifestPath(manifest.name);
|
|
60
|
+
const diag = createRegistryToolsPathMismatchDiagnostic(packageName, expected, manifestPath);
|
|
61
|
+
bag.add(diag);
|
|
62
|
+
this.aggregator.add(diag);
|
|
63
|
+
}
|
|
64
|
+
if (this.policy.requireSortedVersions) this.checkVersionsSorted(bag, manifest);
|
|
65
|
+
const ext = this.externalRegistry.validate(manifest);
|
|
66
|
+
bag.mergeArray(ext.diagnostics);
|
|
67
|
+
for (const [version, entry] of Object.entries(manifest.versions)) {
|
|
68
|
+
if (!entry) continue;
|
|
69
|
+
const dep = await this.dependencyReachability.validate(packageName, version, entry);
|
|
70
|
+
bag.mergeArray(dep.diagnostics);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
packageName,
|
|
74
|
+
manifestPath,
|
|
75
|
+
diagnostics: bag.all()
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
checkVersionsSorted(bag, manifest) {
|
|
79
|
+
const actual = Object.keys(manifest.versions);
|
|
80
|
+
const expected = sortVersionsNewestFirst(actual);
|
|
81
|
+
if (!(actual.length === expected.length && actual.every((v, i) => v === expected[i]))) {
|
|
82
|
+
const diag = createRegistryToolsVersionsUnsortedDiagnostic(manifest.name, actual, expected);
|
|
83
|
+
bag.add(diag);
|
|
84
|
+
this.aggregator.add(diag);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { RegistryValidator };
|
|
89
91
|
//# sourceMappingURL=RegistryValidator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegistryValidator.js","
|
|
1
|
+
{"version":3,"file":"RegistryValidator.js","names":["actual"],"sources":["../../src/validation/RegistryValidator.ts"],"sourcesContent":["import type { PackageName, PackageVersion } from '@uapkg/common-schema';\nimport {\n createRegistryToolsPathMismatchDiagnostic,\n createRegistryToolsVersionsUnsortedDiagnostic,\n DiagnosticBag,\n ok,\n type Result,\n} from '@uapkg/diagnostics';\nimport type { PackageRegistryManifest } from '@uapkg/registry-schema';\nimport type { RegistryToolsAggregator } from '../aggregator/RegistryToolsAggregator.js';\nimport type {\n PackageValidationReport,\n RegistryValidationReport,\n ResolvedRegistryToolsPolicy,\n} from '../contracts/RegistryToolsTypes.js';\nimport type { ManifestStore } from '../io/ManifestStore.js';\nimport type { PackageLister } from '../listing/PackageLister.js';\nimport { sortVersionsNewestFirst } from '../mutation/VersionSorter.js';\nimport type { RegistryRepoPaths } from '../paths/RegistryRepoPaths.js';\nimport type { DependencyReachabilityValidator } from './DependencyReachabilityValidator.js';\nimport type { ExternalRegistryPolicyValidator } from './ExternalRegistryPolicyValidator.js';\n\n/**\n * High-level validator that runs every cross-cutting check across one or more\n * packages in the registry. Composes per-concern validators rather than doing\n * the work itself (SRP).\n */\nexport class RegistryValidator {\n constructor(\n private readonly policy: ResolvedRegistryToolsPolicy,\n private readonly paths: RegistryRepoPaths,\n private readonly store: ManifestStore,\n private readonly lister: PackageLister,\n private readonly externalRegistry: ExternalRegistryPolicyValidator,\n private readonly dependencyReachability: DependencyReachabilityValidator,\n private readonly aggregator: RegistryToolsAggregator,\n ) {}\n\n async validateRegistry(): Promise<Result<RegistryValidationReport>> {\n const namesResult = await this.lister.listPackageNames();\n if (!namesResult.ok) {\n return namesResult;\n }\n return this.validatePackages(namesResult.value);\n }\n\n async validatePackages(packageNames: readonly PackageName[]): Promise<Result<RegistryValidationReport>> {\n const reports: PackageValidationReport[] = [];\n const overall = new DiagnosticBag();\n\n for (const name of packageNames) {\n const report = await this.validateSinglePackage(name);\n reports.push(report);\n overall.mergeArray(report.diagnostics);\n }\n\n return ok(\n {\n packageReports: reports,\n diagnostics: overall.all(),\n },\n overall.all(),\n );\n }\n\n async validateSinglePackage(packageName: PackageName): Promise<PackageValidationReport> {\n const manifestPath = this.store.resolveManifestPath(packageName);\n const bag = new DiagnosticBag();\n\n const read = await this.store.read(packageName);\n if (!read.ok) {\n bag.mergeArray(read.diagnostics);\n return { packageName, manifestPath, diagnostics: bag.all() };\n }\n\n const manifest = read.value;\n\n // Path/name mismatch\n if (manifest.name !== packageName) {\n const expected = this.paths.manifestPath(manifest.name);\n const actual = manifestPath;\n const diag = createRegistryToolsPathMismatchDiagnostic(packageName, expected, actual);\n bag.add(diag);\n this.aggregator.add(diag);\n }\n\n // Version sort order\n if (this.policy.requireSortedVersions) {\n this.checkVersionsSorted(bag, manifest);\n }\n\n // External registry policy\n const ext = this.externalRegistry.validate(manifest);\n bag.mergeArray(ext.diagnostics);\n\n // Dependency reachability per version\n for (const [version, entry] of Object.entries(manifest.versions)) {\n if (!entry) continue;\n const dep = await this.dependencyReachability.validate(packageName, version as PackageVersion, entry);\n bag.mergeArray(dep.diagnostics);\n }\n\n return { packageName, manifestPath, diagnostics: bag.all() };\n }\n\n private checkVersionsSorted(bag: DiagnosticBag, manifest: PackageRegistryManifest): void {\n const actual = Object.keys(manifest.versions);\n const expected = sortVersionsNewestFirst(actual);\n const isSorted = actual.length === expected.length && actual.every((v, i) => v === expected[i]);\n if (!isSorted) {\n const diag = createRegistryToolsVersionsUnsortedDiagnostic(manifest.name, actual, expected);\n bag.add(diag);\n this.aggregator.add(diag);\n }\n }\n}\n"],"mappings":";;;;;;;;;AA2BA,IAAa,oBAAb,MAA+B;CAEV;CACA;CACA;CACA;CACA;CACA;CACA;CAPnB,YACE,AAAiB,QACjB,AAAiB,OACjB,AAAiB,OACjB,AAAi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AQ,GAAG;GAChE,IAAI,CAAC,OAAO;GACZ,MAAM,MAAM,MAAM,KAAK,uBAAuB,SAAS,aAAa,SAA2B,KAAK;GACpG,IAAI,WAAW,IAAI,WAAW;EAChC;EAEA,OAAO;GAAE;GAAa;GAAc,aAAa,IAAI,IAAI;EAAE;CAC7D;CAEA,AAAQ,oBAAoB,KAAoB,UAAyC;EACvF,MAAM,SAAS,OAAO,KAAK,SAAS,QAAQ;EAC5C,MAAM,WAAW,wBAAwB,MAAM;EAE/C,IAAI,EADa,OAAO,WAAW,SAAS,UAAU,OAAO,OAAO,GAAG,MAAM,MAAM,SAAS,EAAE,IAC/E;GACb,MAAM,OAAO,8CAA8C,SAAS,MAAM,QAAQ,QAAQ;GAC1F,IAAI,IAAI,IAAI;GACZ,KAAK,WAAW,IAAI,IAAI;EAC1B;CACF;AACF"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { RegistryToolsAggregator } from "../aggregator/RegistryToolsAggregator.js";
|
|
2
|
+
import { ReleaseFileNameReport } from "../contracts/RegistryToolsTypes.js";
|
|
3
|
+
import { Result } from "@uapkg/diagnostics";
|
|
4
|
+
import { PackageName, PackageVersion } from "@uapkg/common-schema";
|
|
5
|
+
//#region src/validation/ReleaseFileNameValidator.d.ts
|
|
5
6
|
/**
|
|
6
7
|
* Validates that release file names follow one of the accepted shapes.
|
|
7
8
|
*
|
|
@@ -10,10 +11,12 @@ import type { ReleaseFileNameReport } from '../contracts/RegistryToolsTypes.js';
|
|
|
10
11
|
* - `${packageName}.tgz`
|
|
11
12
|
* - `${packageName}@${version}.tgz`
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
declare class ReleaseFileNameValidator {
|
|
15
|
+
private readonly aggregator;
|
|
16
|
+
constructor(aggregator: RegistryToolsAggregator);
|
|
17
|
+
validate(packageName: PackageName, version: PackageVersion, fileNames: readonly string[]): Result<ReleaseFileNameReport>;
|
|
18
|
+
acceptedNames(packageName: PackageName, version: PackageVersion): readonly string[];
|
|
18
19
|
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ReleaseFileNameValidator };
|
|
19
22
|
//# sourceMappingURL=ReleaseFileNameValidator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReleaseFileNameValidator.d.ts","
|
|
1
|
+
{"version":3,"file":"ReleaseFileNameValidator.d.ts","names":[],"sources":["../../src/validation/ReleaseFileNameValidator.ts"],"mappings":";;;;;;;;;;;;;cAaa;mBACkB;EAA7B,YAA6B,YAAY;EAEzC,SACE,aAAa,aACb,SAAS,gBACT,+BACC,OAAO;EAeV,cAAc,aAAa,aAAa,SAAS"}
|
|
@@ -1,31 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DiagnosticBag, createRegistryToolsReleaseFileNameInvalidDiagnostic } from "@uapkg/diagnostics";
|
|
2
|
+
|
|
3
|
+
//#region src/validation/ReleaseFileNameValidator.ts
|
|
2
4
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
* Validates that release file names follow one of the accepted shapes.
|
|
6
|
+
*
|
|
7
|
+
* Accepted file names for `{packageName}@{version}`:
|
|
8
|
+
* - `package.tgz`
|
|
9
|
+
* - `${packageName}.tgz`
|
|
10
|
+
* - `${packageName}@${version}.tgz`
|
|
11
|
+
*/
|
|
12
|
+
var ReleaseFileNameValidator = class {
|
|
13
|
+
aggregator;
|
|
14
|
+
constructor(aggregator) {
|
|
15
|
+
this.aggregator = aggregator;
|
|
16
|
+
}
|
|
17
|
+
validate(packageName, version, fileNames) {
|
|
18
|
+
const bag = new DiagnosticBag();
|
|
19
|
+
const accepted = this.acceptedNames(packageName, version);
|
|
20
|
+
for (const name of fileNames) if (!accepted.includes(name)) {
|
|
21
|
+
const diag = createRegistryToolsReleaseFileNameInvalidDiagnostic(packageName, version, name, accepted);
|
|
22
|
+
bag.add(diag);
|
|
23
|
+
this.aggregator.add(diag);
|
|
24
|
+
}
|
|
25
|
+
return bag.toResult({ diagnostics: bag.all() });
|
|
26
|
+
}
|
|
27
|
+
acceptedNames(packageName, version) {
|
|
28
|
+
return [
|
|
29
|
+
"package.tgz",
|
|
30
|
+
`${packageName}.tgz`,
|
|
31
|
+
`${packageName}@${version}.tgz`
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { ReleaseFileNameValidator };
|
|
31
38
|
//# sourceMappingURL=ReleaseFileNameValidator.js.map
|