repopo 0.5.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 (81) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +3 -5
  3. package/THIRD-PARTY-LICENSES.txt +2 -2
  4. package/esm/baseCommand.d.ts.map +1 -1
  5. package/esm/baseCommand.js +7 -8
  6. package/esm/baseCommand.js.map +1 -1
  7. package/esm/commands/check.d.ts +17 -6
  8. package/esm/commands/check.d.ts.map +1 -1
  9. package/esm/commands/check.js +134 -94
  10. package/esm/commands/check.js.map +1 -1
  11. package/esm/config.d.ts +4 -15
  12. package/esm/config.d.ts.map +1 -1
  13. package/esm/config.js +3 -2
  14. package/esm/config.js.map +1 -1
  15. package/esm/context.d.ts +3 -3
  16. package/esm/context.d.ts.map +1 -1
  17. package/esm/context.js.map +1 -1
  18. package/esm/generators.d.ts +21 -0
  19. package/esm/generators.d.ts.map +1 -0
  20. package/esm/generators.js +2 -0
  21. package/esm/generators.js.map +1 -0
  22. package/esm/index.d.ts +5 -11
  23. package/esm/index.d.ts.map +1 -1
  24. package/esm/index.js +3 -9
  25. package/esm/index.js.map +1 -1
  26. package/esm/makePolicy.d.ts +9 -0
  27. package/esm/makePolicy.d.ts.map +1 -0
  28. package/esm/makePolicy.js +28 -0
  29. package/esm/makePolicy.js.map +1 -0
  30. package/esm/policies/HtmlFileHeaders.d.ts +2 -2
  31. package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
  32. package/esm/policies/HtmlFileHeaders.js +2 -2
  33. package/esm/policies/HtmlFileHeaders.js.map +1 -1
  34. package/esm/policies/JsTsFileHeaders.d.ts +2 -2
  35. package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
  36. package/esm/policies/JsTsFileHeaders.js +2 -2
  37. package/esm/policies/JsTsFileHeaders.js.map +1 -1
  38. package/esm/policies/NoJsFileExtensions.d.ts +2 -2
  39. package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
  40. package/esm/policies/NoJsFileExtensions.js +13 -15
  41. package/esm/policies/NoJsFileExtensions.js.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/PackageJsonProperties.js +3 -3
  45. package/esm/policies/PackageJsonProperties.js.map +1 -1
  46. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +1 -1
  47. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
  48. package/esm/policies/PackageJsonRepoDirectoryProperty.js +2 -2
  49. package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
  50. package/esm/policies/PackageJsonSorted.d.ts +1 -1
  51. package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
  52. package/esm/policies/PackageJsonSorted.js +2 -2
  53. package/esm/policies/PackageJsonSorted.js.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/PackageScripts.js +2 -2
  57. package/esm/policies/PackageScripts.js.map +1 -1
  58. package/esm/policies.d.ts +4 -3
  59. package/esm/policies.d.ts.map +1 -1
  60. package/esm/policies.js +4 -3
  61. package/esm/policies.js.map +1 -1
  62. package/esm/policy.d.ts +40 -13
  63. package/esm/policy.d.ts.map +1 -1
  64. package/esm/policy.js +18 -7
  65. package/esm/policy.js.map +1 -1
  66. package/esm/{policyGenerators/generateFileHeaderPolicy.d.ts → policyDefiners/defineFileHeaderPolicy.d.ts} +4 -4
  67. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -0
  68. package/esm/{policyGenerators/generateFileHeaderPolicy.js → policyDefiners/defineFileHeaderPolicy.js} +3 -3
  69. package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -0
  70. package/esm/policyDefiners/definePackagePolicy.d.ts +15 -0
  71. package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -0
  72. package/esm/{policyGenerators/generatePackagePolicy.js → policyDefiners/definePackagePolicy.js} +2 -2
  73. package/esm/policyDefiners/definePackagePolicy.js.map +1 -0
  74. package/esm/tsdoc-metadata.json +1 -1
  75. package/oclif.manifest.json +1 -1
  76. package/package.json +10 -12
  77. package/esm/policyGenerators/generateFileHeaderPolicy.d.ts.map +0 -1
  78. package/esm/policyGenerators/generateFileHeaderPolicy.js.map +0 -1
  79. package/esm/policyGenerators/generatePackagePolicy.d.ts +0 -9
  80. package/esm/policyGenerators/generatePackagePolicy.d.ts.map +0 -1
  81. package/esm/policyGenerators/generatePackagePolicy.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"policies.js","sourceRoot":"","sources":["../src/policies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["export { PackageJsonProperties } from \"./policies/PackageJsonProperties.js\";\nexport { NoJsFileExtensions } from \"./policies/NoJsFileExtensions.js\";\nexport { PackageJsonRepoDirectoryProperty } from \"./policies/PackageJsonRepoDirectoryProperty.js\";\nexport { PackageJsonSorted } from \"./policies/PackageJsonSorted.js\";\nexport { JsTsFileHeaders } from \"./policies/JsTsFileHeaders.js\";\nexport { HtmlFileHeaders } from \"./policies/HtmlFileHeaders.js\";\n"]}
