@webpieces/nx-webpieces-rules 0.4.1009 → 0.4.1011
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/README.md +32 -0
- package/package.json +9 -7
- package/src/configs/dependency-policy-config.d.ts +20 -0
- package/src/configs/dependency-policy-config.js +36 -0
- package/src/configs/dependency-policy-config.js.map +1 -0
- package/src/executors/validate-versions-locked/executor.d.ts +2 -1
- package/src/executors/validate-versions-locked/executor.js +42 -253
- package/src/executors/validate-versions-locked/executor.js.map +1 -1
- package/src/lib/dependency-imports.d.ts +14 -0
- package/src/lib/dependency-imports.js +113 -0
- package/src/lib/dependency-imports.js.map +1 -0
- package/src/lib/dependency-policies.d.ts +35 -0
- package/src/lib/dependency-policies.js +271 -0
- package/src/lib/dependency-policies.js.map +1 -0
- package/src/lib/dependency-workspace.d.ts +33 -0
- package/src/lib/dependency-workspace.js +109 -0
- package/src/lib/dependency-workspace.js.map +1 -0
- package/src/native-actions.d.ts +1 -0
- package/src/native-actions.js +4 -0
- package/src/native-actions.js.map +1 -1
- package/src/nx-policy-registry.js +4 -0
- package/src/nx-policy-registry.js.map +1 -1
- package/src/rule-help.js +5 -2
- package/src/rule-help.js.map +1 -1
- package/src/rule-settings.js +161 -204
- package/src/rule-settings.js.map +1 -1
- package/src/validation-targets.js +11 -1
- package/src/validation-targets.js.map +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DependencyImports = exports.DependencyImport = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
6
|
+
const node_module_1 = require("node:module");
|
|
7
|
+
class DependencyImport {
|
|
8
|
+
specifier;
|
|
9
|
+
line;
|
|
10
|
+
runtime;
|
|
11
|
+
unresolved;
|
|
12
|
+
constructor(specifier, line, runtime, unresolved = '') {
|
|
13
|
+
this.specifier = specifier;
|
|
14
|
+
this.line = line;
|
|
15
|
+
this.runtime = runtime;
|
|
16
|
+
this.unresolved = unresolved;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DependencyImport = DependencyImport;
|
|
20
|
+
/** Parse syntax, including createRequire aliases; prose and relative imports are not packages. */
|
|
21
|
+
class DependencyImports {
|
|
22
|
+
read(text, file) {
|
|
23
|
+
const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
|
|
24
|
+
if (source.isDeclarationFile)
|
|
25
|
+
return this.specifiers(source).map((entry) => new DependencyImport(entry.specifier, entry.line, false, entry.unresolved));
|
|
26
|
+
const emitted = ts.transpileModule(text, {
|
|
27
|
+
fileName: file,
|
|
28
|
+
compilerOptions: {
|
|
29
|
+
module: ts.ModuleKind.ESNext,
|
|
30
|
+
target: ts.ScriptTarget.ES2022,
|
|
31
|
+
experimentalDecorators: true,
|
|
32
|
+
emitDecoratorMetadata: true,
|
|
33
|
+
importHelpers: true,
|
|
34
|
+
},
|
|
35
|
+
}).outputText;
|
|
36
|
+
const runtime = new Set(this.specifiers(ts.createSourceFile(file, emitted, ts.ScriptTarget.Latest, true)).map((entry) => entry.specifier));
|
|
37
|
+
const entries = this.specifiers(source).map((entry) => new DependencyImport(entry.specifier, entry.line, runtime.has(entry.specifier), entry.unresolved));
|
|
38
|
+
if (runtime.has('tslib') &&
|
|
39
|
+
!entries.some((entry) => entry.specifier === 'tslib'))
|
|
40
|
+
entries.push(new DependencyImport('tslib', 1, true));
|
|
41
|
+
return entries;
|
|
42
|
+
}
|
|
43
|
+
packageName(specifier) {
|
|
44
|
+
if (!specifier ||
|
|
45
|
+
/^[./#]/u.test(specifier) ||
|
|
46
|
+
(0, node_module_1.isBuiltin)(specifier) ||
|
|
47
|
+
/^[a-z]+:/iu.test(specifier))
|
|
48
|
+
return undefined;
|
|
49
|
+
return specifier.startsWith('@')
|
|
50
|
+
? specifier.split('/').slice(0, 2).join('/')
|
|
51
|
+
: specifier.split('/')[0];
|
|
52
|
+
}
|
|
53
|
+
collectAliases(source, aliases, artifactAliases) {
|
|
54
|
+
const collect = (node) => {
|
|
55
|
+
if (ts.isVariableDeclaration(node) &&
|
|
56
|
+
ts.isIdentifier(node.name) &&
|
|
57
|
+
node.initializer &&
|
|
58
|
+
ts.isCallExpression(node.initializer) &&
|
|
59
|
+
/(?:^|\.)createRequire$/u.test(node.initializer.expression.getText(source))) {
|
|
60
|
+
const anchor = node.initializer.arguments[0]?.getText(source);
|
|
61
|
+
if (anchor === 'import.meta.url' || anchor === '__filename')
|
|
62
|
+
aliases.add(node.name.text);
|
|
63
|
+
else
|
|
64
|
+
artifactAliases.add(node.name.text);
|
|
65
|
+
}
|
|
66
|
+
ts.forEachChild(node, collect);
|
|
67
|
+
};
|
|
68
|
+
collect(source);
|
|
69
|
+
}
|
|
70
|
+
specifiers(source) {
|
|
71
|
+
const result = [];
|
|
72
|
+
const aliases = new Set(['require']);
|
|
73
|
+
const artifactAliases = new Set();
|
|
74
|
+
this.collectAliases(source, aliases, artifactAliases);
|
|
75
|
+
const add = (node) => {
|
|
76
|
+
if (!node)
|
|
77
|
+
return;
|
|
78
|
+
if (!ts.isStringLiteralLike(node)) {
|
|
79
|
+
result.push(new DependencyImport('', source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1, false, node.getText(source)));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
result.push(new DependencyImport(node.text, source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1, true));
|
|
83
|
+
};
|
|
84
|
+
const visit = (node) => {
|
|
85
|
+
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node))
|
|
86
|
+
add(node.moduleSpecifier);
|
|
87
|
+
else if (ts.isImportEqualsDeclaration(node) &&
|
|
88
|
+
ts.isExternalModuleReference(node.moduleReference))
|
|
89
|
+
add(node.moduleReference.expression);
|
|
90
|
+
else if (ts.isImportTypeNode(node) && ts.isLiteralTypeNode(node.argument))
|
|
91
|
+
add(node.argument.literal);
|
|
92
|
+
else if (ts.isCallExpression(node)) {
|
|
93
|
+
if (ts.isIdentifier(node.expression) && artifactAliases.has(node.expression.text)) {
|
|
94
|
+
result.push(new DependencyImport('', source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1, false, `artifact-anchored createRequire: ${node.getText(source)}`));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (node.expression.kind === ts.SyntaxKind.ImportKeyword ||
|
|
98
|
+
(ts.isIdentifier(node.expression) && aliases.has(node.expression.text)))
|
|
99
|
+
add(node.arguments[0]);
|
|
100
|
+
else if (ts.isPropertyAccessExpression(node.expression) &&
|
|
101
|
+
node.expression.name.text === 'resolve' &&
|
|
102
|
+
ts.isIdentifier(node.expression.expression) &&
|
|
103
|
+
aliases.has(node.expression.expression.text))
|
|
104
|
+
add(node.arguments[0]);
|
|
105
|
+
}
|
|
106
|
+
ts.forEachChild(node, visit);
|
|
107
|
+
};
|
|
108
|
+
visit(source);
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.DependencyImports = DependencyImports;
|
|
113
|
+
//# sourceMappingURL=dependency-imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependency-imports.js","sourceRoot":"","sources":["../../../../../../packages/tooling/nx-webpieces-rules/src/lib/dependency-imports.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,6CAAwC;AAExC,MAAa,gBAAgB;IAEZ;IACA;IACA;IACA;IAJb,YACa,SAAiB,EACjB,IAAY,EACZ,OAAgB,EAChB,aAAqB,EAAE;QAHvB,cAAS,GAAT,SAAS,CAAQ;QACjB,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAS;QAChB,eAAU,GAAV,UAAU,CAAa;IACjC,CAAC;CACP;AAPD,4CAOC;AAED,kGAAkG;AAClG,MAAa,iBAAiB;IAC1B,IAAI,CAAC,IAAY,EAAE,IAAY;QAC3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,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;qBACtB,IACD,EAAE,CAAC,0BAA0B,CAAC,IAAI,CAAC,UAAU,CAAC;oBAC9C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS;oBACvC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;oBAC3C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC;oBAE5C,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/B,CAAC;YACD,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC,CAAC;QACF,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AA9ID,8CA8IC","sourcesContent":["import * as ts from 'typescript';\nimport { isBuiltin } from 'node:module';\n\nexport class DependencyImport {\n constructor(\n readonly specifier: string,\n readonly line: number,\n readonly runtime: boolean,\n readonly unresolved: string = '',\n ) {}\n}\n\n/** Parse syntax, including createRequire aliases; prose and relative imports are not packages. */\nexport class DependencyImports {\n read(text: string, file: string): DependencyImport[] {\n const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);\n if (source.isDeclarationFile)\n return this.specifiers(source).map(\n (entry: DependencyImport) =>\n new DependencyImport(entry.specifier, entry.line, false, entry.unresolved),\n );\n const emitted = ts.transpileModule(text, {\n fileName: file,\n compilerOptions: {\n module: ts.ModuleKind.ESNext,\n target: ts.ScriptTarget.ES2022,\n experimentalDecorators: true,\n emitDecoratorMetadata: true,\n importHelpers: true,\n },\n }).outputText;\n const runtime = new Set(\n this.specifiers(ts.createSourceFile(file, emitted, ts.ScriptTarget.Latest, true)).map(\n (entry: DependencyImport) => entry.specifier,\n ),\n );\n const entries = this.specifiers(source).map(\n (entry: DependencyImport) =>\n new DependencyImport(\n entry.specifier,\n entry.line,\n runtime.has(entry.specifier),\n entry.unresolved,\n ),\n );\n if (\n runtime.has('tslib') &&\n !entries.some((entry: DependencyImport) => entry.specifier === 'tslib')\n )\n entries.push(new DependencyImport('tslib', 1, true));\n return entries;\n }\n\n packageName(specifier: string): string | undefined {\n if (\n !specifier ||\n /^[./#]/u.test(specifier) ||\n isBuiltin(specifier) ||\n /^[a-z]+:/iu.test(specifier)\n )\n return undefined;\n return specifier.startsWith('@')\n ? specifier.split('/').slice(0, 2).join('/')\n : specifier.split('/')[0];\n }\n\n private collectAliases(\n source: ts.SourceFile,\n aliases: Set<string>,\n artifactAliases: Set<string>,\n ): void {\n const collect = (node: ts.Node): void => {\n if (\n ts.isVariableDeclaration(node) &&\n ts.isIdentifier(node.name) &&\n node.initializer &&\n ts.isCallExpression(node.initializer) &&\n /(?:^|\\.)createRequire$/u.test(node.initializer.expression.getText(source))\n ) {\n const anchor = node.initializer.arguments[0]?.getText(source);\n if (anchor === 'import.meta.url' || anchor === '__filename')\n aliases.add(node.name.text);\n else artifactAliases.add(node.name.text);\n }\n ts.forEachChild(node, collect);\n };\n collect(source);\n }\n\n private specifiers(source: ts.SourceFile): DependencyImport[] {\n const result: DependencyImport[] = [];\n const aliases = new Set(['require']);\n const artifactAliases = new Set<string>();\n this.collectAliases(source, aliases, artifactAliases);\n const add = (node: ts.Node | undefined): void => {\n if (!node) return;\n if (!ts.isStringLiteralLike(node)) {\n result.push(\n new DependencyImport(\n '',\n source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,\n false,\n node.getText(source),\n ),\n );\n return;\n }\n result.push(\n new DependencyImport(\n node.text,\n source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,\n true,\n ),\n );\n };\n const visit = (node: ts.Node): void => {\n if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node))\n add(node.moduleSpecifier);\n else if (\n ts.isImportEqualsDeclaration(node) &&\n ts.isExternalModuleReference(node.moduleReference)\n )\n add(node.moduleReference.expression);\n else if (ts.isImportTypeNode(node) && ts.isLiteralTypeNode(node.argument))\n add(node.argument.literal);\n else if (ts.isCallExpression(node)) {\n if (ts.isIdentifier(node.expression) && artifactAliases.has(node.expression.text)) {\n result.push(\n new DependencyImport(\n '',\n source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,\n false,\n `artifact-anchored createRequire: ${node.getText(source)}`,\n ),\n );\n return;\n }\n if (\n node.expression.kind === ts.SyntaxKind.ImportKeyword ||\n (ts.isIdentifier(node.expression) && aliases.has(node.expression.text))\n )\n add(node.arguments[0]);\n else if (\n ts.isPropertyAccessExpression(node.expression) &&\n node.expression.name.text === 'resolve' &&\n ts.isIdentifier(node.expression.expression) &&\n aliases.has(node.expression.expression.text)\n )\n add(node.arguments[0]);\n }\n ts.forEachChild(node, visit);\n };\n visit(source);\n return result;\n }\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BuildPolicyResult } from '@webpieces/rules-sdk';
|
|
2
|
+
export declare class DependencyVersion {
|
|
3
|
+
isExact(version: string): boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare class DependencyPolicyOptions {
|
|
6
|
+
readonly catalog: boolean;
|
|
7
|
+
readonly freeze: boolean;
|
|
8
|
+
readonly ownership: boolean;
|
|
9
|
+
readonly allowedNames: string[];
|
|
10
|
+
readonly rootToolPaths: string[];
|
|
11
|
+
readonly testPaths: string[];
|
|
12
|
+
readonly artifactProbePaths: string[];
|
|
13
|
+
readonly toolProviders: string[];
|
|
14
|
+
readonly dynamicImports: string[];
|
|
15
|
+
constructor(catalog: boolean, freeze: boolean, ownership: boolean, allowedNames: string[], rootToolPaths: string[], testPaths: string[], artifactProbePaths: string[], toolProviders: string[], dynamicImports: string[]);
|
|
16
|
+
}
|
|
17
|
+
/** The public workspace feature: declarations, catalogue, and source ownership share one scan. */
|
|
18
|
+
export declare class DependencyPolicies {
|
|
19
|
+
private readonly imports;
|
|
20
|
+
private readonly version;
|
|
21
|
+
private readonly aliases;
|
|
22
|
+
validate(root: string, options: DependencyPolicyOptions): string[];
|
|
23
|
+
enforce(root: string, options: DependencyPolicyOptions): BuildPolicyResult;
|
|
24
|
+
private catalog;
|
|
25
|
+
private freeze;
|
|
26
|
+
private ownership;
|
|
27
|
+
private dynamic;
|
|
28
|
+
private assets;
|
|
29
|
+
private declaration;
|
|
30
|
+
private provided;
|
|
31
|
+
private name;
|
|
32
|
+
}
|
|
33
|
+
export declare class ConfiguredDependencyPolicies {
|
|
34
|
+
run(root: string): BuildPolicyResult;
|
|
35
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfiguredDependencyPolicies = exports.DependencyPolicies = exports.DependencyPolicyOptions = exports.DependencyVersion = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs = tslib_1.__importStar(require("node:fs"));
|
|
6
|
+
const path = tslib_1.__importStar(require("node:path"));
|
|
7
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
8
|
+
const rules_sdk_1 = require("@webpieces/rules-sdk");
|
|
9
|
+
const dependency_workspace_1 = require("./dependency-workspace");
|
|
10
|
+
const dependency_imports_1 = require("./dependency-imports");
|
|
11
|
+
const rule_gate_1 = require("./rule-gate");
|
|
12
|
+
const SECTIONS = [
|
|
13
|
+
'dependencies',
|
|
14
|
+
'devDependencies',
|
|
15
|
+
'optionalDependencies',
|
|
16
|
+
'peerDependencies',
|
|
17
|
+
];
|
|
18
|
+
const EXACT = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u;
|
|
19
|
+
class CompilerAliases {
|
|
20
|
+
paths;
|
|
21
|
+
}
|
|
22
|
+
class AliasFile {
|
|
23
|
+
compilerOptions;
|
|
24
|
+
}
|
|
25
|
+
class StyleAsset {
|
|
26
|
+
input;
|
|
27
|
+
}
|
|
28
|
+
class BuildAssets {
|
|
29
|
+
styles;
|
|
30
|
+
polyfills;
|
|
31
|
+
}
|
|
32
|
+
class BuildTarget {
|
|
33
|
+
options;
|
|
34
|
+
}
|
|
35
|
+
class ProjectAssets {
|
|
36
|
+
targets;
|
|
37
|
+
}
|
|
38
|
+
class DependencyVersion {
|
|
39
|
+
isExact(version) {
|
|
40
|
+
return EXACT.test(version);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.DependencyVersion = DependencyVersion;
|
|
44
|
+
class DependencyPolicyOptions {
|
|
45
|
+
catalog;
|
|
46
|
+
freeze;
|
|
47
|
+
ownership;
|
|
48
|
+
allowedNames;
|
|
49
|
+
rootToolPaths;
|
|
50
|
+
testPaths;
|
|
51
|
+
artifactProbePaths;
|
|
52
|
+
toolProviders;
|
|
53
|
+
dynamicImports;
|
|
54
|
+
// Every choice is supplied by the owning repository, never defaulted by a rule.
|
|
55
|
+
constructor(catalog, freeze, ownership, allowedNames, rootToolPaths, testPaths, artifactProbePaths, toolProviders, dynamicImports) {
|
|
56
|
+
this.catalog = catalog;
|
|
57
|
+
this.freeze = freeze;
|
|
58
|
+
this.ownership = ownership;
|
|
59
|
+
this.allowedNames = allowedNames;
|
|
60
|
+
this.rootToolPaths = rootToolPaths;
|
|
61
|
+
this.testPaths = testPaths;
|
|
62
|
+
this.artifactProbePaths = artifactProbePaths;
|
|
63
|
+
this.toolProviders = toolProviders;
|
|
64
|
+
this.dynamicImports = dynamicImports;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.DependencyPolicyOptions = DependencyPolicyOptions;
|
|
68
|
+
/** The public workspace feature: declarations, catalogue, and source ownership share one scan. */
|
|
69
|
+
class DependencyPolicies {
|
|
70
|
+
imports = new dependency_imports_1.DependencyImports();
|
|
71
|
+
version = new DependencyVersion();
|
|
72
|
+
aliases = new Map();
|
|
73
|
+
validate(root, options) {
|
|
74
|
+
const workspace = new dependency_workspace_1.DependencyWorkspace(root);
|
|
75
|
+
const errors = [];
|
|
76
|
+
const catalogue = [];
|
|
77
|
+
const freeze = [];
|
|
78
|
+
const ownership = [];
|
|
79
|
+
if (options.catalog)
|
|
80
|
+
this.catalog(workspace, catalogue);
|
|
81
|
+
if (options.freeze)
|
|
82
|
+
this.freeze(workspace, options, freeze);
|
|
83
|
+
if (options.ownership)
|
|
84
|
+
this.ownership(workspace, options, ownership);
|
|
85
|
+
errors.push(...catalogue.map((message) => `[dependency-catalog] ${message}`));
|
|
86
|
+
errors.push(...freeze.map((message) => `[root-runtime-freeze] ${message}`));
|
|
87
|
+
errors.push(...ownership.map((message) => `[dependency-ownership] ${message}`));
|
|
88
|
+
return [...new Set(errors)].sort();
|
|
89
|
+
}
|
|
90
|
+
enforce(root, options) {
|
|
91
|
+
const errors = this.validate(root, options);
|
|
92
|
+
if (errors.length) {
|
|
93
|
+
const firstRule = errors[0].slice(1, errors[0].indexOf(']'));
|
|
94
|
+
throw new rules_config_1.RuleFailError(firstRule, errors.join('\n'), undefined, undefined, [
|
|
95
|
+
new rules_config_1.Option('Repair each named importing owner or reviewed policy entry; keep runtime names local and direct versions in the catalogue', true),
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
return new rules_sdk_1.BuildPolicyResult(true);
|
|
99
|
+
}
|
|
100
|
+
catalog(workspace, errors) {
|
|
101
|
+
const owners = [new dependency_workspace_1.DependencyOwner('.', workspace.rootManifest), ...workspace.owners];
|
|
102
|
+
for (const owner of owners) {
|
|
103
|
+
if (!owner.manifest)
|
|
104
|
+
continue;
|
|
105
|
+
for (const section of SECTIONS) {
|
|
106
|
+
for (const declaration of Object.entries(owner.manifest[section] ?? {})) {
|
|
107
|
+
const name = declaration[0];
|
|
108
|
+
const specifier = declaration[1];
|
|
109
|
+
const where = `${owner.directory}/package.json ${section}.${name}`;
|
|
110
|
+
if (specifier === 'workspace:*') {
|
|
111
|
+
if (!workspace.owners.some((entry) => entry.manifest?.name === name))
|
|
112
|
+
errors.push(`${where}: workspace:* must name a managed workspace owner`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (!specifier.startsWith('catalog:')) {
|
|
116
|
+
errors.push(`${where}: use catalog: with an exact centrally owned version (found ${specifier})`);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const catalogName = specifier.slice('catalog:'.length);
|
|
120
|
+
const pins = catalogName
|
|
121
|
+
? workspace.catalog.catalogs?.[catalogName]
|
|
122
|
+
: workspace.catalog.catalog;
|
|
123
|
+
const pin = pins?.[name];
|
|
124
|
+
if (typeof pin !== 'string' || !this.version.isExact(pin))
|
|
125
|
+
errors.push(`${where}: ${specifier} must resolve to an exact version in pnpm-workspace.yaml (found ${String(pin)})`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
freeze(workspace, options, errors) {
|
|
131
|
+
for (const section of [
|
|
132
|
+
'dependencies',
|
|
133
|
+
'optionalDependencies',
|
|
134
|
+
'peerDependencies',
|
|
135
|
+
]) {
|
|
136
|
+
for (const name of Object.keys(workspace.rootManifest[section] ?? {})) {
|
|
137
|
+
if (!options.allowedNames.includes(name))
|
|
138
|
+
errors.push(`package.json ${section}.${name}: new root runtime name; declare it in the consuming module instead, or review the committed root-runtime-freeze baseline`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
ownership(workspace, options, errors) {
|
|
143
|
+
for (const file of workspace.files) {
|
|
144
|
+
if (file.endsWith('/project.json'))
|
|
145
|
+
this.assets(workspace, options, file, errors);
|
|
146
|
+
if (!/\.[cm]?[jt]sx?$/u.test(file))
|
|
147
|
+
continue;
|
|
148
|
+
if (workspace.matches(file, options.artifactProbePaths))
|
|
149
|
+
continue;
|
|
150
|
+
const owner = workspace.owner(file);
|
|
151
|
+
const isTool = workspace.matches(file, options.rootToolPaths);
|
|
152
|
+
const text = fs.readFileSync(path.join(workspace.root, file), 'utf8');
|
|
153
|
+
for (const entry of this.imports.read(text, file)) {
|
|
154
|
+
if (entry.unresolved) {
|
|
155
|
+
this.dynamic(workspace, options, owner, file, entry, isTool, errors);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
this.declaration(workspace, options, owner, file, entry, isTool, errors);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
dynamic(workspace, options, owner, file, entry, isTool, errors) {
|
|
163
|
+
const expression = entry.unresolved.replace(/\s+/gu, ' ').trim();
|
|
164
|
+
const key = `${file}::${expression}::`;
|
|
165
|
+
const reviewed = options.dynamicImports.find((item) => item.startsWith(key));
|
|
166
|
+
if (reviewed === undefined) {
|
|
167
|
+
errors.push(`${file}:${entry.line}: unclassified dependency expression ${expression}; review its actual package names and declare the exact file::expression::package-list mapping in dependency-ownership.dynamicImports (empty package-list only for a verified local/artifact expression)`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
for (const specifier of reviewed.slice(key.length).split(',').filter(Boolean))
|
|
171
|
+
this.declaration(workspace, options, owner, file, new dependency_imports_1.DependencyImport(specifier, entry.line, entry.runtime), isTool, errors);
|
|
172
|
+
}
|
|
173
|
+
assets(workspace, options, file, errors) {
|
|
174
|
+
const project = JSON.parse(fs.readFileSync(path.join(workspace.root, file), 'utf8'));
|
|
175
|
+
const build = project.targets?.['build']?.options;
|
|
176
|
+
const names = [...(build?.polyfills ?? [])];
|
|
177
|
+
for (const asset of build?.styles ?? []) {
|
|
178
|
+
const input = typeof asset === 'string' ? asset : asset.input;
|
|
179
|
+
if (input?.startsWith('node_modules/'))
|
|
180
|
+
names.push(input.slice('node_modules/'.length));
|
|
181
|
+
}
|
|
182
|
+
for (const name of names)
|
|
183
|
+
this.declaration(workspace, options, workspace.owner(file), file, new dependency_imports_1.DependencyImport(name, 1, true), false, errors);
|
|
184
|
+
}
|
|
185
|
+
declaration(workspace, options, owner, file, entry, isTool, errors) {
|
|
186
|
+
const name = this.name(workspace, owner, entry.specifier);
|
|
187
|
+
if (!name || name === owner.manifest?.name)
|
|
188
|
+
return;
|
|
189
|
+
if (isTool &&
|
|
190
|
+
(owner.manifest?.dependencies?.[name] ||
|
|
191
|
+
owner.manifest?.devDependencies?.[name] ||
|
|
192
|
+
owner.manifest?.optionalDependencies?.[name] ||
|
|
193
|
+
owner.manifest?.peerDependencies?.[name]))
|
|
194
|
+
return;
|
|
195
|
+
const declared = isTool ? workspace.rootManifest : owner.manifest;
|
|
196
|
+
if (!declared) {
|
|
197
|
+
errors.push(`${file}:${entry.line}: ${entry.specifier} has no importing manifest; create an owner manifest or explicitly classify this tool file`);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const isTest = workspace.matches(file, options.testPaths) ||
|
|
201
|
+
/(?:^|\/)(?:tests?|__tests__|__mocks__|__fixtures__|e2e)(?:\/|$)|\.(?:spec|test|spec-support|test-support)\.[cm]?[jt]sx?$/u.test(file);
|
|
202
|
+
const publicDeclaration = Boolean(owner.manifest?.types && owner.manifest.private !== true);
|
|
203
|
+
const runtime = (entry.runtime || publicDeclaration) && !isTest && !isTool;
|
|
204
|
+
const present = declared.dependencies?.[name] ||
|
|
205
|
+
declared.optionalDependencies?.[name] ||
|
|
206
|
+
declared.peerDependencies?.[name] ||
|
|
207
|
+
(!runtime && declared.devDependencies?.[name]);
|
|
208
|
+
if (present || (isTool && this.provided(declared, options.toolProviders, name)))
|
|
209
|
+
return;
|
|
210
|
+
const section = runtime ? 'dependencies' : 'devDependencies';
|
|
211
|
+
errors.push(`${file}:${entry.line}: ${name} must be declared in ${isTool ? '.' : owner.directory}/package.json ${section}; root/other-owner hoisting cannot satisfy this import`);
|
|
212
|
+
}
|
|
213
|
+
provided(manifest, providers, name) {
|
|
214
|
+
return providers.some((entry) => {
|
|
215
|
+
const separator = entry.indexOf('=');
|
|
216
|
+
return (separator > 0 &&
|
|
217
|
+
entry.slice(0, separator) === name &&
|
|
218
|
+
Boolean(manifest.devDependencies?.[entry.slice(separator + 1)]));
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
name(workspace, owner, specifier) {
|
|
222
|
+
const raw = this.imports.packageName(specifier);
|
|
223
|
+
if (!raw)
|
|
224
|
+
return undefined;
|
|
225
|
+
if (specifier.startsWith('app/') && owner.directory.startsWith('services/'))
|
|
226
|
+
return owner.manifest?.name;
|
|
227
|
+
const config = path.join(workspace.root, 'tsconfig.base.json');
|
|
228
|
+
if (!fs.existsSync(config))
|
|
229
|
+
return raw;
|
|
230
|
+
let json = this.aliases.get(workspace.root);
|
|
231
|
+
if (!json) {
|
|
232
|
+
json = JSON.parse(fs.readFileSync(config, 'utf8'));
|
|
233
|
+
this.aliases.set(workspace.root, json);
|
|
234
|
+
}
|
|
235
|
+
for (const mapping of Object.entries(json.compilerOptions?.paths ?? {})) {
|
|
236
|
+
const alias = mapping[0];
|
|
237
|
+
const targets = mapping[1];
|
|
238
|
+
const prefix = alias.endsWith('*') ? alias.slice(0, -1) : alias;
|
|
239
|
+
if (alias.endsWith('*') ? specifier.startsWith(prefix) : specifier === alias) {
|
|
240
|
+
const target = targets[0]?.replace('*', specifier.slice(prefix.length));
|
|
241
|
+
if (target)
|
|
242
|
+
return workspace.owner(target).manifest?.name ?? raw;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return raw;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
exports.DependencyPolicies = DependencyPolicies;
|
|
249
|
+
class ConfiguredDependencyPolicies {
|
|
250
|
+
run(root) {
|
|
251
|
+
const rules = (0, rules_config_1.loadAndValidate)(root).resolved.rules;
|
|
252
|
+
const catalog = rules.get('dependency-catalog');
|
|
253
|
+
const freeze = rules.get('root-runtime-freeze');
|
|
254
|
+
const ownership = rules.get('dependency-ownership');
|
|
255
|
+
if (!catalog || !freeze || !ownership)
|
|
256
|
+
throw new rules_config_1.RuleFailError('dependency-catalog', 'Declare all three dependency policies in their owning pack', undefined, undefined, [
|
|
257
|
+
new rules_config_1.Option('Upgrade the owning rule pack and declare its explicit policy entries', true),
|
|
258
|
+
]);
|
|
259
|
+
const list = (rule, field) => {
|
|
260
|
+
const value = rule.options[field];
|
|
261
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== 'string'))
|
|
262
|
+
throw new rules_config_1.RuleFailError('dependency-ownership', `Explicit dependency policy field ${field} must be a string array`, undefined, undefined, [new rules_config_1.Option(`Set ${field} to an explicitly reviewed array of strings`, true)]);
|
|
263
|
+
return value;
|
|
264
|
+
};
|
|
265
|
+
const gate = new rule_gate_1.RuleGate();
|
|
266
|
+
const options = new DependencyPolicyOptions(!gate.isDisabled(root, 'dependency-catalog', true), !gate.isDisabled(root, 'root-runtime-freeze', true), !gate.isDisabled(root, 'dependency-ownership', true), list(freeze, 'allowedNames'), list(ownership, 'rootToolPaths'), list(ownership, 'testPaths'), list(ownership, 'artifactProbePaths'), list(ownership, 'toolProviders'), list(ownership, 'dynamicImports'));
|
|
267
|
+
return new DependencyPolicies().enforce(root, options);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.ConfiguredDependencyPolicies = ConfiguredDependencyPolicies;
|
|
271
|
+
//# sourceMappingURL=dependency-policies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependency-policies.js","sourceRoot":"","sources":["../../../../../../packages/tooling/nx-webpieces-rules/src/lib/dependency-policies.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,0DAAiF;AACjF,oDAAyD;AACzD,iEAAkG;AAClG,6DAA2E;AAC3E,2CAAuC;AAEvC,MAAM,QAAQ,GAAG;IACb,cAAc;IACd,iBAAiB;IACjB,sBAAsB;IACtB,kBAAkB;CACZ,CAAC;AACX,MAAM,KAAK,GACP,wLAAwL,CAAC;AAE7L,MAAM,eAAe;IACjB,KA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import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { loadAndValidate, RuleFailError, Option } from '@webpieces/rules-config';\nimport { BuildPolicyResult } from '@webpieces/rules-sdk';\nimport { DependencyWorkspace, DependencyOwner, DependencyManifest } from './dependency-workspace';\nimport { DependencyImports, DependencyImport } from './dependency-imports';\nimport { RuleGate } from './rule-gate';\n\nconst SECTIONS = [\n 'dependencies',\n 'devDependencies',\n 'optionalDependencies',\n 'peerDependencies',\n] as const;\nconst EXACT =\n /^(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:-(?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$/u;\n\nclass CompilerAliases {\n paths?: Record<string, string[]>;\n}\n\nclass AliasFile {\n compilerOptions?: CompilerAliases;\n}\n\nclass StyleAsset {\n input?: string;\n}\n\nclass BuildAssets {\n styles?: (string | StyleAsset)[];\n polyfills?: string[];\n}\n\nclass BuildTarget {\n options?: BuildAssets;\n}\n\nclass ProjectAssets {\n targets?: Record<string, BuildTarget>;\n}\n\nexport class DependencyVersion {\n isExact(version: string): boolean {\n return EXACT.test(version);\n }\n}\n\nexport class DependencyPolicyOptions {\n // Every choice is supplied by the owning repository, never defaulted by a rule.\n constructor(\n readonly catalog: boolean,\n readonly freeze: boolean,\n readonly ownership: boolean,\n readonly allowedNames: string[],\n readonly rootToolPaths: string[],\n readonly testPaths: string[],\n readonly artifactProbePaths: string[],\n readonly toolProviders: string[],\n readonly dynamicImports: string[],\n ) {}\n}\n\n/** The public workspace feature: declarations, catalogue, and source ownership share one scan. */\nexport class DependencyPolicies {\n private readonly imports = new DependencyImports();\n private readonly version = new DependencyVersion();\n private readonly aliases = new Map<string, AliasFile>();\n\n validate(root: string, options: DependencyPolicyOptions): string[] {\n const workspace = new DependencyWorkspace(root);\n const errors: string[] = [];\n const catalogue: string[] = [];\n const freeze: string[] = [];\n const ownership: string[] = [];\n if (options.catalog) this.catalog(workspace, catalogue);\n if (options.freeze) this.freeze(workspace, options, freeze);\n if (options.ownership) this.ownership(workspace, options, ownership);\n errors.push(...catalogue.map((message: string) => `[dependency-catalog] ${message}`));\n errors.push(...freeze.map((message: string) => `[root-runtime-freeze] ${message}`));\n errors.push(...ownership.map((message: string) => `[dependency-ownership] ${message}`));\n return [...new Set(errors)].sort();\n }\n\n enforce(root: string, options: DependencyPolicyOptions): BuildPolicyResult {\n const errors = this.validate(root, options);\n if (errors.length) {\n const firstRule = errors[0].slice(1, errors[0].indexOf(']'));\n throw new RuleFailError(firstRule, errors.join('\\n'), undefined, undefined, [\n new Option(\n 'Repair each named importing owner or reviewed policy entry; keep runtime names local and direct versions in the catalogue',\n true,\n ),\n ]);\n }\n return new BuildPolicyResult(true);\n }\n\n private catalog(workspace: DependencyWorkspace, errors: string[]): void {\n const owners = [new DependencyOwner('.', workspace.rootManifest), ...workspace.owners];\n for (const owner of owners) {\n if (!owner.manifest) continue;\n for (const section of SECTIONS) {\n for (const declaration of Object.entries(owner.manifest[section] ?? {})) {\n const name = declaration[0];\n const specifier = declaration[1];\n const where = `${owner.directory}/package.json ${section}.${name}`;\n if (specifier === 'workspace:*') {\n if (\n !workspace.owners.some(\n (entry: DependencyOwner) => entry.manifest?.name === name,\n )\n )\n errors.push(\n `${where}: workspace:* must name a managed workspace owner`,\n );\n continue;\n }\n if (!specifier.startsWith('catalog:')) {\n errors.push(\n `${where}: use catalog: with an exact centrally owned version (found ${specifier})`,\n );\n continue;\n }\n const catalogName = specifier.slice('catalog:'.length);\n const pins = catalogName\n ? workspace.catalog.catalogs?.[catalogName]\n : workspace.catalog.catalog;\n const pin = pins?.[name];\n if (typeof pin !== 'string' || !this.version.isExact(pin))\n errors.push(\n `${where}: ${specifier} must resolve to an exact version in pnpm-workspace.yaml (found ${String(pin)})`,\n );\n }\n }\n }\n }\n\n private freeze(\n workspace: DependencyWorkspace,\n options: DependencyPolicyOptions,\n errors: string[],\n ): void {\n for (const section of [\n 'dependencies',\n 'optionalDependencies',\n 'peerDependencies',\n ] as const) {\n for (const name of Object.keys(workspace.rootManifest[section] ?? {})) {\n if (!options.allowedNames.includes(name))\n errors.push(\n `package.json ${section}.${name}: new root runtime name; declare it in the consuming module instead, or review the committed root-runtime-freeze baseline`,\n );\n }\n }\n }\n\n private ownership(\n workspace: DependencyWorkspace,\n options: DependencyPolicyOptions,\n errors: string[],\n ): void {\n for (const file of workspace.files) {\n if (file.endsWith('/project.json')) this.assets(workspace, options, file, errors);\n if (!/\\.[cm]?[jt]sx?$/u.test(file)) continue;\n if (workspace.matches(file, options.artifactProbePaths)) continue;\n const owner = workspace.owner(file);\n const isTool = workspace.matches(file, options.rootToolPaths);\n const text = fs.readFileSync(path.join(workspace.root, file), 'utf8');\n for (const entry of this.imports.read(text, file)) {\n if (entry.unresolved) {\n this.dynamic(workspace, options, owner, file, entry, isTool, errors);\n continue;\n }\n this.declaration(workspace, options, owner, file, entry, isTool, errors);\n }\n }\n }\n\n private dynamic(\n workspace: DependencyWorkspace,\n options: DependencyPolicyOptions,\n owner: DependencyOwner,\n file: string,\n entry: DependencyImport,\n isTool: boolean,\n errors: string[],\n ): void {\n const expression = entry.unresolved.replace(/\\s+/gu, ' ').trim();\n const key = `${file}::${expression}::`;\n const reviewed = options.dynamicImports.find((item: string) => item.startsWith(key));\n if (reviewed === undefined) {\n errors.push(\n `${file}:${entry.line}: unclassified dependency expression ${expression}; review its actual package names and declare the exact file::expression::package-list mapping in dependency-ownership.dynamicImports (empty package-list only for a verified local/artifact expression)`,\n );\n return;\n }\n for (const specifier of reviewed.slice(key.length).split(',').filter(Boolean))\n this.declaration(\n workspace,\n options,\n owner,\n file,\n new DependencyImport(specifier, entry.line, entry.runtime),\n isTool,\n errors,\n );\n }\n\n private assets(\n workspace: DependencyWorkspace,\n options: DependencyPolicyOptions,\n file: string,\n errors: string[],\n ): void {\n const project = JSON.parse(\n fs.readFileSync(path.join(workspace.root, file), 'utf8'),\n ) as ProjectAssets;\n const build = project.targets?.['build']?.options;\n const names = [...(build?.polyfills ?? [])];\n for (const asset of build?.styles ?? []) {\n const input = typeof asset === 'string' ? asset : asset.input;\n if (input?.startsWith('node_modules/')) names.push(input.slice('node_modules/'.length));\n }\n for (const name of names)\n this.declaration(\n workspace,\n options,\n workspace.owner(file),\n file,\n new DependencyImport(name, 1, true),\n false,\n errors,\n );\n }\n\n private declaration(\n workspace: DependencyWorkspace,\n options: DependencyPolicyOptions,\n owner: DependencyOwner,\n file: string,\n entry: DependencyImport,\n isTool: boolean,\n errors: string[],\n ): void {\n const name = this.name(workspace, owner, entry.specifier);\n if (!name || name === owner.manifest?.name) return;\n if (\n isTool &&\n (owner.manifest?.dependencies?.[name] ||\n owner.manifest?.devDependencies?.[name] ||\n owner.manifest?.optionalDependencies?.[name] ||\n owner.manifest?.peerDependencies?.[name])\n )\n return;\n const declared = isTool ? workspace.rootManifest : owner.manifest;\n if (!declared) {\n errors.push(\n `${file}:${entry.line}: ${entry.specifier} has no importing manifest; create an owner manifest or explicitly classify this tool file`,\n );\n return;\n }\n const isTest =\n workspace.matches(file, options.testPaths) ||\n /(?:^|\\/)(?:tests?|__tests__|__mocks__|__fixtures__|e2e)(?:\\/|$)|\\.(?:spec|test|spec-support|test-support)\\.[cm]?[jt]sx?$/u.test(\n file,\n );\n const publicDeclaration = Boolean(owner.manifest?.types && owner.manifest.private !== true);\n const runtime = (entry.runtime || publicDeclaration) && !isTest && !isTool;\n const present =\n declared.dependencies?.[name] ||\n declared.optionalDependencies?.[name] ||\n declared.peerDependencies?.[name] ||\n (!runtime && declared.devDependencies?.[name]);\n if (present || (isTool && this.provided(declared, options.toolProviders, name))) return;\n const section = runtime ? 'dependencies' : 'devDependencies';\n errors.push(\n `${file}:${entry.line}: ${name} must be declared in ${isTool ? '.' : owner.directory}/package.json ${section}; root/other-owner hoisting cannot satisfy this import`,\n );\n }\n\n private provided(\n manifest: DependencyManifest,\n providers: readonly string[],\n name: string,\n ): boolean {\n return providers.some((entry: string) => {\n const separator = entry.indexOf('=');\n return (\n separator > 0 &&\n entry.slice(0, separator) === name &&\n Boolean(manifest.devDependencies?.[entry.slice(separator + 1)])\n );\n });\n }\n\n private name(\n workspace: DependencyWorkspace,\n owner: DependencyOwner,\n specifier: string,\n ): string | undefined {\n const raw = this.imports.packageName(specifier);\n if (!raw) return undefined;\n if (specifier.startsWith('app/') && owner.directory.startsWith('services/'))\n return owner.manifest?.name;\n const config = path.join(workspace.root, 'tsconfig.base.json');\n if (!fs.existsSync(config)) return raw;\n let json = this.aliases.get(workspace.root);\n if (!json) {\n json = JSON.parse(fs.readFileSync(config, 'utf8')) as AliasFile;\n this.aliases.set(workspace.root, json);\n }\n for (const mapping of Object.entries(json.compilerOptions?.paths ?? {})) {\n const alias = mapping[0];\n const targets = mapping[1];\n const prefix = alias.endsWith('*') ? alias.slice(0, -1) : alias;\n if (alias.endsWith('*') ? specifier.startsWith(prefix) : specifier === alias) {\n const target = targets[0]?.replace('*', specifier.slice(prefix.length));\n if (target) return workspace.owner(target).manifest?.name ?? raw;\n }\n }\n return raw;\n }\n}\n\nexport class ConfiguredDependencyPolicies {\n run(root: string): BuildPolicyResult {\n const rules = loadAndValidate(root).resolved.rules;\n const catalog = rules.get('dependency-catalog');\n const freeze = rules.get('root-runtime-freeze');\n const ownership = rules.get('dependency-ownership');\n if (!catalog || !freeze || !ownership)\n throw new RuleFailError(\n 'dependency-catalog',\n 'Declare all three dependency policies in their owning pack',\n undefined,\n undefined,\n [\n new Option(\n 'Upgrade the owning rule pack and declare its explicit policy entries',\n true,\n ),\n ],\n );\n const list = (rule: typeof freeze, field: string): string[] => {\n const value = rule.options[field] as string[];\n if (!Array.isArray(value) || value.some((item: string) => typeof item !== 'string'))\n throw new RuleFailError(\n 'dependency-ownership',\n `Explicit dependency policy field ${field} must be a string array`,\n undefined,\n undefined,\n [new Option(`Set ${field} to an explicitly reviewed array of strings`, true)],\n );\n return value as string[];\n };\n const gate = new RuleGate();\n const options = new DependencyPolicyOptions(\n !gate.isDisabled(root, 'dependency-catalog', true),\n !gate.isDisabled(root, 'root-runtime-freeze', true),\n !gate.isDisabled(root, 'dependency-ownership', true),\n list(freeze, 'allowedNames'),\n list(ownership, 'rootToolPaths'),\n list(ownership, 'testPaths'),\n list(ownership, 'artifactProbePaths'),\n list(ownership, 'toolProviders'),\n list(ownership, 'dynamicImports'),\n );\n return new DependencyPolicies().enforce(root, options);\n }\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare class DependencyManifest {
|
|
2
|
+
name?: string;
|
|
3
|
+
private?: boolean;
|
|
4
|
+
types?: string;
|
|
5
|
+
dependencies?: Record<string, string>;
|
|
6
|
+
devDependencies?: Record<string, string>;
|
|
7
|
+
optionalDependencies?: Record<string, string>;
|
|
8
|
+
peerDependencies?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export declare class WorkspaceCatalog {
|
|
11
|
+
packages?: string[];
|
|
12
|
+
catalog?: Record<string, string>;
|
|
13
|
+
catalogs?: Record<string, Record<string, string>>;
|
|
14
|
+
}
|
|
15
|
+
export declare class DependencyOwner {
|
|
16
|
+
readonly directory: string;
|
|
17
|
+
readonly manifest: DependencyManifest | undefined;
|
|
18
|
+
constructor(directory: string, manifest: DependencyManifest | undefined);
|
|
19
|
+
}
|
|
20
|
+
/** One bounded workspace traversal; nested repositories and symlinks are never governed. */
|
|
21
|
+
export declare class DependencyWorkspace {
|
|
22
|
+
readonly root: string;
|
|
23
|
+
readonly files: string[];
|
|
24
|
+
readonly owners: DependencyOwner[];
|
|
25
|
+
readonly catalog: WorkspaceCatalog;
|
|
26
|
+
readonly rootManifest: DependencyManifest;
|
|
27
|
+
constructor(root: string);
|
|
28
|
+
matches(file: string, patterns: readonly string[]): boolean;
|
|
29
|
+
owner(file: string): DependencyOwner;
|
|
30
|
+
manifest(directory: string): DependencyManifest;
|
|
31
|
+
private loadOwners;
|
|
32
|
+
private walk;
|
|
33
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DependencyWorkspace = exports.DependencyOwner = exports.WorkspaceCatalog = exports.DependencyManifest = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs = tslib_1.__importStar(require("node:fs"));
|
|
6
|
+
const path = tslib_1.__importStar(require("node:path"));
|
|
7
|
+
const minimatch_1 = require("minimatch");
|
|
8
|
+
const yaml_1 = require("yaml");
|
|
9
|
+
class DependencyManifest {
|
|
10
|
+
name;
|
|
11
|
+
private;
|
|
12
|
+
types;
|
|
13
|
+
dependencies;
|
|
14
|
+
devDependencies;
|
|
15
|
+
optionalDependencies;
|
|
16
|
+
peerDependencies;
|
|
17
|
+
}
|
|
18
|
+
exports.DependencyManifest = DependencyManifest;
|
|
19
|
+
class WorkspaceCatalog {
|
|
20
|
+
packages;
|
|
21
|
+
catalog;
|
|
22
|
+
catalogs;
|
|
23
|
+
}
|
|
24
|
+
exports.WorkspaceCatalog = WorkspaceCatalog;
|
|
25
|
+
class DependencyOwner {
|
|
26
|
+
directory;
|
|
27
|
+
manifest;
|
|
28
|
+
constructor(directory, manifest) {
|
|
29
|
+
this.directory = directory;
|
|
30
|
+
this.manifest = manifest;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.DependencyOwner = DependencyOwner;
|
|
34
|
+
const EXCLUDED = new Set([
|
|
35
|
+
'node_modules',
|
|
36
|
+
'dist',
|
|
37
|
+
'build',
|
|
38
|
+
'coverage',
|
|
39
|
+
'tmp',
|
|
40
|
+
'out-tsc',
|
|
41
|
+
'android',
|
|
42
|
+
'ios',
|
|
43
|
+
]);
|
|
44
|
+
/** One bounded workspace traversal; nested repositories and symlinks are never governed. */
|
|
45
|
+
class DependencyWorkspace {
|
|
46
|
+
root;
|
|
47
|
+
files = [];
|
|
48
|
+
owners = [];
|
|
49
|
+
catalog;
|
|
50
|
+
rootManifest;
|
|
51
|
+
constructor(root) {
|
|
52
|
+
this.root = root;
|
|
53
|
+
this.catalog = (0, yaml_1.parse)(fs.readFileSync(path.join(root, 'pnpm-workspace.yaml'), 'utf8'));
|
|
54
|
+
this.rootManifest = this.manifest('.');
|
|
55
|
+
this.walk('.');
|
|
56
|
+
this.loadOwners();
|
|
57
|
+
}
|
|
58
|
+
matches(file, patterns) {
|
|
59
|
+
let included = false;
|
|
60
|
+
for (const pattern of patterns) {
|
|
61
|
+
if (pattern.startsWith('!')) {
|
|
62
|
+
if ((0, minimatch_1.minimatch)(file, pattern.slice(1), { dot: true }))
|
|
63
|
+
included = false;
|
|
64
|
+
}
|
|
65
|
+
else if ((0, minimatch_1.minimatch)(file, pattern, { dot: true }))
|
|
66
|
+
included = true;
|
|
67
|
+
}
|
|
68
|
+
return included;
|
|
69
|
+
}
|
|
70
|
+
owner(file) {
|
|
71
|
+
const owner = this.owners.find((entry) => file.startsWith(entry.directory + '/'));
|
|
72
|
+
return owner ?? new DependencyOwner('.', this.rootManifest);
|
|
73
|
+
}
|
|
74
|
+
manifest(directory) {
|
|
75
|
+
return JSON.parse(fs.readFileSync(path.join(this.root, directory, 'package.json'), 'utf8'));
|
|
76
|
+
}
|
|
77
|
+
loadOwners() {
|
|
78
|
+
const directories = new Set();
|
|
79
|
+
for (const file of this.files) {
|
|
80
|
+
if (path.basename(file) === 'project.json')
|
|
81
|
+
directories.add(path.dirname(file));
|
|
82
|
+
if (path.basename(file) === 'package.json' &&
|
|
83
|
+
this.matches(path.dirname(file), this.catalog.packages ?? []))
|
|
84
|
+
directories.add(path.dirname(file));
|
|
85
|
+
}
|
|
86
|
+
for (const directory of directories) {
|
|
87
|
+
const managed = this.matches(directory, this.catalog.packages ?? []);
|
|
88
|
+
const exists = fs.existsSync(path.join(this.root, directory, 'package.json'));
|
|
89
|
+
this.owners.push(new DependencyOwner(directory, managed && exists ? this.manifest(directory) : undefined));
|
|
90
|
+
}
|
|
91
|
+
this.owners.sort((a, b) => b.directory.length - a.directory.length);
|
|
92
|
+
}
|
|
93
|
+
walk(relative) {
|
|
94
|
+
const directory = path.join(this.root, relative);
|
|
95
|
+
if (relative !== '.' && fs.existsSync(path.join(directory, '.git')))
|
|
96
|
+
return;
|
|
97
|
+
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
98
|
+
if (entry.name.startsWith('.') || EXCLUDED.has(entry.name))
|
|
99
|
+
continue;
|
|
100
|
+
const file = relative === '.' ? entry.name : relative + '/' + entry.name;
|
|
101
|
+
if (entry.isDirectory())
|
|
102
|
+
this.walk(file);
|
|
103
|
+
else if (entry.isFile())
|
|
104
|
+
this.files.push(file);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.DependencyWorkspace = DependencyWorkspace;
|
|
109
|
+
//# sourceMappingURL=dependency-workspace.js.map
|