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.
- package/CHANGELOG.md +79 -0
- package/README.md +40 -23
- package/THIRD-PARTY-LICENSES.txt +21 -11
- package/esm/api.d.ts +2 -0
- package/esm/api.d.ts.map +1 -0
- package/esm/api.js +2 -0
- package/esm/api.js.map +1 -0
- package/esm/baseCommand.d.ts +13 -43
- package/esm/baseCommand.d.ts.map +1 -1
- package/esm/baseCommand.js +31 -67
- package/esm/baseCommand.js.map +1 -1
- package/esm/commands/check.d.ts +17 -12
- package/esm/commands/check.d.ts.map +1 -1
- package/esm/commands/check.js +147 -115
- package/esm/commands/check.js.map +1 -1
- package/esm/commands/list.d.ts +1 -2
- package/esm/commands/list.d.ts.map +1 -1
- package/esm/commands/list.js +5 -6
- package/esm/commands/list.js.map +1 -1
- package/esm/config.d.ts +9 -15
- package/esm/config.d.ts.map +1 -1
- package/esm/config.js +3 -2
- package/esm/config.js.map +1 -1
- package/esm/context.d.ts +29 -0
- package/esm/context.d.ts.map +1 -0
- package/esm/context.js +2 -0
- package/esm/context.js.map +1 -0
- package/esm/generators.d.ts +21 -0
- package/esm/generators.d.ts.map +1 -0
- package/esm/generators.js +2 -0
- package/esm/generators.js.map +1 -0
- package/esm/index.d.ts +5 -4
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -1
- package/esm/index.js.map +1 -1
- package/esm/makePolicy.d.ts +9 -0
- package/esm/makePolicy.d.ts.map +1 -0
- package/esm/makePolicy.js +28 -0
- package/esm/makePolicy.js.map +1 -0
- package/esm/perf.d.ts.map +1 -1
- package/esm/perf.js +1 -5
- package/esm/perf.js.map +1 -1
- package/esm/policies/HtmlFileHeaders.d.ts +8 -0
- package/esm/policies/HtmlFileHeaders.d.ts.map +1 -0
- package/esm/policies/HtmlFileHeaders.js +17 -0
- package/esm/policies/HtmlFileHeaders.js.map +1 -0
- package/esm/policies/JsTsFileHeaders.d.ts +8 -0
- package/esm/policies/JsTsFileHeaders.d.ts.map +1 -0
- package/esm/policies/JsTsFileHeaders.js +24 -0
- package/esm/policies/JsTsFileHeaders.js.map +1 -0
- package/esm/policies/NoJsFileExtensions.d.ts +4 -2
- package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
- package/esm/policies/NoJsFileExtensions.js +15 -15
- package/esm/policies/NoJsFileExtensions.js.map +1 -1
- package/esm/policies/PackageJsonProperties.d.ts +6 -8
- package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
- package/esm/policies/PackageJsonProperties.js +37 -40
- package/esm/policies/PackageJsonProperties.js.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +3 -2
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.js +40 -37
- package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
- package/esm/policies/PackageJsonSorted.d.ts +7 -0
- package/esm/policies/PackageJsonSorted.d.ts.map +1 -0
- package/esm/policies/PackageJsonSorted.js +45 -0
- package/esm/policies/PackageJsonSorted.js.map +1 -0
- package/esm/policies/PackageScripts.d.ts +7 -0
- package/esm/policies/PackageScripts.d.ts.map +1 -0
- package/esm/policies/PackageScripts.js +25 -0
- package/esm/policies/PackageScripts.js.map +1 -0
- package/esm/policies/constants.d.ts +5 -0
- package/esm/policies/constants.d.ts.map +1 -0
- package/esm/policies/constants.js +5 -0
- package/esm/policies/constants.js.map +1 -0
- package/esm/policies.d.ts +8 -0
- package/esm/policies.d.ts.map +1 -0
- package/esm/policies.js +8 -0
- package/esm/policies.js.map +1 -0
- package/esm/policy.d.ts +60 -15
- package/esm/policy.d.ts.map +1 -1
- package/esm/policy.js +21 -22
- package/esm/policy.js.map +1 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +45 -0
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -0
- package/esm/policyDefiners/defineFileHeaderPolicy.js +61 -0
- package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -0
- package/esm/policyDefiners/definePackagePolicy.d.ts +15 -0
- package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -0
- package/esm/policyDefiners/definePackagePolicy.js +20 -0
- package/esm/policyDefiners/definePackagePolicy.js.map +1 -0
- package/esm/tsdoc-metadata.json +1 -1
- package/oclif.manifest.json +45 -53
- package/package.json +39 -23
- package/esm/policies/PackageJsonSortedPolicy.d.ts +0 -6
- package/esm/policies/PackageJsonSortedPolicy.d.ts.map +0 -1
- package/esm/policies/PackageJsonSortedPolicy.js +0 -49
- package/esm/policies/PackageJsonSortedPolicy.js.map +0 -1
- package/esm/policies/SortTsconfigs.d.ts +0 -10
- package/esm/policies/SortTsconfigs.d.ts.map +0 -1
- package/esm/policies/SortTsconfigs.js +0 -33
- package/esm/policies/SortTsconfigs.js.map +0 -1
package/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
|
-
* [
|
|
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
|
|
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
|
|
27
|
-
|
|
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
|
|
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
|
-
#
|
|
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 [-
|
|
108
|
+
$ repopo check [-v | --quiet] [-f] [--stdin]
|
|
88
109
|
|
|
89
110
|
FLAGS
|
|
90
|
-
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
-
|
|
95
|
-
|
|
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 [-
|
|
127
|
+
$ repopo list [-v | --quiet]
|
|
108
128
|
|
|
109
|
-
FLAGS
|
|
110
|
-
-
|
|
111
|
-
|
|
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)_
|
package/THIRD-PARTY-LICENSES.txt
CHANGED
|
@@ -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.
|
|
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.
|
|
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
|
-
-
|
|
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)
|
|
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
|
|
156
|
+
The following npm package may be included in this product:
|
|
146
157
|
|
|
147
|
-
- @
|
|
148
|
-
- @oclif/plugin-help@6.2.21
|
|
158
|
+
- microdiff@1.5.0
|
|
149
159
|
|
|
150
|
-
|
|
160
|
+
This package contains the following license:
|
|
151
161
|
|
|
152
162
|
MIT License
|
|
153
163
|
|
|
154
|
-
Copyright (c)
|
|
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
|
-
-
|
|
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)
|
|
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
package/esm/api.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":""}
|
package/esm/api.js
ADDED
package/esm/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
package/esm/baseCommand.d.ts
CHANGED
|
@@ -1,52 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
3
|
-
import { type
|
|
4
|
-
import
|
|
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
|
-
*
|
|
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
|
|
39
|
-
flags: typeof
|
|
40
|
-
}> extends
|
|
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
|
|
48
|
-
|
|
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
|
package/esm/baseCommand.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseCommand.d.ts","sourceRoot":"","sources":["../src/baseCommand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"baseCommand.d.ts","sourceRoot":"","sources":["../src/baseCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,YAAY,CAAC;AACvD,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAyB,oBAAoB,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"}
|
package/esm/baseCommand.js
CHANGED
|
@@ -1,87 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
|
9
|
+
* This class is the base for all repopo commands. It contains common flags and config loading.
|
|
8
10
|
*/
|
|
9
|
-
export class BaseRepopoCommand extends
|
|
11
|
+
export class BaseRepopoCommand extends CommandWithConfig {
|
|
12
|
+
defaultConfig = DefaultPolicyConfig;
|
|
10
13
|
static flags = {
|
|
11
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
if (this.
|
|
32
|
-
throw new Error("
|
|
16
|
+
_git;
|
|
17
|
+
get git() {
|
|
18
|
+
if (this._git === undefined) {
|
|
19
|
+
throw new Error("git property is undefined");
|
|
33
20
|
}
|
|
34
|
-
return this.
|
|
21
|
+
return this._git;
|
|
35
22
|
}
|
|
36
23
|
async init() {
|
|
37
24
|
await super.init();
|
|
38
|
-
const
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
package/esm/baseCommand.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseCommand.js","sourceRoot":"","sources":["../src/baseCommand.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,CAAC;QAC9C,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEe,KAAK,CAAC,IAAI;QACzB,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QAEnB,MAAM,YAAY,GACjB,IAAI,CAAC,aAAa,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QAExE,MAAM,uBAAuB,GAA0B,IAAI,GAAG,EAAE,CAAC;QACjE,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,aAAa,EAAE,QAAQ,IAAI,EAAE,EAAE,CAAC;YACzD,MAAM,OAAO,GAAG,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YAC1E,uBAAuB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;QAED,MAAM,OAAO,GAAG,eAAe,EAAE,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ,GAAG;YACf,cAAc,EAAE,YAAY;YAC5B,QAAQ,EACP,IAAI,CAAC,aAAa,EAAE,QAAQ;gBAC5B,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC1C,uBAAuB;YACvB,OAAO;YACP,SAAS,EAAE,YAAY,EAAE;SACzB,CAAC;IACH,CAAC;IAEO,QAAQ,CAAmC;IAEnD,yEAAyE;IAClE,KAAK,CAAC,UAAU;QACtB,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,0BAA0B,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"]}
|
package/esm/commands/check.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
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
|
|
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":"
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAYtD;;;;;;;;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;gCAjBiB,wBAAwB,wCACvE,wBAAsB;;;MA4BX;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAwD1C;;;;;OAKG;YACW,aAAa;IAe3B;;;;;OAKG;YACW,kBAAkB;YAkBlB,eAAe;YA4Bf,eAAe;IAsC7B,OAAO,CAAC,gBAAgB;YAYV,oBAAoB;YAsBpB,kBAAkB;IAwBhC,OAAO,CAAC,eAAe;YAoBT,mBAAmB;YAyBnB,iBAAiB;IAyB/B,OAAO,CAAC,gBAAgB;IAcxB,OAAO,CAAC,WAAW;CAOnB"}
|