1
+ {"version":3,"file":"policies.js","sourceRoot":"","sources":["../src/policies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC","sourcesContent":["export { DefaultPolicies } from \"./policy.js\";\n\nexport { HtmlFileHeaders } from \"./policies/HtmlFileHeaders.js\";\nexport { JsTsFileHeaders } from \"./policies/JsTsFileHeaders.js\";\nexport { NoJsFileExtensions } from \"./policies/NoJsFileExtensions.js\";\nexport { PackageJsonProperties } from \"./policies/PackageJsonProperties.js\";\nexport { PackageJsonRepoDirectoryProperty } from \"./policies/PackageJsonRepoDirectoryProperty.js\";\nexport { PackageJsonSorted } from \"./policies/PackageJsonSorted.js\";\n"]}
package/esm/policy.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- /**
2
- * @alpha
3
- */
4
- export type DefaultPolicyConfigType = object | unknown;
5
1
  /**
6
2
  * A type representing a policy name.
7
3
  *
@@ -38,15 +34,15 @@ export interface PolicyFunctionArguments<C> {
38
34
  *
39
35
  * @alpha
40
36
  */
41
- export type PolicyHandler<C = unknown | undefined> = (args: PolicyFunctionArguments<C>) => Promise<true | PolicyFailure | PolicyFixResult>;
37
+ export type PolicyHandler<C = unknown | undefined> = (args: PolicyFunctionArguments<C>) => Promise<PolicyHandlerResult>;
42
38
  /**
43
39
  * A standalone function that can be called to resolve a policy failure.
44
40
  *
45
41
  * @alpha
46
42
  */
47
- export type PolicyStandaloneResolver<C = DefaultPolicyConfigType | undefined> = (args: Omit<PolicyFunctionArguments<C>, "resolve">) => Promise<PolicyFixResult>;
43
+ export type PolicyStandaloneResolver<C = undefined> = (args: Omit<PolicyFunctionArguments<C>, "resolve">) => Promise<PolicyFixResult>;
48
44
  /**
49
- * A RepoPolicy checks and applies policies to files in the repository.
45
+ * A RepoPolicyDefinition checks and applies policies to files in the repository.
50
46
  *
51
47
  * Each policy has a name and a match regex for matching which files it should apply to. Every file in th repo is
52
48
  * enumerated and if it matches the regex for a policy, that policy is applied.
@@ -58,7 +54,7 @@ export type PolicyStandaloneResolver<C = DefaultPolicyConfigType | undefined> =
58
54
  *
59
55
  * @alpha
60
56
  */
61
- export interface RepoPolicy<C extends DefaultPolicyConfigType = unknown | undefined> {
57
+ export interface PolicyDefinition<C = undefined> {
62
58
  /**
63
59
  * The name of the policy; displayed in UI and used in settings.
64
60
  */
@@ -66,7 +62,7 @@ export interface RepoPolicy<C extends DefaultPolicyConfigType = unknown | undefi
66
62
  /**
67
63
  * A more detailed description of the policy and its intended function.
68
64
  */
69
- description?: string;
65
+ description?: string | undefined;
70
66
  /**
71
67
  * A regular expression that is used to match files in the repo.
72
68
  */
@@ -88,13 +84,31 @@ export interface RepoPolicy<C extends DefaultPolicyConfigType = unknown | undefi
88
84
  * @returns true if the file passed the policy; otherwise a PolicyFailure object will be returned.
89
85
  */
90
86
  resolver?: PolicyStandaloneResolver<C> | undefined;
87
+ /**
88
+ * A default config that will be used if none is provided.
89
+ */
90
+ defaultConfig?: C | undefined;
91
+ }
92
+ /**
93
+ * @alpha
94
+ */
95
+ export interface PolicyInstanceSettings<C> {
96
+ /**
97
+ * An array of strings/regular expressions. File paths that match any of these expressions will be completely excluded
98
+ * from policy.
99
+ *
100
+ * Paths will be matched relative to the root of the repo.
101
+ */
102
+ excludeFiles?: (string | RegExp)[];
103
+ /**
104
+ * The config that is applied to the policy instance.
105
+ */
106
+ config?: C | undefined;
91
107
  }
92
108
  /**
93
- * A policy handler especially for policies that target package.json.
94
- *
95
109
  * @alpha
96
110
  */
97
- export type PackageJsonHandler<J, C> = (json: J, args: PolicyFunctionArguments<C>) => Promise<true | PolicyFailure | PolicyFixResult>;
111
+ export type PolicyInstance<C = undefined> = PolicyDefinition<C> & PolicyInstanceSettings<C>;
98
112
  /**
99
113
  * A policy failure.
100
114
  *
@@ -129,11 +143,24 @@ export interface PolicyFixResult extends PolicyFailure {
129
143
  */
130
144
  resolved: boolean;
131
145
  }
146
+ /**
147
+ * @alpha
148
+ */
149
+ export type PolicyHandlerResult = true | PolicyFailure | PolicyFixResult;
132
150
  export declare function isPolicyFixResult(toCheck: any): toCheck is PolicyFixResult;
133
151
  /**
134
152
  * Default policies included with repopo.
135
153
  *
136
154
  * @alpha
137
155
  */
138
- export declare const DefaultPolicies: RepoPolicy<any>[];
156
+ export declare const DefaultPolicies: PolicyDefinition<any>[];
157
+ export declare abstract class Policy<C> implements PolicyDefinition<C> {
158
+ readonly name: string;
159
+ readonly match: RegExp;
160
+ readonly handler: PolicyHandler<C>;
161
+ readonly description?: string | undefined;
162
+ readonly defaultConfig?: C | undefined;
163
+ readonly resolver?: PolicyStandaloneResolver<C> | undefined;
164
+ constructor(name: string, match: RegExp, handler: PolicyHandler<C>, description?: string | undefined, defaultConfig?: C | undefined, resolver?: PolicyStandaloneResolver<C> | undefined);
165
+ }
139
166
  //# sourceMappingURL=policy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG,OAAO,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;;GAIG;AAEH,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACzC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC;CACvB;AAED;;;;GAIG;AAEH,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,GAAG,SAAS,IAAI,CACpD,IAAI,EAAE,uBAAuB,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EAAE,CAAC;aACjB,QAAQ,CAAC,EAAE,wBAAwB,CAAC,CAAC,CAAC;gBALtC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,WAAW,CAAC,EAAE,MAAM,YAAA,EACpB,aAAa,CAAC,EAAE,CAAC,YAAA,EACjB,QAAQ,CAAC,EAAE,wBAAwB,CAAC,CAAC,CAAC,YAAA;CAEvD"}
package/esm/policy.js CHANGED
@@ -1,8 +1,6 @@
1
- import { HtmlFileHeaders } from "./policies.js";
2
- import { JsTsFileHeaders } from "./policies/JsTsFileHeaders.js";
3
1
  import { NoJsFileExtensions } from "./policies/NoJsFileExtensions.js";
4
- import { PackageJsonProperties } from "./policies/PackageJsonProperties.js";
5
2
  import { PackageJsonRepoDirectoryProperty } from "./policies/PackageJsonRepoDirectoryProperty.js";
3
+ import { PackageJsonSorted } from "./policies/PackageJsonSorted.js";
6
4
  import { PackageScripts } from "./policies/PackageScripts.js";
7
5
  // biome-ignore lint/suspicious/noExplicitAny: type guard
8
6
  export function isPolicyFixResult(toCheck) {
@@ -18,12 +16,25 @@ export function isPolicyFixResult(toCheck) {
18
16
  */
19
17
  // biome-ignore lint/suspicious/noExplicitAny: FIXME
20
18
  export const DefaultPolicies = [
21
- HtmlFileHeaders,
22
- JsTsFileHeaders,
23
19
  NoJsFileExtensions,
24
20
  PackageJsonRepoDirectoryProperty,
25
- PackageJsonProperties,
26
- // PackageJsonSorted,
21
+ PackageJsonSorted,
27
22
  PackageScripts,
28
23
  ];
24
+ export class Policy {
25
+ name;
26
+ match;
27
+ handler;
28
+ description;
29
+ defaultConfig;
30
+ resolver;
31
+ constructor(name, match, handler, description, defaultConfig, resolver) {
32
+ this.name = name;
33
+ this.match = match;
34
+ this.handler = handler;
35
+ this.description = description;
36
+ this.defaultConfig = defaultConfig;
37
+ this.resolver = resolver;
38
+ }
39
+ }
29
40
  //# sourceMappingURL=policy.js.map
package/esm/policy.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AA4K9D,yDAAyD;AACzD,MAAM,UAAU,iBAAiB,CAAC,OAAY;IAC7C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,UAAU,IAAI,OAAO,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AAEH,oDAAoD;AACpD,MAAM,CAAC,MAAM,eAAe,GAAsB;IACjD,eAAe;IACf,eAAe;IACf,kBAAkB;IAClB,gCAAgC;IAChC,qBAAqB;IACrB,qBAAqB;IACrB,cAAc;CACL,CAAC","sourcesContent":["import { HtmlFileHeaders } from \"./policies.js\";\nimport { JsTsFileHeaders } from \"./policies/JsTsFileHeaders.js\";\nimport { NoJsFileExtensions } from \"./policies/NoJsFileExtensions.js\";\nimport { PackageJsonProperties } from \"./policies/PackageJsonProperties.js\";\nimport { PackageJsonRepoDirectoryProperty } from \"./policies/PackageJsonRepoDirectoryProperty.js\";\nimport { PackageScripts } from \"./policies/PackageScripts.js\";\n\n/**\n * @alpha\n */\nexport type DefaultPolicyConfigType = object | unknown;\n\n/**\n * A type representing a policy name.\n *\n * @alpha\n */\nexport type PolicyName = string;\n\n/**\n * Arguments passed to policy functions.\n *\n * @alpha\n */\n\nexport interface PolicyFunctionArguments<C> {\n\t/**\n\t * Path to the file, relative to the repo root.\n\t */\n\tfile: string;\n\n\t/**\n\t * Absolute path to the root of the repo.\n\t */\n\troot: string;\n\n\t/**\n\t * If true, the handler should resolve any violations automatically if possible.\n\t */\n\tresolve: boolean;\n\n\t/**\n\t * @remarks\n\t *\n\t * Note that the handler function receives the config as an argument.\n\t */\n\tconfig?: C | undefined;\n}\n\n/**\n * A policy handler is a function that is called to check policy against a file.\n *\n * @alpha\n */\n\nexport type PolicyHandler<C = unknown | undefined> = (\n\targs: PolicyFunctionArguments<C>,\n) => Promise<true | PolicyFailure | PolicyFixResult>;\n\n// export type PolicyCheckOnly = (\n// \tfile: string,\n// \troot: string,\n// ) => Promise<true | PolicyFailure | PolicyFixResult>;\n\n/**\n * A standalone function that can be called to resolve a policy failure.\n *\n * @alpha\n */\nexport type PolicyStandaloneResolver<C = DefaultPolicyConfigType | undefined> =\n\t(\n\t\targs: Omit<PolicyFunctionArguments<C>, \"resolve\">,\n\t) => Promise<PolicyFixResult>;\n\n// function isPolicyHandler(input: PolicyHandler | PolicyCheckOnly): input is PolicyHandler\n\n/**\n * A RepoPolicy checks and applies policies to files in the repository.\n *\n * Each policy has a name and a match regex for matching which files it should apply to. Every file in th repo is\n * enumerated and if it matches the regex for a policy, that policy is applied.\n *\n * Each policy includes a handler function that checks a file against the policy and can optionally resolve any problems\n * (automated resolutions depend on the policy implementation).\n *\n * @typeParam C - type of configuration object used by the policy\n *\n * @alpha\n */\nexport interface RepoPolicy<\n\tC extends DefaultPolicyConfigType = unknown | undefined,\n> {\n\t/**\n\t * The name of the policy; displayed in UI and used in settings.\n\t */\n\tname: PolicyName;\n\n\t/**\n\t * A more detailed description of the policy and its intended function.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * A regular expression that is used to match files in the repo.\n\t */\n\tmatch: RegExp;\n\n\t/**\n\t * A handler function that checks if a file is compliant with the policy.\n\t *\n\t * @param file - Repo-relative path to the file to check.\n\t * @param root - Absolute path to the root of the repo.\n\t * @param resolve - If true, automated policy fixes will be applied. Not all policies support automated fixes.\n\t * @returns True if the file passed the policy; otherwise a PolicyFailure object will be returned.\n\t */\n\n\thandler: PolicyHandler<C>;\n\n\t/**\n\t * A resolver function that can be used to automatically address the policy violation.\n\t *\n\t * @param file - Repo-relative path to the file to check.\n\t * @param root - Absolute path to the root of the repo.\n\t * @returns true if the file passed the policy; otherwise a PolicyFailure object will be returned.\n\t */\n\tresolver?: PolicyStandaloneResolver<C> | undefined;\n}\n\n/**\n * A policy handler especially for policies that target package.json.\n *\n * @alpha\n */\nexport type PackageJsonHandler<J, C> = (\n\tjson: J,\n\targs: PolicyFunctionArguments<C>,\n) => Promise<true | PolicyFailure | PolicyFixResult>;\n\n/**\n * A policy failure.\n *\n * @alpha\n */\nexport interface PolicyFailure {\n\t/**\n\t * Name of the policy that failed.\n\t */\n\tname: PolicyName;\n\n\t/**\n\t * Path to the file that failed the policy.\n\t */\n\tfile: string;\n\n\t/**\n\t * Set to `true` if the policy can be fixed automatically.\n\t */\n\tautoFixable?: boolean | undefined;\n\n\t/**\n\t * An optional error message accompanying the failure.\n\t */\n\terrorMessage?: string | undefined;\n}\n\n/**\n * The result of an automatic fix for a failing policy.\n *\n * @alpha\n */\nexport interface PolicyFixResult extends PolicyFailure {\n\t/**\n\t * Set to true if the failure was resolved by the automated fixer.\n\t */\n\tresolved: boolean;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: type guard\nexport function isPolicyFixResult(toCheck: any): toCheck is PolicyFixResult {\n\tif (typeof toCheck !== \"object\") {\n\t\treturn false;\n\t}\n\treturn \"resolved\" in toCheck;\n}\n\n/**\n * Default policies included with repopo.\n *\n * @alpha\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: FIXME\nexport const DefaultPolicies: RepoPolicy<any>[] = [\n\tHtmlFileHeaders,\n\tJsTsFileHeaders,\n\tNoJsFileExtensions,\n\tPackageJsonRepoDirectoryProperty,\n\tPackageJsonProperties,\n\t// PackageJsonSorted,\n\tPackageScripts,\n] as const;\n"]}
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AA4L9D,yDAAyD;AACzD,MAAM,UAAU,iBAAiB,CAAC,OAAY;IAC7C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,UAAU,IAAI,OAAO,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AAEH,oDAAoD;AACpD,MAAM,CAAC,MAAM,eAAe,GAA4B;IACvD,kBAAkB;IAClB,gCAAgC;IAChC,iBAAiB;IACjB,cAAc;CACL,CAAC;AAEX,MAAM,OAAgB,MAAM;IAEV;IACA;IACA;IACA;IACA;IACA;IANjB,YACiB,IAAY,EACZ,KAAa,EACb,OAAyB,EACzB,WAAoB,EACpB,aAAiB,EACjB,QAAsC;QALtC,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAAkB;QACzB,gBAAW,GAAX,WAAW,CAAS;QACpB,kBAAa,GAAb,aAAa,CAAI;QACjB,aAAQ,GAAR,QAAQ,CAA8B;IACpD,CAAC;CACJ","sourcesContent":["import { NoJsFileExtensions } from \"./policies/NoJsFileExtensions.js\";\nimport { PackageJsonRepoDirectoryProperty } from \"./policies/PackageJsonRepoDirectoryProperty.js\";\nimport { PackageJsonSorted } from \"./policies/PackageJsonSorted.js\";\nimport { PackageScripts } from \"./policies/PackageScripts.js\";\n\n/**\n * A type representing a policy name.\n *\n * @alpha\n */\nexport type PolicyName = string;\n\n/**\n * Arguments passed to policy functions.\n *\n * @alpha\n */\n\nexport interface PolicyFunctionArguments<C> {\n\t/**\n\t * Path to the file, relative to the repo root.\n\t */\n\tfile: string;\n\n\t/**\n\t * Absolute path to the root of the repo.\n\t */\n\troot: string;\n\n\t/**\n\t * If true, the handler should resolve any violations automatically if possible.\n\t */\n\tresolve: boolean;\n\n\t/**\n\t * @remarks\n\t *\n\t * Note that the handler function receives the config as an argument.\n\t */\n\tconfig?: C | undefined;\n}\n\n/**\n * A policy handler is a function that is called to check policy against a file.\n *\n * @alpha\n */\n\nexport type PolicyHandler<C = unknown | undefined> = (\n\targs: PolicyFunctionArguments<C>,\n) => Promise<PolicyHandlerResult>;\n\n// export type PolicyCheckOnly = (\n// \tfile: string,\n// \troot: string,\n// ) => Promise<PolicyHandlerResult>;\n\n/**\n * A standalone function that can be called to resolve a policy failure.\n *\n * @alpha\n */\nexport type PolicyStandaloneResolver<C = undefined> = (\n\targs: Omit<PolicyFunctionArguments<C>, \"resolve\">,\n) => Promise<PolicyFixResult>;\n\n// function isPolicyHandler(input: PolicyHandler | PolicyCheckOnly): input is PolicyHandler\n\n/**\n * A RepoPolicyDefinition checks and applies policies to files in the repository.\n *\n * Each policy has a name and a match regex for matching which files it should apply to. Every file in th repo is\n * enumerated and if it matches the regex for a policy, that policy is applied.\n *\n * Each policy includes a handler function that checks a file against the policy and can optionally resolve any problems\n * (automated resolutions depend on the policy implementation).\n *\n * @typeParam C - type of configuration object used by the policy\n *\n * @alpha\n */\nexport interface PolicyDefinition<C = undefined> {\n\t/**\n\t * The name of the policy; displayed in UI and used in settings.\n\t */\n\tname: PolicyName;\n\n\t/**\n\t * A more detailed description of the policy and its intended function.\n\t */\n\tdescription?: string | undefined;\n\n\t/**\n\t * A regular expression that is used to match files in the repo.\n\t */\n\tmatch: RegExp;\n\n\t/**\n\t * A handler function that checks if a file is compliant with the policy.\n\t *\n\t * @param file - Repo-relative path to the file to check.\n\t * @param root - Absolute path to the root of the repo.\n\t * @param resolve - If true, automated policy fixes will be applied. Not all policies support automated fixes.\n\t * @returns True if the file passed the policy; otherwise a PolicyFailure object will be returned.\n\t */\n\n\thandler: PolicyHandler<C>;\n\n\t/**\n\t * A resolver function that can be used to automatically address the policy violation.\n\t *\n\t * @param file - Repo-relative path to the file to check.\n\t * @param root - Absolute path to the root of the repo.\n\t * @returns true if the file passed the policy; otherwise a PolicyFailure object will be returned.\n\t */\n\tresolver?: PolicyStandaloneResolver<C> | undefined;\n\n\t/**\n\t * A default config that will be used if none is provided.\n\t */\n\tdefaultConfig?: C | undefined;\n}\n\n/**\n * @alpha\n */\nexport interface PolicyInstanceSettings<C> {\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\t * Paths will be matched relative to the root of the repo.\n\t */\n\texcludeFiles?: (string | RegExp)[];\n\n\t/**\n\t * The config that is applied to the policy instance.\n\t */\n\tconfig?: C | undefined;\n}\n\n/**\n * @alpha\n */\nexport type PolicyInstance<C = undefined> = PolicyDefinition<C> &\n\tPolicyInstanceSettings<C>;\n\n/**\n * A policy failure.\n *\n * @alpha\n */\nexport interface PolicyFailure {\n\t/**\n\t * Name of the policy that failed.\n\t */\n\tname: PolicyName;\n\n\t/**\n\t * Path to the file that failed the policy.\n\t */\n\tfile: string;\n\n\t/**\n\t * Set to `true` if the policy can be fixed automatically.\n\t */\n\tautoFixable?: boolean | undefined;\n\n\t/**\n\t * An optional error message accompanying the failure.\n\t */\n\terrorMessage?: string | undefined;\n}\n\n/**\n * The result of an automatic fix for a failing policy.\n *\n * @alpha\n */\nexport interface PolicyFixResult extends PolicyFailure {\n\t/**\n\t * Set to true if the failure was resolved by the automated fixer.\n\t */\n\tresolved: boolean;\n}\n\n/**\n * @alpha\n */\nexport type PolicyHandlerResult = true | PolicyFailure | PolicyFixResult;\n\n// biome-ignore lint/suspicious/noExplicitAny: type guard\nexport function isPolicyFixResult(toCheck: any): toCheck is PolicyFixResult {\n\tif (typeof toCheck !== \"object\") {\n\t\treturn false;\n\t}\n\treturn \"resolved\" in toCheck;\n}\n\n/**\n * Default policies included with repopo.\n *\n * @alpha\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: FIXME\nexport const DefaultPolicies: PolicyDefinition<any>[] = [\n\tNoJsFileExtensions,\n\tPackageJsonRepoDirectoryProperty,\n\tPackageJsonSorted,\n\tPackageScripts,\n] as const;\n\nexport abstract class Policy<C> implements PolicyDefinition<C> {\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly match: RegExp,\n\t\tpublic readonly handler: PolicyHandler<C>,\n\t\tpublic readonly description?: string,\n\t\tpublic readonly defaultConfig?: C,\n\t\tpublic readonly resolver?: PolicyStandaloneResolver<C>,\n\t) {}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { RepoPolicy } from "../policy.js";
1
+ import type { PolicyDefinition } from "../policy.js";
2
2
  /**
3
3
  * @alpha
4
4
  */
@@ -36,10 +36,10 @@ export interface FileHeaderGeneratorConfig extends Partial<FileHeaderPolicyConfi
36
36
  replacer: (content: string, config: FileHeaderPolicyConfig) => string;
37
37
  }
