repopo 0.9.0 → 0.10.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 (83) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/esm/commands/check.d.ts +1 -0
  3. package/esm/commands/check.d.ts.map +1 -1
  4. package/esm/commands/check.js +48 -11
  5. package/esm/commands/check.js.map +1 -1
  6. package/esm/config.d.ts +19 -4
  7. package/esm/config.d.ts.map +1 -1
  8. package/esm/config.js +2 -3
  9. package/esm/config.js.map +1 -1
  10. package/esm/index.d.ts +2 -2
  11. package/esm/index.d.ts.map +1 -1
  12. package/esm/index.js +6 -1
  13. package/esm/index.js.map +1 -1
  14. package/esm/makePolicy.d.ts +50 -8
  15. package/esm/makePolicy.d.ts.map +1 -1
  16. package/esm/makePolicy.js +64 -4
  17. package/esm/makePolicy.js.map +1 -1
  18. package/esm/policies/ConditionalScripts.d.ts +94 -0
  19. package/esm/policies/ConditionalScripts.d.ts.map +1 -0
  20. package/esm/policies/ConditionalScripts.js +144 -0
  21. package/esm/policies/ConditionalScripts.js.map +1 -0
  22. package/esm/policies/ExactScripts.d.ts +51 -0
  23. package/esm/policies/ExactScripts.d.ts.map +1 -0
  24. package/esm/policies/ExactScripts.js +107 -0
  25. package/esm/policies/ExactScripts.js.map +1 -0
  26. package/esm/policies/HtmlFileHeaders.d.ts +1 -1
  27. package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
  28. package/esm/policies/JsTsFileHeaders.d.ts +1 -1
  29. package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
  30. package/esm/policies/MutuallyExclusiveScripts.d.ts +46 -0
  31. package/esm/policies/MutuallyExclusiveScripts.d.ts.map +1 -0
  32. package/esm/policies/MutuallyExclusiveScripts.js +52 -0
  33. package/esm/policies/MutuallyExclusiveScripts.js.map +1 -0
  34. package/esm/policies/NoPrivateWorkspaceDependencies.d.ts +1 -1
  35. package/esm/policies/NoPrivateWorkspaceDependencies.d.ts.map +1 -1
  36. package/esm/policies/PackageAllowedScopes.d.ts +1 -1
  37. package/esm/policies/PackageAllowedScopes.d.ts.map +1 -1
  38. package/esm/policies/PackageEsmType.d.ts +1 -1
  39. package/esm/policies/PackageEsmType.d.ts.map +1 -1
  40. package/esm/policies/PackageFolderName.d.ts +1 -1
  41. package/esm/policies/PackageFolderName.d.ts.map +1 -1
  42. package/esm/policies/PackageJsonProperties.d.ts +1 -1
  43. package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
  44. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +1 -1
  45. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
  46. package/esm/policies/PackageJsonSorted.d.ts +1 -1
  47. package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
  48. package/esm/policies/PackageLicense.d.ts +1 -1
  49. package/esm/policies/PackageLicense.d.ts.map +1 -1
  50. package/esm/policies/PackagePrivateField.d.ts +1 -1
  51. package/esm/policies/PackagePrivateField.d.ts.map +1 -1
  52. package/esm/policies/PackageReadme.d.ts +1 -1
  53. package/esm/policies/PackageReadme.d.ts.map +1 -1
  54. package/esm/policies/PackageScripts.d.ts +1 -1
  55. package/esm/policies/PackageScripts.d.ts.map +1 -1
  56. package/esm/policies/PackageTestScripts.d.ts +1 -1
  57. package/esm/policies/PackageTestScripts.d.ts.map +1 -1
  58. package/esm/policies/RequiredScripts.d.ts +71 -0
  59. package/esm/policies/RequiredScripts.d.ts.map +1 -0
  60. package/esm/policies/RequiredScripts.js +120 -0
  61. package/esm/policies/RequiredScripts.js.map +1 -0
  62. package/esm/policies/ScriptContains.d.ts +64 -0
  63. package/esm/policies/ScriptContains.d.ts.map +1 -0
  64. package/esm/policies/ScriptContains.js +62 -0
  65. package/esm/policies/ScriptContains.js.map +1 -0
  66. package/esm/policies.d.ts +6 -1
  67. package/esm/policies.d.ts.map +1 -1
  68. package/esm/policies.js +18 -0
  69. package/esm/policies.js.map +1 -1
  70. package/esm/policy.d.ts +180 -86
  71. package/esm/policy.d.ts.map +1 -1
  72. package/esm/policy.js +103 -21
  73. package/esm/policy.js.map +1 -1
  74. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +7 -2
  75. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -1
  76. package/esm/policyDefiners/defineFileHeaderPolicy.js +5 -0
  77. package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -1
  78. package/esm/policyDefiners/definePackagePolicy.d.ts +18 -5
  79. package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -1
  80. package/esm/policyDefiners/definePackagePolicy.js +14 -4
  81. package/esm/policyDefiners/definePackagePolicy.js.map +1 -1
  82. package/oclif.manifest.json +1 -1
  83. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # repopo
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add new `policy()` function as simplified API for defining repository policies, replacing the more complex `makePolicy`/`makePolicyDefinition` workflow. _[`#617`](https://github.com/tylerbutler/tools-monorepo/pull/617) [`becd406`](https://github.com/tylerbutler/tools-monorepo/commit/becd4064e1434b2384cda991f2d0702d91ed5ed9) [@tylerbutler](https://github.com/tylerbutler)_
8
+
9
+ New features:
10
+ - `policy()` function with multiple overload signatures for defining policies concisely
11
+ - `PolicyShape` interface for object-literal policy definitions
12
+ - `ConfiguredPolicy` and `PolicyError` types for the new API surface
13
+ - Five new script-focused policies: `RequiredScripts`, `ExactScripts`, `MutuallyExclusiveScripts`, `ConditionalScripts`, and `ScriptContains`
14
+ - `isPolicyError` type guard and `convertLegacyResult`/`convertToPolicyFailure` conversion utilities
15
+
16
+ Deprecations (old APIs still work but are marked `@deprecated`):
17
+ - `makePolicy` → use `policy()` instead
18
+ - `makePolicyDefinition` → use `PolicyShape` object literals instead
19
+ - `PolicyFailure` → use `PolicyError` instead
20
+ - `PolicyInstance` → use `ConfiguredPolicy` instead
21
+ - `PolicyStandaloneResolver` → use `PolicyResolver` instead
22
+ - `isPolicyFailure` → use `isPolicyError` instead
23
+
3
24
  ## 0.9.0
4
25
 
5
26
  ### Minor Changes
@@ -39,6 +39,7 @@ export declare class CheckPolicy<T extends typeof BaseRepopoCommand & {
39
39
  private executePolicyHandler;
40
40
  private handlePolicyResult;
41
41
  private handleFixResult;
42
+ private handlePolicyErrorFixResult;
42
43
  private handleFailureResult;
43
44
  private attemptResolution;
44
45
  private logPolicyFailure;
@@ -1 +1 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAgCtD;;;;;;;;GAQG;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,gBAAgC,OAAO,iEACwB;IAE/D,gBAAgC,KAAK;;;;MAY1B;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IA0D1C;;;;;OAKG;IACH,OAAO,CAAE,aAAa;IAetB;;;;;OAKG;IACH,OAAO,CAAE,kBAAkB;IAgB3B,OAAO,CAAE,eAAe;IAwBxB,OAAO,CAAE,eAAe;IAsCxB,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAE,oBAAoB;IA6C7B,OAAO,CAAE,kBAAkB;IAwB3B,OAAO,CAAC,eAAe;IAoBvB,OAAO,CAAE,mBAAmB;IAyB5B,OAAO,CAAE,iBAAiB;IAsC1B,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,WAAW;CAOnB"}
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAkCtD;;;;;;;;GAQG;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,gBAAgC,OAAO,iEACwB;IAE/D,gBAAgC,KAAK;;;;MAY1B;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IA0D1C;;;;;OAKG;IACH,OAAO,CAAE,aAAa;IAetB;;;;;OAKG;IACH,OAAO,CAAE,kBAAkB;IAgB3B,OAAO,CAAE,eAAe;IAwBxB,OAAO,CAAE,eAAe;IAsCxB,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAE,oBAAoB;IAsD7B,OAAO,CAAE,kBAAkB;IAiC3B,OAAO,CAAC,eAAe;IAoBvB,OAAO,CAAC,0BAA0B;IAsBlC,OAAO,CAAE,mBAAmB;IAyB5B,OAAO,CAAE,iBAAiB;IAsC1B,OAAO,CAAC,gBAAgB;IA4BxB,OAAO,CAAC,WAAW;CAOnB"}
@@ -15,7 +15,7 @@ function isOperation(value) {
15
15
  }
16
16
  import { BaseRepopoCommand } from "../baseCommand.js";
17
17
  import { logStats, runWithPerf } from "../perf.js";
18
- import { isPolicyFixResult, } from "../policy.js";
18
+ import { isPolicyError, isPolicyFixResult, } from "../policy.js";
19
19
  async function readStdin() {
20
20
  return new Promise((resolve) => {
21
21
  const stdin = process.stdin;
@@ -170,12 +170,19 @@ export class CheckPolicy extends BaseRepopoCommand {
170
170
  const resolve = this.flags.fix;
171
171
  try {
172
172
  const result = yield* runWithPerf(policy.name, "handle", perfStats, function* () {
173
- const handlerResult = policy.handler({
173
+ const args = {
174
174
  file: relPath,
175
175
  root: gitRoot,
176
176
  resolve,
177
177
  config: policy.config,
178
- });
178
+ };
179
+ // Use normalized _internalHandler if available (from policy() function)
180
+ // This avoids per-invocation type checking
181
+ if (policy._internalHandler) {
182
+ return yield* policy._internalHandler(args);
183
+ }
184
+ // Fallback for policies not created with policy() function
185
+ const handlerResult = policy.handler(args);
179
186
  // Handle both Operation (generator) and Promise return types
180
187
  if (handlerResult instanceof Promise) {
181
188
  return yield* call(() => handlerResult);
@@ -200,12 +207,18 @@ export class CheckPolicy extends BaseRepopoCommand {
200
207
  if (result === true) {
201
208
  return;
202
209
  }
210
+ // Handle fix results (both legacy and new formats)
203
211
  if (isPolicyFixResult(result)) {
204
212
  this.handleFixResult(result, policy);
213
+ return;
205
214
  }
206
- else {
207
- yield* this.handleFailureResult(result, relPath, policy, perfStats, gitRoot);
215
+ // Handle new PolicyError with fixed property (fix was attempted)
216
+ if (isPolicyError(result) && result.fixed !== undefined) {
217
+ this.handlePolicyErrorFixResult(result, relPath, policy);
218
+ return;
208
219
  }
220
+ // Handle failure results (PolicyFailure or PolicyError without fix)
221
+ yield* this.handleFailureResult(result, relPath, policy, perfStats, gitRoot);
209
222
  }
210
223
  handleFixResult(result, policy) {
211
224
  const messages = new StringBuilder();
@@ -218,13 +231,27 @@ export class CheckPolicy extends BaseRepopoCommand {
218
231
  }
219
232
  this.logMessages(messages);
220
233
  }
234
+ handlePolicyErrorFixResult(result, file, policy) {
235
+ const messages = new StringBuilder();
236
+ if (result.fixed) {
237
+ messages.append(`Resolved ${policy.name} policy failure for file: ${file}`);
238
+ }
239
+ else {
240
+ messages.append(`Error fixing ${policy.name} policy failure in ${file}`);
241
+ if (result.error) {
242
+ messages.append(`${newline}\t${result.error}`);
243
+ }
244
+ process.exitCode = 1;
245
+ }
246
+ this.logMessages(messages);
247
+ }
221
248
  *handleFailureResult(result, relPath, policy, perfStats, gitRoot) {
222
249
  const messages = new StringBuilder();
223
250
  if (this.flags.fix && policy.resolver) {
224
251
  yield* this.attemptResolution(relPath, policy, policy.resolver, perfStats, gitRoot, messages);
225
252
  }
226
253
  else {
227
- this.logPolicyFailure(result, policy, messages);
254
+ this.logPolicyFailure(result, relPath, policy, messages);
228
255
  }
229
256
  this.logMessages(messages);
230
257
  }
@@ -250,11 +277,21 @@ export class CheckPolicy extends BaseRepopoCommand {
250
277
  messages.append(newline + resolveResult.errorMessages.join(newline));
251
278
  }
252
279
  }
253
- logPolicyFailure(result, policy, messages) {
254
- const autoFixable = result.autoFixable ? chalk.green(" (autofixable)") : "";
255
- messages.append(`'${chalk.bold(policy.name)}' policy failure${autoFixable}: ${result.file}`);
256
- if (result.errorMessages?.length > 0) {
257
- messages.append(`${newline}\t${result.errorMessages.join(`${newline}\t`)}`);
280
+ logPolicyFailure(result, file, policy, messages) {
281
+ // Handle both legacy PolicyFailure and new PolicyError formats
282
+ if (isPolicyError(result)) {
283
+ const autoFixable = result.fixable ? chalk.green(" (autofixable)") : "";
284
+ messages.append(`'${chalk.bold(policy.name)}' policy failure${autoFixable}: ${file}`);
285
+ messages.append(`${newline}\t${result.error}`);
286
+ }
287
+ else {
288
+ const autoFixable = result.autoFixable
289
+ ? chalk.green(" (autofixable)")
290
+ : "";
291
+ messages.append(`'${chalk.bold(policy.name)}' policy failure${autoFixable}: ${result.file}`);
292
+ if (result.errorMessages?.length > 0) {
293
+ messages.append(`${newline}\t${result.errorMessages.join(`${newline}\t`)}`);
294
+ }
258
295
  }
259
296
  process.exitCode = 1;
260
297
  }
@@ -1 +1 @@
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,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,IAAI,EAAkB,GAAG,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B;;GAEG;AACH,S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\"node:os\";\nimport process from \"node:process\";\nimport { Flags } from \"@oclif/core\";\nimport { StringBuilder } from \"@rushstack/node-core-library\";\nimport { all, call, type Operation, run } from \"effection\";\nimport chalk from \"picocolors\";\n\n/**\n * Type guard to check if a value is an Effection Operation (generator).\n */\nfunction isOperation<T>(value: unknown): value is Operation<T> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"next\" in value &&\n\t\ttypeof (value as { next: unknown }).next === \"function\"\n\t);\n}\n\nimport { BaseRepopoCommand } from \"../baseCommand.js\";\nimport type { RepopoCommandContext } from \"../context.js\";\nimport { logStats, type PolicyHandlerPerfStats, runWithPerf } from \"../perf.js\";\nimport {\n\tisPolicyFixResult,\n\ttype PolicyFailure,\n\ttype PolicyFixResult,\n\ttype PolicyHandlerResult,\n\ttype PolicyInstance,\n\ttype PolicyStandaloneResolver,\n} from \"../policy.js\";\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\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\tpublic static override readonly summary =\n\t\t\"Checks and applies policies to the files in the repository.\";\n\n\tpublic static 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 run(function* () {\n\t\t\t\treturn yield* call(() => readStdin());\n\t\t\t});\n\n\t\t\tif (stdInput !== undefined && stdInput !== null) {\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 run(() => 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 *checkAllFiles(\n\t\tpathsToCheck: string[],\n\t\tcontext: RepopoCommandContext,\n\t): Operation<void> {\n\t\ttry {\n\t\t\tfor (const pathToCheck of pathsToCheck) {\n\t\t\t\tyield* 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.logger);\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 *checkOrExcludeFile(\n\t\trelPath: string,\n\t\tcontext: RepopoCommandContext,\n\t): Operation<void> {\n\t\tconst { perfStats } = context;\n\t\tperfStats.count++;\n\n\t\ttry {\n\t\t\tyield* 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\t}\n\n\tprivate *routeToPolicies(\n\t\trelPath: string,\n\t\tcontext: RepopoCommandContext,\n\t): Operation<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;\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\tyield* all(\n\t\t\tmatchingPolicies.map((policy) => {\n\t\t\t\treturn this.runPolicyOnFile(relPath, policy, context);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate *runPolicyOnFile(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tcontext: RepopoCommandContext,\n\t): Operation<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 = yield* 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\tyield* 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.exit(\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 *executePolicyHandler(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Operation<PolicyHandlerResult> {\n\t\tconst resolve = this.flags.fix;\n\t\ttry {\n\t\t\tconst result = yield* runWithPerf(\n\t\t\t\tpolicy.name,\n\t\t\t\t\"handle\",\n\t\t\t\tperfStats,\n\t\t\t\tfunction* () {\n\t\t\t\t\tconst handlerResult = policy.handler({\n\t\t\t\t\t\tfile: relPath,\n\t\t\t\t\t\troot: gitRoot,\n\t\t\t\t\t\tresolve,\n\t\t\t\t\t\tconfig: policy.config,\n\t\t\t\t\t});\n\n\t\t\t\t\t// Handle both Operation (generator) and Promise return types\n\t\t\t\t\tif (handlerResult instanceof Promise) {\n\t\t\t\t\t\treturn yield* call(() => handlerResult);\n\t\t\t\t\t}\n\t\t\t\t\t// Check if it's an Effection Operation (generator)\n\t\t\t\t\tif (isOperation<PolicyHandlerResult>(handlerResult)) {\n\t\t\t\t\t\treturn yield* handlerResult;\n\t\t\t\t\t}\n\t\t\t\t\t// This should never happen with proper handler typing\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Unexpected handler result type: ${typeof handlerResult}`,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (result === undefined) {\n\t\t\t\tthrow new Error(\"Policy result was undefined.\");\n\t\t\t}\n\t\t\treturn result;\n\t\t} catch (error: unknown) {\n\t\t\tthis.exit(\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 *handlePolicyResult(\n\t\tresult: PolicyHandlerResult,\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Operation<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\tyield* 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 *handleFailureResult(\n\t\tresult: PolicyFailure,\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Operation<void> {\n\t\tconst messages = new StringBuilder();\n\n\t\tif (this.flags.fix && policy.resolver) {\n\t\t\tyield* 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 *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): Operation<void> {\n\t\tmessages.append(`${newline}Attempting to resolve: ${relPath}`);\n\t\tconst resolveResult = yield* runWithPerf(\n\t\t\tpolicy.name,\n\t\t\t\"resolve\",\n\t\t\tperfStats,\n\t\t\tfunction* () {\n\t\t\t\tconst result = resolver({ file: relPath, root: gitRoot });\n\n\t\t\t\t// Handle both Operation (generator) and Promise return types\n\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\treturn yield* call(() => result);\n\t\t\t\t}\n\t\t\t\t// Check if it's an Effection Operation (generator)\n\t\t\t\tif (isOperation<PolicyFixResult>(result)) {\n\t\t\t\t\treturn yield* result;\n\t\t\t\t}\n\t\t\t\t// This should never happen with proper resolver typing\n\t\t\t\tthrow new Error(`Unexpected resolver result type: ${typeof result}`);\n\t\t\t},\n\t\t);\n\n\t\tif (!resolveResult.resolved) {\n\t\t\tprocess.exitCode = 1;\n\t\t}\n\n\t\tif (resolveResult.errorMessages?.length > 0) {\n\t\t\tmessages.append(newline + resolveResult.errorMessages.join(newline));\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.errorMessages?.length > 0) {\n\t\t\tmessages.append(\n\t\t\t\t`${newline}\\t${result.errorMessages.join(`${newline}\\t`)}`,\n\t\t\t);\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"]}
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,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,IAAI,EAAkB,GAAG,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B;;GAEG;AACH,SAAS,W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IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnC,CAAC;IACF,CAAC","sourcesContent":["import { EOL as newline } from \"node:os\";\nimport process from \"node:process\";\nimport { Flags } from \"@oclif/core\";\nimport { StringBuilder } from \"@rushstack/node-core-library\";\nimport { all, call, type Operation, run } from \"effection\";\nimport chalk from \"picocolors\";\n\n/**\n * Type guard to check if a value is an Effection Operation (generator).\n */\nfunction isOperation<T>(value: unknown): value is Operation<T> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"next\" in value &&\n\t\ttypeof (value as { next: unknown }).next === \"function\"\n\t);\n}\n\nimport { BaseRepopoCommand } from \"../baseCommand.js\";\nimport type { RepopoCommandContext } from \"../context.js\";\nimport { logStats, type PolicyHandlerPerfStats, runWithPerf } from \"../perf.js\";\nimport {\n\tisPolicyError,\n\tisPolicyFixResult,\n\ttype PolicyError,\n\ttype PolicyFailure,\n\ttype PolicyFixResult,\n\ttype PolicyHandlerResult,\n\ttype PolicyInstance,\n\ttype PolicyStandaloneResolver,\n} from \"../policy.js\";\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\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\tpublic static override readonly summary =\n\t\t\"Checks and applies policies to the files in the repository.\";\n\n\tpublic static 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 run(function* () {\n\t\t\t\treturn yield* call(() => readStdin());\n\t\t\t});\n\n\t\t\tif (stdInput !== undefined && stdInput !== null) {\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 run(() => 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 *checkAllFiles(\n\t\tpathsToCheck: string[],\n\t\tcontext: RepopoCommandContext,\n\t): Operation<void> {\n\t\ttry {\n\t\t\tfor (const pathToCheck of pathsToCheck) {\n\t\t\t\tyield* 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.logger);\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 *checkOrExcludeFile(\n\t\trelPath: string,\n\t\tcontext: RepopoCommandContext,\n\t): Operation<void> {\n\t\tconst { perfStats } = context;\n\t\tperfStats.count++;\n\n\t\ttry {\n\t\t\tyield* 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\t}\n\n\tprivate *routeToPolicies(\n\t\trelPath: string,\n\t\tcontext: RepopoCommandContext,\n\t): Operation<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;\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\tyield* all(\n\t\t\tmatchingPolicies.map((policy) => {\n\t\t\t\treturn this.runPolicyOnFile(relPath, policy, context);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate *runPolicyOnFile(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tcontext: RepopoCommandContext,\n\t): Operation<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 = yield* 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\tyield* 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.exit(\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 *executePolicyHandler(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Operation<PolicyHandlerResult> {\n\t\tconst resolve = this.flags.fix;\n\t\ttry {\n\t\t\tconst result = yield* runWithPerf(\n\t\t\t\tpolicy.name,\n\t\t\t\t\"handle\",\n\t\t\t\tperfStats,\n\t\t\t\tfunction* () {\n\t\t\t\t\tconst args = {\n\t\t\t\t\t\tfile: relPath,\n\t\t\t\t\t\troot: gitRoot,\n\t\t\t\t\t\tresolve,\n\t\t\t\t\t\tconfig: policy.config,\n\t\t\t\t\t};\n\n\t\t\t\t\t// Use normalized _internalHandler if available (from policy() function)\n\t\t\t\t\t// This avoids per-invocation type checking\n\t\t\t\t\tif (policy._internalHandler) {\n\t\t\t\t\t\treturn yield* policy._internalHandler(args);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Fallback for policies not created with policy() function\n\t\t\t\t\tconst handlerResult = policy.handler(args);\n\n\t\t\t\t\t// Handle both Operation (generator) and Promise return types\n\t\t\t\t\tif (handlerResult instanceof Promise) {\n\t\t\t\t\t\treturn yield* call(() => handlerResult);\n\t\t\t\t\t}\n\t\t\t\t\t// Check if it's an Effection Operation (generator)\n\t\t\t\t\tif (isOperation<PolicyHandlerResult>(handlerResult)) {\n\t\t\t\t\t\treturn yield* handlerResult;\n\t\t\t\t\t}\n\t\t\t\t\t// This should never happen with proper handler typing\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Unexpected handler result type: ${typeof handlerResult}`,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (result === undefined) {\n\t\t\t\tthrow new Error(\"Policy result was undefined.\");\n\t\t\t}\n\t\t\treturn result;\n\t\t} catch (error: unknown) {\n\t\t\tthis.exit(\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 *handlePolicyResult(\n\t\tresult: PolicyHandlerResult,\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Operation<void> {\n\t\tif (result === true) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Handle fix results (both legacy and new formats)\n\t\tif (isPolicyFixResult(result)) {\n\t\t\tthis.handleFixResult(result, policy);\n\t\t\treturn;\n\t\t}\n\n\t\t// Handle new PolicyError with fixed property (fix was attempted)\n\t\tif (isPolicyError(result) && result.fixed !== undefined) {\n\t\t\tthis.handlePolicyErrorFixResult(result, relPath, policy);\n\t\t\treturn;\n\t\t}\n\n\t\t// Handle failure results (PolicyFailure or PolicyError without fix)\n\t\tyield* this.handleFailureResult(\n\t\t\tresult,\n\t\t\trelPath,\n\t\t\tpolicy,\n\t\t\tperfStats,\n\t\t\tgitRoot,\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 handlePolicyErrorFixResult(\n\t\tresult: PolicyError,\n\t\tfile: string,\n\t\tpolicy: PolicyInstance,\n\t): void {\n\t\tconst messages = new StringBuilder();\n\n\t\tif (result.fixed) {\n\t\t\tmessages.append(\n\t\t\t\t`Resolved ${policy.name} policy failure for file: ${file}`,\n\t\t\t);\n\t\t} else {\n\t\t\tmessages.append(`Error fixing ${policy.name} policy failure in ${file}`);\n\t\t\tif (result.error) {\n\t\t\t\tmessages.append(`${newline}\\t${result.error}`);\n\t\t\t}\n\t\t\tprocess.exitCode = 1;\n\t\t}\n\n\t\tthis.logMessages(messages);\n\t}\n\n\tprivate *handleFailureResult(\n\t\tresult: PolicyFailure | PolicyError,\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Operation<void> {\n\t\tconst messages = new StringBuilder();\n\n\t\tif (this.flags.fix && policy.resolver) {\n\t\t\tyield* 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, relPath, policy, messages);\n\t\t}\n\n\t\tthis.logMessages(messages);\n\t}\n\n\tprivate *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): Operation<void> {\n\t\tmessages.append(`${newline}Attempting to resolve: ${relPath}`);\n\t\tconst resolveResult = yield* runWithPerf(\n\t\t\tpolicy.name,\n\t\t\t\"resolve\",\n\t\t\tperfStats,\n\t\t\tfunction* () {\n\t\t\t\tconst result = resolver({ file: relPath, root: gitRoot });\n\n\t\t\t\t// Handle both Operation (generator) and Promise return types\n\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\treturn yield* call(() => result);\n\t\t\t\t}\n\t\t\t\t// Check if it's an Effection Operation (generator)\n\t\t\t\tif (isOperation<PolicyFixResult>(result)) {\n\t\t\t\t\treturn yield* result;\n\t\t\t\t}\n\t\t\t\t// This should never happen with proper resolver typing\n\t\t\t\tthrow new Error(`Unexpected resolver result type: ${typeof result}`);\n\t\t\t},\n\t\t);\n\n\t\tif (!resolveResult.resolved) {\n\t\t\tprocess.exitCode = 1;\n\t\t}\n\n\t\tif (resolveResult.errorMessages?.length > 0) {\n\t\t\tmessages.append(newline + resolveResult.errorMessages.join(newline));\n\t\t}\n\t}\n\n\tprivate logPolicyFailure(\n\t\tresult: PolicyFailure | PolicyError,\n\t\tfile: string,\n\t\tpolicy: PolicyInstance,\n\t\tmessages: StringBuilder,\n\t): void {\n\t\t// Handle both legacy PolicyFailure and new PolicyError formats\n\t\tif (isPolicyError(result)) {\n\t\t\tconst autoFixable = result.fixable ? chalk.green(\" (autofixable)\") : \"\";\n\t\t\tmessages.append(\n\t\t\t\t`'${chalk.bold(policy.name)}' policy failure${autoFixable}: ${file}`,\n\t\t\t);\n\t\t\tmessages.append(`${newline}\\t${result.error}`);\n\t\t} else {\n\t\t\tconst autoFixable = result.autoFixable\n\t\t\t\t? chalk.green(\" (autofixable)\")\n\t\t\t\t: \"\";\n\t\t\tmessages.append(\n\t\t\t\t`'${chalk.bold(policy.name)}' policy failure${autoFixable}: ${result.file}`,\n\t\t\t);\n\t\t\tif (result.errorMessages?.length > 0) {\n\t\t\t\tmessages.append(\n\t\t\t\t\t`${newline}\\t${result.errorMessages.join(`${newline}\\t`)}`,\n\t\t\t\t);\n\t\t\t}\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"]}
package/esm/config.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { PolicyCreator } from "./generators.js";
2
- import { type PolicyInstance } from "./policy.js";
2
+ import type { ConfiguredPolicy, PolicyInstance } from "./policy.js";
3
3
  /**
4
4
  * @alpha
5
5
  */
@@ -9,14 +9,29 @@ export type PolicyList = PolicyCreator[];
9
9
  */
10
10
  export interface RepopoConfig {
11
11
  /**
12
- * An array of policies that are enabled.
12
+ * An array of configured policies that are enabled.
13
+ *
14
+ * Use the `policy()` function to configure policies before adding them to this array.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { policy, type RepopoConfig } from "repopo";
19
+ * import { NoJsFileExtensions, PackageJsonProperties } from "repopo/policies";
20
+ *
21
+ * const config: RepopoConfig = {
22
+ * policies: [
23
+ * policy(NoJsFileExtensions, { exclude: ["bin/*"] }),
24
+ * policy(PackageJsonProperties, { verbatim: { license: "MIT" } }),
25
+ * ],
26
+ * };
27
+ * ```
13
28
  *
14
29
  * See `DefaultPolicies` for the policies that will be enabled by default if this is `undefined`.
15
30
  */
16
- policies?: PolicyInstance<any>[];
31
+ policies?: (ConfiguredPolicy<any> | PolicyInstance<any>)[];
17
32
  /**
18
33
  * An array of strings/regular expressions. File paths that match any of these expressions will be completely excluded
19
- * from policy.
34
+ * from all policies.
20
35
  */
21
36
  excludeFiles?: (string | RegExp)[];
22
37
  }
@@ -1 +1 @@
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"}
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,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGpE;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;;;;;;;;;;;;;;;;OAmBG;IAEH,QAAQ,CAAC,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IAE3D;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CACnC;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAGjC,CAAC"}
package/esm/config.js CHANGED
@@ -1,4 +1,4 @@
1
- import { makePolicy } from "./makePolicy.js";
1
+ import { policy } from "./makePolicy.js";
2
2
  import { DefaultPolicies } from "./policy.js";
3
3
  /**
4
4
  * The default config applied when no config is found.
@@ -6,8 +6,7 @@ import { DefaultPolicies } from "./policy.js";
6
6
  * @alpha
7
7
  */
8
8
  export const DefaultPolicyConfig = {
9
- policies: DefaultPolicies.map((p) => makePolicy(p)),
9
+ policies: DefaultPolicies.map((p) => policy(p)),
10
10
  excludeFiles: [],
11
- // excludePoliciesForFiles: {},
12
11
  };
13
12
  //# 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,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"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAyC9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAiB;IAChD,QAAQ,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/C,YAAY,EAAE,EAAE;CAChB,CAAC","sourcesContent":["import type { PolicyCreator } from \"./generators.js\";\nimport { policy } from \"./makePolicy.js\";\nimport type { ConfiguredPolicy, PolicyInstance } from \"./policy.js\";\nimport { DefaultPolicies } 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 configured policies that are enabled.\n\t *\n\t * Use the `policy()` function to configure policies before adding them to this array.\n\t *\n\t * @example\n\t * ```typescript\n\t * import { policy, type RepopoConfig } from \"repopo\";\n\t * import { NoJsFileExtensions, PackageJsonProperties } from \"repopo/policies\";\n\t *\n\t * const config: RepopoConfig = {\n\t * policies: [\n\t * policy(NoJsFileExtensions, { exclude: [\"bin/*\"] }),\n\t * policy(PackageJsonProperties, { verbatim: { license: \"MIT\" } }),\n\t * ],\n\t * };\n\t * ```\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?: (ConfiguredPolicy<any> | 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 all policies.\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) => policy(p)),\n\texcludeFiles: [],\n};\n"]}
package/esm/index.d.ts CHANGED
@@ -11,8 +11,8 @@
11
11
  export { run } from "@oclif/core";
12
12
  export { type FluidAdapterOptions, type FluidHandler, fromFluidHandlers, } from "./adapters/fluidFramework.js";
13
13
  export type { RepopoConfig, } from "./config.js";
14
- export { makePolicy, makePolicyDefinition, type PolicyDefinitionInput, } from "./makePolicy.js";
15
- export type { PolicyDefinition, PolicyFailure, PolicyFixResult, PolicyFunctionArguments, PolicyHandler, PolicyHandlerResult, PolicyInstance, PolicyInstanceSettings, PolicyName, PolicyStandaloneResolver, } from "./policy.js";
14
+ export { makePolicy, makePolicyDefinition, type PolicyDefinitionInput, type PolicyOptions, policy, } from "./makePolicy.js";
15
+ export { type ConfiguredPolicy, isPolicyError, isPolicyFailure, isPolicyFixResult, Policy, type PolicyArgs, type PolicyDefinition, type PolicyError, type PolicyFailure, type PolicyFixResult, type PolicyFunctionArguments, type PolicyHandler, type PolicyHandlerResult, type PolicyInstance, type PolicyInstanceSettings, type PolicyName, type PolicyResolver, type PolicyResult, type PolicyShape, type PolicyStandaloneResolver, } from "./policy.js";
16
16
  export { type DefineFileHeaderPolicyArgs, defineFileHeaderPolicy, type FileHeaderGeneratorConfig, type FileHeaderPolicyConfig, } from "./policyDefiners/defineFileHeaderPolicy.js";
17
17
  export { type DefinePackagePolicyArgs, definePackagePolicy as generatePackagePolicy, type PackageJsonHandler, } from "./policyDefiners/definePackagePolicy.js";
18
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAEX,YAAY,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,UAAU,EACV,oBAAoB,EACpB,KAAK,qBAAqB,GAC1B,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACX,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,sBAAsB,EACtB,UAAU,EACV,wBAAwB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,KAAK,0BAA0B,EAC/B,sBAAsB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,GAC3B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,KAAK,uBAAuB,EAC5B,mBAAmB,IAAI,qBAAqB,EAC5C,KAAK,kBAAkB,GACvB,MAAM,yCAAyC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAEX,YAAY,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,UAAU,EACV,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,MAAM,GACN,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,KAAK,gBAAgB,EAErB,aAAa,EACb,eAAe,EACf,iBAAiB,EAEjB,MAAM,EACN,KAAK,UAAU,EAEf,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,wBAAwB,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,KAAK,0BAA0B,EAC/B,sBAAsB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,GAC3B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,KAAK,uBAAuB,EAC5B,mBAAmB,IAAI,qBAAqB,EAC5C,KAAK,kBAAkB,GACvB,MAAM,yCAAyC,CAAC"}
package/esm/index.js CHANGED
@@ -10,7 +10,12 @@
10
10
  */
11
11
  export { run } from "@oclif/core";
12
12
  export { fromFluidHandlers, } from "./adapters/fluidFramework.js";
13
- export { makePolicy, makePolicyDefinition, } from "./makePolicy.js";
13
+ export { makePolicy, makePolicyDefinition, policy, } from "./makePolicy.js";
14
+ export {
15
+ // Type guards
16
+ isPolicyError, isPolicyFailure, isPolicyFixResult,
17
+ // New types
18
+ Policy, } from "./policy.js";
14
19
  export { defineFileHeaderPolicy, } from "./policyDefiners/defineFileHeaderPolicy.js";
15
20
  export { definePackagePolicy as generatePackagePolicy, } from "./policyDefiners/definePackagePolicy.js";
16
21
  //# 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;;;;;;;;;GASG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAGN,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EACN,UAAU,EACV,oBAAoB,GAEpB,MAAM,iBAAiB,CAAC;AAazB,OAAO,EAEN,sBAAsB,GAGtB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAEN,mBAAmB,IAAI,qBAAqB,GAE5C,MAAM,yCAAyC,CAAC","sourcesContent":["/**\n * A tool for enforcing repository policies and standards across codebases.\n *\n * @remarks\n * Repopo provides a framework for defining and enforcing policies across repositories,\n * such as file headers, package.json consistency, and other code standards.\n * It can be used as a CLI tool or integrated into CI/CD pipelines.\n *\n * @packageDocumentation\n */\n\nexport { run } from \"@oclif/core\";\nexport {\n\ttype FluidAdapterOptions,\n\ttype FluidHandler,\n\tfromFluidHandlers,\n} from \"./adapters/fluidFramework.js\";\nexport type {\n\t// PolicyList,\n\tRepopoConfig,\n} from \"./config.js\";\nexport {\n\tmakePolicy,\n\tmakePolicyDefinition,\n\ttype PolicyDefinitionInput,\n} from \"./makePolicy.js\";\nexport type {\n\tPolicyDefinition,\n\tPolicyFailure,\n\tPolicyFixResult,\n\tPolicyFunctionArguments,\n\tPolicyHandler,\n\tPolicyHandlerResult,\n\tPolicyInstance,\n\tPolicyInstanceSettings,\n\tPolicyName,\n\tPolicyStandaloneResolver,\n} from \"./policy.js\";\nexport {\n\ttype DefineFileHeaderPolicyArgs,\n\tdefineFileHeaderPolicy,\n\ttype FileHeaderGeneratorConfig,\n\ttype FileHeaderPolicyConfig,\n} from \"./policyDefiners/defineFileHeaderPolicy.js\";\nexport {\n\ttype DefinePackagePolicyArgs,\n\tdefinePackagePolicy as generatePackagePolicy,\n\ttype PackageJsonHandler,\n} from \"./policyDefiners/definePackagePolicy.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAGN,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EACN,UAAU,EACV,oBAAoB,EAGpB,MAAM,GACN,MAAM,iBAAiB,CAAC;AACzB,OAAO;AAEN,cAAc;AACd,aAAa,EACb,eAAe,EACf,iBAAiB;AACjB,YAAY;AACZ,MAAM,GAiBN,MAAM,aAAa,CAAC;AACrB,OAAO,EAEN,sBAAsB,GAGtB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAEN,mBAAmB,IAAI,qBAAqB,GAE5C,MAAM,yCAAyC,CAAC","sourcesContent":["/**\n * A tool for enforcing repository policies and standards across codebases.\n *\n * @remarks\n * Repopo provides a framework for defining and enforcing policies across repositories,\n * such as file headers, package.json consistency, and other code standards.\n * It can be used as a CLI tool or integrated into CI/CD pipelines.\n *\n * @packageDocumentation\n */\n\nexport { run } from \"@oclif/core\";\nexport {\n\ttype FluidAdapterOptions,\n\ttype FluidHandler,\n\tfromFluidHandlers,\n} from \"./adapters/fluidFramework.js\";\nexport type {\n\t// PolicyList,\n\tRepopoConfig,\n} from \"./config.js\";\nexport {\n\tmakePolicy,\n\tmakePolicyDefinition,\n\ttype PolicyDefinitionInput,\n\ttype PolicyOptions,\n\tpolicy,\n} from \"./makePolicy.js\";\nexport {\n\ttype ConfiguredPolicy,\n\t// Type guards\n\tisPolicyError,\n\tisPolicyFailure,\n\tisPolicyFixResult,\n\t// New types\n\tPolicy,\n\ttype PolicyArgs,\n\t// Legacy types (for backward compatibility)\n\ttype PolicyDefinition,\n\ttype PolicyError,\n\ttype PolicyFailure,\n\ttype PolicyFixResult,\n\ttype PolicyFunctionArguments,\n\ttype PolicyHandler,\n\ttype PolicyHandlerResult,\n\ttype PolicyInstance,\n\ttype PolicyInstanceSettings,\n\ttype PolicyName,\n\ttype PolicyResolver,\n\ttype PolicyResult,\n\ttype PolicyShape,\n\ttype PolicyStandaloneResolver,\n} from \"./policy.js\";\nexport {\n\ttype DefineFileHeaderPolicyArgs,\n\tdefineFileHeaderPolicy,\n\ttype FileHeaderGeneratorConfig,\n\ttype FileHeaderPolicyConfig,\n} from \"./policyDefiners/defineFileHeaderPolicy.js\";\nexport {\n\ttype DefinePackagePolicyArgs,\n\tdefinePackagePolicy as generatePackagePolicy,\n\ttype PackageJsonHandler,\n} from \"./policyDefiners/definePackagePolicy.js\";\n"]}
@@ -1,10 +1,47 @@
1
- import type { PolicyDefinition, PolicyInstance, PolicyInstanceSettings } from "./policy.js";
1
+ import type { ConfiguredPolicy, PolicyDefinition, PolicyInstance, PolicyInstanceSettings, PolicyShape } from "./policy.js";
2
2
  /**
3
- * Input arguments for creating a policy definition.
3
+ * Options for configuring a policy instance.
4
+ *
5
+ * @alpha
6
+ */
7
+ export interface PolicyOptions {
8
+ /**
9
+ * File paths matching these patterns will be excluded from this policy.
10
+ * Patterns are matched against repo-relative paths.
11
+ */
12
+ exclude?: (string | RegExp)[];
13
+ }
14
+ /**
15
+ * Configure a policy for use in repopo.
4
16
  *
5
17
  * @remarks
6
- * This type is identical to {@link PolicyDefinition} but is used as the input type
7
- * for {@link makePolicyDefinition} to make the API more explicit.
18
+ * This function takes a policy definition and returns a configured policy instance
19
+ * that can be added to the `policies` array in `repopo.config.ts`.
20
+ *
21
+ * Handlers are automatically normalized: async functions are wrapped for Effection
22
+ * compatibility, while generator functions are used directly.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // Policy with no config, just options
27
+ * policy(NoJsFileExtensions, { exclude: ["bin/*"] })
28
+ *
29
+ * // Policy with config
30
+ * policy(PackageJsonProperties, { verbatim: { license: "MIT" } })
31
+ *
32
+ * // Policy with config and options
33
+ * policy(PackageJsonProperties, { verbatim: { license: "MIT" } }, { exclude: ["vendor/*"] })
34
+ * ```
35
+ *
36
+ * @alpha
37
+ */
38
+ export declare function policy<C = void>(policyDef: PolicyShape<C>, options?: PolicyOptions): ConfiguredPolicy<C>;
39
+ /** @alpha */
40
+ export declare function policy<C>(policyDef: PolicyShape<C>, config: C, options?: PolicyOptions): ConfiguredPolicy<C>;
41
+ /**
42
+ * Input arguments for creating a policy definition.
43
+ *
44
+ * @deprecated Use {@link PolicyShape} directly instead.
8
45
  *
9
46
  * @alpha
10
47
  */
@@ -12,9 +49,7 @@ export type PolicyDefinitionInput<C = undefined> = PolicyDefinition<C>;
12
49
  /**
13
50
  * Creates a {@link PolicyDefinition} from the provided arguments.
14
51
  *
15
- * @remarks
16
- * This function accepts an object with all policy properties, making it easier
17
- * to add new optional properties in the future without breaking changes.
52
+ * @deprecated Define policies as object literals satisfying {@link PolicyShape} instead.
18
53
  *
19
54
  * @example
20
55
  * ```typescript
@@ -30,7 +65,14 @@ export type PolicyDefinitionInput<C = undefined> = PolicyDefinition<C>;
30
65
  */
31
66
  export declare function makePolicyDefinition<C = undefined>(args: PolicyDefinitionInput<C>): PolicyDefinition<C>;
32
67
  /**
33
- * Combine a {@link PolicyDefinition} with a policy-specific config and other settings to produce a {@link PolicyInstance}.
68
+ * Combine a {@link PolicyDefinition} with a policy-specific config and other settings.
69
+ *
70
+ * @deprecated Use the `policy` function instead, which has a simpler API.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * makePolicy(NoJsFileExtensions, undefined, { excludeFiles: ["bin/*"] })
75
+ * ```
34
76
  *
35
77
  * @alpha
36
78
  */
@@ -1 +1 @@
1
- {"version":3,"file":"makePolicy.d.ts","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,MAAM,aAAa,CAAC;AAErB;;;;;;;;GAQG;AACH,MAAM,MAAM,qBA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AAC;AAEvE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,SAAS,EACjD,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAC5B,gBAAgB,CAAC,CAAC,CAAC,CASrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC3B,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC/B,MAAM,CAAC,EAAE,CAAC,EACV,QAAQ,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAClC,cAAc,CAAC,CAAC,CAAC,CAMnB"}
package/esm/makePolicy.js CHANGED
@@ -1,9 +1,62 @@
1
+ import { call } from "effection";
2
+ import { isGeneratorFunction } from "./generators.js";
3
+ /**
4
+ * Normalizes a handler to always return an Effection Operation.
5
+ * Detection happens once at registration time, not per-invocation.
6
+ */
7
+ function normalizeHandler(handler) {
8
+ if (isGeneratorFunction(handler)) {
9
+ // Already a generator, return as-is
10
+ return handler;
11
+ }
12
+ // Async function - wrap with call()
13
+ return function* (args) {
14
+ const asyncHandler = handler;
15
+ return yield* call(() => asyncHandler(args));
16
+ };
17
+ }
18
+ /** @alpha */
19
+ export function policy(policyDef, configOrOptions, maybeOptions) {
20
+ // Determine if the second argument is config or options
21
+ let config;
22
+ let options;
23
+ if (maybeOptions !== undefined) {
24
+ // Three-argument form: policy(def, config, options)
25
+ config = configOrOptions;
26
+ options = maybeOptions;
27
+ }
28
+ else if (configOrOptions !== undefined) {
29
+ // Two-argument form: need to determine if it's config or options
30
+ // PolicyOptions has a specific shape with 'exclude' property
31
+ if (typeof configOrOptions === "object" &&
32
+ configOrOptions !== null &&
33
+ "exclude" in configOrOptions &&
34
+ !("name" in configOrOptions) &&
35
+ Object.keys(configOrOptions).every((k) => k === "exclude")) {
36
+ // It's options (has only 'exclude')
37
+ options = configOrOptions;
38
+ }
39
+ else {
40
+ // It's config
41
+ config = configOrOptions;
42
+ }
43
+ }
44
+ // Merge with default config if available
45
+ const effectiveConfig = config ?? policyDef.defaultConfig;
46
+ // Support both 'exclude' and 'excludeFiles' for backward compatibility
47
+ const excludePatterns = options?.exclude;
48
+ return {
49
+ ...policyDef,
50
+ config: effectiveConfig,
51
+ exclude: excludePatterns,
52
+ excludeFiles: excludePatterns,
53
+ _internalHandler: normalizeHandler(policyDef.handler),
54
+ };
55
+ }
1
56
  /**
2
57
  * Creates a {@link PolicyDefinition} from the provided arguments.
3
58
  *
4
- * @remarks
5
- * This function accepts an object with all policy properties, making it easier
6
- * to add new optional properties in the future without breaking changes.
59
+ * @deprecated Define policies as object literals satisfying {@link PolicyShape} instead.
7
60
  *
8
61
  * @example
9
62
  * ```typescript
@@ -28,7 +81,14 @@ export function makePolicyDefinition(args) {
28
81
  };
29
82
  }
30
83
  /**
31
- * Combine a {@link PolicyDefinition} with a policy-specific config and other settings to produce a {@link PolicyInstance}.
84
+ * Combine a {@link PolicyDefinition} with a policy-specific config and other settings.
85
+ *
86
+ * @deprecated Use the `policy` function instead, which has a simpler API.
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * makePolicy(NoJsFileExtensions, undefined, { excludeFiles: ["bin/*"] })
91
+ * ```
32
92
  *
33
93
  * @alpha
34
94
  */
@@ -1 +1 @@
1
- {"version":3,"file":"makePolicy.js","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,oBAAoB,CACnC,IAA8B;IAE9B,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;KACvB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACzB,UAA+B,EAC/B,MAAU,EACV,QAAoC;IAEpC,OAAO;QACN,GAAG,UAAU;QACb,GAAG,QAAQ;QACX,MAAM;KACsB,CAAC;AAC/B,CAAC","sourcesContent":["import type {\n\tPolicyDefinition,\n\tPolicyInstance,\n\tPolicyInstanceSettings,\n} from \"./policy.js\";\n\n/**\n * Input arguments for creating a policy definition.\n *\n * @remarks\n * This type is identical to {@link PolicyDefinition} but is used as the input type\n * for {@link makePolicyDefinition} to make the API more explicit.\n *\n * @alpha\n */\nexport type PolicyDefinitionInput<C = undefined> = PolicyDefinition<C>;\n\n/**\n * Creates a {@link PolicyDefinition} from the provided arguments.\n *\n * @remarks\n * This function accepts an object with all policy properties, making it easier\n * to add new optional properties in the future without breaking changes.\n *\n * @example\n * ```typescript\n * const MyPolicy = makePolicyDefinition({\n * name: \"MyPolicy\",\n * description: \"Ensures files follow conventions\",\n * match: /\\.ts$/,\n * handler: async ({ file }) => true,\n * });\n * ```\n *\n * @alpha\n */\nexport function makePolicyDefinition<C = undefined>(\n\targs: PolicyDefinitionInput<C>,\n): PolicyDefinition<C> {\n\treturn {\n\t\tname: args.name,\n\t\tdescription: args.description,\n\t\tmatch: args.match,\n\t\thandler: args.handler,\n\t\tdefaultConfig: args.defaultConfig,\n\t\tresolver: args.resolver,\n\t};\n}\n\n/**\n * Combine a {@link PolicyDefinition} with a policy-specific config and other settings to produce a {@link PolicyInstance}.\n *\n * @alpha\n */\nexport function makePolicy<C>(\n\tdefinition: PolicyDefinition<C>,\n\tconfig?: C,\n\tsettings?: PolicyInstanceSettings<C>,\n): PolicyInstance<C> {\n\treturn {\n\t\t...definition,\n\t\t...settings,\n\t\tconfig,\n\t} satisfies PolicyInstance<C>;\n}\n"]}
1
+ {"version":3,"file":"makePolicy.js","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;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,OAAO,CAAC;IAEzC,OAAO;QACN,GAAG,SAAS;QACZ,MAAM,EAAE,eAAe;QACvB,OAAO,EAAE,eAAe;QACxB,YAAY,EAAE,eAAe;QAC7B,gBAAgB,EAAE,gBAAgB,CAAC,SAAS,CAAC,OAAO,CAAC;KACrD,CAAC;AACH,CAAC;AAeD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,oBAAoB,CACnC,IAA8B;IAE9B,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;KACvB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CACzB,UAA+B,EAC/B,MAAU,EACV,QAAoC;IAEpC,OAAO;QACN,GAAG,UAAU;QACb,GAAG,QAAQ;QACX,MAAM;KACsB,CAAC;AAC/B,CAAC","sourcesContent":["import { call, type Operation } from \"effection\";\nimport { isGeneratorFunction } from \"./generators.js\";\nimport type {\n\tConfiguredPolicy,\n\tPolicyArgs,\n\tPolicyDefinition,\n\tPolicyHandler,\n\tPolicyHandlerResult,\n\tPolicyInstance,\n\tPolicyInstanceSettings,\n\tPolicyShape,\n} from \"./policy.js\";\n\n// ============================================================================\n// New API: policy() function\n// ============================================================================\n\n/**\n * Options for configuring a policy instance.\n *\n * @alpha\n */\nexport interface PolicyOptions {\n\t/**\n\t * File paths matching these patterns will be excluded from this policy.\n\t * Patterns are matched against repo-relative paths.\n\t */\n\texclude?: (string | RegExp)[];\n}\n\n/**\n * Normalizes a handler to always return an Effection Operation.\n * Detection happens once at registration time, not per-invocation.\n */\nfunction normalizeHandler<C>(\n\thandler: PolicyHandler<C>,\n): (args: PolicyArgs<C>) => Operation<PolicyHandlerResult> {\n\tif (isGeneratorFunction(handler)) {\n\t\t// Already a generator, return as-is\n\t\treturn handler as (args: PolicyArgs<C>) => Operation<PolicyHandlerResult>;\n\t}\n\n\t// Async function - wrap with call()\n\treturn function* (args: PolicyArgs<C>): Operation<PolicyHandlerResult> {\n\t\tconst asyncHandler = handler as (\n\t\t\tpolicyArgs: PolicyArgs<C>,\n\t\t) => Promise<PolicyHandlerResult>;\n\t\treturn yield* call(() => asyncHandler(args));\n\t};\n}\n\n/**\n * Configure a policy for use in repopo.\n *\n * @remarks\n * This function takes a policy definition and returns a configured policy instance\n * that can be added to the `policies` array in `repopo.config.ts`.\n *\n * Handlers are automatically normalized: async functions are wrapped for Effection\n * compatibility, while generator functions are used directly.\n *\n * @example\n * ```typescript\n * // Policy with no config, just options\n * policy(NoJsFileExtensions, { exclude: [\"bin/*\"] })\n *\n * // Policy with config\n * policy(PackageJsonProperties, { verbatim: { license: \"MIT\" } })\n *\n * // Policy with config and options\n * policy(PackageJsonProperties, { verbatim: { license: \"MIT\" } }, { exclude: [\"vendor/*\"] })\n * ```\n *\n * @alpha\n */\nexport function policy<C = void>(\n\tpolicyDef: PolicyShape<C>,\n\toptions?: PolicyOptions,\n): ConfiguredPolicy<C>;\n/** @alpha */\nexport function policy<C>(\n\tpolicyDef: PolicyShape<C>,\n\tconfig: C,\n\toptions?: PolicyOptions,\n): ConfiguredPolicy<C>;\n/** @alpha */\nexport function policy<C>(\n\tpolicyDef: PolicyShape<C>,\n\tconfigOrOptions?: C | PolicyOptions,\n\tmaybeOptions?: PolicyOptions,\n): ConfiguredPolicy<C> {\n\t// Determine if the second argument is config or options\n\tlet config: C | undefined;\n\tlet options: PolicyOptions | undefined;\n\n\tif (maybeOptions !== undefined) {\n\t\t// Three-argument form: policy(def, config, options)\n\t\tconfig = configOrOptions as C;\n\t\toptions = maybeOptions;\n\t} else if (configOrOptions !== undefined) {\n\t\t// Two-argument form: need to determine if it's config or options\n\t\t// PolicyOptions has a specific shape with 'exclude' property\n\t\tif (\n\t\t\ttypeof configOrOptions === \"object\" &&\n\t\t\tconfigOrOptions !== null &&\n\t\t\t\"exclude\" in configOrOptions &&\n\t\t\t!(\"name\" in configOrOptions) &&\n\t\t\tObject.keys(configOrOptions).every((k) => k === \"exclude\")\n\t\t) {\n\t\t\t// It's options (has only 'exclude')\n\t\t\toptions = configOrOptions as PolicyOptions;\n\t\t} else {\n\t\t\t// It's config\n\t\t\tconfig = configOrOptions as C;\n\t\t}\n\t}\n\n\t// Merge with default config if available\n\tconst effectiveConfig = config ?? (policyDef.defaultConfig as C | undefined);\n\n\t// Support both 'exclude' and 'excludeFiles' for backward compatibility\n\tconst excludePatterns = options?.exclude;\n\n\treturn {\n\t\t...policyDef,\n\t\tconfig: effectiveConfig,\n\t\texclude: excludePatterns,\n\t\texcludeFiles: excludePatterns,\n\t\t_internalHandler: normalizeHandler(policyDef.handler),\n\t};\n}\n\n// ============================================================================\n// Legacy API (Still supported for backward compatibility)\n// ============================================================================\n\n/**\n * Input arguments for creating a policy definition.\n *\n * @deprecated Use {@link PolicyShape} directly instead.\n *\n * @alpha\n */\nexport type PolicyDefinitionInput<C = undefined> = PolicyDefinition<C>;\n\n/**\n * Creates a {@link PolicyDefinition} from the provided arguments.\n *\n * @deprecated Define policies as object literals satisfying {@link PolicyShape} instead.\n *\n * @example\n * ```typescript\n * const MyPolicy = makePolicyDefinition({\n * name: \"MyPolicy\",\n * description: \"Ensures files follow conventions\",\n * match: /\\.ts$/,\n * handler: async ({ file }) => true,\n * });\n * ```\n *\n * @alpha\n */\nexport function makePolicyDefinition<C = undefined>(\n\targs: PolicyDefinitionInput<C>,\n): PolicyDefinition<C> {\n\treturn {\n\t\tname: args.name,\n\t\tdescription: args.description,\n\t\tmatch: args.match,\n\t\thandler: args.handler,\n\t\tdefaultConfig: args.defaultConfig,\n\t\tresolver: args.resolver,\n\t};\n}\n\n/**\n * Combine a {@link PolicyDefinition} with a policy-specific config and other settings.\n *\n * @deprecated Use the `policy` function instead, which has a simpler API.\n *\n * @example\n * ```typescript\n * makePolicy(NoJsFileExtensions, undefined, { excludeFiles: [\"bin/*\"] })\n * ```\n *\n * @alpha\n */\nexport function makePolicy<C>(\n\tdefinition: PolicyDefinition<C>,\n\tconfig?: C,\n\tsettings?: PolicyInstanceSettings<C>,\n): PolicyInstance<C> {\n\treturn {\n\t\t...definition,\n\t\t...settings,\n\t\tconfig,\n\t} satisfies PolicyInstance<C>;\n}\n"]}