repopo 0.4.0 → 0.6.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.
Files changed (101) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +40 -23
  3. package/THIRD-PARTY-LICENSES.txt +21 -11
  4. package/esm/api.d.ts +2 -0
  5. package/esm/api.d.ts.map +1 -0
  6. package/esm/api.js +2 -0
  7. package/esm/api.js.map +1 -0
  8. package/esm/baseCommand.d.ts +13 -43
  9. package/esm/baseCommand.d.ts.map +1 -1
  10. package/esm/baseCommand.js +31 -67
  11. package/esm/baseCommand.js.map +1 -1
  12. package/esm/commands/check.d.ts +17 -12
  13. package/esm/commands/check.d.ts.map +1 -1
  14. package/esm/commands/check.js +147 -115
  15. package/esm/commands/check.js.map +1 -1
  16. package/esm/commands/list.d.ts +1 -2
  17. package/esm/commands/list.d.ts.map +1 -1
  18. package/esm/commands/list.js +5 -6
  19. package/esm/commands/list.js.map +1 -1
  20. package/esm/config.d.ts +9 -15
  21. package/esm/config.d.ts.map +1 -1
  22. package/esm/config.js +3 -2
  23. package/esm/config.js.map +1 -1
  24. package/esm/context.d.ts +29 -0
  25. package/esm/context.d.ts.map +1 -0
  26. package/esm/context.js +2 -0
  27. package/esm/context.js.map +1 -0
  28. package/esm/generators.d.ts +21 -0
  29. package/esm/generators.d.ts.map +1 -0
  30. package/esm/generators.js +2 -0
  31. package/esm/generators.js.map +1 -0
  32. package/esm/index.d.ts +5 -4
  33. package/esm/index.d.ts.map +1 -1
  34. package/esm/index.js +3 -1
  35. package/esm/index.js.map +1 -1
  36. package/esm/makePolicy.d.ts +9 -0
  37. package/esm/makePolicy.d.ts.map +1 -0
  38. package/esm/makePolicy.js +28 -0
  39. package/esm/makePolicy.js.map +1 -0
  40. package/esm/perf.d.ts.map +1 -1
  41. package/esm/perf.js +1 -5
  42. package/esm/perf.js.map +1 -1
  43. package/esm/policies/HtmlFileHeaders.d.ts +8 -0
  44. package/esm/policies/HtmlFileHeaders.d.ts.map +1 -0
  45. package/esm/policies/HtmlFileHeaders.js +17 -0
  46. package/esm/policies/HtmlFileHeaders.js.map +1 -0
  47. package/esm/policies/JsTsFileHeaders.d.ts +8 -0
  48. package/esm/policies/JsTsFileHeaders.d.ts.map +1 -0
  49. package/esm/policies/JsTsFileHeaders.js +24 -0
  50. package/esm/policies/JsTsFileHeaders.js.map +1 -0
  51. package/esm/policies/NoJsFileExtensions.d.ts +4 -2
  52. package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
  53. package/esm/policies/NoJsFileExtensions.js +15 -15
  54. package/esm/policies/NoJsFileExtensions.js.map +1 -1
  55. package/esm/policies/PackageJsonProperties.d.ts +6 -8
  56. package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
  57. package/esm/policies/PackageJsonProperties.js +37 -40
  58. package/esm/policies/PackageJsonProperties.js.map +1 -1
  59. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +3 -2
  60. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
  61. package/esm/policies/PackageJsonRepoDirectoryProperty.js +40 -37
  62. package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
  63. package/esm/policies/PackageJsonSorted.d.ts +7 -0
  64. package/esm/policies/PackageJsonSorted.d.ts.map +1 -0
  65. package/esm/policies/PackageJsonSorted.js +45 -0
  66. package/esm/policies/PackageJsonSorted.js.map +1 -0
  67. package/esm/policies/PackageScripts.d.ts +7 -0
  68. package/esm/policies/PackageScripts.d.ts.map +1 -0
  69. package/esm/policies/PackageScripts.js +25 -0
  70. package/esm/policies/PackageScripts.js.map +1 -0
  71. package/esm/policies/constants.d.ts +5 -0
  72. package/esm/policies/constants.d.ts.map +1 -0
  73. package/esm/policies/constants.js +5 -0
  74. package/esm/policies/constants.js.map +1 -0
  75. package/esm/policies.d.ts +8 -0
  76. package/esm/policies.d.ts.map +1 -0
  77. package/esm/policies.js +8 -0
  78. package/esm/policies.js.map +1 -0
  79. package/esm/policy.d.ts +60 -15
  80. package/esm/policy.d.ts.map +1 -1
  81. package/esm/policy.js +21 -22
  82. package/esm/policy.js.map +1 -1
  83. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +45 -0
  84. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -0
  85. package/esm/policyDefiners/defineFileHeaderPolicy.js +61 -0
  86. package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -0
  87. package/esm/policyDefiners/definePackagePolicy.d.ts +15 -0
  88. package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -0
  89. package/esm/policyDefiners/definePackagePolicy.js +20 -0
  90. package/esm/policyDefiners/definePackagePolicy.js.map +1 -0
  91. package/esm/tsdoc-metadata.json +1 -1
  92. package/oclif.manifest.json +45 -53
  93. package/package.json +39 -23
  94. package/esm/policies/PackageJsonSortedPolicy.d.ts +0 -6
  95. package/esm/policies/PackageJsonSortedPolicy.d.ts.map +0 -1
  96. package/esm/policies/PackageJsonSortedPolicy.js +0 -49
  97. package/esm/policies/PackageJsonSortedPolicy.js.map +0 -1
  98. package/esm/policies/SortTsconfigs.d.ts +0 -10
  99. package/esm/policies/SortTsconfigs.d.ts.map +0 -1
  100. package/esm/policies/SortTsconfigs.js +0 -33
  101. package/esm/policies/SortTsconfigs.js.map +0 -1