38
38
  /**
39
- * Given a `FileHeaderGeneratorConfig`, produces a function that detects correct file headers
39
+ * Given a {@link FileHeaderPolicyConfig}, produces a function that detects correct file headers
40
40
  * and returns an error string if the header is missing or incorrect.
41
41
  *
42
42
  * @alpha
43
43
  */
44
- export declare function generateFileHeaderPolicy(name: string, config: FileHeaderGeneratorConfig): RepoPolicy<FileHeaderPolicyConfig>;
45
- //# sourceMappingURL=generateFileHeaderPolicy.d.ts.map
44
+ export declare function defineFileHeaderPolicy(name: string, config: FileHeaderGeneratorConfig): PolicyDefinition<FileHeaderPolicyConfig>;
45
+ //# sourceMappingURL=defineFileHeaderPolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineFileHeaderPolicy.d.ts","sourceRoot":"","sources":["../../src/policyDefiners/defineFileHeaderPolicy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,gBAAgB,EAGhB,MAAM,cAAc,CAAC;AAItB;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,yBAChB,SAAQ,OAAO,CAAC,sBAAsB,CAAC;IACvC,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB,KAAK,MAAM,CAAC;CACtE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,yBAAyB,GAC/B,gBAAgB,CAAC,sBAAsB,CAAC,CAiE1C"}
@@ -3,12 +3,12 @@ import { EOL as newline } from "node:os";
3
3
  import { extname } from "pathe";
