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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,84 @@
1
1
  # repopo
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Configuration changes _[`#224`](https://github.com/tylerbutler/tools-monorepo/pull/224) [`2b7db34`](https://github.com/tylerbutler/tools-monorepo/commit/2b7db343d74ab2e518ab2f232f47ea365ca784b8) [@tylerbutler](https://github.com/tylerbutler)_
8
+
9
+ The configuration for repopo has changed a lot in this release. The goal is to improve the typing of config and make it
10
+ easier to configure things in one place.
11
+
12
+ Policies are now declared as `PolicyDefinition`, and are then combined with a configuration (if the policy has
13
+ configuration) using `makePolicy` to form a `PolicyInstance`, which is the primary type used internally.
14
+
15
+ Generators now generate `PolicyDefinition`s, and can be used directly inline with `makePolicy`.
16
+
17
+ - Export policies from /policies entrypoint only _[`#224`](https://github.com/tylerbutler/tools-monorepo/pull/224) [`2b7db34`](https://github.com/tylerbutler/tools-monorepo/commit/2b7db343d74ab2e518ab2f232f47ea365ca784b8) [@tylerbutler](https://github.com/tylerbutler)_
18
+
19
+ Policies included with repopo are now exported from `repopo/policies`.
20
+
21
+ ### Patch Changes
22
+
23
+ - Update package metadata _[`#221`](https://github.com/tylerbutler/tools-monorepo/pull/221) [`9e5225a`](https://github.com/tylerbutler/tools-monorepo/commit/9e5225abfb67af1575af13dff60830d8da28eafd) [@tylerbutler](https://github.com/tylerbutler)_
24
+
25
+ <details><summary>Updated 2 dependencies</summary>
26
+
27
+ <small>
28
+
29
+ [`9e5225a`](https://github.com/tylerbutler/tools-monorepo/commit/9e5225abfb67af1575af13dff60830d8da28eafd)
30
+
31
+ </small>
32
+
33
+ - `@tylerbu/fundamentals@0.2.2`
34
+ - `@tylerbu/cli-api@0.7.2`
35
+
36
+ </details>
37
+
38
+ ## 0.5.0
39
+
40
+ ### Minor Changes
41
+
42
+ - Export all default policies _[`#213`](https://github.com/tylerbutler/tools-monorepo/pull/213) [`3fc530b`](https://github.com/tylerbutler/tools-monorepo/commit/3fc530bad66259339547b3d8ec12b9265daea9a5) [@tylerbutler](https://github.com/tylerbutler)_
43
+
44
+ repopo now exports all included policies individually so users can opt in and out of them in their config.
45
+
46
+ - New policies _[`#31`](https://github.com/tylerbutler/tools-monorepo/pull/31) [`c97a565`](https://github.com/tylerbutler/tools-monorepo/commit/c97a56518d9726667531aa71de9445fed8d56b96) [@tylerbutler](https://github.com/tylerbutler)_
47
+
48
+ - JsTsFileHeaders
49
+ - HtmlFileHeaders
50
+ - PackageScripts
51
+
52
+ - API changes: _[`#120`](https://github.com/tylerbutler/tools-monorepo/pull/120) [`1108950`](https://github.com/tylerbutler/tools-monorepo/commit/1108950a7732dcc3ac9b8da10bd014bfec6c45b7) [@tylerbutler](https://github.com/tylerbutler)_
53
+
54
+ - **Breaking change**: `PolicyConfig` was renamed to `RepopoConfig`.
55
+ - **Breaking change**: Removed several flags from the check command.
56
+
57
+ Other changes:
58
+
59
+ - Refactor check command for clarity (more to do)
60
+
61
+ - Functions to more easily create package.json handlers _[`#190`](https://github.com/tylerbutler/tools-monorepo/pull/190) [`84c4185`](https://github.com/tylerbutler/tools-monorepo/commit/84c4185e76186c3489a4b70e3a3015ba289df139) [@tylerbutler](https://github.com/tylerbutler)_
62
+
63
+ repopo now provides functions that can be used to generate policies for common files like package.json.
64
+
65
+ ### Patch Changes
66
+
67
+ - Update dependencies _[`#217`](https://github.com/tylerbutler/tools-monorepo/pull/217) [`dcec014`](https://github.com/tylerbutler/tools-monorepo/commit/dcec014dfb70e5804a7535b5b8b9a3406f3e623d) [@tylerbutler](https://github.com/tylerbutler)_
68
+
69
+ <details><summary>Updated 2 dependencies</summary>
70
+
71
+ <small>
72
+
73
+ [`dcec014`](https://github.com/tylerbutler/tools-monorepo/commit/dcec014dfb70e5804a7535b5b8b9a3406f3e623d)
74
+
75
+ </small>
76
+
77
+ - `@tylerbu/fundamentals@0.2.1`
78
+ - `@tylerbu/cli-api@0.7.1`
79
+
80
+ </details>
81
+
3
82
  ## 0.4.0
4
83
 
5
84
  ### Minor Changes
package/README.md CHANGED
@@ -7,12 +7,13 @@ file in your git repo, with a straightforward way to write your own policies.
7
7
  * [repopo - police the files in your git repo with extensible policies](#repopo---police-the-files-in-your-git-repo-with-extensible-policies)
8
8
  * [Configuring policies](#configuring-policies)
9
9
  * [Included policies](#included-policies)
10
- * [Usage](#usage)
10
+ * [Policy generators](#policy-generators)
11
+ * [CLI Usage](#cli-usage)
11
12
  <!-- tocstop -->
12
13
 
13
14
  # Configuring policies
14
15
 
15
- Repopo and its policies can be configured in a repopo.config.ts (or .cjs, or .mjs) file in the root of the repo. Using a
16
+ Repopo and its policies can be configured in a `repopo.config.ts` (or `.cjs`, or `.mjs`) file in the root of the repo. Using a
16
17
  TypeScript configuration file is recommended.
17
18
 
18
19
  The policy config must export a default object of the type `PolicyConfig`.
@@ -23,19 +24,25 @@ By default, all files in the repo are checked. You can exclude files completely
23
24
  d `excludeFiles` setting. It should be an array of strings/regular expressions. Paths that match any of these
24
25
  expressions will be completely excluded from all policies.
25
26
 
26
- You can exclude files from individual policies as well. To do this, set the `excludePoliciesForFiles` setting. It should
27
- be an object with keys that match policy names. The value is an array of strings/regular expressions. Paths that match
28
- any of these expressions will be excluded from that policy only.
27
+ You can exclude files from individual policies as well by configuring the `excludeFiles` setting when calling
28
+ `makePolicy`.
29
29
 
30
30
  ## Configuring individual policies
31
31
 
32
- Individual policies can be configured using the `policySettings` setting. Use the policy name as the key, with the
33
- policy settings as the value.
32
+ Individual policies can be configured by passing configuration settings to a `PolicyDefinition` in `makePolicy`.
34
33
 
35
34
  # Included policies
36
35
 
37
36
  repopo includes the following policies. All of the included policies are enabled by default.
38
37
 
38
+ ## HtmlFileHeaders and JsTsFileHeaders
39
+
40
+ These policies set a common file header for JavaScript/TypeScript and HTML files.
41
+
42
+ ### Configuration
43
+
44
+ TODO
45
+
39
46
  ## NoJsFileExtensions
40
47
 
41
48
  The NoJsFileExtensions policy checks for JavaScript source files that just use the .js file extension. Such files may be
@@ -61,6 +68,10 @@ const config: PolicyConfig = {
61
68
  license: "MIT",
62
69
  author: "Tyler Butler <tyler@tylerbutler.com>",
63
70
  bugs: "https://github.com/tylerbutler/tools-monorepo/issues",
71
+ repository: {
72
+ type: "git",
73
+ url: "git+https://github.com/tylerbutler/tools-monorepo.git",
74
+ }
64
75
  }
65
76
  }
66
77
  }
@@ -72,7 +83,17 @@ const config: PolicyConfig = {
72
83
  A RepoPolicy that checks that the `repository.directory` property in package.json is set correctly. If the repository
73
84
  field is a string instead of an object the package will be ignored.
74
85
 
75
- # Usage
86
+ # Policy generators
87
+
88
+ There are some filetypes that often have policies applied to them, like package.json. You can use the policy generator
89
+ functions to generate policies for those filetypes. Using the generators is not required; they simply reduce the amount
90
+ of boilerplate code you have to write for a policy.
91
+
92
+ ## generatePackagePolicy
93
+
94
+ Use `generatePackagePolicy` to generate policies for package.json files.
95
+
96
+ # CLI Usage
76
97
 
77
98
  <!-- commands -->
78
99
  * [`repopo check`](#repopo-check)
@@ -84,16 +105,15 @@ Checks and applies policies to the files in the repository.
84
105
 
85
106
  ```
86
107
  USAGE
87
- $ repopo check [-f] [--stdin] [-D <value>... | -d <value>] [-p <value>]
108
+ $ repopo check [-v | --quiet] [-f] [--stdin]
88
109
 
89
110
  FLAGS
90
- -D, --excludePolicy=<value>... Exclude policies by name. Can be specified multiple times to exclude multiple
91
- policies.
92
- -d, --policy=<value> Filter policies to apply by <regex>. Only policies with a name matching the regex will
93
- be applied.
94
- -f, --fix Fix errors if possible.
95
- -p, --path=<value> Filter file paths by <regex>.
96
- --stdin Read list of files from stdin.
111
+ -f, --fix Fix errors if possible.
112
+ --stdin Read list of files from stdin.
113
+
114
+ LOGGING FLAGS
115
+ -v, --verbose Enable verbose logging.
116
+ --quiet Disable all logging.
97
117
  ```
98
118
 
99
119
  _See code: [src/commands/check.ts](https://github.com/tylerbutler/tools-monorepo/blob/main/packages/repopo/src/commands/check.ts)_
@@ -104,14 +124,11 @@ Lists the policies configured to run.
104
124
 
105
125
  ```
106
126
  USAGE
107
- $ repopo list [-D <value>... | -d <value>] [-p <value>]
127
+ $ repopo list [-v | --quiet]
108
128
 
109
- FLAGS
110
- -D, --excludePolicy=<value>... Exclude policies by name. Can be specified multiple times to exclude multiple
111
- policies.
112
- -d, --policy=<value> Filter policies to apply by <regex>. Only policies with a name matching the regex will
113
- be applied.
114
- -p, --path=<value> Filter file paths by <regex>.
129
+ LOGGING FLAGS
130
+ -v, --verbose Enable verbose logging.
131
+ --quiet Disable all logging.
115
132
  ```
116
133
 
117
134
  _See code: [src/commands/list.ts](https://github.com/tylerbutler/tools-monorepo/blob/main/packages/repopo/src/commands/list.ts)_
@@ -27,7 +27,7 @@ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHE
27
27
 
28
28
  The following npm package may be included in this product:
29
29
 
30
- - @rushstack/node-core-library@5.9.0
30
+ - @rushstack/node-core-library@5.13.1
31
31
 
32
32
  This package contains the following license:
33
33
 
@@ -60,7 +60,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
60
60
 
61
61
  The following npm package may be included in this product:
62
62
 
63
- - @fluid-tools/build-infrastructure@0.52.0
63
+ - @fluid-tools/build-infrastructure@0.56.0
64
64
 
65
65
  This package contains the following license:
66
66
 
@@ -114,13 +114,24 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
114
114
 
115
115
  The following npm package may be included in this product:
116
116
 
117
- - sort-package-json@2.14.0
117
+ - simple-git@3.27.0
118
118
 
119
119
  This package contains the following license:
120
120
 
121
+ MIT
122
+
123
+ -----------
124
+
125
+ The following npm packages may be included in this product:
126
+
127
+ - @oclif/core@4.3.0
128
+ - @oclif/plugin-help@6.2.27
129
+
130
+ These packages each contain the following license:
131
+
121
132
  MIT License
122
133
 
123
- Copyright (c) 2015 Keith Cirkel
134
+ Copyright (c) 2018 Salesforce.com
124
135
 
125
136
  Permission is hereby granted, free of charge, to any person obtaining a copy
126
137
  of this software and associated documentation files (the "Software"), to deal
@@ -142,16 +153,15 @@ SOFTWARE.
142
153
 
143
154
  -----------
144
155
 
145
- The following npm packages may be included in this product:
156
+ The following npm package may be included in this product:
146
157
 
147
- - @oclif/core@4.2.3
148
- - @oclif/plugin-help@6.2.21
158
+ - microdiff@1.5.0
149
159
 
150
- These packages each contain the following license:
160
+ This package contains the following license:
151
161
 
152
162
  MIT License
153
163
 
154
- Copyright (c) 2018 Salesforce.com
164
+ Copyright (c) 2021 AsyncBanana
155
165
 
156
166
  Permission is hereby granted, free of charge, to any person obtaining a copy
157
167
  of this software and associated documentation files (the "Software"), to deal
@@ -175,13 +185,13 @@ SOFTWARE.
175
185
 
176
186
  The following npm package may be included in this product:
177
187
 
178
- - sort-tsconfig@0.2.0
188
+ - defu@6.1.4
179
189
 
180
190
  This package contains the following license:
181
191
 
182
192
  MIT License
183
193
 
184
- Copyright (c) 2023 Tyler Butler <tyler@tylerbutler.com>
194
+ Copyright (c) Pooya Parsa <pooya@pi0.io>
185
195
 
186
196
  Permission is hereby granted, free of charge, to any person obtaining a copy
187
197
  of this software and associated documentation files (the "Software"), to deal
package/esm/api.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":""}
package/esm/api.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=api.js.map
package/esm/api.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"","sourcesContent":[""]}
@@ -1,52 +1,22 @@
1
- import { GitCommand } from "@tylerbu/cli-api";
2
- import type { PolicyConfig } from "./config.js";
3
- import { type PolicyHandlerPerfStats } from "./perf.js";
4
- import { type PolicyName, type RepoPolicy } from "./policy.js";
1
+ import { CommandWithConfig, type CommandWithContext, type RequiresGit } from "@tylerbu/cli-api";
2
+ import { type SimpleGit } from "simple-git";
3
+ import { type RepopoConfig } from "./config.js";
4
+ import type { RepopoCommandContext } from "./context.js";
5
5
  /**
6
- * A convenience interface used to pass commonly used parameters between functions.
7
- */
8
- export interface PolicyCommandContext {
9
- /**
10
- * A regular expression used to filter selected files.
11
- */
12
- pathRegex: RegExp;
13
- /**
14
- * A list of regular expressions used to exclude files from all handlers.
15
- */
16
- excludeFiles: RegExp[];
17
- /**
18
- * A list of handlers to apply to selected files.
19
- */
20
- policies: RepoPolicy[];
21
- /**
22
- * A per-handler list of regular expressions used to exclude files from specific handlers.
23
- */
24
- excludePoliciesForFiles: ExcludedPolicyFileMap;
25
- /**
26
- * Path to the root of the git repo.
27
- */
28
- gitRoot: string;
29
- /**
30
- * Performance information for each handler.
31
- */
32
- perfStats: PolicyHandlerPerfStats;
33
- }
34
- /**
35
- * This command lists all the policies configured to run.
6
+ * This class is the base for all repopo commands. It contains common flags and config loading.
36
7
  */
37
8
  export declare abstract class BaseRepopoCommand<T extends typeof BaseRepopoCommand & {
38
- args: typeof GitCommand.args;
39
- flags: typeof GitCommand.flags;
40
- }> extends GitCommand<T, PolicyConfig> {
9
+ args: typeof CommandWithConfig.args;
10
+ flags: typeof CommandWithConfig.flags;
11
+ }> extends CommandWithConfig<T, RepopoConfig> implements CommandWithContext<RepopoCommandContext>, RequiresGit {
12
+ protected defaultConfig: RepopoConfig;
41
13
  static readonly flags: {
42
14
  readonly config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
43
- readonly policy: import("@oclif/core/interfaces").OptionFlag<RegExp | undefined, import("@oclif/core/interfaces").CustomOptions>;
44
- readonly excludePolicy: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
45
- readonly path: import("@oclif/core/interfaces").OptionFlag<RegExp | undefined, import("@oclif/core/interfaces").CustomOptions>;
46
15
  };
47
- private context;
48
- protected getContext(): PolicyCommandContext;
16
+ private _git;
17
+ get git(): SimpleGit;
49
18
  init(): Promise<void>;
19
+ private _context;
20
+ getContext(): Promise<RepopoCommandContext>;
50
21
  }
51
- export type ExcludedPolicyFileMap = Map<PolicyName, RegExp[]>;
52
22
  //# sourceMappingURL=baseCommand.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"baseCommand.d.ts","sourceRoot":"","sources":["../src/baseCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAA2B,MAAM,kBAAkB,CAAC;AAEvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,KAA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,EAAE,MAAM,cAAc,CAAC;AAKhF;;GAEG;AACH,8BAAsB,iBAAiB,CACrC,CAAC,SAAS,OAAO,iBAAiB,GAAG;IACpC,IAAI,EAAE,OAAO,iBAAiB,CAAC,IAAI,CAAC;IACpC,KAAK,EAAE,OAAO,iBAAiB,CAAC,KAAK,CAAC;CACtC,CAEF,SAAQ,iBAAiB,CAAC,CAAC,EAAE,YAAY,CACzC,YAAW,kBAAkB,CAAC,oBAAoB,CAAC,EAAE,WAAW;IAEhE,UAAmB,aAAa,eAAuB;IAEvD,gBAAyB,KAAK;gCAb2D,wBAE5E,wCACD,wBAAwB;MAYzB;IAEX,OAAO,CAAC,IAAI,CAAwB;IACpC,IAAW,GAAG,IAAI,SAAS,CAK1B;IAEqB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB3C,OAAO,CAAC,QAAQ,CAAmC;IAGtC,UAAU,IAAI,OAAO,CAAC,oBAAoB,CAAC;CAMxD"}
@@ -1,87 +1,51 @@
1
- import { Flags } from "@oclif/core";
2
- import { GitCommand, RegExpFlag, findGitRoot } from "@tylerbu/cli-api";
1
+ import { CommandWithConfig, } from "@tylerbu/cli-api";
2
+ import { findGitRootSync } from "@tylerbu/fundamentals/git";
3
+ import { simpleGit } from "simple-git";
4
+ import { DefaultPolicyConfig } from "./config.js";
5
+ import { makePolicy } from "./makePolicy.js";
3
6
  import { newPerfStats } from "./perf.js";
4
7
  import { DefaultPolicies } from "./policy.js";
5
- const DEFAULT_PATH_REGEX = /.?/;
6
8
  /**
7
- * This command lists all the policies configured to run.
9
+ * This class is the base for all repopo commands. It contains common flags and config loading.
8
10
  */
9
- export class BaseRepopoCommand extends GitCommand {
11
+ export class BaseRepopoCommand extends CommandWithConfig {
12
+ defaultConfig = DefaultPolicyConfig;
10
13
  static flags = {
11
- policy: RegExpFlag({
12
- description: "Filter policies to apply by <regex>. Only policies with a name matching the regex will be applied.",
13
- required: false,
14
- char: "d",
15
- }),
16
- excludePolicy: Flags.string({
17
- char: "D",
18
- description: "Exclude policies by name. Can be specified multiple times to exclude multiple policies.",
19
- exclusive: ["policy"],
20
- multiple: true,
21
- }),
22
- path: RegExpFlag({
23
- description: "Filter file paths by <regex>.",
24
- required: false,
25
- char: "p",
26
- }),
27
- ...GitCommand.flags,
14
+ ...CommandWithConfig.flags,
28
15
  };
29
- context;
30
- getContext() {
31
- if (this.context === undefined) {
32
- throw new Error("context undefined");
16
+ _git;
17
+ get git() {
18
+ if (this._git === undefined) {
19
+ throw new Error("git property is undefined");
33
20
  }
34
- return this.context;
21
+ return this._git;
35
22
  }
36
23
  async init() {
37
24
  await super.init();
38
- const { flags } = this;
39
- const config = this.commandConfig;
40
- let policies = config?.policies ?? DefaultPolicies;
41
- policies =
42
- policies.filter((h) => {
43
- if (flags.excludePolicy === undefined ||
44
- flags.excludePolicy.length === 0) {
45
- return true;
46
- }
47
- const shouldRun = flags.excludePolicy?.includes(h.name) === false;
48
- if (!shouldRun) {
49
- this.info(`Disabled policy: ${h.name}`);
50
- }
51
- return shouldRun;
52
- }) ?? [];
53
- if (flags.policy !== undefined) {
54
- this.info(`Filtering handlers by regex: ${flags.policy}`);
55
- policies = policies.filter((h) => flags.policy?.test(h.name));
56
- }
57
- const excludeFiles = config?.excludeFiles?.map((e) => toRegExp(e)) ?? [];
58
- const excludePoliciesForFilesRaw = config?.excludePoliciesForFiles;
25
+ const excludeFiles = this.commandConfig?.excludeFiles?.map((e) => new RegExp(e, "i")) ?? [];
59
26
  const excludePoliciesForFiles = new Map();
60
- if (excludePoliciesForFilesRaw) {
61
- for (const [policyName, filters] of Object.entries(excludePoliciesForFilesRaw)) {
62
- const regexes = filters.map((e) => toRegExp(e));
63
- excludePoliciesForFiles.set(policyName, regexes);
64
- }
65
- }
66
- const gitRoot = await findGitRoot();
67
- const pathRegex = this.flags.path ?? DEFAULT_PATH_REGEX;
68
- if (this.flags.path !== undefined) {
69
- this.info(`Filtering file paths by regex: ${pathRegex}`);
27
+ for (const policy of this.commandConfig?.policies ?? []) {
28
+ const regexes = policy.excludeFiles?.map((e) => new RegExp(e, "i")) ?? [];
29
+ excludePoliciesForFiles.set(policy.name, regexes);
70
30
  }
71
- this.context = {
72
- pathRegex,
73
- excludeFiles,
74
- policies,
31
+ const gitRoot = findGitRootSync();
32
+ this._git = simpleGit({ baseDir: gitRoot });
33
+ this._context = {
34
+ excludeFromAll: excludeFiles,
35
+ policies: this.commandConfig?.policies ??
36
+ DefaultPolicies.map((p) => makePolicy(p)),
75
37
  excludePoliciesForFiles,
76
38
  gitRoot,
77
39
  perfStats: newPerfStats(),
78
40
  };
79
41
  }
80
- }
81
- function toRegExp(input) {
82
- if (typeof input === "string") {
83
- return new RegExp(input, "i");
42
+ _context;
43
+ // biome-ignore lint/suspicious/useAwait: interface defines this as async
44
+ async getContext() {
45
+ if (this._context === undefined) {
46
+ throw new Error("Context not initialized.");
47
+ }
48
+ return this._context;
84
49
  }
85
- return input;
86
50
  }
87
51
  //# sourceMappingURL=baseCommand.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"baseCommand.js","sourceRoot":"","sources":["../src/baseCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGvE,OAAO,EAA+B,YAAY,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,eAAe,EAAoC,MAAM,aAAa,CAAC;AAEhF,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAqChC;;GAEG;AACH,MAAM,OAAgB,iBAKpB,SAAQ,UAA2B;IACpC,MAAM,CAAmB,KAAK,GAAG;QAChC,MAAM,EAAE,UAAU,CAAC;YAClB,WAAW,EACV,oGAAoG;YACrG,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,GAAG;SACT,CAAC;QACF,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC;YAC3B,IAAI,EAAE,GAAG;YAC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Q,CAAC,KAAsB;IACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,IAAI,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { Flags } from \"@oclif/core\";\nimport { GitCommand, RegExpFlag, findGitRoot } from \"@tylerbu/cli-api\";\n\nimport type { PolicyConfig } from \"./config.js\";\nimport { type PolicyHandlerPerfStats, newPerfStats } from \"./perf.js\";\nimport { DefaultPolicies, type PolicyName, type RepoPolicy } from \"./policy.js\";\n\nconst DEFAULT_PATH_REGEX = /.?/;\n\n/**\n * A convenience interface used to pass commonly used parameters between functions.\n */\nexport interface PolicyCommandContext {\n\t/**\n\t * A regular expression used to filter selected files.\n\t */\n\tpathRegex: RegExp;\n\n\t/**\n\t * A list of regular expressions used to exclude files from all handlers.\n\t */\n\texcludeFiles: RegExp[];\n\n\t/**\n\t * A list of handlers to apply to selected files.\n\t */\n\tpolicies: RepoPolicy[];\n\n\t/**\n\t * A per-handler list of regular expressions used to exclude files from specific handlers.\n\t */\n\texcludePoliciesForFiles: ExcludedPolicyFileMap;\n\n\t/**\n\t * Path to the root of the git repo.\n\t */\n\tgitRoot: string;\n\n\t/**\n\t * Performance information for each handler.\n\t */\n\tperfStats: PolicyHandlerPerfStats;\n}\n\n/**\n * This command lists all the policies configured to run.\n */\nexport abstract class BaseRepopoCommand<\n\tT extends typeof BaseRepopoCommand & {\n\t\targs: typeof GitCommand.args;\n\t\tflags: typeof GitCommand.flags;\n\t},\n> extends GitCommand<T, PolicyConfig> {\n\tstatic override readonly flags = {\n\t\tpolicy: RegExpFlag({\n\t\t\tdescription:\n\t\t\t\t\"Filter policies to apply by <regex>. Only policies with a name matching the regex will be applied.\",\n\t\t\trequired: false,\n\t\t\tchar: \"d\",\n\t\t}),\n\t\texcludePolicy: Flags.string({\n\t\t\tchar: \"D\",\n\t\t\tdescription:\n\t\t\t\t\"Exclude policies by name. Can be specified multiple times to exclude multiple policies.\",\n\t\t\texclusive: [\"policy\"],\n\t\t\tmultiple: true,\n\t\t}),\n\t\tpath: RegExpFlag({\n\t\t\tdescription: \"Filter file paths by <regex>.\",\n\t\t\trequired: false,\n\t\t\tchar: \"p\",\n\t\t}),\n\t\t...GitCommand.flags,\n\t} as const;\n\n\tprivate context: PolicyCommandContext | undefined;\n\n\tprotected getContext(): PolicyCommandContext {\n\t\tif (this.context === undefined) {\n\t\t\tthrow new Error(\"context undefined\");\n\t\t}\n\t\treturn this.context;\n\t}\n\n\tpublic override async init(): Promise<void> {\n\t\tawait super.init();\n\t\tconst { flags } = this;\n\t\tconst config = this.commandConfig;\n\t\tlet policies = config?.policies ?? DefaultPolicies;\n\t\tpolicies =\n\t\t\tpolicies.filter((h) => {\n\t\t\t\tif (\n\t\t\t\t\tflags.excludePolicy === undefined ||\n\t\t\t\t\tflags.excludePolicy.length === 0\n\t\t\t\t) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconst shouldRun = flags.excludePolicy?.includes(h.name) === false;\n\t\t\t\tif (!shouldRun) {\n\t\t\t\t\tthis.info(`Disabled policy: ${h.name}`);\n\t\t\t\t}\n\t\t\t\treturn shouldRun;\n\t\t\t}) ?? [];\n\t\tif (flags.policy !== undefined) {\n\t\t\tthis.info(`Filtering handlers by regex: ${flags.policy}`);\n\t\t\tpolicies = policies.filter((h) => flags.policy?.test(h.name));\n\t\t}\n\n\t\tconst excludeFiles: RegExp[] =\n\t\t\tconfig?.excludeFiles?.map((e) => toRegExp(e)) ?? [];\n\t\tconst excludePoliciesForFilesRaw = config?.excludePoliciesForFiles;\n\t\tconst excludePoliciesForFiles: ExcludedPolicyFileMap = new Map();\n\t\tif (excludePoliciesForFilesRaw) {\n\t\t\tfor (const [policyName, filters] of Object.entries(\n\t\t\t\texcludePoliciesForFilesRaw,\n\t\t\t)) {\n\t\t\t\tconst regexes = filters.map((e) => toRegExp(e));\n\t\t\t\texcludePoliciesForFiles.set(policyName, regexes);\n\t\t\t}\n\t\t}\n\t\tconst gitRoot = await findGitRoot();\n\n\t\tconst pathRegex = this.flags.path ?? DEFAULT_PATH_REGEX;\n\t\tif (this.flags.path !== undefined) {\n\t\t\tthis.info(`Filtering file paths by regex: ${pathRegex}`);\n\t\t}\n\n\t\tthis.context = {\n\t\t\tpathRegex,\n\t\t\texcludeFiles,\n\t\t\tpolicies,\n\t\t\texcludePoliciesForFiles,\n\t\t\tgitRoot,\n\t\t\tperfStats: newPerfStats(),\n\t\t};\n\t}\n}\n\nexport type ExcludedPolicyFileMap = Map<PolicyName, RegExp[]>;\n\nfunction toRegExp(input: string | RegExp): RegExp {\n\tif (typeof input === \"string\") {\n\t\treturn new RegExp(input, \"i\");\n\t}\n\treturn input;\n}\n"]}
1
+ {"version":3,"file":"baseCommand.js","sourceRoot":"","sources":["../src/baseCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,GAGjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAkB,SAAS,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAqB,MAAM,aAAa,CAAC;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAgB,iBAMrB,SAAQ,iBAAkC;IAGvB,aAAa,GAAG,mBAAmB,CAAC;IAEvD,MAAM,CAAmB,KAAK,GAAG;QAChC,GAAG,iBAAiB,CAAC,KAAK;KACjB,CAAC;IAEH,IAAI,CAAwB;IACpC,IAAW,GAAG;QACb,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CA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AA0B,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC","sourcesContent":["import {\n\tCommandWithConfig,\n\ttype CommandWithContext,\n\ttype RequiresGit,\n} from \"@tylerbu/cli-api\";\nimport { findGitRootSync } from \"@tylerbu/fundamentals/git\";\nimport { type SimpleGit, simpleGit } from \"simple-git\";\nimport { DefaultPolicyConfig, type RepopoConfig } from \"./config.js\";\nimport type { ExcludedPolicyFileMap, RepopoCommandContext } from \"./context.js\";\nimport { makePolicy } from \"./makePolicy.js\";\nimport { newPerfStats } from \"./perf.js\";\nimport { DefaultPolicies } from \"./policy.js\";\n\n/**\n * This class is the base for all repopo commands. It contains common flags and config loading.\n */\nexport abstract class BaseRepopoCommand<\n\t\tT extends typeof BaseRepopoCommand & {\n\t\t\targs: typeof CommandWithConfig.args;\n\t\t\tflags: typeof CommandWithConfig.flags;\n\t\t},\n\t>\n\textends CommandWithConfig<T, RepopoConfig>\n\timplements CommandWithContext<RepopoCommandContext>, RequiresGit\n{\n\tprotected override defaultConfig = DefaultPolicyConfig;\n\n\tstatic override readonly flags = {\n\t\t...CommandWithConfig.flags,\n\t} as const;\n\n\tprivate _git: SimpleGit | undefined;\n\tpublic get git(): SimpleGit {\n\t\tif (this._git === undefined) {\n\t\t\tthrow new Error(\"git property is undefined\");\n\t\t}\n\t\treturn this._git;\n\t}\n\n\tpublic override async init(): Promise<void> {\n\t\tawait super.init();\n\n\t\tconst excludeFiles: RegExp[] =\n\t\t\tthis.commandConfig?.excludeFiles?.map((e) => new RegExp(e, \"i\")) ?? [];\n\n\t\tconst excludePoliciesForFiles: ExcludedPolicyFileMap = new Map();\n\t\tfor (const policy of this.commandConfig?.policies ?? []) {\n\t\t\tconst regexes = policy.excludeFiles?.map((e) => new RegExp(e, \"i\")) ?? [];\n\t\t\texcludePoliciesForFiles.set(policy.name, regexes);\n\t\t}\n\n\t\tconst gitRoot = findGitRootSync();\n\t\tthis._git = simpleGit({ baseDir: gitRoot });\n\t\tthis._context = {\n\t\t\texcludeFromAll: excludeFiles,\n\t\t\tpolicies:\n\t\t\t\tthis.commandConfig?.policies ??\n\t\t\t\tDefaultPolicies.map((p) => makePolicy(p)),\n\t\t\texcludePoliciesForFiles,\n\t\t\tgitRoot,\n\t\t\tperfStats: newPerfStats(),\n\t\t};\n\t}\n\n\tprivate _context: RepopoCommandContext | undefined;\n\n\t// biome-ignore lint/suspicious/useAwait: interface defines this as async\n\tpublic async getContext(): Promise<RepopoCommandContext> {\n\t\tif (this._context === undefined) {\n\t\t\tthrow new Error(\"Context not initialized.\");\n\t\t}\n\t\treturn this._context;\n\t}\n}\n"]}
@@ -15,28 +15,33 @@ export declare class CheckPolicy<T extends typeof BaseRepopoCommand & {
15
15
  static readonly summary = "Checks and applies policies to the files in the repository.";
16
16
  static readonly flags: {
17
17
  readonly config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
- readonly policy: import("@oclif/core/interfaces").OptionFlag<RegExp | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
- readonly excludePolicy: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
- readonly path: import("@oclif/core/interfaces").OptionFlag<RegExp | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
18
  readonly fix: import("@oclif/core/interfaces").BooleanFlag<boolean>;
22
19
  readonly stdin: import("@oclif/core/interfaces").BooleanFlag<boolean>;
23
20
  };
24
- private processed;
25
- private count;
26
- defaultConfig: import("../config.js").PolicyConfig;
27
- init(): Promise<void>;
28
21
  run(): Promise<void>;
29
- private executePolicy;
30
22
  /**
31
- * Routes files to their handlers and resolvers by regex testing their full paths. If a file fails a policy that has a
32
- * resolver, the resolver will be invoked as well. Synchronizes the output, exit codes, and resolve
33
- * decision for all handlers.
23
+ * Executes all policies against the provided paths.
24
+ *
25
+ * @param pathsToCheck - All paths that should be checked. Paths should be relative to the repository root.
26
+ * @param context - The context.
34
27
  */
35
- private routeToHandlers;
28
+ private checkAllFiles;
36
29
  /**
37
30
  * Given a string that represents a path to a file in the repo, determines if the file should be checked, and if so,
38
31
  * routes the file to the appropriate handlers.
32
+ *
33
+ * @param relPath - A git repo-relative path to a file.
39
34
  */
40
35
  private checkOrExcludeFile;
36
+ private routeToPolicies;
37
+ private runPolicyOnFile;
38
+ private isPolicyExcluded;
39
+ private executePolicyHandler;
40
+ private handlePolicyResult;
41
+ private handleFixResult;
42
+ private handleFailureResult;
43
+ private attemptResolution;
44
+ private logPolicyFailure;
45
+ private logMessages;
41
46
  }
42
47
  //# sourceMappingURL=check.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAOA,OAAO,EACN,iBAAiB,EAEjB,MAAM,mBAAmB,CAAC;AAK3B;;;;;;;;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,gBAAyB,OAAO,iEAC+B;IAE/D,gBAAyB,KAAK;gCAhBf,wBAAwB,wCAAwC,wBAAwB;;;;;;MA4B5F;IAEX,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,KAAK,CAAK;IAEF,aAAa,sCAAuB;IAE9B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;YAuC5B,aAAa;IAc3B;;;;OAIG;YACW,eAAe;IA0G7B;;;OAGG;YACW,kBAAkB;CA0BhC"}
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;A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