@@ -1,13 +1,10 @@
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
- import path from "pathe";
6
4
  import chalk from "picocolors";
7
- import { BaseRepopoCommand, } from "../baseCommand.js";
8
- import { DefaultPolicyConfig } from "../config.js";
5
+ import { BaseRepopoCommand } from "../baseCommand.js";
9
6
  import { logStats, runWithPerf } from "../perf.js";
10
- import { isPolicyFixResult } from "../policy.js";
7
+ import { isPolicyFixResult, } from "../policy.js";
11
8
  /**
12
9
  * This tool enforces policies across the code base via a series of handler functions. The handler functions are
13
10
  * associated with a regular expression, and all files matching that expression are passed to the handler function.
@@ -32,17 +29,10 @@ export class CheckPolicy extends BaseRepopoCommand {
32
29
  }),
33
30
  ...BaseRepopoCommand.flags,
34
31
  };
35
- processed = 0;
36
- count = 0;
37
- defaultConfig = DefaultPolicyConfig;
38
- async init() {
39
- await super.init();
32
+ async run() {
40
33
  if (this.flags.fix) {
41
34
  this.info("Resolving errors if possible.");
42
35
  }
43
- }
44
- async run() {
45
- // list the handlers then exit
46
36
  const config = this.commandConfig;
47
37
  const policies = config?.policies ?? [];
48
38
  this.verbose(`${policies.length} policies loaded.`);
@@ -53,132 +43,174 @@ export class CheckPolicy extends BaseRepopoCommand {
53
43
  if (this.flags.stdin) {
54
44
  const stdInput = await readStdin();
55
45
  if (stdInput !== undefined) {
56
- filePathsToCheck.push(...stdInput.split("\n"));
46
+ filePathsToCheck.push(...stdInput
47
+ .replace(
48
+ // normalize slashes in case they're windows paths
49
+ /\\/g, "/")
50
+ .split("\n"));
57
51
  }
58
52
  }
59
53
  else {
60
- const gitFiles = (await this.git.raw("ls-files", "-co", "--exclude-standard", "--full-name")) ?? "";
61
- filePathsToCheck.push(...gitFiles.split("\n"));
62
- }
63
- try {
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
- });
54
+ const gitFiles = (await this.git.raw("ls-files",
55
+ // include staged files and untracked files
56
+ "-co",
57
+ // exclude gitignored files and other standard ignore rules
58
+ "--exclude-standard",
59
+ // Outputs paths relative to the root of the repository, regardless of the current working directory.
60
+ "--full-name")) ?? "";
61
+ filePathsToCheck.push(...gitFiles
62
+ .replace(
63
+ // normalize slashes in case they're windows paths
64
+ /\\/g, "/")
65
+ .split("\n"));
71
66
  }
67
+ const context = await this.getContext();
68
+ await this.checkAllFiles(filePathsToCheck, context);
72
69
  }
73
- async executePolicy(pathsToCheck, commandContext) {
70
+ /**
71
+ * Executes all policies against the provided paths.
72
+ *
73
+ * @param pathsToCheck - All paths that should be checked. Paths should be relative to the repository root.
74
+ * @param context - The context.
75
+ */
76
+ async checkAllFiles(pathsToCheck, context) {
74
77
  try {
75
78
  for (const pathToCheck of pathsToCheck) {
76
- // eslint-disable-next-line no-await-in-loop
77
- await this.checkOrExcludeFile(pathToCheck, commandContext);
79
+ await this.checkOrExcludeFile(pathToCheck, context);
78
80
  }
79
81
  }
80
82
  finally {
81
- logStats(commandContext.perfStats, this);
83
+ if (!this.flags.quiet) {
84
+ logStats(context.perfStats, this);
85
+ }
82
86
  }
83
87
  }