4
4
  const trailingSpaces = /\s*\\r\?\\n/;
5
5
  /**
6
- * Given a `FileHeaderGeneratorConfig`, produces a function that detects correct file headers
6
+ * Given a {@link FileHeaderPolicyConfig}, produces a function that detects correct file headers
7
7
  * and returns an error string if the header is missing or incorrect.
8
8
  *
9
9
  * @alpha
10
10
  */
11
- export function generateFileHeaderPolicy(name, config) {
11
+ export function defineFileHeaderPolicy(name, config) {
12
12
  const pre = config.headerStart?.source ?? "";
13
13
  const start = config.lineStart.source;
14
14
  const end = config.lineEnd.source;
@@ -58,4 +58,4 @@ export function generateFileHeaderPolicy(name, config) {
58
58
  },
59
59
  };
60
60
  }
61
- //# sourceMappingURL=generateFileHeaderPolicy.js.map
61
+ //# sourceMappingURL=defineFileHeaderPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineFileHeaderPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/def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AK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE;YAC1D,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;gBAChC,OAAO,IAAI,CAAC;YACb,CAAC;YAED,MAAM,UAAU,GAAkB;gBACjC,IAAI;gBACJ,IAAI;gBACJ,WAAW,EAAE,IAAI;aACjB,CAAC;YAEF,+EAA+E;YAC/E,gCAAgC;YAChC,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;YAC3D,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAEpC,IAAI,MAAM,EAAE,CAAC;gBACZ,UAAU,CAAC,YAAY,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC;YAClE,CAAC;YAED,IAAI,MAAM,EAAE,CAAC;gBACZ,IAAI,OAAO,EAAE,CAAC;oBACb,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;oBAC1D,MAAM,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;oBAElC,MAAM,SAAS,GAAoB;wBAClC,GAAG,UAAU;wBACb,QAAQ,EAAE,IAAI;qBACd,CAAC;oBAEF,OAAO,SAAS,CAAC;gBAClB,CAAC;gBACD,OAAO,UAAU,CAAC;YACnB,CAAC;YAED,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\nimport { EOL as newline } from \"node:os\";\nimport { extname } from \"pathe\";\nimport type {\n\tPolicyDefinition,\n\tPolicyFailure,\n\tPolicyFixResult,\n} from \"../policy.js\";\n\nconst trailingSpaces = /\\s*\\\\r\\?\\\\n/;\n\n/**\n * @alpha\n */\nexport interface FileHeaderPolicyConfig {\n\t/**\n\t * The text to use as the header.\n\t */\n\theaderText: string;\n\n\t/**\n\t * An optional string that will be appended to the headerText.\n\t */\n\tautoGenText?: string;\n}\n\n/**\n * @alpha\n */\nexport interface FileHeaderGeneratorConfig\n\textends Partial<FileHeaderPolicyConfig> {\n\tmatch: RegExp;\n\n\t/**\n\t * Regex matching header prefix (e.g. `/*!\\r?\\n`)\n\t */\n\theaderStart?: RegExp;\n\n\t/**\n\t * Regex matching beginning of each line (e.g. ' * ')\n\t */\n\tlineStart: RegExp;\n\n\t/**\n\t * Regex matching the end of each line (e.g., `\\r?\\n`)\n\t */\n\tlineEnd: RegExp;\n\n\t/**\n\t * Regex matching the header postfix.\n\t */\n\theaderEnd?: RegExp;\n\n\treplacer: (content: string, config: FileHeaderPolicyConfig) => string;\n}\n\n/**\n * Given a {@link FileHeaderPolicyConfig}, produces a function that detects correct file headers\n * and returns an error string if the header is missing or incorrect.\n *\n * @alpha\n */\nexport function defineFileHeaderPolicy(\n\tname: string,\n\tconfig: FileHeaderGeneratorConfig,\n): PolicyDefinition<FileHeaderPolicyConfig> {\n\tconst pre = config.headerStart?.source ?? \"\";\n\tconst start = config.lineStart.source;\n\tconst end = config.lineEnd.source;\n\tconst post = config.headerEnd?.source ?? \"\";\n\n\t// Helper which constructs a matching RegExp from a given multiline string.\n\t// (See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping)\n\tconst toRegex = (text: string): string =>\n\t\ttext\n\t\t\t.split(newline)\n\t\t\t.map(\n\t\t\t\t(line) =>\n\t\t\t\t\t`${start}${line.replace(/[$()*+.?[\\\\\\]^{|}]/g, \"\\\\$&\")}${end}`,\n\t\t\t)\n\t\t\t.join(\"\")\n\t\t\t.replace(trailingSpaces, \"\\\\r?\\\\n\"); // Trim trailing spaces at end-of-line.\n\n\t// Detection regex matches the header start (if any), followed by lines in 'headerText',\n\t// optionally followed by lines in the 'autoGenText', and finally the header end (if any).\n\tconst regex = new RegExp(\n\t\t`^${pre}${toRegex(config.headerText ?? \"\")}(${toRegex(config.autoGenText ?? \"\")})?${post}`,\n\t);\n\n\treturn {\n\t\tname,\n\t\tmatch: config.match,\n\t\thandler: async ({ file, resolve, config: policyConfig }) => {\n\t\t\tif (policyConfig === undefined) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst failResult: PolicyFailure = {\n\t\t\t\tname,\n\t\t\t\tfile,\n\t\t\t\tautoFixable: true,\n\t\t\t};\n\n\t\t\t// TODO: Consider reading only the first 512B or so since headers are typically\n\t\t\t// at the beginning of the file.\n\t\t\tconst content = await readFile(file, { encoding: \"utf8\" });\n\t\t\tconst failed = !regex.test(content);\n\n\t\t\tif (failed) {\n\t\t\t\tfailResult.errorMessage = `${extname(file)} file missing header`;\n\t\t\t}\n\n\t\t\tif (failed) {\n\t\t\t\tif (resolve) {\n\t\t\t\t\tconst newContent = config.replacer(content, policyConfig);\n\t\t\t\t\tawait writeFile(file, newContent);\n\n\t\t\t\t\tconst fixResult: PolicyFixResult = {\n\t\t\t\t\t\t...failResult,\n\t\t\t\t\t\tresolved: true,\n\t\t\t\t\t};\n\n\t\t\t\t\treturn fixResult;\n\t\t\t\t}\n\t\t\t\treturn failResult;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { PackageJson } from "type-fest";
2
+ import type { PolicyDefinition, PolicyFunctionArguments, PolicyHandlerResult } from "../policy.js";
3
+ /**
4
+ * A policy handler especially for policies that target package.json.
5
+ *
6
+ * @alpha
7
+ */
8
+ export type PackageJsonHandler<J, C> = (json: J, args: PolicyFunctionArguments<C>) => Promise<PolicyHandlerResult>;
9
+ /**
10
+ * Define a repo policy for package.json files.
11
+ *
12
+ * @alpha
13
+ */
14
+ export declare function definePackagePolicy<J = PackageJson, C = undefined>(name: string, packagePolicy: PackageJsonHandler<J, C>): PolicyDefinition<C>;
15
+ //# sourceMappingURL=definePackagePolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definePackagePolicy.d.ts","sourceRoot":"","sources":["../../src/policyDefiners/definePackagePolicy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,KAAK,EACX,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,MAAM,cAAc,CAAC;AAItB;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI,CACtC,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,uBAAuB,CAAC,CAAC,CAAC,KAC5B,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAElC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,GAAG,WAAW,EAAE,CAAC,GAAG,SAAS,EACjE,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAErC,gBAAgB,CAAC,CAAC,CAAC,CAUrB"}
@@ -6,7 +6,7 @@ const { readFile: readJson } = jsonfile;
6
6
  *
