repopo 0.4.0 → 0.5.0
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/CHANGELOG.md +44 -0
- package/README.md +37 -18
- package/THIRD-PARTY-LICENSES.txt +21 -11
- package/esm/api.d.ts +2 -0
- package/esm/api.d.ts.map +1 -0
- package/esm/api.js +2 -0
- package/esm/api.js.map +1 -0
- package/esm/baseCommand.d.ts +13 -43
- package/esm/baseCommand.d.ts.map +1 -1
- package/esm/baseCommand.js +27 -62
- package/esm/baseCommand.js.map +1 -1
- package/esm/commands/check.d.ts +2 -8
- package/esm/commands/check.d.ts.map +1 -1
- package/esm/commands/check.js +79 -87
- package/esm/commands/check.js.map +1 -1
- package/esm/commands/list.d.ts +1 -2
- package/esm/commands/list.d.ts.map +1 -1
- package/esm/commands/list.js +5 -6
- package/esm/commands/list.js.map +1 -1
- package/esm/config.d.ts +10 -5
- package/esm/config.d.ts.map +1 -1
- package/esm/config.js.map +1 -1
- package/esm/context.d.ts +29 -0
- package/esm/context.d.ts.map +1 -0
- package/esm/context.js +2 -0
- package/esm/context.js.map +1 -0
- package/esm/index.d.ts +11 -4
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +8 -0
- package/esm/index.js.map +1 -1
- package/esm/perf.d.ts.map +1 -1
- package/esm/perf.js +1 -5
- package/esm/perf.js.map +1 -1
- package/esm/policies/HtmlFileHeaders.d.ts +8 -0
- package/esm/policies/HtmlFileHeaders.d.ts.map +1 -0
- package/esm/policies/HtmlFileHeaders.js +17 -0
- package/esm/policies/HtmlFileHeaders.js.map +1 -0
- package/esm/policies/JsTsFileHeaders.d.ts +8 -0
- package/esm/policies/JsTsFileHeaders.d.ts.map +1 -0
- package/esm/policies/JsTsFileHeaders.js +24 -0
- package/esm/policies/JsTsFileHeaders.js.map +1 -0
- package/esm/policies/NoJsFileExtensions.d.ts +2 -0
- package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
- package/esm/policies/NoJsFileExtensions.js +2 -0
- package/esm/policies/NoJsFileExtensions.js.map +1 -1
- package/esm/policies/PackageJsonProperties.d.ts +6 -8
- package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
- package/esm/policies/PackageJsonProperties.js +37 -40
- package/esm/policies/PackageJsonProperties.js.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +3 -2
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.js +40 -37
- package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
- package/esm/policies/PackageJsonSorted.d.ts +7 -0
- package/esm/policies/PackageJsonSorted.d.ts.map +1 -0
- package/esm/policies/PackageJsonSorted.js +45 -0
- package/esm/policies/PackageJsonSorted.js.map +1 -0
- package/esm/policies/PackageScripts.d.ts +7 -0
- package/esm/policies/PackageScripts.d.ts.map +1 -0
- package/esm/policies/PackageScripts.js +25 -0
- package/esm/policies/PackageScripts.js.map +1 -0
- package/esm/policies/constants.d.ts +5 -0
- package/esm/policies/constants.d.ts.map +1 -0
- package/esm/policies/constants.js +5 -0
- package/esm/policies/constants.js.map +1 -0
- package/esm/policies.d.ts +7 -0
- package/esm/policies.d.ts.map +1 -0
- package/esm/policies.js +7 -0
- package/esm/policies.js.map +1 -0
- package/esm/policy.d.ts +31 -13
- package/esm/policy.d.ts.map +1 -1
- package/esm/policy.js +8 -20
- package/esm/policy.js.map +1 -1
- package/esm/policyGenerators/generateFileHeaderPolicy.d.ts +45 -0
- package/esm/policyGenerators/generateFileHeaderPolicy.d.ts.map +1 -0
- package/esm/policyGenerators/generateFileHeaderPolicy.js +61 -0
- package/esm/policyGenerators/generateFileHeaderPolicy.js.map +1 -0
- package/esm/policyGenerators/generatePackagePolicy.d.ts +9 -0
- package/esm/policyGenerators/generatePackagePolicy.d.ts.map +1 -0
- package/esm/policyGenerators/generatePackagePolicy.js +20 -0
- package/esm/policyGenerators/generatePackagePolicy.js.map +1 -0
- package/esm/tsdoc-metadata.json +1 -1
- package/oclif.manifest.json +45 -53
- package/package.json +39 -21
- package/esm/policies/PackageJsonSortedPolicy.d.ts +0 -6
- package/esm/policies/PackageJsonSortedPolicy.d.ts.map +0 -1
- package/esm/policies/PackageJsonSortedPolicy.js +0 -49
- package/esm/policies/PackageJsonSortedPolicy.js.map +0 -1
- package/esm/policies/SortTsconfigs.d.ts +0 -10
- package/esm/policies/SortTsconfigs.d.ts.map +0 -1
- package/esm/policies/SortTsconfigs.js +0 -33
- package/esm/policies/SortTsconfigs.js.map +0 -1
package/esm/commands/check.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import { EOL as newline } from "node:os";
|
|
3
2
|
import { Flags } from "@oclif/core";
|
|
4
3
|
import { StringBuilder } from "@rushstack/node-core-library";
|
|
5
4
|
import path from "pathe";
|
|
6
5
|
import chalk from "picocolors";
|
|
7
|
-
import { BaseRepopoCommand
|
|
8
|
-
import { DefaultPolicyConfig } from "../config.js";
|
|
6
|
+
import { BaseRepopoCommand } from "../baseCommand.js";
|
|
9
7
|
import { logStats, runWithPerf } from "../perf.js";
|
|
10
8
|
import { isPolicyFixResult } from "../policy.js";
|
|
11
9
|
/**
|
|
@@ -32,17 +30,10 @@ export class CheckPolicy extends BaseRepopoCommand {
|
|
|
32
30
|
}),
|
|
33
31
|
...BaseRepopoCommand.flags,
|
|
34
32
|
};
|
|
35
|
-
|
|
36
|
-
count = 0;
|
|
37
|
-
defaultConfig = DefaultPolicyConfig;
|
|
38
|
-
async init() {
|
|
39
|
-
await super.init();
|
|
33
|
+
async run() {
|
|
40
34
|
if (this.flags.fix) {
|
|
41
35
|
this.info("Resolving errors if possible.");
|
|
42
36
|
}
|
|
43
|
-
}
|
|
44
|
-
async run() {
|
|
45
|
-
// list the handlers then exit
|
|
46
37
|
const config = this.commandConfig;
|
|
47
38
|
const policies = config?.policies ?? [];
|
|
48
39
|
this.verbose(`${policies.length} policies loaded.`);
|
|
@@ -60,17 +51,10 @@ export class CheckPolicy extends BaseRepopoCommand {
|
|
|
60
51
|
const gitFiles = (await this.git.raw("ls-files", "-co", "--exclude-standard", "--full-name")) ?? "";
|
|
61
52
|
filePathsToCheck.push(...gitFiles.split("\n"));
|
|
62
53
|
}
|
|
63
|
-
|
|
64
|
-
const context = this.getContext();
|
|
65
|
-
await this.executePolicy(filePathsToCheck, context);
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
this.error(`Command context was undefined - fatal error: ${error}`, {
|
|
69
|
-
exit: 100,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
54
|
+
await this.executeAllPolicies(filePathsToCheck);
|
|
72
55
|
}
|
|
73
|
-
async
|
|
56
|
+
async executeAllPolicies(pathsToCheck) {
|
|
57
|
+
const commandContext = await this.getContext();
|
|
74
58
|
try {
|
|
75
59
|
for (const pathToCheck of pathsToCheck) {
|
|
76
60
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -78,7 +62,9 @@ export class CheckPolicy extends BaseRepopoCommand {
|
|
|
78
62
|
}
|
|
79
63
|
}
|
|
80
64
|
finally {
|
|
81
|
-
|
|
65
|
+
if (!this.flags.quiet) {
|
|
66
|
+
logStats(commandContext.perfStats, this);
|
|
67
|
+
}
|
|
82
68
|
}
|
|
83
69
|
}
|
|
84
70
|
/**
|
|
@@ -87,87 +73,93 @@ export class CheckPolicy extends BaseRepopoCommand {
|
|
|
87
73
|
* decision for all handlers.
|
|
88
74
|
*/
|
|
89
75
|
async routeToHandlers(file, commandContext) {
|
|
90
|
-
const { policies,
|
|
76
|
+
const { policies, gitRoot } = commandContext;
|
|
91
77
|
// Use the repo-relative path so that regexes that specify string start (^) will match repo paths.
|
|
92
78
|
// Replace \ in result with / in case OS is Windows.
|
|
93
79
|
const relPath = path.relative(gitRoot, file).replace(/\\/g, "/");
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
80
|
+
const filteredPolicies = policies.filter((handler) => handler.match.test(relPath));
|
|
81
|
+
const resultsP = [];
|
|
82
|
+
for (const policy of filteredPolicies) {
|
|
83
|
+
resultsP.push(this.runPolicyOnFile(relPath, policy));
|
|
84
|
+
}
|
|
85
|
+
await Promise.all(resultsP);
|
|
86
|
+
}
|
|
87
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: FIXME
|
|
88
|
+
async runPolicyOnFile(relPath,
|
|
89
|
+
// policies: RepoPolicy[],
|
|
90
|
+
policy) {
|
|
91
|
+
const context = await this.getContext();
|
|
92
|
+
const { excludePoliciesForFiles, perfStats, gitRoot } = context;
|
|
93
|
+
// doing exclusion per handler
|
|
94
|
+
const exclusions = excludePoliciesForFiles.get(policy.name);
|
|
95
|
+
if (exclusions !== undefined &&
|
|
96
|
+
!exclusions.every((regex) => !regex.test(relPath))) {
|
|
97
|
+
this.verbose(`Excluded from '${policy.name}' policy: ${relPath}`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const result = await runWithPerf(policy.name, "handle", perfStats, async () => policy.handler({
|
|
101
|
+
file: relPath,
|
|
102
|
+
root: gitRoot,
|
|
103
|
+
resolve: this.flags.fix,
|
|
104
|
+
config: this.commandConfig?.perPolicyConfig?.[policy.name
|
|
105
|
+
// biome-ignore lint/suspicious/noExplicitAny: FIXME
|
|
106
|
+
],
|
|
107
|
+
}));
|
|
108
|
+
if (result === true) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const messages = new StringBuilder();
|
|
112
|
+
if (isPolicyFixResult(result)) {
|
|
113
|
+
if (result.resolved) {
|
|
114
|
+
messages.append(`Resolved ${policy.name} policy failure for file: ${result.file}`);
|
|
124
115
|
}
|
|
125
116
|
else {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
117
|
+
messages.append(`Error when trying to fix ${policy.name} policy failure in ${result.file}`);
|
|
118
|
+
process.exitCode = 1;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// result must be a PolicyFailureResult; check if there is a standalone resolver.
|
|
123
|
+
const { resolver } = policy;
|
|
124
|
+
if (this.flags.fix && resolver !== undefined) {
|
|
125
|
+
// Resolve the failure
|
|
126
|
+
messages.append(`${newline}attempting to resolve: ${relPath}`);
|
|
127
|
+
const resolveResult = await runWithPerf(policy.name, "resolve", perfStats, async () => resolver({ file: relPath, root: gitRoot }));
|
|
128
|
+
if (resolveResult.errorMessage !== undefined &&
|
|
129
|
+
resolveResult.errorMessage !== "") {
|
|
130
|
+
messages.append(newline + resolveResult.errorMessage);
|
|
139
131
|
}
|
|
140
|
-
|
|
141
|
-
// No resolver, or fix is false, so we're in the full failure case.
|
|
142
|
-
const autoFixable = result.autoFixable
|
|
143
|
-
? chalk.green(" (autofixable)")
|
|
144
|
-
: "";
|
|
145
|
-
messages.append(`'${policy.name}' policy failure${autoFixable}: ${result.file}`);
|
|
146
|
-
messages.append(result.errorMessage === undefined
|
|
147
|
-
? ""
|
|
148
|
-
: `${newline}${result.errorMessage}`);
|
|
132
|
+
if (!resolveResult.resolved) {
|
|
149
133
|
process.exitCode = 1;
|
|
150
134
|
}
|
|
151
135
|
}
|
|
152
|
-
if ((process.exitCode ?? 0) === 0) {
|
|
153
|
-
this.info(messages.toString());
|
|
154
|
-
}
|
|
155
136
|
else {
|
|
156
|
-
|
|
137
|
+
// No resolver, or fix is false, so we're in the full failure case.
|
|
138
|
+
const autoFixable = result.autoFixable
|
|
139
|
+
? chalk.green(" (autofixable)")
|
|
140
|
+
: "";
|
|
141
|
+
messages.append(`'${chalk.bold(policy.name)}' policy failure${autoFixable}: ${result.file}`);
|
|
142
|
+
messages.append(result.errorMessage === undefined
|
|
143
|
+
? ""
|
|
144
|
+
: `${newline}\t${result.errorMessage}`);
|
|
145
|
+
process.exitCode = 1;
|
|
157
146
|
}
|
|
158
|
-
}
|
|
147
|
+
}
|
|
148
|
+
if ((process.exitCode ?? 0) === 0) {
|
|
149
|
+
this.info(messages.toString());
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
this.warning(messages.toString());
|
|
153
|
+
}
|
|
159
154
|
}
|
|
160
155
|
/**
|
|
161
156
|
* Given a string that represents a path to a file in the repo, determines if the file should be checked, and if so,
|
|
162
157
|
* routes the file to the appropriate handlers.
|
|
163
158
|
*/
|
|
164
159
|
async checkOrExcludeFile(inputPath, commandContext) {
|
|
165
|
-
const { excludeFiles: exclusions, gitRoot,
|
|
160
|
+
const { excludeFiles: exclusions, gitRoot, perfStats } = commandContext;
|
|
166
161
|
const filePath = path.join(gitRoot, inputPath).trim().replace(/\\/g, "/");
|
|
167
|
-
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
this.count++;
|
|
162
|
+
perfStats.count++;
|
|
171
163
|
if (!exclusions.every((value) => !value.test(inputPath))) {
|
|
172
164
|
this.verbose(`Excluded all handlers: ${inputPath}`);
|
|
173
165
|
return;
|
|
@@ -176,9 +168,9 @@ export class CheckPolicy extends BaseRepopoCommand {
|
|
|
176
168
|
await this.routeToHandlers(filePath, commandContext);
|
|
177
169
|
}
|
|
178
170
|
catch (error) {
|
|
179
|
-
throw new Error(`Error routing ${filePath} to handler: ${error}`);
|
|
171
|
+
throw new Error(`Error routing ${filePath} to handler: ${error}\nStack:\n${error.stack}`);
|
|
180
172
|
}
|
|
181
|
-
|
|
173
|
+
perfStats.processed++;
|
|
182
174
|
}
|
|
183
175
|
}
|
|
184
176
|
async function readStdin() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,EACN,iBAAiB,GAEjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,OAAO,WAKX,SAAQ,iBAAoB;IAC7B,MAAM,CAAmB,OAAO,GAC/B,6DAA6D,CAAC;IAE/D,MAAM,CAAmB,KAAK,GAAG;QAChC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC;YAClB,OAAO,EAAE,CAAC,SAAS,CAAC;YACpB,WAAW,EAAE,yBAAyB;YACtC,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,GAAG;SACT,CAAC;QACF,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;YACpB,WAAW,EAAE,gCAAgC;YAC7C,QAAQ,EAAE,KAAK;SACf,CAAC;QACF,GAAG,iBAAiB,CAAC,KAAK;KACjB,CAAC;IAEH,SAAS,GAAG,CAAC,CAAC;IACd,KAAK,GAAG,CAAC,CAAC;IAEF,aAAa,GAAG,mBAAmB,CAAC;IAEpC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QAE1B,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YAC1B,IAAI,IAAI,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO,CAAC,EAAE,CAAC,CAAC;QACb,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport { EOL as newline } from \"node:os\";\nimport { Flags } from \"@oclif/core\";\nimport { StringBuilder } from \"@rushstack/node-core-library\";\nimport path from \"pathe\";\nimport chalk from \"picocolors\";\n\nimport {\n\tBaseRepopoCommand,\n\ttype PolicyCommandContext,\n} from \"../baseCommand.js\";\nimport { DefaultPolicyConfig } from \"../config.js\";\nimport { logStats, runWithPerf } from \"../perf.js\";\nimport { isPolicyFixResult } from \"../policy.js\";\n\n/**\n * This tool enforces policies across the code base via a series of handler functions. The handler functions are\n * associated with a regular expression, and all files matching that expression are passed to the handler function.\n *\n * By default, the list of files to check comes from `git ls-files. You can also pipe in file names from stdin. For\n * example:\n *\n * `git ls-files -co --exclude-standard --full-name | repopo check --stdin --verbose`\n */\nexport class CheckPolicy<\n\tT extends typeof BaseRepopoCommand & {\n\t\targs: typeof CheckPolicy.args;\n\t\tflags: typeof CheckPolicy.flags;\n\t},\n> extends BaseRepopoCommand<T> {\n\tstatic override readonly summary =\n\t\t\"Checks and applies policies to the files in the repository.\";\n\n\tstatic override readonly flags = {\n\t\tfix: Flags.boolean({\n\t\t\taliases: [\"resolve\"],\n\t\t\tdescription: \"Fix errors if possible.\",\n\t\t\trequired: false,\n\t\t\tchar: \"f\",\n\t\t}),\n\t\tstdin: Flags.boolean({\n\t\t\tdescription: \"Read list of files from stdin.\",\n\t\t\trequired: false,\n\t\t}),\n\t\t...BaseRepopoCommand.flags,\n\t} as const;\n\n\tprivate processed = 0;\n\tprivate count = 0;\n\n\tpublic override defaultConfig = DefaultPolicyConfig;\n\n\tpublic override async init(): Promise<void> {\n\t\tawait super.init();\n\n\t\tif (this.flags.fix) {\n\t\t\tthis.info(\"Resolving errors if possible.\");\n\t\t}\n\t}\n\n\tpublic override async run(): Promise<void> {\n\t\t// list the handlers then exit\n\t\tconst config = this.commandConfig;\n\t\tconst policies = config?.policies ?? [];\n\t\tthis.verbose(`${policies.length} policies loaded.`);\n\t\tfor (const h of policies) {\n\t\t\tthis.verbose(h.name);\n\t\t}\n\n\t\tconst filePathsToCheck: string[] = [];\n\n\t\tif (this.flags.stdin) {\n\t\t\tconst stdInput = await readStdin();\n\n\t\t\tif (stdInput !== undefined) {\n\t\t\t\tfilePathsToCheck.push(...stdInput.split(\"\\n\"));\n\t\t\t}\n\t\t} else {\n\t\t\tconst gitFiles =\n\t\t\t\t(await this.git.raw(\n\t\t\t\t\t\"ls-files\",\n\t\t\t\t\t\"-co\",\n\t\t\t\t\t\"--exclude-standard\",\n\t\t\t\t\t\"--full-name\",\n\t\t\t\t)) ?? \"\";\n\n\t\t\tfilePathsToCheck.push(...gitFiles.split(\"\\n\"));\n\t\t}\n\n\t\ttry {\n\t\t\tconst context = this.getContext();\n\t\t\tawait this.executePolicy(filePathsToCheck, context);\n\t\t} catch (error) {\n\t\t\tthis.error(`Command context was undefined - fatal error: ${error}`, {\n\t\t\t\texit: 100,\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async executePolicy(\n\t\tpathsToCheck: string[],\n\t\tcommandContext: PolicyCommandContext,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tfor (const pathToCheck of pathsToCheck) {\n\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\tawait this.checkOrExcludeFile(pathToCheck, commandContext);\n\t\t\t}\n\t\t} finally {\n\t\t\tlogStats(commandContext.perfStats, this);\n\t\t}\n\t}\n\n\t/**\n\t * Routes files to their handlers and resolvers by regex testing their full paths. If a file fails a policy that has a\n\t * resolver, the resolver will be invoked as well. Synchronizes the output, exit codes, and resolve\n\t * decision for all handlers.\n\t */\n\tprivate async routeToHandlers(\n\t\tfile: string,\n\t\tcommandContext: PolicyCommandContext,\n\t): Promise<void> {\n\t\tconst { policies, excludePoliciesForFiles, gitRoot, perfStats } =\n\t\t\tcommandContext;\n\n\t\t// Use the repo-relative path so that regexes that specify string start (^) will match repo paths.\n\t\t// Replace \\ in result with / in case OS is Windows.\n\t\tconst relPath = path.relative(gitRoot, file).replace(/\\\\/g, \"/\");\n\t\tconst config = this.commandConfig;\n\n\t\tawait Promise.all(\n\t\t\tpolicies\n\t\t\t\t.filter((handler) => handler.match.test(relPath))\n\t\t\t\t// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>\n\t\t\t\t.map(async (policy): Promise<void> => {\n\t\t\t\t\t// doing exclusion per handler\n\t\t\t\t\tconst exclusions = excludePoliciesForFiles.get(policy.name);\n\t\t\t\t\tif (\n\t\t\t\t\t\texclusions !== undefined &&\n\t\t\t\t\t\t!exclusions.every((regex) => !regex.test(relPath))\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.verbose(`Excluded from '${policy.name}' policy: ${relPath}`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst result = await runWithPerf(\n\t\t\t\t\t\tpolicy.name,\n\t\t\t\t\t\t\"handle\",\n\t\t\t\t\t\tperfStats,\n\t\t\t\t\t\tasync () =>\n\t\t\t\t\t\t\tpolicy.handler({\n\t\t\t\t\t\t\t\tfile: relPath,\n\t\t\t\t\t\t\t\troot: gitRoot,\n\t\t\t\t\t\t\t\tresolve: this.flags.fix,\n\t\t\t\t\t\t\t\tconfig: config?.policySettings?.[policy.name],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\n\t\t\t\t\tif (result === true) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst messages = new StringBuilder();\n\t\t\t\t\tif (isPolicyFixResult(result)) {\n\t\t\t\t\t\tif (result.resolved) {\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\t`Resolved ${policy.name} policy failure for file: ${result.file}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\t`Error when trying to fix ${policy.name} policy failure in ${result.file}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// result must be a PolicyFailureResult; check if there is a standalone resolver.\n\t\t\t\t\t\tconst { resolver } = policy;\n\n\t\t\t\t\t\tif (this.flags.fix && resolver !== undefined) {\n\t\t\t\t\t\t\t// Resolve the failure\n\t\t\t\t\t\t\tmessages.append(`${newline}attempting to resolve: ${relPath}`);\n\t\t\t\t\t\t\tconst resolveResult = await runWithPerf(\n\t\t\t\t\t\t\t\tpolicy.name,\n\t\t\t\t\t\t\t\t\"resolve\",\n\t\t\t\t\t\t\t\tperfStats,\n\t\t\t\t\t\t\t\tasync () => resolver({ file: relPath, root: gitRoot }),\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tresolveResult.errorMessage !== undefined &&\n\t\t\t\t\t\t\t\tresolveResult.errorMessage !== \"\"\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tmessages.append(newline + resolveResult.errorMessage);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!resolveResult.resolved) {\n\t\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// No resolver, or fix is false, so we're in the full failure case.\n\t\t\t\t\t\t\tconst autoFixable = result.autoFixable\n\t\t\t\t\t\t\t\t? chalk.green(\" (autofixable)\")\n\t\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\t`'${policy.name}' policy failure${autoFixable}: ${result.file}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\tresult.errorMessage === undefined\n\t\t\t\t\t\t\t\t\t? \"\"\n\t\t\t\t\t\t\t\t\t: `${newline}${result.errorMessage}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif ((process.exitCode ?? 0) === 0) {\n\t\t\t\t\t\tthis.info(messages.toString());\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.warning(messages.toString());\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Given a string that represents a path to a file in the repo, determines if the file should be checked, and if so,\n\t * routes the file to the appropriate handlers.\n\t */\n\tprivate async checkOrExcludeFile(\n\t\tinputPath: string,\n\t\tcommandContext: PolicyCommandContext,\n\t): Promise<void> {\n\t\tconst { excludeFiles: exclusions, gitRoot, pathRegex } = commandContext;\n\n\t\tconst filePath = path.join(gitRoot, inputPath).trim().replace(/\\\\/g, \"/\");\n\n\t\tif (!(pathRegex.test(inputPath) && fs.existsSync(filePath))) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.count++;\n\t\tif (!exclusions.every((value) => !value.test(inputPath))) {\n\t\t\tthis.verbose(`Excluded all handlers: ${inputPath}`);\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.routeToHandlers(filePath, commandContext);\n\t\t} catch (error: unknown) {\n\t\t\tthrow new Error(`Error routing ${filePath} to handler: ${error}`);\n\t\t}\n\n\t\tthis.processed++;\n\t}\n}\n\nasync function readStdin(): Promise<string> {\n\treturn new Promise((resolve) => {\n\t\tconst stdin = process.stdin;\n\t\tstdin.setEncoding(\"utf8\");\n\n\t\tlet data = \"\";\n\t\tstdin.on(\"data\", (chunk) => {\n\t\t\tdata += chunk;\n\t\t});\n\n\t\tstdin.on(\"end\", () => {\n\t\t\tresolve(data);\n\t\t});\n\n\t\tif (stdin.isTTY) {\n\t\t\tresolve(\"\");\n\t\t}\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAmB,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAElE;;;;;;;;GAQG;AACH,MAAM,OAAO,WAKX,SAAQ,iBAAoB;IAC7B,MAAM,CAAmB,OAAO,GAC/B,6DAA6D,CAAC;IAE/D,MAAM,CAAmB,KAAK,GAAG;QAChC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC;YAClB,OAAO,EAAE,CAAC,SAAS,CAAC;YACpB,WAAW,EAAE,yBAAyB;YACtC,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,GAAG;SACT,CAAC;QACF,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;YACpB,WAAW,EAAE,gCAAgC;YAC7C,QAAQ,EAAE,KAAK;SACf,CAAC;QACF,GAAG,iBAAiB,CAAC,KAAK;KACjB,CAAC;IAEK,KAAK,CAAC,GAAG;QACxB,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;YACpB,IAAI,CAAC,IAAI,CAAC,+BAA+B,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AC1B,IAAI,IAAI,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO,CAAC,EAAE,CAAC,CAAC;QACb,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { EOL as newline } from \"node:os\";\nimport { Flags } from \"@oclif/core\";\nimport { StringBuilder } from \"@rushstack/node-core-library\";\nimport path from \"pathe\";\nimport chalk from \"picocolors\";\n\nimport { BaseRepopoCommand } from \"../baseCommand.js\";\nimport type { RepopoCommandContext } from \"../context.js\";\nimport { logStats, runWithPerf } from \"../perf.js\";\nimport { type RepoPolicy, isPolicyFixResult } from \"../policy.js\";\n\n/**\n * This tool enforces policies across the code base via a series of handler functions. The handler functions are\n * associated with a regular expression, and all files matching that expression are passed to the handler function.\n *\n * By default, the list of files to check comes from `git ls-files. You can also pipe in file names from stdin. For\n * example:\n *\n * `git ls-files -co --exclude-standard --full-name | repopo check --stdin --verbose`\n */\nexport class CheckPolicy<\n\tT extends typeof BaseRepopoCommand & {\n\t\targs: typeof CheckPolicy.args;\n\t\tflags: typeof CheckPolicy.flags;\n\t},\n> extends BaseRepopoCommand<T> {\n\tstatic override readonly summary =\n\t\t\"Checks and applies policies to the files in the repository.\";\n\n\tstatic override readonly flags = {\n\t\tfix: Flags.boolean({\n\t\t\taliases: [\"resolve\"],\n\t\t\tdescription: \"Fix errors if possible.\",\n\t\t\trequired: false,\n\t\t\tchar: \"f\",\n\t\t}),\n\t\tstdin: Flags.boolean({\n\t\t\tdescription: \"Read list of files from stdin.\",\n\t\t\trequired: false,\n\t\t}),\n\t\t...BaseRepopoCommand.flags,\n\t} as const;\n\n\tpublic override async run(): Promise<void> {\n\t\tif (this.flags.fix) {\n\t\t\tthis.info(\"Resolving errors if possible.\");\n\t\t}\n\n\t\tconst config = this.commandConfig;\n\t\tconst policies = config?.policies ?? [];\n\t\tthis.verbose(`${policies.length} policies loaded.`);\n\t\tfor (const h of policies) {\n\t\t\tthis.verbose(h.name);\n\t\t}\n\n\t\tconst filePathsToCheck: string[] = [];\n\n\t\tif (this.flags.stdin) {\n\t\t\tconst stdInput = await readStdin();\n\n\t\t\tif (stdInput !== undefined) {\n\t\t\t\tfilePathsToCheck.push(...stdInput.split(\"\\n\"));\n\t\t\t}\n\t\t} else {\n\t\t\tconst gitFiles =\n\t\t\t\t(await this.git.raw(\n\t\t\t\t\t\"ls-files\",\n\t\t\t\t\t\"-co\",\n\t\t\t\t\t\"--exclude-standard\",\n\t\t\t\t\t\"--full-name\",\n\t\t\t\t)) ?? \"\";\n\n\t\t\tfilePathsToCheck.push(...gitFiles.split(\"\\n\"));\n\t\t}\n\n\t\tawait this.executeAllPolicies(filePathsToCheck);\n\t}\n\n\tprivate async executeAllPolicies(pathsToCheck: string[]): Promise<void> {\n\t\tconst commandContext: RepopoCommandContext = await this.getContext();\n\n\t\ttry {\n\t\t\tfor (const pathToCheck of pathsToCheck) {\n\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\tawait this.checkOrExcludeFile(pathToCheck, commandContext);\n\t\t\t}\n\t\t} finally {\n\t\t\tif (!this.flags.quiet) {\n\t\t\t\tlogStats(commandContext.perfStats, this);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Routes files to their handlers and resolvers by regex testing their full paths. If a file fails a policy that has a\n\t * resolver, the resolver will be invoked as well. Synchronizes the output, exit codes, and resolve\n\t * decision for all handlers.\n\t */\n\tprivate async routeToHandlers(\n\t\tfile: string,\n\t\tcommandContext: RepopoCommandContext,\n\t): Promise<void> {\n\t\tconst { policies, gitRoot } = commandContext;\n\n\t\t// Use the repo-relative path so that regexes that specify string start (^) will match repo paths.\n\t\t// Replace \\ in result with / in case OS is Windows.\n\t\tconst relPath = path.relative(gitRoot, file).replace(/\\\\/g, \"/\");\n\n\t\tconst filteredPolicies = policies.filter((handler) =>\n\t\t\thandler.match.test(relPath),\n\t\t);\n\n\t\tconst resultsP: Promise<void>[] = [];\n\n\t\tfor (const policy of filteredPolicies) {\n\t\t\tresultsP.push(this.runPolicyOnFile(relPath, policy));\n\t\t}\n\n\t\tawait Promise.all(resultsP);\n\t}\n\n\t// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: FIXME\n\tprivate async runPolicyOnFile(\n\t\trelPath: string,\n\t\t// policies: RepoPolicy[],\n\t\tpolicy: RepoPolicy,\n\t): Promise<void> {\n\t\tconst context = await this.getContext();\n\t\tconst { excludePoliciesForFiles, perfStats, gitRoot } = context;\n\n\t\t// doing exclusion per handler\n\t\tconst exclusions = excludePoliciesForFiles.get(policy.name);\n\t\tif (\n\t\t\texclusions !== undefined &&\n\t\t\t!exclusions.every((regex) => !regex.test(relPath))\n\t\t) {\n\t\t\tthis.verbose(`Excluded from '${policy.name}' policy: ${relPath}`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst result = await runWithPerf(\n\t\t\tpolicy.name,\n\t\t\t\"handle\",\n\t\t\tperfStats,\n\t\t\tasync () =>\n\t\t\t\tpolicy.handler({\n\t\t\t\t\tfile: relPath,\n\t\t\t\t\troot: gitRoot,\n\t\t\t\t\tresolve: this.flags.fix,\n\t\t\t\t\tconfig: this.commandConfig?.perPolicyConfig?.[\n\t\t\t\t\t\tpolicy.name\n\t\t\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: FIXME\n\t\t\t\t\t] as any,\n\t\t\t\t}),\n\t\t);\n\n\t\tif (result === true) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst messages = new StringBuilder();\n\t\tif (isPolicyFixResult(result)) {\n\t\t\tif (result.resolved) {\n\t\t\t\tmessages.append(\n\t\t\t\t\t`Resolved ${policy.name} policy failure for file: ${result.file}`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tmessages.append(\n\t\t\t\t\t`Error when trying to fix ${policy.name} policy failure in ${result.file}`,\n\t\t\t\t);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t} else {\n\t\t\t// result must be a PolicyFailureResult; check if there is a standalone resolver.\n\t\t\tconst { resolver } = policy;\n\n\t\t\tif (this.flags.fix && resolver !== undefined) {\n\t\t\t\t// Resolve the failure\n\t\t\t\tmessages.append(`${newline}attempting to resolve: ${relPath}`);\n\t\t\t\tconst resolveResult = await runWithPerf(\n\t\t\t\t\tpolicy.name,\n\t\t\t\t\t\"resolve\",\n\t\t\t\t\tperfStats,\n\t\t\t\t\tasync () => resolver({ file: relPath, root: gitRoot }),\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\tresolveResult.errorMessage !== undefined &&\n\t\t\t\t\tresolveResult.errorMessage !== \"\"\n\t\t\t\t) {\n\t\t\t\t\tmessages.append(newline + resolveResult.errorMessage);\n\t\t\t\t}\n\n\t\t\t\tif (!resolveResult.resolved) {\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No resolver, or fix is false, so we're in the full failure case.\n\t\t\t\tconst autoFixable = result.autoFixable\n\t\t\t\t\t? chalk.green(\" (autofixable)\")\n\t\t\t\t\t: \"\";\n\t\t\t\tmessages.append(\n\t\t\t\t\t`'${chalk.bold(policy.name)}' policy failure${autoFixable}: ${result.file}`,\n\t\t\t\t);\n\t\t\t\tmessages.append(\n\t\t\t\t\tresult.errorMessage === undefined\n\t\t\t\t\t\t? \"\"\n\t\t\t\t\t\t: `${newline}\\t${result.errorMessage}`,\n\t\t\t\t);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t}\n\n\t\tif ((process.exitCode ?? 0) === 0) {\n\t\t\tthis.info(messages.toString());\n\t\t} else {\n\t\t\tthis.warning(messages.toString());\n\t\t}\n\t}\n\n\t/**\n\t * Given a string that represents a path to a file in the repo, determines if the file should be checked, and if so,\n\t * routes the file to the appropriate handlers.\n\t */\n\tprivate async checkOrExcludeFile(\n\t\tinputPath: string,\n\t\tcommandContext: RepopoCommandContext,\n\t): Promise<void> {\n\t\tconst { excludeFiles: exclusions, gitRoot, perfStats } = commandContext;\n\n\t\tconst filePath = path.join(gitRoot, inputPath).trim().replace(/\\\\/g, \"/\");\n\n\t\tperfStats.count++;\n\t\tif (!exclusions.every((value) => !value.test(inputPath))) {\n\t\t\tthis.verbose(`Excluded all handlers: ${inputPath}`);\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.routeToHandlers(filePath, commandContext);\n\t\t} catch (error: unknown) {\n\t\t\tthrow new Error(\n\t\t\t\t`Error routing ${filePath} to handler: ${error}\\nStack:\\n${(error as Error).stack}`,\n\t\t\t);\n\t\t}\n\n\t\tperfStats.processed++;\n\t}\n}\n\nasync function readStdin(): Promise<string> {\n\treturn new Promise((resolve) => {\n\t\tconst stdin = process.stdin;\n\t\tstdin.setEncoding(\"utf8\");\n\n\t\tlet data = \"\";\n\t\tstdin.on(\"data\", (chunk) => {\n\t\t\tdata += chunk;\n\t\t});\n\n\t\tstdin.on(\"end\", () => {\n\t\t\tresolve(data);\n\t\t});\n\n\t\tif (stdin.isTTY) {\n\t\t\tresolve(\"\");\n\t\t}\n\t});\n}\n"]}
|
package/esm/commands/list.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseRepopoCommand } from "../baseCommand.js";
|
|
2
|
-
import type { RepoPolicy } from "../policy.js";
|
|
3
2
|
/**
|
|
4
3
|
* This command lists all the policies configured to run.
|
|
5
4
|
*/
|
|
@@ -8,6 +7,6 @@ export declare class ListCommand<T extends typeof BaseRepopoCommand & {
|
|
|
8
7
|
flags: typeof ListCommand.flags;
|
|
9
8
|
}> extends BaseRepopoCommand<T> {
|
|
10
9
|
static readonly summary = "Lists the policies configured to run.";
|
|
11
|
-
run(): Promise<
|
|
10
|
+
run(): Promise<void>;
|
|
12
11
|
}
|
|
13
12
|
//# sourceMappingURL=list.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;GAEG;AACH,qBAAa,WAAW,CACvB,CAAC,SAAS,OAAO,iBAAiB,GAAG;IACpC,IAAI,EAAE,OAAO,WAAW,CAAC,IAAI,CAAC;IAC9B,KAAK,EAAE,OAAO,WAAW,CAAC,KAAK,CAAC;CAChC,CACA,SAAQ,iBAAiB,CAAC,CAAC,CAAC;IAC7B,gBAAyB,OAAO,2CAA2C;IAGrD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ1C"}
|
package/esm/commands/list.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import chalk from "picocolors";
|
|
2
1
|
import { BaseRepopoCommand } from "../baseCommand.js";
|
|
2
|
+
import { DefaultPolicies } from "../policy.js";
|
|
3
3
|
/**
|
|
4
4
|
* This command lists all the policies configured to run.
|
|
5
5
|
*/
|
|
6
6
|
export class ListCommand extends BaseRepopoCommand {
|
|
7
7
|
static summary = "Lists the policies configured to run.";
|
|
8
|
-
// biome-ignore lint/suspicious/useAwait:
|
|
8
|
+
// biome-ignore lint/suspicious/useAwait: overridden method
|
|
9
9
|
async run() {
|
|
10
|
-
const
|
|
10
|
+
const policies = this.commandConfig?.policies ?? DefaultPolicies;
|
|
11
11
|
// list the handlers then exit
|
|
12
|
-
this.log(`${policies.length} POLICIES ENABLED`);
|
|
13
12
|
for (const h of policies) {
|
|
14
|
-
this.log(`${
|
|
13
|
+
this.log(`${h.name}\nresolver: ${h.resolver !== undefined}\n`);
|
|
15
14
|
}
|
|
16
|
-
|
|
15
|
+
this.log(`${policies.length} TOTAL POLICY HANDLERS`);
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
//# sourceMappingURL=list.js.map
|
package/esm/commands/list.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,WAKX,SAAQ,iBAAoB;IAC7B,MAAM,CAAmB,OAAO,GAAG,uCAAuC,CAAC;IAE3E,2DAA2D;IAC3C,KAAK,CAAC,GAAG;QACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,EAAE,QAAQ,IAAI,eAAe,CAAC;QACjE,8BAA8B;QAC9B,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,wBAAwB,CAAC,CAAC;IACtD,CAAC","sourcesContent":["import { BaseRepopoCommand } from \"../baseCommand.js\";\nimport { DefaultPolicies } from \"../policy.js\";\n\n/**\n * This command lists all the policies configured to run.\n */\nexport class ListCommand<\n\tT extends typeof BaseRepopoCommand & {\n\t\targs: typeof ListCommand.args;\n\t\tflags: typeof ListCommand.flags;\n\t},\n> extends BaseRepopoCommand<T> {\n\tstatic override readonly summary = \"Lists the policies configured to run.\";\n\n\t// biome-ignore lint/suspicious/useAwait: overridden method\n\tpublic override async run(): Promise<void> {\n\t\tconst policies = this.commandConfig?.policies ?? DefaultPolicies;\n\t\t// list the handlers then exit\n\t\tfor (const h of policies) {\n\t\t\tthis.log(`${h.name}\\nresolver: ${h.resolver !== undefined}\\n`);\n\t\t}\n\t\tthis.log(`${policies.length} TOTAL POLICY HANDLERS`);\n\t}\n}\n"]}
|
package/esm/config.d.ts
CHANGED
|
@@ -9,11 +9,16 @@ export type PerPolicySettings = ({
|
|
|
9
9
|
/**
|
|
10
10
|
* @alpha
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
export interface RepopoConfig {
|
|
13
16
|
/**
|
|
14
|
-
* An array of policies that are enabled.
|
|
17
|
+
* An array of policies that are enabled.
|
|
18
|
+
*
|
|
19
|
+
* See `DefaultPolicies` for the policies that will be enabled by default if this is `undefined`.
|
|
15
20
|
*/
|
|
16
|
-
policies?: RepoPolicy[];
|
|
21
|
+
policies?: RepoPolicy<any>[];
|
|
17
22
|
/**
|
|
18
23
|
* An array of strings/regular expressions. File paths that match any of these expressions will be completely excluded
|
|
19
24
|
* from policy.
|
|
@@ -24,12 +29,12 @@ export interface PolicyConfig {
|
|
|
24
29
|
* exclude that rule from being checked.
|
|
25
30
|
*/
|
|
26
31
|
excludePoliciesForFiles?: Record<PolicyName, (string | RegExp)[]>;
|
|
27
|
-
|
|
32
|
+
perPolicyConfig?: PerPolicySettings | undefined;
|
|
28
33
|
}
|
|
29
34
|
/**
|
|
30
35
|
* The default config applied when no config is found.
|
|
31
36
|
*
|
|
32
37
|
* @alpha
|
|
33
38
|
*/
|
|
34
|
-
export declare const DefaultPolicyConfig:
|
|
39
|
+
export declare const DefaultPolicyConfig: RepopoConfig;
|
|
35
40
|
//# sourceMappingURL=config.d.ts.map
|
package/esm/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,qCAAqC,CAAC;AACzF,OAAO,EAAmB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAC1B,CAAC;IACD,qBAAqB,EAAE,6BAA6B,CAAC;CACpD,GAAG,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,GAChC,SAAS,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,qCAAqC,CAAC;AACzF,OAAO,EAAmB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAC1B,CAAC;IACD,qBAAqB,EAAE,6BAA6B,CAAC;CACpD,GAAG,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,GAChC,SAAS,CAAC;AAEb;;GAEG;AACH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;OAIG;IAGH,QAAQ,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;IAE7B;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAEnC;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IAGlE,eAAe,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAChD;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAIjC,CAAC"}
|
package/esm/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAoC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAoC,MAAM,aAAa,CAAC;AA2ChF;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAiB;IAChD,QAAQ,EAAE,eAAe;IACzB,YAAY,EAAE,EAAE;IAChB,uBAAuB,EAAE,EAAE;CAC3B,CAAC","sourcesContent":["import type { PackageJsonPropertiesSettings } from \"./policies/PackageJsonProperties.js\";\nimport { DefaultPolicies, type PolicyName, type RepoPolicy } from \"./policy.js\";\n\n/**\n * @alpha\n */\nexport type PerPolicySettings =\n\t| ({\n\t\t\tPackageJsonProperties: PackageJsonPropertiesSettings;\n\t } & Record<PolicyName, unknown>)\n\t| undefined;\n\n/**\n * @alpha\n */\n/**\n * @alpha\n */\nexport interface RepopoConfig {\n\t/**\n\t * An array of policies that are enabled.\n\t *\n\t * See `DefaultPolicies` for the policies that will be enabled by default if this is `undefined`.\n\t */\n\n\t// biome-ignore lint/suspicious/noExplicitAny: FIXME\n\tpolicies?: RepoPolicy<any>[];\n\n\t/**\n\t * An array of strings/regular expressions. File paths that match any of these expressions will be completely excluded\n\t * from policy.\n\t */\n\texcludeFiles?: (string | RegExp)[];\n\n\t/**\n\t * An object with a policy name as keys that map to an array of strings/regular expressions to\n\t * exclude that rule from being checked.\n\t */\n\texcludePoliciesForFiles?: Record<PolicyName, (string | RegExp)[]>;\n\n\t// TODO: The type of this argument would ideally be a union of all types Record<Name of RepoPolicy, C of RepoPolicy>\n\tperPolicyConfig?: PerPolicySettings | undefined;\n}\n\n/**\n * The default config applied when no config is found.\n *\n * @alpha\n */\nexport const DefaultPolicyConfig: RepopoConfig = {\n\tpolicies: DefaultPolicies,\n\texcludeFiles: [],\n\texcludePoliciesForFiles: {},\n};\n"]}
|
package/esm/context.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PolicyHandlerPerfStats } from "./perf.js";
|
|
2
|
+
import type { PolicyName, RepoPolicy } from "./policy.js";
|
|
3
|
+
export type ExcludedPolicyFileMap = Map<PolicyName, RegExp[]>;
|
|
4
|
+
/**
|
|
5
|
+
* Contextual data available to all Repopo commands.
|
|
6
|
+
*/
|
|
7
|
+
export interface RepopoCommandContext {
|
|
8
|
+
/**
|
|
9
|
+
* A list of regular expressions used to exclude files from all handlers.
|
|
10
|
+
*/
|
|
11
|
+
excludeFiles: RegExp[];
|
|
12
|
+
/**
|
|
13
|
+
* A list of handlers to apply to selected files.
|
|
14
|
+
*/
|
|
15
|
+
policies: RepoPolicy[];
|
|
16
|
+
/**
|
|
17
|
+
* A per-handler list of regular expressions used to exclude files from specific handlers.
|
|
18
|
+
*/
|
|
19
|
+
excludePoliciesForFiles: ExcludedPolicyFileMap;
|
|
20
|
+
/**
|
|
21
|
+
* Path to the root of the git repo.
|
|
22
|
+
*/
|
|
23
|
+
gitRoot: string;
|
|
24
|
+
/**
|
|
25
|
+
* Stores performance data for each handler. Used to collect and display performance stats.
|
|
26
|
+
*/
|
|
27
|
+
perfStats: PolicyHandlerPerfStats;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,MAAM,qBAAqB,GAAG,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IAEvB;;OAEG;IACH,QAAQ,EAAE,UAAU,EAAE,CAAC;IAEvB;;OAEG;IACH,uBAAuB,EAAE,qBAAqB,CAAC;IAE/C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,sBAAsB,CAAC;CAClC"}
|
package/esm/context.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"","sourcesContent":["import type { PolicyHandlerPerfStats } from \"./perf.js\";\nimport type { PolicyName, RepoPolicy } from \"./policy.js\";\n\nexport type ExcludedPolicyFileMap = Map<PolicyName, RegExp[]>;\n\n/**\n * Contextual data available to all Repopo commands.\n */\nexport interface RepopoCommandContext {\n\t/**\n\t * A list of regular expressions used to exclude files from all handlers.\n\t */\n\texcludeFiles: RegExp[];\n\n\t/**\n\t * A list of handlers to apply to selected files.\n\t */\n\tpolicies: RepoPolicy[];\n\n\t/**\n\t * A per-handler list of regular expressions used to exclude files from specific handlers.\n\t */\n\texcludePoliciesForFiles: ExcludedPolicyFileMap;\n\n\t/**\n\t * Path to the root of the git repo.\n\t */\n\tgitRoot: string;\n\n\t/**\n\t * Stores performance data for each handler. Used to collect and display performance stats.\n\t */\n\tperfStats: PolicyHandlerPerfStats;\n}\n"]}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export { run } from "@oclif/core";
|
|
2
|
-
export type { PolicyFailure, PolicyFixResult, PolicyFunctionArguments, PolicyHandler, PolicyName, PolicyStandaloneResolver, RepoPolicy, } from "./policy.js";
|
|
3
|
-
export { DefaultPolicies } from "./policy.js";
|
|
4
|
-
export
|
|
5
|
-
export
|
|
2
|
+
export type { DefaultPolicyConfigType, PolicyFailure, PolicyFixResult, PolicyFunctionArguments, PolicyHandler, PolicyName, PolicyStandaloneResolver, RepoPolicy, } from "./policy.js";
|
|
3
|
+
export { DefaultPolicies, type PackageJsonHandler } from "./policy.js";
|
|
4
|
+
export { JsTsFileHeaders } from "./policies/JsTsFileHeaders.js";
|
|
5
|
+
export { NoJsFileExtensions } from "./policies/NoJsFileExtensions.js";
|
|
6
|
+
export { PackageJsonProperties, type PackageJsonPropertiesSettings, } from "./policies/PackageJsonProperties.js";
|
|
7
|
+
export { PackageJsonRepoDirectoryProperty } from "./policies/PackageJsonRepoDirectoryProperty.js";
|
|
8
|
+
export { PackageJsonSorted } from "./policies/PackageJsonSorted.js";
|
|
9
|
+
export { PackageScripts } from "./policies/PackageScripts.js";
|
|
10
|
+
export type { PerPolicySettings, RepopoConfig, } from "./config.js";
|
|
11
|
+
export { generatePackagePolicy } from "./policyGenerators/generatePackagePolicy.js";
|
|
12
|
+
export { generateFileHeaderPolicy, type FileHeaderGeneratorConfig, type FileHeaderPolicyConfig, } from "./policyGenerators/generateFileHeaderPolicy.js";
|
|
6
13
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,YAAY,EACX,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,UAAU,EACV,wBAAwB,EACxB,UAAU,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,YAAY,EACX,uBAAuB,EACvB,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,UAAU,EACV,wBAAwB,EACxB,UAAU,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EACN,qBAAqB,EACrB,KAAK,6BAA6B,GAClC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,YAAY,EACX,iBAAiB,EACjB,YAAY,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EACN,wBAAwB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,GAC3B,MAAM,gDAAgD,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
export { run } from "@oclif/core";
|
|
2
2
|
export { DefaultPolicies } from "./policy.js";
|
|
3
|
+
export { JsTsFileHeaders } from "./policies/JsTsFileHeaders.js";
|
|
4
|
+
export { NoJsFileExtensions } from "./policies/NoJsFileExtensions.js";
|
|
5
|
+
export { PackageJsonProperties, } from "./policies/PackageJsonProperties.js";
|
|
6
|
+
export { PackageJsonRepoDirectoryProperty } from "./policies/PackageJsonRepoDirectoryProperty.js";
|
|
7
|
+
export { PackageJsonSorted } from "./policies/PackageJsonSorted.js";
|
|
8
|
+
export { PackageScripts } from "./policies/PackageScripts.js";
|
|
9
|
+
export { generatePackagePolicy } from "./policyGenerators/generatePackagePolicy.js";
|
|
10
|
+
export { generateFileHeaderPolicy, } from "./policyGenerators/generateFileHeaderPolicy.js";
|
|
3
11
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAYlC,OAAO,EAAE,eAAe,EAA2B,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EACN,qBAAqB,GAErB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAM9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EACN,wBAAwB,GAGxB,MAAM,gDAAgD,CAAC","sourcesContent":["export { run } from \"@oclif/core\";\n\nexport type {\n\tDefaultPolicyConfigType,\n\tPolicyFailure,\n\tPolicyFixResult,\n\tPolicyFunctionArguments,\n\tPolicyHandler,\n\tPolicyName,\n\tPolicyStandaloneResolver,\n\tRepoPolicy,\n} from \"./policy.js\";\nexport { DefaultPolicies, type PackageJsonHandler } from \"./policy.js\";\nexport { JsTsFileHeaders } from \"./policies/JsTsFileHeaders.js\";\nexport { NoJsFileExtensions } from \"./policies/NoJsFileExtensions.js\";\nexport {\n\tPackageJsonProperties,\n\ttype PackageJsonPropertiesSettings,\n} from \"./policies/PackageJsonProperties.js\";\nexport { PackageJsonRepoDirectoryProperty } from \"./policies/PackageJsonRepoDirectoryProperty.js\";\nexport { PackageJsonSorted } from \"./policies/PackageJsonSorted.js\";\nexport { PackageScripts } from \"./policies/PackageScripts.js\";\n\nexport type {\n\tPerPolicySettings,\n\tRepopoConfig,\n} from \"./config.js\";\nexport { generatePackagePolicy } from \"./policyGenerators/generatePackagePolicy.js\";\nexport {\n\tgenerateFileHeaderPolicy,\n\ttype FileHeaderGeneratorConfig,\n\ttype FileHeaderPolicyConfig,\n} from \"./policyGenerators/generateFileHeaderPolicy.js\";\n"]}
|
package/esm/perf.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perf.d.ts","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"perf.d.ts","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEhD,MAAM,WAAW,sBAAsB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;CACjD;AAED,wBAAgB,YAAY,IAAI,sBAAsB,CAMrD;AAED,wBAAsB,WAAW,CAAC,CAAC,EAClC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,sBAAsB,EAC7B,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAWZ;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,sBAAsB,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAYzE"}
|
package/esm/perf.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stores performance data for each handler. Used to collect and display performance stats.
|
|
3
|
-
*/
|
|
4
|
-
const handlerPerformanceData = new Map();
|
|
5
1
|
export function newPerfStats() {
|
|
6
2
|
return {
|
|
7
3
|
count: 0,
|
|
@@ -21,7 +17,7 @@ export async function runWithPerf(name, action, stats, run) {
|
|
|
21
17
|
}
|
|
22
18
|
export function logStats(stats, log) {
|
|
23
19
|
log.log(`Statistics: ${stats.processed} processed, ${stats.count - stats.processed} excluded, ${stats.count} total`);
|
|
24
|
-
for (const [action, handlerPerf] of
|
|
20
|
+
for (const [action, handlerPerf] of stats.data.entries()) {
|
|
25
21
|
log.log(`Performance for "${action}":`);
|
|
26
22
|
for (const [handler, dur] of handlerPerf.entries()) {
|
|
27
23
|
log.log(`\t${handler}: ${dur}ms`);
|
package/esm/perf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perf.js","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"perf.js","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,YAAY;IAC3B,OAAO;QACN,KAAK,EAAE,CAAC;QACR,SAAS,EAAE,CAAC;QACZ,IAAI,EAAE,IAAI,GAAG,EAAyC;KACtD,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,IAAY,EACZ,MAAoB,EACpB,KAA6B,EAC7B,GAAqB;IAErB,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,GAAG,EAAkB,CAAC;IACtE,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEnC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,MAAM,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC;IAC3B,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAE1B,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAA6B,EAAE,GAAW;IAClE,GAAG,CAAC,GAAG,CACN,eAAe,KAAK,CAAC,SAAS,eAC7B,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,SACrB,cAAc,KAAK,CAAC,KAAK,QAAQ,CACjC,CAAC;IACF,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QAC1D,GAAG,CAAC,GAAG,CAAC,oBAAoB,MAAM,IAAI,CAAC,CAAC;QACxC,KAAK,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;YACpD,GAAG,CAAC,GAAG,CAAC,KAAK,OAAO,KAAK,GAAG,IAAI,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import type { Logger } from \"@tylerbu/cli-api\";\nimport type { PolicyName } from \"./policy.js\";\n\nexport type PolicyAction = \"handle\" | \"resolve\";\n\nexport interface PolicyHandlerPerfStats {\n\tcount: number;\n\tprocessed: number;\n\tdata: Map<PolicyAction, Map<PolicyName, number>>;\n}\n\nexport function newPerfStats(): PolicyHandlerPerfStats {\n\treturn {\n\t\tcount: 0,\n\t\tprocessed: 0,\n\t\tdata: new Map<PolicyAction, Map<PolicyName, number>>(),\n\t};\n}\n\nexport async function runWithPerf<T>(\n\tname: string,\n\taction: PolicyAction,\n\tstats: PolicyHandlerPerfStats,\n\trun: () => Promise<T>,\n): Promise<T> {\n\tconst actionMap = stats.data.get(action) ?? new Map<string, number>();\n\tlet dur = actionMap.get(name) ?? 0;\n\n\tconst start = Date.now();\n\tconst result = await run();\n\tdur += Date.now() - start;\n\n\tactionMap.set(name, dur);\n\tstats.data.set(action, actionMap);\n\treturn result;\n}\n\nexport function logStats(stats: PolicyHandlerPerfStats, log: Logger): void {\n\tlog.log(\n\t\t`Statistics: ${stats.processed} processed, ${\n\t\t\tstats.count - stats.processed\n\t\t} excluded, ${stats.count} total`,\n\t);\n\tfor (const [action, handlerPerf] of stats.data.entries()) {\n\t\tlog.log(`Performance for \"${action}\":`);\n\t\tfor (const [handler, dur] of handlerPerf.entries()) {\n\t\t\tlog.log(`\\t${handler}: ${dur}ms`);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type FileHeaderPolicyConfig } from "../policyGenerators/generateFileHeaderPolicy.js";
|
|
2
|
+
/**
|
|
3
|
+
* A RepoPolicy that checks that HTML files have the configured header comment.
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
6
|
+
*/
|
|
7
|
+
export declare const HtmlFileHeaders: import("../policy.js").RepoPolicy<FileHeaderPolicyConfig>;
|
|
8
|
+
//# sourceMappingURL=HtmlFileHeaders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HtmlFileHeaders.d.ts","sourceRoot":"","sources":["../../src/policies/HtmlFileHeaders.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,sBAAsB,EAE3B,MAAM,iDAAiD,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,eAAe,2DAc1B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EOL as newline } from "node:os";
|
|
2
|
+
import { generateFileHeaderPolicy, } from "../policyGenerators/generateFileHeaderPolicy.js";
|
|
3
|
+
/**
|
|
4
|
+
* A RepoPolicy that checks that HTML files have the configured header comment.
|
|
5
|
+
*
|
|
6
|
+
* @alpha
|
|
7
|
+
*/
|
|
8
|
+
export const HtmlFileHeaders = generateFileHeaderPolicy("HtmlFileHeaders", {
|
|
9
|
+
match: /(^|\/)[^/]+\.[mc]?[jt]sx?$/i,
|
|
10
|
+
lineStart: /<!-- /, // Lines begin with '<!-- '
|
|
11
|
+
lineEnd: / -->\r?\n/, // Lines end with ' -->' followed by CRLF or LF
|
|
12
|
+
replacer: (content, { headerText }) => {
|
|
13
|
+
const newContent = `<!-- ${headerText.replace(newline, ` -->${newline}<!-- `)} -->${newline}${newline}${content}`;
|
|
14
|
+
return newContent;
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=HtmlFileHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HtmlFileHeaders.js","sourceRoot":"","sources":["../../src/policies/HtmlFileHeaders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAEN,wBAAwB,GACxB,MAAM,iDAAiD,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,wBAAwB,CAAC,iBAAiB,EAAE;IAC1E,KAAK,EAAE,6BAA6B;IACpC,SAAS,EAAE,OAAO,EAAE,2BAA2B;IAC/C,OAAO,EAAE,WAAW,EAAE,+CAA+C;IACrE,QAAQ,EAAE,CACT,OAAe,EACf,EAAE,UAAU,EAA0B,EAC7B,EAAE;QACX,MAAM,UAAU,GAAG,QAAQ,UAAU,CAAC,OAAO,CAC5C,OAAO,EACP,OAAO,OAAO,OAAO,CACrB,OAAO,OAAO,GAAG,OAAO,GAAG,OAAO,EAAE,CAAC;QACtC,OAAO,UAAU,CAAC;IACnB,CAAC;CACD,CAAC,CAAC","sourcesContent":["import { EOL as newline } from \"node:os\";\nimport {\n\ttype FileHeaderPolicyConfig,\n\tgenerateFileHeaderPolicy,\n} from \"../policyGenerators/generateFileHeaderPolicy.js\";\n\n/**\n * A RepoPolicy that checks that HTML files have the configured header comment.\n *\n * @alpha\n */\nexport const HtmlFileHeaders = generateFileHeaderPolicy(\"HtmlFileHeaders\", {\n\tmatch: /(^|\\/)[^/]+\\.[mc]?[jt]sx?$/i,\n\tlineStart: /<!-- /, // Lines begin with '<!-- '\n\tlineEnd: / -->\\r?\\n/, // Lines end with ' -->' followed by CRLF or LF\n\treplacer: (\n\t\tcontent: string,\n\t\t{ headerText }: FileHeaderPolicyConfig,\n\t): string => {\n\t\tconst newContent = `<!-- ${headerText.replace(\n\t\t\tnewline,\n\t\t\t` -->${newline}<!-- `,\n\t\t)} -->${newline}${newline}${content}`;\n\t\treturn newContent;\n\t},\n});\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type FileHeaderPolicyConfig } from "../policyGenerators/generateFileHeaderPolicy.js";
|
|
2
|
+
/**
|
|
3
|
+
* A RepoPolicy that checks that JavaScript and TypeScript source files have the configured header comment
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
6
|
+
*/
|
|
7
|
+
export declare const JsTsFileHeaders: import("../policy.js").RepoPolicy<FileHeaderPolicyConfig>;
|
|
8
|
+
//# sourceMappingURL=JsTsFileHeaders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsTsFileHeaders.d.ts","sourceRoot":"","sources":["../../src/policies/JsTsFileHeaders.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,sBAAsB,EAE3B,MAAM,iDAAiD,CAAC;AAkBzD;;;;GAIG;AACH,eAAO,MAAM,eAAe,2DAO1B,CAAC"}
|