84
88
  /**
85
- * Routes files to their handlers and resolvers by regex testing their full paths. If a file fails a policy that has a
86
- * resolver, the resolver will be invoked as well. Synchronizes the output, exit codes, and resolve
87
- * decision for all handlers.
89
+ * Given a string that represents a path to a file in the repo, determines if the file should be checked, and if so,
90
+ * routes the file to the appropriate handlers.
91
+ *
92
+ * @param relPath - A git repo-relative path to a file.
88
93
  */
89
- async routeToHandlers(file, commandContext) {
90
- const { policies, excludePoliciesForFiles, gitRoot, perfStats } = commandContext;
91
- // Use the repo-relative path so that regexes that specify string start (^) will match repo paths.
92
- // Replace \ in result with / in case OS is Windows.
93
- const relPath = path.relative(gitRoot, file).replace(/\\/g, "/");
94
- const config = this.commandConfig;
95
- await Promise.all(policies
96
- .filter((handler) => handler.match.test(relPath))
97
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
98
- .map(async (policy) => {
99
- // doing exclusion per handler
100
- const exclusions = excludePoliciesForFiles.get(policy.name);
101
- if (exclusions !== undefined &&
102
- !exclusions.every((regex) => !regex.test(relPath))) {
103
- this.verbose(`Excluded from '${policy.name}' policy: ${relPath}`);
104
- return;
105
- }
106
- const result = await runWithPerf(policy.name, "handle", perfStats, async () => policy.handler({
94
+ async checkOrExcludeFile(relPath, context) {
95
+ const { perfStats } = context;
96
+ perfStats.count++;
97
+ try {
98
+ await this.routeToPolicies(relPath, context);
99
+ }
100
+ catch (error) {
101
+ throw new Error(`Error routing ${relPath} to handler: ${error}\nStack:\n${error.stack}`);
102
+ }
103
+ perfStats.processed++;
104
+ }
105
+ async routeToPolicies(relPath, context) {
106
+ const { policies, excludeFromAll } = context;
107
+ // Check exclusions
108
+ if (excludeFromAll.some((regex) => regex.test(relPath))) {
109
+ this.verbose(`Excluded all handlers: ${relPath}`);
110
+ return; // Early return for excluded files
111
+ }
112
+ // Run all matching policies
113
+ const matchingPolicies = policies.filter((policy) => policy.match.test(relPath));
114
+ // for(const policy of matchingPolicies) {
115
+ // bars.addFile(policy.name,
116
+ // }
117
+ await Promise.all(matchingPolicies.map(async (policy) => {
118
+ return await this.runPolicyOnFile(relPath, policy, context);
119
+ }));
120
+ }
121
+ async runPolicyOnFile(relPath, policy, context) {
122
+ const { excludePoliciesForFiles, perfStats, gitRoot } = context;
123
+ // Check if the policy is excluded for the file
124
+ if (this.isPolicyExcluded(relPath, policy, excludePoliciesForFiles)) {
125
+ this.verbose(`Excluded from '${policy.name}' policy: ${relPath}`);
126
+ return;
127
+ }
128
+ try {
129
+ // Execute the policy handler
130
+ const result = await this.executePolicyHandler(relPath, policy, perfStats, gitRoot);
131
+ // Handle the result of the policy execution
132
+ await this.handlePolicyResult(result, relPath, policy, perfStats, gitRoot);
133
+ }
134
+ catch (error) {
135
+ // Log and rethrow the error for higher-level handling
136
+ this.error(`Error executing policy '${policy.name}' for file '${relPath}': ${error}`);
137
+ }
138
+ }
139
+ isPolicyExcluded(relPath, policy, excludePoliciesForFiles) {
140
+ return (excludePoliciesForFiles
141
+ .get(policy.name)
142
+ ?.some((regex) => regex.test(relPath)) ?? false);
143
+ }
144
+ async executePolicyHandler(relPath, policy, perfStats, gitRoot) {
145
+ try {
146
+ return await runWithPerf(policy.name, "handle", perfStats, () => policy.handler({
107
147
  file: relPath,
108
148
  root: gitRoot,
109
149
  resolve: this.flags.fix,
110
- config: config?.policySettings?.[policy.name],
150
+ config: policy.config,
111
151
  }));
112
- if (result === true) {
113
- return;
114
- }
115
- const messages = new StringBuilder();
116
- if (isPolicyFixResult(result)) {
117
- if (result.resolved) {
118
- messages.append(`Resolved ${policy.name} policy failure for file: ${result.file}`);
119
- }
120
- else {
121
- messages.append(`Error when trying to fix ${policy.name} policy failure in ${result.file}`);
122
- process.exitCode = 1;
123
- }
124
- }
125
- else {
126
- // result must be a PolicyFailureResult; check if there is a standalone resolver.
127
- const { resolver } = policy;
128
- if (this.flags.fix && resolver !== undefined) {
129
- // Resolve the failure
130
- messages.append(`${newline}attempting to resolve: ${relPath}`);
131
- const resolveResult = await runWithPerf(policy.name, "resolve", perfStats, async () => resolver({ file: relPath, root: gitRoot }));
132
- if (resolveResult.errorMessage !== undefined &&
133
- resolveResult.errorMessage !== "") {
134
- messages.append(newline + resolveResult.errorMessage);
135
- }
136
- if (!resolveResult.resolved) {
137
- process.exitCode = 1;
138
- }
139
- }
140
- else {
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}`);
149
- process.exitCode = 1;
150
- }
151
- }
152
- if ((process.exitCode ?? 0) === 0) {
153
- this.info(messages.toString());
154
- }
155
- else {
156
- this.warning(messages.toString());
157
- }
158
- }));
152
+ }
153
+ catch (error) {
154
+ this.error(`Error in policy handler '${policy.name}' for file '${relPath}': ${error}`);
155
+ }
159
156
  }
160
- /**
161
- * Given a string that represents a path to a file in the repo, determines if the file should be checked, and if so,
162
- * routes the file to the appropriate handlers.
163
- */
164
- async checkOrExcludeFile(inputPath, commandContext) {
165
- const { excludeFiles: exclusions, gitRoot, pathRegex } = commandContext;
166
- const filePath = path.join(gitRoot, inputPath).trim().replace(/\\/g, "/");
167
- if (!(pathRegex.test(inputPath) && fs.existsSync(filePath))) {
157
+ async handlePolicyResult(result, relPath, policy, perfStats, gitRoot) {
158
+ if (result === true) {
168
159
  return;
169
160
  }
170
- this.count++;
171
- if (!exclusions.every((value) => !value.test(inputPath))) {
172
- this.verbose(`Excluded all handlers: ${inputPath}`);
173
- return;
161
+ if (isPolicyFixResult(result)) {
162
+ this.handleFixResult(result, policy);
174
163
  }
175
- try {
176
- await this.routeToHandlers(filePath, commandContext);
164
+ else {
165
+ await this.handleFailureResult(result, relPath, policy, perfStats, gitRoot);
177
166
  }
178
- catch (error) {
179
- throw new Error(`Error routing ${filePath} to handler: ${error}`);
167
+ }
168
+ handleFixResult(result, policy) {
169
+ const messages = new StringBuilder();
170
+ if (result.resolved) {
171
+ messages.append(`Resolved ${policy.name} policy failure for file: ${result.file}`);
172
+ }
173
+ else {
174
+ messages.append(`Error fixing ${policy.name} policy failure in ${result.file}`);
175
+ process.exitCode = 1;
176
+ }
177
+ this.logMessages(messages);
178
+ }
179
+ async handleFailureResult(result, relPath, policy, perfStats, gitRoot) {
180
+ const messages = new StringBuilder();
181
+ if (this.flags.fix && policy.resolver) {
182
+ await this.attemptResolution(relPath, policy, policy.resolver, perfStats, gitRoot, messages);
183
+ }
184
+ else {
185
+ this.logPolicyFailure(result, policy, messages);
186
+ }
187
+ this.logMessages(messages);
188
+ }
189
+ async attemptResolution(relPath, policy, resolver, perfStats, gitRoot, messages) {
190
+ messages.append(`${newline}Attempting to resolve: ${relPath}`);
191
+ const resolveResult = await runWithPerf(policy.name, "resolve", perfStats, () => resolver({ file: relPath, root: gitRoot }));
192
+ if (!resolveResult.resolved) {
193
+ process.exitCode = 1;
194
+ }
195
+ if (resolveResult.errorMessage) {
196
+ messages.append(newline + resolveResult.errorMessage);
197
+ }
198
+ }
199
+ logPolicyFailure(result, policy, messages) {
200
+ const autoFixable = result.autoFixable ? chalk.green(" (autofixable)") : "";
201
+ messages.append(`'${chalk.bold(policy.name)}' policy failure${autoFixable}: ${result.file}`);
202
+ if (result.errorMessage) {
203
+ messages.append(`${newline}\t${result.errorMessage}`);
204
+ }
205
+ process.exitCode = 1;
206
+ }
207
+ logMessages(messages) {
208
+ if ((process.exitCode ?? 0) === 0) {
209
+ this.info(messages.toString());
210
+ }
211
+ else {
212
+ this.warning(messages.toString());
180
213
  }
181
- this.processed++;
182
214
  }
183
215
  }
184
216
  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,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B,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;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,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAA+B,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EAMN,iBAAiB,GACjB,MAAM,cAAc,CAAC;AAEtB;;;;;;;;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+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AK,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 { EOL as newline } from \"node:os\";\nimport { Flags } from \"@oclif/core\";\nimport { StringBuilder } from \"@rushstack/node-core-library\";\nimport chalk from \"picocolors\";\n\nimport { BaseRepopoCommand } from \"../baseCommand.js\";\nimport type { RepopoCommandContext } from \"../context.js\";\nimport { type PolicyHandlerPerfStats, logStats, runWithPerf } from \"../perf.js\";\nimport {\n\ttype PolicyFailure,\n\ttype PolicyFixResult,\n\ttype PolicyHandlerResult,\n\ttype PolicyInstance,\n\ttype PolicyStandaloneResolver,\n\tisPolicyFixResult,\n} 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(\n\t\t\t\t\t...stdInput\n\t\t\t\t\t\t.replace(\n\t\t\t\t\t\t\t// normalize slashes in case they're windows paths\n\t\t\t\t\t\t\t/\\\\/g,\n\t\t\t\t\t\t\t\"/\",\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.split(\"\\n\"),\n\t\t\t\t);\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// include staged files and untracked files\n\t\t\t\t\t\"-co\",\n\t\t\t\t\t// exclude gitignored files and other standard ignore rules\n\t\t\t\t\t\"--exclude-standard\",\n\t\t\t\t\t// Outputs paths relative to the root of the repository, regardless of the current working directory.\n\t\t\t\t\t\"--full-name\",\n\t\t\t\t)) ?? \"\";\n\n\t\t\tfilePathsToCheck.push(\n\t\t\t\t...gitFiles\n\t\t\t\t\t.replace(\n\t\t\t\t\t\t// normalize slashes in case they're windows paths\n\t\t\t\t\t\t/\\\\/g,\n\t\t\t\t\t\t\"/\",\n\t\t\t\t\t)\n\t\t\t\t\t.split(\"\\n\"),\n\t\t\t);\n\t\t}\n\n\t\tconst context: RepopoCommandContext = await this.getContext();\n\n\t\tawait this.checkAllFiles(filePathsToCheck, context);\n\t}\n\n\t/**\n\t * Executes all policies against the provided paths.\n\t *\n\t * @param pathsToCheck - All paths that should be checked. Paths should be relative to the repository root.\n\t * @param context - The context.\n\t */\n\tprivate async checkAllFiles(\n\t\tpathsToCheck: string[],\n\t\tcontext: RepopoCommandContext,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tfor (const pathToCheck of pathsToCheck) {\n\t\t\t\tawait this.checkOrExcludeFile(pathToCheck, context);\n\t\t\t}\n\t\t} finally {\n\t\t\tif (!this.flags.quiet) {\n\t\t\t\tlogStats(context.perfStats, this);\n\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\t * @param relPath - A git repo-relative path to a file.\n\t */\n\tprivate async checkOrExcludeFile(\n\t\trelPath: string,\n\t\tcontext: RepopoCommandContext,\n\t): Promise<void> {\n\t\tconst { perfStats } = context;\n\t\tperfStats.count++;\n\n\t\ttry {\n\t\t\tawait this.routeToPolicies(relPath, context);\n\t\t} catch (error: unknown) {\n\t\t\tthrow new Error(\n\t\t\t\t`Error routing ${relPath} 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\tprivate async routeToPolicies(\n\t\trelPath: string,\n\t\tcontext: RepopoCommandContext,\n\t): Promise<void> {\n\t\tconst { policies, excludeFromAll } = context;\n\n\t\t// Check exclusions\n\t\tif (excludeFromAll.some((regex) => regex.test(relPath))) {\n\t\t\tthis.verbose(`Excluded all handlers: ${relPath}`);\n\t\t\treturn; // Early return for excluded files\n\t\t}\n\n\t\t// Run all matching policies\n\t\tconst matchingPolicies = policies.filter((policy) =>\n\t\t\tpolicy.match.test(relPath),\n\t\t);\n\n\t\t// for(const policy of matchingPolicies) {\n\t\t// \tbars.addFile(policy.name,\n\t\t// }\n\n\t\tawait Promise.all(\n\t\t\tmatchingPolicies.map(async (policy) => {\n\t\t\t\treturn await this.runPolicyOnFile(relPath, policy, context);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate async runPolicyOnFile(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tcontext: RepopoCommandContext,\n\t): Promise<void> {\n\t\tconst { excludePoliciesForFiles, perfStats, gitRoot } = context;\n\n\t\t// Check if the policy is excluded for the file\n\t\tif (this.isPolicyExcluded(relPath, policy, excludePoliciesForFiles)) {\n\t\t\tthis.verbose(`Excluded from '${policy.name}' policy: ${relPath}`);\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Execute the policy handler\n\t\t\tconst result = await this.executePolicyHandler(\n\t\t\t\trelPath,\n\t\t\t\tpolicy,\n\t\t\t\tperfStats,\n\t\t\t\tgitRoot,\n\t\t\t);\n\n\t\t\t// Handle the result of the policy execution\n\t\t\tawait this.handlePolicyResult(\n\t\t\t\tresult,\n\t\t\t\trelPath,\n\t\t\t\tpolicy,\n\t\t\t\tperfStats,\n\t\t\t\tgitRoot,\n\t\t\t);\n\t\t} catch (error: unknown) {\n\t\t\t// Log and rethrow the error for higher-level handling\n\t\t\tthis.error(\n\t\t\t\t`Error executing policy '${policy.name}' for file '${relPath}': ${error}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate isPolicyExcluded(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\texcludePoliciesForFiles: Map<string, RegExp[]>,\n\t): boolean {\n\t\treturn (\n\t\t\texcludePoliciesForFiles\n\t\t\t\t.get(policy.name)\n\t\t\t\t?.some((regex) => regex.test(relPath)) ?? false\n\t\t);\n\t}\n\n\tprivate async executePolicyHandler(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Promise<PolicyHandlerResult> {\n\t\ttry {\n\t\t\treturn await runWithPerf(policy.name, \"handle\", perfStats, () =>\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: policy.config,\n\t\t\t\t}),\n\t\t\t);\n\t\t} catch (error: unknown) {\n\t\t\tthis.error(\n\t\t\t\t`Error in policy handler '${policy.name}' for file '${relPath}': ${error}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async handlePolicyResult(\n\t\tresult: PolicyHandlerResult,\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Promise<void> {\n\t\tif (result === true) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (isPolicyFixResult(result)) {\n\t\t\tthis.handleFixResult(result, policy);\n\t\t} else {\n\t\t\tawait this.handleFailureResult(\n\t\t\t\tresult,\n\t\t\t\trelPath,\n\t\t\t\tpolicy,\n\t\t\t\tperfStats,\n\t\t\t\tgitRoot,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate handleFixResult(\n\t\tresult: PolicyFixResult,\n\t\tpolicy: PolicyInstance,\n\t): void {\n\t\tconst messages = new StringBuilder();\n\n\t\tif (result.resolved) {\n\t\t\tmessages.append(\n\t\t\t\t`Resolved ${policy.name} policy failure for file: ${result.file}`,\n\t\t\t);\n\t\t} else {\n\t\t\tmessages.append(\n\t\t\t\t`Error fixing ${policy.name} policy failure in ${result.file}`,\n\t\t\t);\n\t\t\tprocess.exitCode = 1;\n\t\t}\n\n\t\tthis.logMessages(messages);\n\t}\n\n\tprivate async handleFailureResult(\n\t\tresult: PolicyFailure,\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Promise<void> {\n\t\tconst messages = new StringBuilder();\n\n\t\tif (this.flags.fix && policy.resolver) {\n\t\t\tawait this.attemptResolution(\n\t\t\t\trelPath,\n\t\t\t\tpolicy,\n\t\t\t\tpolicy.resolver,\n\t\t\t\tperfStats,\n\t\t\t\tgitRoot,\n\t\t\t\tmessages,\n\t\t\t);\n\t\t} else {\n\t\t\tthis.logPolicyFailure(result, policy, messages);\n\t\t}\n\n\t\tthis.logMessages(messages);\n\t}\n\n\tprivate async attemptResolution(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tresolver: PolicyStandaloneResolver,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t\tmessages: StringBuilder,\n\t): Promise<void> {\n\t\tmessages.append(`${newline}Attempting to resolve: ${relPath}`);\n\t\tconst resolveResult = await runWithPerf(\n\t\t\tpolicy.name,\n\t\t\t\"resolve\",\n\t\t\tperfStats,\n\t\t\t() => resolver({ file: relPath, root: gitRoot }),\n\t\t);\n\n\t\tif (!resolveResult.resolved) {\n\t\t\tprocess.exitCode = 1;\n\t\t}\n\n\t\tif (resolveResult.errorMessage) {\n\t\t\tmessages.append(newline + resolveResult.errorMessage);\n\t\t}\n\t}\n\n\tprivate logPolicyFailure(\n\t\tresult: PolicyFailure,\n\t\tpolicy: PolicyInstance,\n\t\tmessages: StringBuilder,\n\t): void {\n\t\tconst autoFixable = result.autoFixable ? chalk.green(\" (autofixable)\") : \"\";\n\t\tmessages.append(\n\t\t\t`'${chalk.bold(policy.name)}' policy failure${autoFixable}: ${result.file}`,\n\t\t);\n\t\tif (result.errorMessage) {\n\t\t\tmessages.append(`${newline}\\t${result.errorMessage}`);\n\t\t}\n\t\tprocess.exitCode = 1;\n\t}\n\tprivate logMessages(messages: StringBuilder): void {\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\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,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<RepoPolicy[]>;
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":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;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,UAAU,EAAE,CAAC;CAUlD"}
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"}
@@ -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: inherited method
8
+ // biome-ignore lint/suspicious/useAwait: overridden method
9
9
  async run() {
10
- const { policies } = this.getContext();
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(`${chalk.bold(h.name)} (auto-fix: ${h.resolver !== undefined})`);
13
+ this.log(`${h.name}\nresolver: ${h.resolver !== undefined}\n`);
15
14
  }
16
- return policies;
15
+ this.log(`${policies.length} TOTAL POLICY HANDLERS`);
17
16
  }
18
17
  }
19
18
  //# sourceMappingURL=list.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;GAEG;AACH,MAAM,OAAO,WAKX,SAAQ,iBAAoB;IAC7B,MAAM,CAAmB,OAAO,GAAG,uCAAuC,CAAC;IAE3E,0DAA0D;IAC1C,KAAK,CAAC,GAAG;QACxB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAEvC,8BAA8B;QAC9B,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,mBAAmB,CAAC,CAAC;QAChD,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,QAAQ,KAAK,SAAS,GAAG,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC","sourcesContent":["import chalk from \"picocolors\";\n\nimport { BaseRepopoCommand } from \"../baseCommand.js\";\nimport type { RepoPolicy } 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: inherited method\n\tpublic override async run(): Promise<RepoPolicy[]> {\n\t\tconst { policies } = this.getContext();\n\n\t\t// list the handlers then exit\n\t\tthis.log(`${policies.length} POLICIES ENABLED`);\n\t\tfor (const h of policies) {\n\t\t\tthis.log(`${chalk.bold(h.name)} (auto-fix: ${h.resolver !== undefined})`);\n\t\t}\n\t\treturn policies;\n\t}\n}\n"]}
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
@@ -1,35 +1,29 @@
1
- import type { PackageJsonPropertiesSettings } from "./policies/PackageJsonProperties.js";
2
- import { type PolicyName, type RepoPolicy } from "./policy.js";
1
+ import type { PolicyCreator } from "./generators.js";
2
+ import { type PolicyInstance } from "./policy.js";
3
3
  /**
4
4
  * @alpha
5
5
  */
6
- export type PerPolicySettings = ({
7
- PackageJsonProperties: PackageJsonPropertiesSettings;
8
- } & Record<PolicyName, unknown>) | undefined;
6
+ export type PolicyList = PolicyCreator[];
9
7
  /**
10
8
  * @alpha
11
9
  */
12
- export interface PolicyConfig {
10
+ export interface RepopoConfig {
13
11
  /**
14
- * An array of policies that are enabled. If this is `undefined`, then all {@link DefaultPolicies} will be enabled.
12
+ * An array of policies that are enabled.
13
+ *
14
+ * See `DefaultPolicies` for the policies that will be enabled by default if this is `undefined`.
15
15
  */
16
- policies?: RepoPolicy[];
16
+ policies?: PolicyInstance<any>[];
17
17
  /**
18
18
  * An array of strings/regular expressions. File paths that match any of these expressions will be completely excluded
19
19
  * from policy.
20
20
  */
21
21
  excludeFiles?: (string | RegExp)[];
22
- /**
23
- * An object with a policy name as keys that map to an array of strings/regular expressions to
24
- * exclude that rule from being checked.
25
- */
26
- excludePoliciesForFiles?: Record<PolicyName, (string | RegExp)[]>;
27
- policySettings?: PerPolicySettings | undefined;
28
22
  }
29
23
  /**
30
24
  * The default config applied when no config is found.
31
25
  *
32
26
  * @alpha
33
27
  */
34
- export declare const DefaultPolicyConfig: PolicyConfig;
28
+ export declare const DefaultPolicyConfig: RepopoConfig;
35
29
  //# sourceMappingURL=config.d.ts.map
@@ -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;;OAEG;IACH,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IAExB;;;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;IAElE,cAAc,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAC/C;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAIjC,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;OAIG;IAEH,QAAQ,CAAC,EAAE,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;IAEjC;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CACnC;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAIjC,CAAC"}
package/esm/config.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { makePolicy } from "./makePolicy.js";
1
2
  import { DefaultPolicies } from "./policy.js";
2
3
  /**
3
4
  * The default config applied when no config is found.
@@ -5,8 +6,8 @@ import { DefaultPolicies } from "./policy.js";
5
6
  * @alpha
6
7
  */
7
8
  export const DefaultPolicyConfig = {
8
- policies: DefaultPolicies,
9
+ policies: DefaultPolicies.map((p) => makePolicy(p)),
9
10
  excludeFiles: [],
10
- excludePoliciesForFiles: {},
11
+ // excludePoliciesForFiles: {},
11
12
  };
12
13
  //# sourceMappingURL=config.js.map
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;AAmChF;;;;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 */\nexport interface PolicyConfig {\n\t/**\n\t * An array of policies that are enabled. If this is `undefined`, then all {@link DefaultPolicies} will be enabled.\n\t */\n\tpolicies?: RepoPolicy[];\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\tpolicySettings?: PerPolicySettings | undefined;\n}\n\n/**\n * The default config applied when no config is found.\n *\n * @alpha\n */\nexport const DefaultPolicyConfig: PolicyConfig = {\n\tpolicies: DefaultPolicies,\n\texcludeFiles: [],\n\texcludePoliciesForFiles: {},\n};\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAuB,MAAM,aAAa,CAAC;AA0BnE;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAiB;IAChD,QAAQ,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACnD,YAAY,EAAE,EAAE;IAChB,+BAA+B;CAC/B,CAAC","sourcesContent":["import type { PolicyCreator } from \"./generators.js\";\nimport { makePolicy } from \"./makePolicy.js\";\nimport { DefaultPolicies, type PolicyInstance } from \"./policy.js\";\n\n/**\n * @alpha\n */\nexport type PolicyList = PolicyCreator[];\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\t// biome-ignore lint/suspicious/noExplicitAny: FIXME\n\tpolicies?: PolicyInstance<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\n/**\n * The default config applied when no config is found.\n *\n * @alpha\n */\nexport const DefaultPolicyConfig: RepopoConfig = {\n\tpolicies: DefaultPolicies.map((p) => makePolicy(p)),\n\texcludeFiles: [],\n\t// excludePoliciesForFiles: {},\n};\n"]}
@@ -0,0 +1,29 @@
1
+ import type { PolicyHandlerPerfStats } from "./perf.js";
2
+ import type { PolicyInstance, PolicyName } 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
+ excludeFromAll: RegExp[];
12
+ /**
13
+ * A list of handlers to apply to selected files.
14
+ */
15
+ policies: PolicyInstance[];
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,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,MAAM,qBAAqB,GAAG,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,cAAc,EAAE,MAAM,EAAE,CAAC;IAEzB;;OAEG;IACH,QAAQ,EAAE,cAAc,EAAE,CAAC;IAE3B;;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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=context.js.map
@@ -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 { PolicyInstance, PolicyName } 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\texcludeFromAll: RegExp[];\n\n\t/**\n\t * A list of handlers to apply to selected files.\n\t */\n\tpolicies: PolicyInstance[];\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"]}
@@ -0,0 +1,21 @@
1
+ import type { PolicyDefinition } from "./policy.js";
2
+ /**
3
+ * The definition of a free function that returns a RepoPolicy.
4
+ *
5
+ * @alpha
6
+ */
7
+ export type PolicyCreatorFunction<C = undefined> = (args: PolicyDefinition<C>) => PolicyDefinition<C>;
8
+ /**
9
+ * The definition of a constructor function that returns a RepoPolicy.
10
+ *
11
+ * @alpha
12
+ */
13
+ export type PolicyCreatorConstructor<C = undefined> = new (args: PolicyDefinition<C>) => PolicyDefinition<C>;
14
+ /**
15
+ * A PolicyCreator is a function that can be used to generate a {@link PolicyDefinition}. The function can be a free function
16
+ * or a constructor that creates a class implementing the {@link PolicyDefinition} interface.
17
+ *
18
+ * @alpha
19
+ */
20
+ export type PolicyCreator = PolicyCreatorConstructor | PolicyCreatorFunction;
21
+ //# sourceMappingURL=generators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,SAAS,IAAI,CAClD,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,KACrB,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAEzB;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,GAAG,SAAS,IAAI,KACrD,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,KACrB,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAEzB;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,wBAAwB,GAAG,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=generators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators.js","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"","sourcesContent":["import type { PolicyDefinition } from \"./policy.js\";\n\n/**\n * The definition of a free function that returns a RepoPolicy.\n *\n * @alpha\n */\nexport type PolicyCreatorFunction<C = undefined> = (\n\targs: PolicyDefinition<C>,\n) => PolicyDefinition<C>;\n\n/**\n * The definition of a constructor function that returns a RepoPolicy.\n *\n * @alpha\n */\nexport type PolicyCreatorConstructor<C = undefined> = new (\n\targs: PolicyDefinition<C>,\n) => PolicyDefinition<C>;\n\n/**\n * A PolicyCreator is a function that can be used to generate a {@link PolicyDefinition}. The function can be a free function\n * or a constructor that creates a class implementing the {@link PolicyDefinition} interface.\n *\n * @alpha\n */\nexport type PolicyCreator = PolicyCreatorConstructor | PolicyCreatorFunction;\n"]}
package/esm/index.d.ts CHANGED
@@ -1,6 +1,7 @@
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 type { PolicyConfig, PerPolicySettings, } from "./config.js";
5
- export type { PackageJsonPropertiesSettings, PackageJsonProperty, } from "./policies/PackageJsonProperties.js";
2
+ export type { PolicyFailure, PolicyFixResult, PolicyFunctionArguments, PolicyHandler, PolicyInstance, PolicyInstanceSettings, PolicyHandlerResult, PolicyName, PolicyStandaloneResolver, PolicyDefinition, } from "./policy.js";
3
+ export type { RepopoConfig, } from "./config.js";
4
+ export { makePolicy } from "./makePolicy.js";
5
+ export { definePackagePolicy as generatePackagePolicy, type PackageJsonHandler, } from "./policyDefiners/definePackagePolicy.js";
6
+ export { defineFileHeaderPolicy as generateFileHeaderPolicy, type FileHeaderGeneratorConfig, type FileHeaderPolicyConfig, } from "./policyDefiners/defineFileHeaderPolicy.js";
6
7
  //# sourceMappingURL=index.d.ts.map