7
7
  * @alpha
8
8
  */
9
- export function generatePackagePolicy(name, packagePolicy) {
9
+ export function definePackagePolicy(name, packagePolicy) {
10
10
  // const func = () => handler(json, args);
11
11
  return {
12
12
  name,
@@ -17,4 +17,4 @@ export function generatePackagePolicy(name, packagePolicy) {
17
17
  },
18
18
  };
19
19
  }
20
- //# sourceMappingURL=generatePackagePolicy.js.map
20
+ //# sourceMappingURL=definePackagePolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definePackagePolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/definePackagePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAOjE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC;AAYxC;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAClC,IAAY,EACZ,aAAuC;IAGvC,0CAA0C;IAC1C,OAAO;QACN,IAAI;QACJ,KAAK,EAAE,qBAAqB;QAC5B,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;YAC5B,MAAM,IAAI,GAAM,MAAM,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC/C,OAAO,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACvC,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import jsonfile from \"jsonfile\";\nimport type { PackageJson } from \"type-fest\";\nimport { PackageJsonRegexMatch } from \"../policies/constants.js\";\nimport type {\n\tPolicyDefinition,\n\tPolicyFunctionArguments,\n\tPolicyHandlerResult,\n} from \"../policy.js\";\n\nconst { readFile: readJson } = jsonfile;\n\n/**\n * A policy handler especially for policies that target package.json.\n *\n * @alpha\n */\nexport type PackageJsonHandler<J, C> = (\n\tjson: J,\n\targs: PolicyFunctionArguments<C>,\n) => Promise<PolicyHandlerResult>;\n\n/**\n * Define a repo policy for package.json files.\n *\n * @alpha\n */\nexport function definePackagePolicy<J = PackageJson, C = undefined>(\n\tname: string,\n\tpackagePolicy: PackageJsonHandler<J, C>,\n\t// args: PolicyFunctionArguments<C>,\n): PolicyDefinition<C> {\n\t// const func = () => handler(json, args);\n\treturn {\n\t\tname,\n\t\tmatch: PackageJsonRegexMatch,\n\t\thandler: async (innerArgs) => {\n\t\t\tconst json: J = await readJson(innerArgs.file);\n\t\t\treturn packagePolicy(json, innerArgs);\n\t\t},\n\t};\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.52.4"
8
+ "packageVersion": "7.52.7"
9
9
  }
