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/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,YAAY,EACX,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,UAAU,EACV,wBAAwB,EACxB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,YAAY,EACX,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,mBAAmB,EACnB,UAAU,EACV,wBAAwB,EACxB,gBAAgB,GAChB,MAAM,aAAa,CAAC;AAErB,YAAY,EAEX,YAAY,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACN,mBAAmB,IAAI,qBAAqB,EAC5C,KAAK,kBAAkB,GACvB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACN,sBAAsB,IAAI,wBAAwB,EAClD,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,GAC3B,MAAM,4CAA4C,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { run } from "@oclif/core";
|
|
2
|
-
export {
|
|
2
|
+
export { makePolicy } from "./makePolicy.js";
|
|
3
|
+
export { definePackagePolicy as generatePackagePolicy, } from "./policyDefiners/definePackagePolicy.js";
|
|
4
|
+
export { defineFileHeaderPolicy as generateFileHeaderPolicy, } from "./policyDefiners/defineFileHeaderPolicy.js";
|
|
3
5
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAmBlC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACN,mBAAmB,IAAI,qBAAqB,GAE5C,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACN,sBAAsB,IAAI,wBAAwB,GAGlD,MAAM,4CAA4C,CAAC","sourcesContent":["export { run } from \"@oclif/core\";\n\nexport type {\n\tPolicyFailure,\n\tPolicyFixResult,\n\tPolicyFunctionArguments,\n\tPolicyHandler,\n\tPolicyInstance,\n\tPolicyInstanceSettings,\n\tPolicyHandlerResult,\n\tPolicyName,\n\tPolicyStandaloneResolver,\n\tPolicyDefinition,\n} from \"./policy.js\";\n\nexport type {\n\t// PolicyList,\n\tRepopoConfig,\n} from \"./config.js\";\nexport { makePolicy } from \"./makePolicy.js\";\nexport {\n\tdefinePackagePolicy as generatePackagePolicy,\n\ttype PackageJsonHandler,\n} from \"./policyDefiners/definePackagePolicy.js\";\nexport {\n\tdefineFileHeaderPolicy as generateFileHeaderPolicy,\n\ttype FileHeaderGeneratorConfig,\n\ttype FileHeaderPolicyConfig,\n} from \"./policyDefiners/defineFileHeaderPolicy.js\";\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PolicyDefinition, PolicyHandler, PolicyInstance, PolicyInstanceSettings, PolicyName, PolicyStandaloneResolver } from "./policy.js";
|
|
2
|
+
export declare function makePolicyDefinition<C = undefined>(name: PolicyName, match: RegExp, handler: PolicyHandler<C>, defaultConfig?: C, description?: string, resolver?: PolicyStandaloneResolver<C>): PolicyDefinition<C>;
|
|
3
|
+
/**
|
|
4
|
+
* Combine a {@link PolicyDefinition} with a policy-specific config and other settings to produce a {@link PolicyInstance}.
|
|
5
|
+
*
|
|
6
|
+
* @alpha
|
|
7
|
+
*/
|
|
8
|
+
export declare function makePolicy<C>(definition: PolicyDefinition<C>, config?: C, settings?: PolicyInstanceSettings<C>): PolicyInstance<C>;
|
|
9
|
+
//# sourceMappingURL=makePolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makePolicy.d.ts","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,UAAU,EACV,wBAAwB,EACxB,MAAM,aAAa,CAAC;AAoBrB,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,SAAS,EACjD,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,aAAa,CAAC,EAAE,CAAC,EACjB,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,wBAAwB,CAAC,CAAC,CAAC,GACpC,gBAAgB,CAAC,CAAC,CAAC,CAOrB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC3B,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC/B,MAAM,CAAC,EAAE,CAAC,EACV,QAAQ,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAClC,cAAc,CAAC,CAAC,CAAC,CAMnB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function generatePolicyFunction(name, description) {
|
|
2
|
+
return (match, handler, defaultConfig, resolver) => {
|
|
3
|
+
return {
|
|
4
|
+
name,
|
|
5
|
+
match,
|
|
6
|
+
handler,
|
|
7
|
+
description,
|
|
8
|
+
defaultConfig,
|
|
9
|
+
resolver,
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function makePolicyDefinition(name, match, handler, defaultConfig, description, resolver) {
|
|
14
|
+
return generatePolicyFunction(name, description)(match, handler, defaultConfig, resolver);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Combine a {@link PolicyDefinition} with a policy-specific config and other settings to produce a {@link PolicyInstance}.
|
|
18
|
+
*
|
|
19
|
+
* @alpha
|
|
20
|
+
*/
|
|
21
|
+
export function makePolicy(definition, config, settings) {
|
|
22
|
+
return {
|
|
23
|
+
...definition,
|
|
24
|
+
...settings,
|
|
25
|
+
config,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=makePolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makePolicy.js","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AASA,SAAS,sBAAsB,CAAC,IAAgB,EAAE,WAAoB;IACrE,OAAO,CACN,KAAa,EACb,OAAyB,EACzB,aAAiB,EACjB,QAAsC,EAChB,EAAE;QACxB,OAAO;YACN,IAAI;YACJ,KAAK;YACL,OAAO;YACP,WAAW;YACX,aAAa;YACb,QAAQ;SACR,CAAC;IACH,CAAC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CACnC,IAAgB,EAChB,KAAa,EACb,OAAyB,EACzB,aAAiB,EACjB,WAAoB,EACpB,QAAsC;IAEtC,OAAO,sBAAsB,CAAC,IAAI,EAAE,WAAW,CAAC,CAC/C,KAAK,EACL,OAAO,EACP,aAAa,EACb,QAAQ,CACR,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACzB,UAA+B,EAC/B,MAAU,EACV,QAAoC;IAEpC,OAAO;QACN,GAAG,UAAU;QACb,GAAG,QAAQ;QACX,MAAM;KACsB,CAAC;AAC/B,CAAC","sourcesContent":["import type {\n\tPolicyDefinition,\n\tPolicyHandler,\n\tPolicyInstance,\n\tPolicyInstanceSettings,\n\tPolicyName,\n\tPolicyStandaloneResolver,\n} from \"./policy.js\";\n\nfunction generatePolicyFunction(name: PolicyName, description?: string) {\n\treturn <C>(\n\t\tmatch: RegExp,\n\t\thandler: PolicyHandler<C>,\n\t\tdefaultConfig?: C,\n\t\tresolver?: PolicyStandaloneResolver<C>,\n\t): PolicyDefinition<C> => {\n\t\treturn {\n\t\t\tname,\n\t\t\tmatch,\n\t\t\thandler,\n\t\t\tdescription,\n\t\t\tdefaultConfig,\n\t\t\tresolver,\n\t\t};\n\t};\n}\n\nexport function makePolicyDefinition<C = undefined>(\n\tname: PolicyName,\n\tmatch: RegExp,\n\thandler: PolicyHandler<C>,\n\tdefaultConfig?: C,\n\tdescription?: string,\n\tresolver?: PolicyStandaloneResolver<C>,\n): PolicyDefinition<C> {\n\treturn generatePolicyFunction(name, description)(\n\t\tmatch,\n\t\thandler,\n\t\tdefaultConfig,\n\t\tresolver,\n\t);\n}\n\n/**\n * Combine a {@link PolicyDefinition} with a policy-specific config and other settings to produce a {@link PolicyInstance}.\n *\n * @alpha\n */\nexport function makePolicy<C>(\n\tdefinition: PolicyDefinition<C>,\n\tconfig?: C,\n\tsettings?: PolicyInstanceSettings<C>,\n): PolicyInstance<C> {\n\treturn {\n\t\t...definition,\n\t\t...settings,\n\t\tconfig,\n\t} satisfies PolicyInstance<C>;\n}\n"]}
|
package/esm/perf.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perf.d.ts","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"perf.d.ts","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEhD,MAAM,WAAW,sBAAsB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;CACjD;AAED,wBAAgB,YAAY,IAAI,sBAAsB,CAMrD;AAED,wBAAsB,WAAW,CAAC,CAAC,EAClC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,sBAAsB,EAC7B,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAWZ;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,sBAAsB,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAYzE"}
|
package/esm/perf.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stores performance data for each handler. Used to collect and display performance stats.
|
|
3
|
-
*/
|
|
4
|
-
const handlerPerformanceData = new Map();
|
|
5
1
|
export function newPerfStats() {
|
|
6
2
|
return {
|
|
7
3
|
count: 0,
|
|
@@ -21,7 +17,7 @@ export async function runWithPerf(name, action, stats, run) {
|
|
|
21
17
|
}
|
|
22
18
|
export function logStats(stats, log) {
|
|
23
19
|
log.log(`Statistics: ${stats.processed} processed, ${stats.count - stats.processed} excluded, ${stats.count} total`);
|
|
24
|
-
for (const [action, handlerPerf] of
|
|
20
|
+
for (const [action, handlerPerf] of stats.data.entries()) {
|
|
25
21
|
log.log(`Performance for "${action}":`);
|
|
26
22
|
for (const [handler, dur] of handlerPerf.entries()) {
|
|
27
23
|
log.log(`\t${handler}: ${dur}ms`);
|
package/esm/perf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perf.js","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"perf.js","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,YAAY;IAC3B,OAAO;QACN,KAAK,EAAE,CAAC;QACR,SAAS,EAAE,CAAC;QACZ,IAAI,EAAE,IAAI,GAAG,EAAyC;KACtD,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,IAAY,EACZ,MAAoB,EACpB,KAA6B,EAC7B,GAAqB;IAErB,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,GAAG,EAAkB,CAAC;IACtE,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEnC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,MAAM,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC;IAC3B,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAE1B,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAA6B,EAAE,GAAW;IAClE,GAAG,CAAC,GAAG,CACN,eAAe,KAAK,CAAC,SAAS,eAC7B,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,SACrB,cAAc,KAAK,CAAC,KAAK,QAAQ,CACjC,CAAC;IACF,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QAC1D,GAAG,CAAC,GAAG,CAAC,oBAAoB,MAAM,IAAI,CAAC,CAAC;QACxC,KAAK,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;YACpD,GAAG,CAAC,GAAG,CAAC,KAAK,OAAO,KAAK,GAAG,IAAI,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import type { Logger } from \"@tylerbu/cli-api\";\nimport type { PolicyName } from \"./policy.js\";\n\nexport type PolicyAction = \"handle\" | \"resolve\";\n\nexport interface PolicyHandlerPerfStats {\n\tcount: number;\n\tprocessed: number;\n\tdata: Map<PolicyAction, Map<PolicyName, number>>;\n}\n\nexport function newPerfStats(): PolicyHandlerPerfStats {\n\treturn {\n\t\tcount: 0,\n\t\tprocessed: 0,\n\t\tdata: new Map<PolicyAction, Map<PolicyName, number>>(),\n\t};\n}\n\nexport async function runWithPerf<T>(\n\tname: string,\n\taction: PolicyAction,\n\tstats: PolicyHandlerPerfStats,\n\trun: () => Promise<T>,\n): Promise<T> {\n\tconst actionMap = stats.data.get(action) ?? new Map<string, number>();\n\tlet dur = actionMap.get(name) ?? 0;\n\n\tconst start = Date.now();\n\tconst result = await run();\n\tdur += Date.now() - start;\n\n\tactionMap.set(name, dur);\n\tstats.data.set(action, actionMap);\n\treturn result;\n}\n\nexport function logStats(stats: PolicyHandlerPerfStats, log: Logger): void {\n\tlog.log(\n\t\t`Statistics: ${stats.processed} processed, ${\n\t\t\tstats.count - stats.processed\n\t\t} excluded, ${stats.count} total`,\n\t);\n\tfor (const [action, handlerPerf] of stats.data.entries()) {\n\t\tlog.log(`Performance for \"${action}\":`);\n\t\tfor (const [handler, dur] of handlerPerf.entries()) {\n\t\t\tlog.log(`\\t${handler}: ${dur}ms`);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type FileHeaderPolicyConfig } from "../policyDefiners/defineFileHeaderPolicy.js";
|
|
2
|
+
/**
|
|
3
|
+
* A RepoPolicy that checks that HTML files have the configured header comment.
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
6
|
+
*/
|
|
7
|
+
export declare const HtmlFileHeaders: import("../policy.js").PolicyDefinition<FileHeaderPolicyConfig>;
|
|
8
|
+
//# sourceMappingURL=HtmlFileHeaders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HtmlFileHeaders.d.ts","sourceRoot":"","sources":["../../src/policies/HtmlFileHeaders.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,sBAAsB,EAE3B,MAAM,6CAA6C,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,eAAe,iEAc1B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EOL as newline } from "node:os";
|
|
2
|
+
import { defineFileHeaderPolicy, } from "../policyDefiners/defineFileHeaderPolicy.js";
|
|
3
|
+
/**
|
|
4
|
+
* A RepoPolicy that checks that HTML files have the configured header comment.
|
|
5
|
+
*
|
|
6
|
+
* @alpha
|
|
7
|
+
*/
|
|
8
|
+
export const HtmlFileHeaders = defineFileHeaderPolicy("HtmlFileHeaders", {
|
|
9
|
+
match: /(^|\/)[^/]+\.[mc]?[jt]sx?$/i,
|
|
10
|
+
lineStart: /<!-- /, // Lines begin with '<!-- '
|
|
11
|
+
lineEnd: / -->\r?\n/, // Lines end with ' -->' followed by CRLF or LF
|
|
12
|
+
replacer: (content, { headerText }) => {
|
|
13
|
+
const newContent = `<!-- ${headerText.replace(newline, ` -->${newline}<!-- `)} -->${newline}${newline}${content}`;
|
|
14
|
+
return newContent;
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=HtmlFileHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HtmlFileHeaders.js","sourceRoot":"","sources":["../../src/policies/HtmlFileHeaders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAEN,sBAAsB,GACtB,MAAM,6CAA6C,CAAC;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAC,iBAAiB,EAAE;IACxE,KAAK,EAAE,6BAA6B;IACpC,SAAS,EAAE,OAAO,EAAE,2BAA2B;IAC/C,OAAO,EAAE,WAAW,EAAE,+CAA+C;IACrE,QAAQ,EAAE,CACT,OAAe,EACf,EAAE,UAAU,EAA0B,EAC7B,EAAE;QACX,MAAM,UAAU,GAAG,QAAQ,UAAU,CAAC,OAAO,CAC5C,OAAO,EACP,OAAO,OAAO,OAAO,CACrB,OAAO,OAAO,GAAG,OAAO,GAAG,OAAO,EAAE,CAAC;QACtC,OAAO,UAAU,CAAC;IACnB,CAAC;CACD,CAAC,CAAC","sourcesContent":["import { EOL as newline } from \"node:os\";\nimport {\n\ttype FileHeaderPolicyConfig,\n\tdefineFileHeaderPolicy,\n} from \"../policyDefiners/defineFileHeaderPolicy.js\";\n\n/**\n * A RepoPolicy that checks that HTML files have the configured header comment.\n *\n * @alpha\n */\nexport const HtmlFileHeaders = defineFileHeaderPolicy(\"HtmlFileHeaders\", {\n\tmatch: /(^|\\/)[^/]+\\.[mc]?[jt]sx?$/i,\n\tlineStart: /<!-- /, // Lines begin with '<!-- '\n\tlineEnd: / -->\\r?\\n/, // Lines end with ' -->' followed by CRLF or LF\n\treplacer: (\n\t\tcontent: string,\n\t\t{ headerText }: FileHeaderPolicyConfig,\n\t): string => {\n\t\tconst newContent = `<!-- ${headerText.replace(\n\t\t\tnewline,\n\t\t\t` -->${newline}<!-- `,\n\t\t)} -->${newline}${newline}${content}`;\n\t\treturn newContent;\n\t},\n});\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type FileHeaderPolicyConfig } from "../policyDefiners/defineFileHeaderPolicy.js";
|
|
2
|
+
/**
|
|
3
|
+
* A RepoPolicy that checks that JavaScript and TypeScript source files have the configured header comment
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
6
|
+
*/
|
|
7
|
+
export declare const JsTsFileHeaders: import("../policy.js").PolicyDefinition<FileHeaderPolicyConfig>;
|
|
8
|
+
//# sourceMappingURL=JsTsFileHeaders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsTsFileHeaders.d.ts","sourceRoot":"","sources":["../../src/policies/JsTsFileHeaders.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,sBAAsB,EAE3B,MAAM,6CAA6C,CAAC;AAkBrD;;;;GAIG;AACH,eAAO,MAAM,eAAe,iEAO1B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EOL as newline } from "node:os";
|
|
2
|
+
import { defineFileHeaderPolicy, } from "../policyDefiners/defineFileHeaderPolicy.js";
|
|
3
|
+
const jsTsReplacer = (prevContent, { headerText }) => {
|
|
4
|
+
// prepend header to existing content
|
|
5
|
+
const separator = prevContent.startsWith("\r") || prevContent.startsWith("\n")
|
|
6
|
+
? newline
|
|
7
|
+
: newline + newline;
|
|
8
|
+
const newContent = `/*!${newline} * ${headerText.replace(newline, `${newline} * `)}${newline} */${separator}${prevContent}`;
|
|
9
|
+
return newContent;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A RepoPolicy that checks that JavaScript and TypeScript source files have the configured header comment
|
|
13
|
+
*
|
|
14
|
+
* @alpha
|
|
15
|
+
*/
|
|
16
|
+
export const JsTsFileHeaders = defineFileHeaderPolicy("JsTsFileHeaders", {
|
|
17
|
+
match: /(^|\/)[^/]+\.[mc]?[jt]sx?$/i,
|
|
18
|
+
headerStart: /(#![^\n]*\r?\n)?\/\*!\r?\n/, // Begins with optional hashbang followed by '/*!'
|
|
19
|
+
lineStart: / \* /, // Subsequent lines begins with ' * '
|
|
20
|
+
lineEnd: /\r?\n/, // Subsequent lines end with CRLF or LF
|
|
21
|
+
headerEnd: / \*\/\r?\n\r?\n/, // Header ends with ' */' on a line by itself, followed by another newline
|
|
22
|
+
replacer: jsTsReplacer,
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=JsTsFileHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsTsFileHeaders.js","sourceRoot":"","sources":["../../src/policies/JsTsFileHeaders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAEN,sBAAsB,GACtB,MAAM,6CAA6C,CAAC;AAErD,MAAM,YAAY,GAAG,CACpB,WAAmB,EACnB,EAAE,UAAU,EAA0B,EAC7B,EAAE;IACX,qCAAqC;IACrC,MAAM,SAAS,GACd,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC;QAC3D,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC;IACtB,MAAM,UAAU,GAAG,MAAM,OAAO,MAAM,UAAU,CAAC,OAAO,CACvD,OAAO,EACP,GAAG,OAAO,KAAK,CACf,GAAG,OAAO,MAAM,SAAS,GAAG,WAAW,EAAE,CAAC;IAC3C,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAC,iBAAiB,EAAE;IACxE,KAAK,EAAE,6BAA6B;IACpC,WAAW,EAAE,4BAA4B,EAAE,kDAAkD;IAC7F,SAAS,EAAE,MAAM,EAAE,qCAAqC;IACxD,OAAO,EAAE,OAAO,EAAE,uCAAuC;IACzD,SAAS,EAAE,iBAAiB,EAAE,0EAA0E;IACxG,QAAQ,EAAE,YAAY;CACtB,CAAC,CAAC","sourcesContent":["import { EOL as newline } from \"node:os\";\nimport {\n\ttype FileHeaderPolicyConfig,\n\tdefineFileHeaderPolicy,\n} from \"../policyDefiners/defineFileHeaderPolicy.js\";\n\nconst jsTsReplacer = (\n\tprevContent: string,\n\t{ headerText }: FileHeaderPolicyConfig,\n): string => {\n\t// prepend header to existing content\n\tconst separator =\n\t\tprevContent.startsWith(\"\\r\") || prevContent.startsWith(\"\\n\")\n\t\t\t? newline\n\t\t\t: newline + newline;\n\tconst newContent = `/*!${newline} * ${headerText.replace(\n\t\tnewline,\n\t\t`${newline} * `,\n\t)}${newline} */${separator}${prevContent}`;\n\treturn newContent;\n};\n\n/**\n * A RepoPolicy that checks that JavaScript and TypeScript source files have the configured header comment\n *\n * @alpha\n */\nexport const JsTsFileHeaders = defineFileHeaderPolicy(\"JsTsFileHeaders\", {\n\tmatch: /(^|\\/)[^/]+\\.[mc]?[jt]sx?$/i,\n\theaderStart: /(#![^\\n]*\\r?\\n)?\\/\\*!\\r?\\n/, // Begins with optional hashbang followed by '/*!'\n\tlineStart: / \\* /, // Subsequent lines begins with ' * '\n\tlineEnd: /\\r?\\n/, // Subsequent lines end with CRLF or LF\n\theaderEnd: / \\*\\/\\r?\\n\\r?\\n/, // Header ends with ' */' on a line by itself, followed by another newline\n\treplacer: jsTsReplacer,\n});\n"]}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PolicyDefinition } from "../policy.js";
|
|
2
2
|
/**
|
|
3
3
|
* A repo policy that checks for JavaScript source files that just use the .js file extension. Such files may be
|
|
4
4
|
* interpreted by node as either CommonJS or ESM based on the `type` field in the nearest package.json file. This
|
|
5
5
|
* can create unexpected behavior for JS files; changing the package.json nearest to one will change how the JS
|
|
6
6
|
* is processed by node. Using explicit file extensions reduces ambiguity and ensures a CJS file isn't suddenly treated
|
|
7
7
|
* like an ESM file.
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
8
10
|
*/
|
|
9
|
-
export declare const NoJsFileExtensions:
|
|
11
|
+
export declare const NoJsFileExtensions: PolicyDefinition;
|
|
10
12
|
//# sourceMappingURL=NoJsFileExtensions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoJsFileExtensions.d.ts","sourceRoot":"","sources":["../../src/policies/NoJsFileExtensions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NoJsFileExtensions.d.ts","sourceRoot":"","sources":["../../src/policies/NoJsFileExtensions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,cAAc,CAAC;AAEpE;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBAehC,CAAC"}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
+
import { makePolicyDefinition } from "../makePolicy.js";
|
|
1
2
|
/**
|
|
2
3
|
* A repo policy that checks for JavaScript source files that just use the .js file extension. Such files may be
|
|
3
4
|
* interpreted by node as either CommonJS or ESM based on the `type` field in the nearest package.json file. This
|
|
4
5
|
* can create unexpected behavior for JS files; changing the package.json nearest to one will change how the JS
|
|
5
6
|
* is processed by node. Using explicit file extensions reduces ambiguity and ensures a CJS file isn't suddenly treated
|
|
6
7
|
* like an ESM file.
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
7
10
|
*/
|
|
8
|
-
export const NoJsFileExtensions =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return result;
|
|
21
|
-
},
|
|
22
|
-
};
|
|
11
|
+
export const NoJsFileExtensions = makePolicyDefinition("NoJsFileExtensions", /(^|\/)[^/]+\.js$/i,
|
|
12
|
+
// biome-ignore lint/suspicious/useAwait: <explanation>
|
|
13
|
+
async ({ file }) => {
|
|
14
|
+
// Any match is considered a failure.
|
|
15
|
+
const result = {
|
|
16
|
+
name: NoJsFileExtensions.name,
|
|
17
|
+
file,
|
|
18
|
+
autoFixable: false,
|
|
19
|
+
errorMessage: "JavaScript files should have a .cjs or .mjs file extension based on the module format of the file. Rename the file accordingly.",
|
|
20
|
+
};
|
|
21
|
+
return result;
|
|
22
|
+
});
|
|
23
23
|
//# sourceMappingURL=NoJsFileExtensions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoJsFileExtensions.js","sourceRoot":"","sources":["../../src/policies/NoJsFileExtensions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NoJsFileExtensions.js","sourceRoot":"","sources":["../../src/policies/NoJsFileExtensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAqB,oBAAoB,CACvE,oBAAoB,EACpB,mBAAmB;AACnB,uDAAuD;AACvD,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;IAClB,qCAAqC;IACrC,MAAM,MAAM,GAAkB;QAC7B,IAAI,EAAE,kBAAkB,CAAC,IAAI;QAC7B,IAAI;QACJ,WAAW,EAAE,KAAK;QAClB,YAAY,EACX,iIAAiI;KAClI,CAAC;IACF,OAAO,MAAM,CAAC;AACf,CAAC,CACD,CAAC","sourcesContent":["import { makePolicyDefinition } from \"../makePolicy.js\";\nimport type { PolicyDefinition, PolicyFailure } from \"../policy.js\";\n\n/**\n * A repo policy that checks for JavaScript source files that just use the .js file extension. Such files may be\n * interpreted by node as either CommonJS or ESM based on the `type` field in the nearest package.json file. This\n * can create unexpected behavior for JS files; changing the package.json nearest to one will change how the JS\n * is processed by node. Using explicit file extensions reduces ambiguity and ensures a CJS file isn't suddenly treated\n * like an ESM file.\n *\n * @alpha\n */\nexport const NoJsFileExtensions: PolicyDefinition = makePolicyDefinition(\n\t\"NoJsFileExtensions\",\n\t/(^|\\/)[^/]+\\.js$/i,\n\t// biome-ignore lint/suspicious/useAwait: <explanation>\n\tasync ({ file }) => {\n\t\t// Any match is considered a failure.\n\t\tconst result: PolicyFailure = {\n\t\t\tname: NoJsFileExtensions.name,\n\t\t\tfile,\n\t\t\tautoFixable: false,\n\t\t\terrorMessage:\n\t\t\t\t\"JavaScript files should have a .cjs or .mjs file extension based on the module format of the file. Rename the file accordingly.\",\n\t\t};\n\t\treturn result;\n\t},\n);\n"]}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
* @alpha
|
|
4
|
-
*/
|
|
5
|
-
export type PackageJsonProperty = string;
|
|
1
|
+
import type { PackageJson } from "type-fest";
|
|
6
2
|
/**
|
|
7
3
|
* Policy settings for the PackageJsonProperties repo policy.
|
|
8
4
|
*
|
|
@@ -10,12 +6,14 @@ export type PackageJsonProperty = string;
|
|
|
10
6
|
*/
|
|
11
7
|
export interface PackageJsonPropertiesSettings {
|
|
12
8
|
/**
|
|
13
|
-
* Sets a package.json property to the
|
|
9
|
+
* Sets a package.json property to the value provided. The value will be used verbatim.
|
|
14
10
|
*/
|
|
15
|
-
verbatim:
|
|
11
|
+
verbatim: PackageJson;
|
|
16
12
|
}
|
|
17
13
|
/**
|
|
18
14
|
* A RepoPolicy that checks that package.json properties in packages match expected values.
|
|
15
|
+
*
|
|
16
|
+
* @alpha
|
|
19
17
|
*/
|
|
20
|
-
export declare const PackageJsonProperties:
|
|
18
|
+
export declare const PackageJsonProperties: import("../policy.js").PolicyDefinition<PackageJsonPropertiesSettings | undefined>;
|
|
21
19
|
//# sourceMappingURL=PackageJsonProperties.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJsonProperties.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PackageJsonProperties.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAM7C;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC7C;;OAEG;IACH,QAAQ,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,oFA4ChC,CAAC"}
|
|
@@ -1,46 +1,43 @@
|
|
|
1
|
+
import { defu } from "defu";
|
|
1
2
|
import jsonfile from "jsonfile";
|
|
2
|
-
|
|
3
|
+
import diff from "microdiff";
|
|
4
|
+
import { definePackagePolicy } from "../policyDefiners/definePackagePolicy.js";
|
|
5
|
+
const { writeFile: writeJson } = jsonfile;
|
|
3
6
|
/**
|
|
4
7
|
* A RepoPolicy that checks that package.json properties in packages match expected values.
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
5
10
|
*/
|
|
6
|
-
export const PackageJsonProperties = {
|
|
7
|
-
|
|
8
|
-
match: /(^|\/)package\.json/i,
|
|
9
|
-
handler: async ({ file, config, resolve }) => {
|
|
10
|
-
if (config === undefined) {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
const failResult = {
|
|
14
|
-
name: PackageJsonProperties.name,
|
|
15
|
-
file,
|
|
16
|
-
autoFixable: true,
|
|
17
|
-
};
|
|
18
|
-
const { verbatim } = config;
|
|
19
|
-
const json = (await readJson(file));
|
|
20
|
-
const messages = [];
|
|
21
|
-
for (const [propName, value] of Object.entries(verbatim)) {
|
|
22
|
-
if (json[propName] !== value) {
|
|
23
|
-
messages.push(`Incorrect package.json field value for '${propName}'. Expected '${value}', got '${json[propName]}'.`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (messages.length > 0) {
|
|
27
|
-
if (resolve) {
|
|
28
|
-
const fixResult = {
|
|
29
|
-
...failResult,
|
|
30
|
-
resolved: false,
|
|
31
|
-
};
|
|
32
|
-
for (const [propName, value] of Object.entries(verbatim)) {
|
|
33
|
-
json[propName] = value;
|
|
34
|
-
}
|
|
35
|
-
await writeJson(file, json, { spaces: "\t" });
|
|
36
|
-
fixResult.resolved = true;
|
|
37
|
-
return fixResult;
|
|
38
|
-
}
|
|
39
|
-
// There were errors, and we're not resolving them, so return a fail result
|
|
40
|
-
failResult.errorMessage = messages.join("\n");
|
|
41
|
-
return failResult;
|
|
42
|
-
}
|
|
11
|
+
export const PackageJsonProperties = definePackagePolicy("PackageJsonProperties", async (json, { file, config, resolve }) => {
|
|
12
|
+
if (config === undefined) {
|
|
43
13
|
return true;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
14
|
+
}
|
|
15
|
+
const { verbatim } = config;
|
|
16
|
+
const failResult = {
|
|
17
|
+
name: PackageJsonProperties.name,
|
|
18
|
+
file,
|
|
19
|
+
autoFixable: true,
|
|
20
|
+
};
|
|
21
|
+
const merged = defu(verbatim, json);
|
|
22
|
+
const result = diff(merged, json);
|
|
23
|
+
const messages = [];
|
|
24
|
+
for (const diffResult of result) {
|
|
25
|
+
messages.push(`Incorrect package.json field value for '${diffResult.path}'.`);
|
|
26
|
+
}
|
|
27
|
+
if (messages.length > 0) {
|
|
28
|
+
if (resolve) {
|
|
29
|
+
const fixResult = {
|
|
30
|
+
...failResult,
|
|
31
|
+
resolved: false,
|
|
32
|
+
};
|
|
33
|
+
await writeJson(file, merged, { spaces: "\t" });
|
|
34
|
+
fixResult.resolved = true;
|
|
35
|
+
return fixResult;
|
|
36
|
+
}
|
|
37
|
+
// There were errors, and we're not resolving them, so return a fail result
|
|
38
|
+
failResult.errorMessage = messages.join("\n");
|
|
39
|
+
return failResult;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
46
43
|
//# sourceMappingURL=PackageJsonProperties.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJsonProperties.js","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PackageJsonProperties.js","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;AAc1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,mBAAmB,CAGtD,uBAAuB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;IACpE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAE5B,MAAM,UAAU,GAAkB;QACjC,IAAI,EAAE,qBAAqB,CAAC,IAAI;QAChC,IAAI;QACJ,WAAW,EAAE,IAAI;KACjB,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAElC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,KAAK,MAAM,UAAU,IAAI,MAAM,EAAE,CAAC;QACjC,QAAQ,CAAC,IAAI,CACZ,2CAA2C,UAAU,CAAC,IAAI,IAAI,CAC9D,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,IAAI,OAAO,EAAE,CAAC;YACb,MAAM,SAAS,GAAoB;gBAClC,GAAG,UAAU;gBACb,QAAQ,EAAE,KAAK;aACf,CAAC;YAEF,MAAM,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAEhD,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC;YAC1B,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,2EAA2E;QAC3E,UAAU,CAAC,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,OAAO,UAAU,CAAC;IACnB,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC,CAAC","sourcesContent":["import { defu } from \"defu\";\nimport jsonfile from \"jsonfile\";\nimport diff from \"microdiff\";\nimport type { PackageJson } from \"type-fest\";\nimport type { PolicyFailure, PolicyFixResult } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\nconst { writeFile: writeJson } = jsonfile;\n\n/**\n * Policy settings for the PackageJsonProperties repo policy.\n *\n * @alpha\n */\nexport interface PackageJsonPropertiesSettings {\n\t/**\n\t * Sets a package.json property to the value provided. The value will be used verbatim.\n\t */\n\tverbatim: PackageJson;\n}\n\n/**\n * A RepoPolicy that checks that package.json properties in packages match expected values.\n *\n * @alpha\n */\nexport const PackageJsonProperties = definePackagePolicy<\n\tPackageJson,\n\tPackageJsonPropertiesSettings | undefined\n>(\"PackageJsonProperties\", async (json, { file, config, resolve }) => {\n\tif (config === undefined) {\n\t\treturn true;\n\t}\n\tconst { verbatim } = config;\n\n\tconst failResult: PolicyFailure = {\n\t\tname: PackageJsonProperties.name,\n\t\tfile,\n\t\tautoFixable: true,\n\t};\n\n\tconst merged = defu(verbatim, json);\n\tconst result = diff(merged, json);\n\n\tconst messages: string[] = [];\n\tfor (const diffResult of result) {\n\t\tmessages.push(\n\t\t\t`Incorrect package.json field value for '${diffResult.path}'.`,\n\t\t);\n\t}\n\n\tif (messages.length > 0) {\n\t\tif (resolve) {\n\t\t\tconst fixResult: PolicyFixResult = {\n\t\t\t\t...failResult,\n\t\t\t\tresolved: false,\n\t\t\t};\n\n\t\t\tawait writeJson(file, merged, { spaces: \"\\t\" });\n\n\t\t\tfixResult.resolved = true;\n\t\t\treturn fixResult;\n\t\t}\n\n\t\t// There were errors, and we're not resolving them, so return a fail result\n\t\tfailResult.errorMessage = messages.join(\"\\n\");\n\t\treturn failResult;\n\t}\n\n\treturn true;\n});\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { RepoPolicy } from "../policy.js";
|
|
2
1
|
/**
|
|
3
2
|
* A RepoPolicy that checks that the repository.directory property in package.json is set correctly. If the repository
|
|
4
3
|
* field is a string instead of an object the package will be ignored.
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
5
6
|
*/
|
|
6
|
-
export declare const PackageJsonRepoDirectoryProperty:
|
|
7
|
+
export declare const PackageJsonRepoDirectoryProperty: import("../policy.js").PolicyDefinition<undefined>;
|
|
7
8
|
//# sourceMappingURL=PackageJsonRepoDirectoryProperty.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJsonRepoDirectoryProperty.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PackageJsonRepoDirectoryProperty.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,oDA+C3C,CAAC"}
|
|
@@ -1,49 +1,52 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { updatePackageJsonFile } from "@fluid-tools/build-infrastructure";
|
|
3
3
|
import path from "pathe";
|
|
4
|
-
import
|
|
5
|
-
const { readFile: readJson } = jsonfile;
|
|
4
|
+
import { definePackagePolicy } from "../policyDefiners/definePackagePolicy.js";
|
|
6
5
|
/**
|
|
7
6
|
* A RepoPolicy that checks that the repository.directory property in package.json is set correctly. If the repository
|
|
8
7
|
* field is a string instead of an object the package will be ignored.
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
9
10
|
*/
|
|
10
|
-
export const PackageJsonRepoDirectoryProperty = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
export const PackageJsonRepoDirectoryProperty = definePackagePolicy("PackageJsonRepoDirectoryProperty", async (json, { file, root, resolve }) => {
|
|
12
|
+
const failResult = {
|
|
13
|
+
name: PackageJsonRepoDirectoryProperty.name,
|
|
14
|
+
file,
|
|
15
|
+
autoFixable: true,
|
|
16
|
+
};
|
|
17
|
+
const fixResult = {
|
|
18
|
+
...failResult,
|
|
19
|
+
resolved: false,
|
|
20
|
+
};
|
|
21
|
+
const pkgDir = path.dirname(file);
|
|
22
|
+
const maybeDir = path.relative(root, pkgDir);
|
|
23
|
+
const relativePkgDir = maybeDir === "" ? undefined : maybeDir;
|
|
24
|
+
if (typeof json.repository === "object") {
|
|
25
|
+
if (json.repository.directory !== relativePkgDir) {
|
|
26
|
+
if (resolve) {
|
|
27
|
+
try {
|
|
28
|
+
updatePackageJsonFile(file, (json) => {
|
|
29
|
+
assert(typeof json.repository === "object");
|
|
30
|
+
if (relativePkgDir === undefined) {
|
|
31
|
+
// biome-ignore lint/performance/noDelete: <explanation>
|
|
32
|
+
delete json.repository.directory;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
32
35
|
json.repository.directory = relativePkgDir;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
catch (error) {
|
|
37
|
-
fixResult.resolved = false;
|
|
38
|
-
fixResult.errorMessage = `${error.message}\n${error.stack}`;
|
|
39
|
-
}
|
|
40
|
-
return fixResult;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
fixResult.resolved = true;
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
catch (error) {
|
|
41
|
+
fixResult.resolved = false;
|
|
42
|
+
fixResult.errorMessage = `${error.message}\n${error.stack}`;
|
|
43
|
+
}
|
|
44
|
+
return fixResult;
|
|
44
45
|
}
|
|
46
|
+
failResult.errorMessage = `repository.directory value is wrong. Expected '${relativePkgDir}', got '${json.repository.directory}'`;
|
|
47
|
+
return failResult;
|
|
45
48
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
});
|
|
49
52
|
//# sourceMappingURL=PackageJsonRepoDirectoryProperty.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJsonRepoDirectoryProperty.js","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,IAAI,MAAM,OAAO,CAAC;AAGzB,OAAO,
|
|
1
|
+
{"version":3,"file":"PackageJsonRepoDirectoryProperty.js","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,IAAI,MAAM,OAAO,CAAC;AAGzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAGjE,kCAAkC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;IAC7E,MAAM,UAAU,GAAkB;QACjC,IAAI,EAAE,gCAAgC,CAAC,IAAI;QAC3C,IAAI;QACJ,WAAW,EAAE,IAAI;KACjB,CAAC;IAEF,MAAM,SAAS,GAAoB;QAClC,GAAG,UAAU;QACb,QAAQ,EAAE,KAAK;KACf,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7C,MAAM,cAAc,GAAG,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;IAE9D,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;QACzC,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,KAAK,cAAc,EAAE,CAAC;YAClD,IAAI,OAAO,EAAE,CAAC;gBACb,IAAI,CAAC;oBACJ,qBAAqB,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;wBACpC,MAAM,CAAC,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC;wBAC5C,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;4BAClC,wDAAwD;4BACxD,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;wBAClC,CAAC;6BAAM,CAAC;4BACP,IAAI,CAAC,UAAU,CAAC,SAAS,GAAG,cAAc,CAAC;wBAC5C,CAAC;oBACF,CAAC,CAAC,CAAC;oBACH,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC;gBAC3B,CAAC;gBAAC,OAAO,KAAc,EAAE,CAAC;oBACzB,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;oBAC3B,SAAS,CAAC,YAAY,GAAG,GAAI,KAAe,CAAC,OAAO,KAClD,KAAe,CAAC,KAClB,EAAE,CAAC;gBACJ,CAAC;gBACD,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,UAAU,CAAC,YAAY,GAAG,kDAAkD,cAAc,WAAW,IAAI,CAAC,UAAU,CAAC,SAAS,GAAG,CAAC;YAClI,OAAO,UAAU,CAAC;QACnB,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { updatePackageJsonFile } from \"@fluid-tools/build-infrastructure\";\nimport path from \"pathe\";\nimport type { PackageJson } from \"type-fest\";\nimport type { PolicyFailure, PolicyFixResult } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/**\n * A RepoPolicy that checks that the repository.directory property in package.json is set correctly. If the repository\n * field is a string instead of an object the package will be ignored.\n *\n * @alpha\n */\nexport const PackageJsonRepoDirectoryProperty = definePackagePolicy<\n\tPackageJson,\n\tundefined\n>(\"PackageJsonRepoDirectoryProperty\", async (json, { file, root, resolve }) => {\n\tconst failResult: PolicyFailure = {\n\t\tname: PackageJsonRepoDirectoryProperty.name,\n\t\tfile,\n\t\tautoFixable: true,\n\t};\n\n\tconst fixResult: PolicyFixResult = {\n\t\t...failResult,\n\t\tresolved: false,\n\t};\n\n\tconst pkgDir = path.dirname(file);\n\tconst maybeDir = path.relative(root, pkgDir);\n\tconst relativePkgDir = maybeDir === \"\" ? undefined : maybeDir;\n\n\tif (typeof json.repository === \"object\") {\n\t\tif (json.repository.directory !== relativePkgDir) {\n\t\t\tif (resolve) {\n\t\t\t\ttry {\n\t\t\t\t\tupdatePackageJsonFile(file, (json) => {\n\t\t\t\t\t\tassert(typeof json.repository === \"object\");\n\t\t\t\t\t\tif (relativePkgDir === undefined) {\n\t\t\t\t\t\t\t// biome-ignore lint/performance/noDelete: <explanation>\n\t\t\t\t\t\t\tdelete json.repository.directory;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tjson.repository.directory = relativePkgDir;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tfixResult.resolved = true;\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tfixResult.resolved = false;\n\t\t\t\t\tfixResult.errorMessage = `${(error as Error).message}\\n${\n\t\t\t\t\t\t(error as Error).stack\n\t\t\t\t\t}`;\n\t\t\t\t}\n\t\t\t\treturn fixResult;\n\t\t\t}\n\t\t\tfailResult.errorMessage = `repository.directory value is wrong. Expected '${relativePkgDir}', got '${json.repository.directory}'`;\n\t\t\treturn failResult;\n\t\t}\n\t}\n\n\treturn true;\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PackageJsonSorted.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonSorted.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,oDAsC7B,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { updatePackageJsonFile } from "@tylerbu/cli-api";
|
|
2
|
+
import { sortPackageJson } from "sort-package-json";
|
|
3
|
+
import { definePackagePolicy } from "../policyDefiners/definePackagePolicy.js";
|
|
4
|
+
/**
|
|
5
|
+
* A repo policy that checks if package.json files in the repo are sorted using sort-package-json.
|
|
6
|
+
*
|
|
7
|
+
* @alpha
|
|
8
|
+
*/
|
|
9
|
+
export const PackageJsonSorted = definePackagePolicy("PackageJsonSorted", async (json, { file, resolve }) => {
|
|
10
|
+
const sortedJson = sortPackageJson(json);
|
|
11
|
+
const isSorted = JSON.stringify(sortedJson) === JSON.stringify(json);
|
|
12
|
+
if (isSorted) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (resolve) {
|
|
16
|
+
try {
|
|
17
|
+
await updatePackageJsonFile(file, (json) => json, { sort: true });
|
|
18
|
+
const result = {
|
|
19
|
+
name: PackageJsonSorted.name,
|
|
20
|
+
file,
|
|
21
|
+
resolved: true,
|
|
22
|
+
};
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
const result = {
|
|
27
|
+
name: PackageJsonSorted.name,
|
|
28
|
+
file,
|
|
29
|
+
resolved: false,
|
|
30
|
+
autoFixable: true,
|
|
31
|
+
errorMessage: error.message,
|
|
32
|
+
};
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const result = {
|
|
38
|
+
name: PackageJsonSorted.name,
|
|
39
|
+
file,
|
|
40
|
+
autoFixable: true,
|
|
41
|
+
};
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=PackageJsonSorted.js.map
|