10
10
  ]
11
11
  }
@@ -125,5 +125,5 @@
125
125
  ]
126
126
  }
127
127
  },
128
- "version": "0.5.0"
128
+ "version": "0.6.0"
129
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repopo",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Enforce policies on all or some of the files in a git repository.",
5
5
  "keywords": [
6
6
  "policy",
@@ -10,7 +10,7 @@
10
10
  "bugs": "https://github.com/tylerbutler/tools-monorepo/issues",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/tylerbutler/tools-monorepo.git",
13
+ "url": "git+https://github.com/tylerbutler/tools-monorepo.git",
14
14
  "directory": "packages/repopo"
15
15
  },
16
16
  "license": "MIT",
@@ -54,36 +54,34 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@fluid-tools/build-infrastructure": "^0.56.0",
57
- "@oclif/core": "^4.2.10",
57
+ "@oclif/core": "^4.3.0",
58
58
  "@oclif/plugin-help": "^6.2.27",
59
- "@rushstack/node-core-library": "^5.13.0",
59
+ "@rushstack/node-core-library": "^5.13.1",
60
60
  "defu": "^6.1.4",
61
61
  "jsonfile": "^6.1.0",
62
62
  "microdiff": "^1.5.0",
63
63
  "pathe": "^2.0.3",
64
64
  "picocolors": "^1.1.1",
65
65
  "simple-git": "^3.27.0",
66
- "@tylerbu/cli-api": "^0.7.1",
67
- "@tylerbu/fundamentals": "^0.2.1"
66
+ "@tylerbu/cli-api": "^0.7.2",
67
+ "@tylerbu/fundamentals": "^0.2.2"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@biomejs/biome": "1.9.4",
71
- "@microsoft/api-extractor": "^7.52.4",
71
+ "@microsoft/api-extractor": "^7.52.7",
72
72
  "@oclif/plugin-command-snapshot": "^5.2.38",
73
73
  "@oclif/test": "^4.1.12",
74
74
  "@types/jsonfile": "^6.1.4",
75
75
  "@types/node": "^20.12.7",
76
76
  "@types/tmp": "^0.2.6",
77
77
  "generate-license-file": "^4.0.0",
78
- "oclif": "^4.17.45",
78
+ "oclif": "^4.17.46",
79
79
  "rimraf": "^6.0.1",
80
- "serve": "^14.2.4",
81
- "start-server-and-test": "^2.0.11",
82
80
  "tmp-promise": "^3.0.3",
83
81
  "ts-node": "^10.9.2",
84
- "type-fest": "^4.40.0",
82
+ "type-fest": "^4.40.1",
85
83
  "typescript": "~5.5.4",
86
- "vitest": "^3.1.1"
84
+ "vitest": "^3.1.2"
87
85
  },
88
86
  "peerDependencies": {
89
87
  "sort-package-json": "*"
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateFileHeaderPolicy.d.ts","sourceRoot":"","sources":["../../src/policyGenerators/generateFileHeaderPolicy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAkC,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/E;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,yBAChB,SAAQ,OAAO,CAAC,sBAAsB,CAAC;IACvC,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB,KAAK,MAAM,CAAC;CACtE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACvC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,yBAAyB,GAC/B,UAAU,CAAC,sBAAsB,CAAC,CAiEpC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateFileHeaderPolicy.js","sourceRoot":"","sources":["../../src/policyGenerators/generateFileHeaderPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,C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AC;YAED,MAAM,UAAU,GAAkB;gBACjC,IAAI;gBACJ,IAAI;gBACJ,WAAW,EAAE,IAAI;aACjB,CAAC;YAEF,+EAA+E;YAC/E,gCAAgC;YAChC,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;YAC3D,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAEpC,IAAI,MAAM,EAAE,CAAC;gBACZ,UAAU,CAAC,YAAY,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC;YAClE,CAAC;YAED,IAAI,MAAM,EAAE,CAAC;gBACZ,IAAI,OAAO,EAAE,CAAC;oBACb,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;oBAC1D,MAAM,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;oBAElC,MAAM,SAAS,GAAoB;wBAClC,GAAG,UAAU;wBACb,QAAQ,EAAE,IAAI;qBACd,CAAC;oBAEF,OAAO,SAAS,CAAC;gBAClB,CAAC;gBACD,OAAO,UAAU,CAAC;YACnB,CAAC;YAED,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\nimport { EOL as newline } from \"node:os\";\nimport { extname } from \"pathe\";\nimport type { PolicyFailure, PolicyFixResult, RepoPolicy } from \"../policy.js\";\n\nconst trailingSpaces = /\\s*\\\\r\\?\\\\n/;\n\n/**\n * @alpha\n */\nexport interface FileHeaderPolicyConfig {\n\t/**\n\t * The text to use as the header.\n\t */\n\theaderText: string;\n\n\t/**\n\t * An optional string that will be appended to the headerText.\n\t */\n\tautoGenText?: string;\n}\n\n/**\n * @alpha\n */\nexport interface FileHeaderGeneratorConfig\n\textends Partial<FileHeaderPolicyConfig> {\n\tmatch: RegExp;\n\n\t/**\n\t * Regex matching header prefix (e.g. `/*!\\r?\\n`)\n\t */\n\theaderStart?: RegExp;\n\n\t/**\n\t * Regex matching beginning of each line (e.g. ' * ')\n\t */\n\tlineStart: RegExp;\n\n\t/**\n\t * Regex matching the end of each line (e.g., `\\r?\\n`)\n\t */\n\tlineEnd: RegExp;\n\n\t/**\n\t * Regex matching the header postfix.\n\t */\n\theaderEnd?: RegExp;\n\n\treplacer: (content: string, config: FileHeaderPolicyConfig) => string;\n}\n\n/**\n * Given a `FileHeaderGeneratorConfig`, produces a function that detects correct file headers\n * and returns an error string if the header is missing or incorrect.\n *\n * @alpha\n */\nexport function generateFileHeaderPolicy(\n\tname: string,\n\tconfig: FileHeaderGeneratorConfig,\n): RepoPolicy<FileHeaderPolicyConfig> {\n\tconst pre = config.headerStart?.source ?? \"\";\n\tconst start = config.lineStart.source;\n\tconst end = config.lineEnd.source;\n\tconst post = config.headerEnd?.source ?? \"\";\n\n\t// Helper which constructs a matching RegExp from a given multiline string.\n\t// (See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping)\n\tconst toRegex = (text: string): string =>\n\t\ttext\n\t\t\t.split(newline)\n\t\t\t.map(\n\t\t\t\t(line) =>\n\t\t\t\t\t`${start}${line.replace(/[$()*+.?[\\\\\\]^{|}]/g, \"\\\\$&\")}${end}`,\n\t\t\t)\n\t\t\t.join(\"\")\n\t\t\t.replace(trailingSpaces, \"\\\\r?\\\\n\"); // Trim trailing spaces at end-of-line.\n\n\t// Detection regex matches the header start (if any), followed by lines in 'headerText',\n\t// optionally followed by lines in the 'autoGenText', and finally the header end (if any).\n\tconst regex = new RegExp(\n\t\t`^${pre}${toRegex(config.headerText ?? \"\")}(${toRegex(config.autoGenText ?? \"\")})?${post}`,\n\t);\n\n\treturn {\n\t\tname,\n\t\tmatch: config.match,\n\t\thandler: async ({ file, resolve, config: policyConfig }) => {\n\t\t\tif (policyConfig === undefined) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst failResult: PolicyFailure = {\n\t\t\t\tname,\n\t\t\t\tfile,\n\t\t\t\tautoFixable: true,\n\t\t\t};\n\n\t\t\t// TODO: Consider reading only the first 512B or so since headers are typically\n\t\t\t// at the beginning of the file.\n\t\t\tconst content = await readFile(file, { encoding: \"utf8\" });\n\t\t\tconst failed = !regex.test(content);\n\n\t\t\tif (failed) {\n\t\t\t\tfailResult.errorMessage = `${extname(file)} file missing header`;\n\t\t\t}\n\n\t\t\tif (failed) {\n\t\t\t\tif (resolve) {\n\t\t\t\t\tconst newContent = config.replacer(content, policyConfig);\n\t\t\t\t\tawait writeFile(file, newContent);\n\n\t\t\t\t\tconst fixResult: PolicyFixResult = {\n\t\t\t\t\t\t...failResult,\n\t\t\t\t\t\tresolved: true,\n\t\t\t\t\t};\n\n\t\t\t\t\treturn fixResult;\n\t\t\t\t}\n\t\t\t\treturn failResult;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t},\n\t};\n}\n"]}
@@ -1,9 +0,0 @@
1
- import type { PackageJson } from "type-fest";
2
- import type { PackageJsonHandler, RepoPolicy } from "../policy.js";
3
- /**
4
- * Define a repo policy for package.json files.
5
- *
6
- * @alpha
7
- */
8
- export declare function generatePackagePolicy<J = PackageJson, C = undefined>(name: string, packagePolicy: PackageJsonHandler<J, C>): RepoPolicy<C>;
9
- //# sourceMappingURL=generatePackagePolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generatePackagePolicy.d.ts","sourceRoot":"","sources":["../../src/policyGenerators/generatePackagePolicy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAInE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,GAAG,WAAW,EAAE,CAAC,GAAG,SAAS,EACnE,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAErC,UAAU,CAAC,CAAC,CAAC,CAUf"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generatePackagePolicy.js","sourceRoot":"","sources":["../../src/policyGenerators/generatePackagePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAGjE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC;AAExC;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACpC,IAAY,EACZ,aAAuC;IAGvC,0CAA0C;IAC1C,OAAO;QACN,IAAI;QACJ,KAAK,EAAE,qBAAqB;QAC5B,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;YAC5B,MAAM,IAAI,GAAM,MAAM,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC/C,OAAO,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACvC,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import jsonfile from \"jsonfile\";\nimport type { PackageJson } from \"type-fest\";\nimport { PackageJsonRegexMatch } from \"../policies/constants.js\";\nimport type { PackageJsonHandler, RepoPolicy } from \"../policy.js\";\n\nconst { readFile: readJson } = jsonfile;\n\n/**\n * Define a repo policy for package.json files.\n *\n * @alpha\n */\nexport function generatePackagePolicy<J = PackageJson, C = undefined>(\n\tname: string,\n\tpackagePolicy: PackageJsonHandler<J, C>,\n\t// args: PolicyFunctionArguments<C>,\n): RepoPolicy<C> {\n\t// const func = () => handler(json, args);\n\treturn {\n\t\tname,\n\t\tmatch: PackageJsonRegexMatch,\n\t\thandler: async (innerArgs) => {\n\t\t\tconst json: J = await readJson(innerArgs.file);\n\t\t\treturn packagePolicy(json, innerArgs);\n\t\t},\n\t};\n}\n"]}