repopo 0.8.0 → 0.9.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 +46 -0
- package/THIRD-PARTY-LICENSES.txt +4 -3
- package/esm/adapters/fluidFramework.js +8 -3
- package/esm/adapters/fluidFramework.js.map +1 -1
- package/esm/baseCommand.d.ts.map +1 -1
- package/esm/baseCommand.js +2 -1
- package/esm/baseCommand.js.map +1 -1
- package/esm/commands/check.d.ts.map +1 -1
- package/esm/commands/check.js +69 -44
- package/esm/commands/check.js.map +1 -1
- package/esm/commands/list.d.ts.map +1 -1
- package/esm/commands/list.js +3 -1
- package/esm/commands/list.js.map +1 -1
- package/esm/generators.d.ts +30 -2
- package/esm/generators.d.ts.map +1 -1
- package/esm/generators.js +31 -1
- package/esm/generators.js.map +1 -1
- package/esm/index.d.ts +13 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +12 -2
- package/esm/index.js.map +1 -1
- package/esm/makePolicy.d.ts +31 -2
- package/esm/makePolicy.d.ts.map +1 -1
- package/esm/makePolicy.js +27 -13
- package/esm/makePolicy.js.map +1 -1
- package/esm/perf.d.ts +3 -2
- package/esm/perf.d.ts.map +1 -1
- package/esm/perf.js +2 -2
- package/esm/perf.js.map +1 -1
- package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
- package/esm/policies/HtmlFileHeaders.js +11 -7
- package/esm/policies/HtmlFileHeaders.js.map +1 -1
- package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
- package/esm/policies/JsTsFileHeaders.js +11 -7
- package/esm/policies/JsTsFileHeaders.js.map +1 -1
- package/esm/policies/LicenseFileExists.d.ts.map +1 -1
- package/esm/policies/LicenseFileExists.js +22 -18
- package/esm/policies/LicenseFileExists.js.map +1 -1
- package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
- package/esm/policies/NoJsFileExtensions.js +16 -12
- package/esm/policies/NoJsFileExtensions.js.map +1 -1
- package/esm/policies/NoLargeBinaryFiles.d.ts.map +1 -1
- package/esm/policies/NoLargeBinaryFiles.js +35 -31
- package/esm/policies/NoLargeBinaryFiles.js.map +1 -1
- package/esm/policies/NoPrivateWorkspaceDependencies.d.ts.map +1 -1
- package/esm/policies/NoPrivateWorkspaceDependencies.js +53 -45
- package/esm/policies/NoPrivateWorkspaceDependencies.js.map +1 -1
- package/esm/policies/PackageAllowedScopes.d.ts.map +1 -1
- package/esm/policies/PackageAllowedScopes.js +45 -40
- package/esm/policies/PackageAllowedScopes.js.map +1 -1
- package/esm/policies/PackageEsmType.d.ts.map +1 -1
- package/esm/policies/PackageEsmType.js +48 -44
- package/esm/policies/PackageEsmType.js.map +1 -1
- package/esm/policies/PackageFolderName.d.ts.map +1 -1
- package/esm/policies/PackageFolderName.js +38 -34
- package/esm/policies/PackageFolderName.js.map +1 -1
- package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
- package/esm/policies/PackageJsonProperties.js +36 -31
- package/esm/policies/PackageJsonProperties.js.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.js +41 -38
- package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
- package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
- package/esm/policies/PackageJsonSorted.js +40 -36
- package/esm/policies/PackageJsonSorted.js.map +1 -1
- package/esm/policies/PackageLicense.d.ts.map +1 -1
- package/esm/policies/PackageLicense.js +58 -54
- package/esm/policies/PackageLicense.js.map +1 -1
- package/esm/policies/PackagePrivateField.d.ts.map +1 -1
- package/esm/policies/PackagePrivateField.js +58 -54
- package/esm/policies/PackagePrivateField.js.map +1 -1
- package/esm/policies/PackageReadme.d.ts.map +1 -1
- package/esm/policies/PackageReadme.js +30 -26
- package/esm/policies/PackageReadme.js.map +1 -1
- package/esm/policies/PackageScripts.d.ts.map +1 -1
- package/esm/policies/PackageScripts.js +39 -35
- package/esm/policies/PackageScripts.js.map +1 -1
- package/esm/policies/PackageTestScripts.d.ts.map +1 -1
- package/esm/policies/PackageTestScripts.js +46 -40
- package/esm/policies/PackageTestScripts.js.map +1 -1
- package/esm/policies/RequiredGitignorePatterns.d.ts.map +1 -1
- package/esm/policies/RequiredGitignorePatterns.js +20 -15
- package/esm/policies/RequiredGitignorePatterns.js.map +1 -1
- package/esm/policy.d.ts +32 -7
- package/esm/policy.d.ts.map +1 -1
- package/esm/policy.js +18 -9
- package/esm/policy.js.map +1 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +43 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.js +16 -4
- package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -1
- package/esm/policyDefiners/definePackagePolicy.d.ts +43 -2
- package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -1
- package/esm/policyDefiners/definePackagePolicy.js +40 -5
- package/esm/policyDefiners/definePackagePolicy.js.map +1 -1
- package/esm/tsdoc-metadata.json +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +6 -4
package/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tool for enforcing repository policies and standards across codebases.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Repopo provides a framework for defining and enforcing policies across repositories,
|
|
6
|
+
* such as file headers, package.json consistency, and other code standards.
|
|
7
|
+
* It can be used as a CLI tool or integrated into CI/CD pipelines.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
1
11
|
export { run } from "@oclif/core";
|
|
2
12
|
export { type FluidAdapterOptions, type FluidHandler, fromFluidHandlers, } from "./adapters/fluidFramework.js";
|
|
3
13
|
export type { RepopoConfig, } from "./config.js";
|
|
4
|
-
export { makePolicy } from "./makePolicy.js";
|
|
14
|
+
export { makePolicy, makePolicyDefinition, type PolicyDefinitionInput, } from "./makePolicy.js";
|
|
5
15
|
export type { PolicyDefinition, PolicyFailure, PolicyFixResult, PolicyFunctionArguments, PolicyHandler, PolicyHandlerResult, PolicyInstance, PolicyInstanceSettings, PolicyName, PolicyStandaloneResolver, } from "./policy.js";
|
|
6
|
-
export {
|
|
7
|
-
export { definePackagePolicy as generatePackagePolicy, type PackageJsonHandler, } from "./policyDefiners/definePackagePolicy.js";
|
|
16
|
+
export { type DefineFileHeaderPolicyArgs, defineFileHeaderPolicy, type FileHeaderGeneratorConfig, type FileHeaderPolicyConfig, } from "./policyDefiners/defineFileHeaderPolicy.js";
|
|
17
|
+
export { type DefinePackagePolicyArgs, definePackagePolicy as generatePackagePolicy, type PackageJsonHandler, } from "./policyDefiners/definePackagePolicy.js";
|
|
8
18
|
//# sourceMappingURL=index.d.ts.map
|
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;AAClC,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAEX,YAAY,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAEX,YAAY,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,UAAU,EACV,oBAAoB,EACpB,KAAK,qBAAqB,GAC1B,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACX,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,sBAAsB,EACtB,UAAU,EACV,wBAAwB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,KAAK,0BAA0B,EAC/B,sBAAsB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,GAC3B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,KAAK,uBAAuB,EAC5B,mBAAmB,IAAI,qBAAqB,EAC5C,KAAK,kBAAkB,GACvB,MAAM,yCAAyC,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tool for enforcing repository policies and standards across codebases.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Repopo provides a framework for defining and enforcing policies across repositories,
|
|
6
|
+
* such as file headers, package.json consistency, and other code standards.
|
|
7
|
+
* It can be used as a CLI tool or integrated into CI/CD pipelines.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
1
11
|
export { run } from "@oclif/core";
|
|
2
12
|
export { fromFluidHandlers, } from "./adapters/fluidFramework.js";
|
|
3
|
-
export { makePolicy } from "./makePolicy.js";
|
|
4
|
-
export { defineFileHeaderPolicy
|
|
13
|
+
export { makePolicy, makePolicyDefinition, } from "./makePolicy.js";
|
|
14
|
+
export { defineFileHeaderPolicy, } from "./policyDefiners/defineFileHeaderPolicy.js";
|
|
5
15
|
export { definePackagePolicy as generatePackagePolicy, } from "./policyDefiners/definePackagePolicy.js";
|
|
6
16
|
//# 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;AAClC,OAAO,EAGN,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAGN,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EACN,UAAU,EACV,oBAAoB,GAEpB,MAAM,iBAAiB,CAAC;AAazB,OAAO,EAEN,sBAAsB,GAGtB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAEN,mBAAmB,IAAI,qBAAqB,GAE5C,MAAM,yCAAyC,CAAC","sourcesContent":["/**\n * A tool for enforcing repository policies and standards across codebases.\n *\n * @remarks\n * Repopo provides a framework for defining and enforcing policies across repositories,\n * such as file headers, package.json consistency, and other code standards.\n * It can be used as a CLI tool or integrated into CI/CD pipelines.\n *\n * @packageDocumentation\n */\n\nexport { run } from \"@oclif/core\";\nexport {\n\ttype FluidAdapterOptions,\n\ttype FluidHandler,\n\tfromFluidHandlers,\n} from \"./adapters/fluidFramework.js\";\nexport type {\n\t// PolicyList,\n\tRepopoConfig,\n} from \"./config.js\";\nexport {\n\tmakePolicy,\n\tmakePolicyDefinition,\n\ttype PolicyDefinitionInput,\n} from \"./makePolicy.js\";\nexport type {\n\tPolicyDefinition,\n\tPolicyFailure,\n\tPolicyFixResult,\n\tPolicyFunctionArguments,\n\tPolicyHandler,\n\tPolicyHandlerResult,\n\tPolicyInstance,\n\tPolicyInstanceSettings,\n\tPolicyName,\n\tPolicyStandaloneResolver,\n} from \"./policy.js\";\nexport {\n\ttype DefineFileHeaderPolicyArgs,\n\tdefineFileHeaderPolicy,\n\ttype FileHeaderGeneratorConfig,\n\ttype FileHeaderPolicyConfig,\n} from \"./policyDefiners/defineFileHeaderPolicy.js\";\nexport {\n\ttype DefinePackagePolicyArgs,\n\tdefinePackagePolicy as generatePackagePolicy,\n\ttype PackageJsonHandler,\n} from \"./policyDefiners/definePackagePolicy.js\";\n"]}
|
package/esm/makePolicy.d.ts
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
|
-
import type { PolicyDefinition,
|
|
2
|
-
|
|
1
|
+
import type { PolicyDefinition, PolicyInstance, PolicyInstanceSettings } from "./policy.js";
|
|
2
|
+
/**
|
|
3
|
+
* Input arguments for creating a policy definition.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This type is identical to {@link PolicyDefinition} but is used as the input type
|
|
7
|
+
* for {@link makePolicyDefinition} to make the API more explicit.
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
export type PolicyDefinitionInput<C = undefined> = PolicyDefinition<C>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a {@link PolicyDefinition} from the provided arguments.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This function accepts an object with all policy properties, making it easier
|
|
17
|
+
* to add new optional properties in the future without breaking changes.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const MyPolicy = makePolicyDefinition({
|
|
22
|
+
* name: "MyPolicy",
|
|
23
|
+
* description: "Ensures files follow conventions",
|
|
24
|
+
* match: /\.ts$/,
|
|
25
|
+
* handler: async ({ file }) => true,
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @alpha
|
|
30
|
+
*/
|
|
31
|
+
export declare function makePolicyDefinition<C = undefined>(args: PolicyDefinitionInput<C>): PolicyDefinition<C>;
|
|
3
32
|
/**
|
|
4
33
|
* Combine a {@link PolicyDefinition} with a policy-specific config and other settings to produce a {@link PolicyInstance}.
|
|
5
34
|
*
|
package/esm/makePolicy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makePolicy.d.ts","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,
|
|
1
|
+
{"version":3,"file":"makePolicy.d.ts","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,MAAM,aAAa,CAAC;AAErB;;;;;;;;GAQG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,SAAS,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAEvE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,SAAS,EACjD,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAC5B,gBAAgB,CAAC,CAAC,CAAC,CASrB;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"}
|
package/esm/makePolicy.js
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Creates a {@link PolicyDefinition} from the provided arguments.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This function accepts an object with all policy properties, making it easier
|
|
6
|
+
* to add new optional properties in the future without breaking changes.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const MyPolicy = makePolicyDefinition({
|
|
11
|
+
* name: "MyPolicy",
|
|
12
|
+
* description: "Ensures files follow conventions",
|
|
13
|
+
* match: /\.ts$/,
|
|
14
|
+
* handler: async ({ file }) => true,
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @alpha
|
|
19
|
+
*/
|
|
20
|
+
export function makePolicyDefinition(args) {
|
|
21
|
+
return {
|
|
22
|
+
name: args.name,
|
|
23
|
+
description: args.description,
|
|
24
|
+
match: args.match,
|
|
25
|
+
handler: args.handler,
|
|
26
|
+
defaultConfig: args.defaultConfig,
|
|
27
|
+
resolver: args.resolver,
|
|
11
28
|
};
|
|
12
29
|
}
|
|
13
|
-
export function makePolicyDefinition(name, match, handler, defaultConfig, description, resolver) {
|
|
14
|
-
return generatePolicyFunction(name, description)(match, handler, defaultConfig, resolver);
|
|
15
|
-
}
|
|
16
30
|
/**
|
|
17
31
|
* Combine a {@link PolicyDefinition} with a policy-specific config and other settings to produce a {@link PolicyInstance}.
|
|
18
32
|
*
|
package/esm/makePolicy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makePolicy.js","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"makePolicy.js","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,oBAAoB,CACnC,IAA8B;IAE9B,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;KACvB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACzB,UAA+B,EAC/B,MAAU,EACV,QAAoC;IAEpC,OAAO;QACN,GAAG,UAAU;QACb,GAAG,QAAQ;QACX,MAAM;KACsB,CAAC;AAC/B,CAAC","sourcesContent":["import type {\n\tPolicyDefinition,\n\tPolicyInstance,\n\tPolicyInstanceSettings,\n} from \"./policy.js\";\n\n/**\n * Input arguments for creating a policy definition.\n *\n * @remarks\n * This type is identical to {@link PolicyDefinition} but is used as the input type\n * for {@link makePolicyDefinition} to make the API more explicit.\n *\n * @alpha\n */\nexport type PolicyDefinitionInput<C = undefined> = PolicyDefinition<C>;\n\n/**\n * Creates a {@link PolicyDefinition} from the provided arguments.\n *\n * @remarks\n * This function accepts an object with all policy properties, making it easier\n * to add new optional properties in the future without breaking changes.\n *\n * @example\n * ```typescript\n * const MyPolicy = makePolicyDefinition({\n * name: \"MyPolicy\",\n * description: \"Ensures files follow conventions\",\n * match: /\\.ts$/,\n * handler: async ({ file }) => true,\n * });\n * ```\n *\n * @alpha\n */\nexport function makePolicyDefinition<C = undefined>(\n\targs: PolicyDefinitionInput<C>,\n): PolicyDefinition<C> {\n\treturn {\n\t\tname: args.name,\n\t\tdescription: args.description,\n\t\tmatch: args.match,\n\t\thandler: args.handler,\n\t\tdefaultConfig: args.defaultConfig,\n\t\tresolver: args.resolver,\n\t};\n}\n\n/**\n * Combine a {@link PolicyDefinition} with a policy-specific config and other settings to produce a {@link PolicyInstance}.\n *\n * @alpha\n */\nexport function makePolicy<C>(\n\tdefinition: PolicyDefinition<C>,\n\tconfig?: C,\n\tsettings?: PolicyInstanceSettings<C>,\n): PolicyInstance<C> {\n\treturn {\n\t\t...definition,\n\t\t...settings,\n\t\tconfig,\n\t} satisfies PolicyInstance<C>;\n}\n"]}
|
package/esm/perf.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Logger } from "@tylerbu/cli-api";
|
|
2
|
+
import type { Operation } from "effection";
|
|
2
3
|
import type { PolicyName } from "./policy.js";
|
|
3
|
-
export type PolicyAction = "check" | "resolve";
|
|
4
|
+
export type PolicyAction = "check" | "resolve" | "handle";
|
|
4
5
|
/**
|
|
5
6
|
* Stores performance data for each handler. Used to collect and display performance stats.
|
|
6
7
|
*/
|
|
@@ -10,6 +11,6 @@ export interface PolicyHandlerPerfStats {
|
|
|
10
11
|
data: Map<PolicyAction, Map<PolicyName, number>>;
|
|
11
12
|
}
|
|
12
13
|
export declare function newPerfStats(): PolicyHandlerPerfStats;
|
|
13
|
-
export declare function runWithPerf<T>(name: string, action: PolicyAction, stats: PolicyHandlerPerfStats, run: () =>
|
|
14
|
+
export declare function runWithPerf<T>(name: string, action: PolicyAction, stats: PolicyHandlerPerfStats, run: () => Operation<T>): Operation<T>;
|
|
14
15
|
export declare function logStats(stats: PolicyHandlerPerfStats, log: Logger): void;
|
|
15
16
|
//# sourceMappingURL=perf.d.ts.map
|
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,OAAO,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,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE1D;;GAEG;AACH,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,wBAAiB,WAAW,CAAC,CAAC,EAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,sBAAsB,EAC7B,GAAG,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,GACrB,SAAS,CAAC,CAAC,CAAC,CAWd;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,sBAAsB,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAWzE"}
|
package/esm/perf.js
CHANGED
|
@@ -5,11 +5,11 @@ export function newPerfStats() {
|
|
|
5
5
|
data: new Map(),
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
|
-
export
|
|
8
|
+
export function* runWithPerf(name, action, stats, run) {
|
|
9
9
|
const actionMap = stats.data.get(action) ?? new Map();
|
|
10
10
|
let dur = actionMap.get(name) ?? 0;
|
|
11
11
|
const start = Date.now();
|
|
12
|
-
const result =
|
|
12
|
+
const result = yield* run();
|
|
13
13
|
dur += Date.now() - start;
|
|
14
14
|
actionMap.set(name, dur);
|
|
15
15
|
stats.data.set(action, actionMap);
|
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":"AAeA,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,SAAS,CAAC,CAAC,WAAW,CAC3B,IAAY,EACZ,MAAoB,EACpB,KAA6B,EAC7B,GAAuB;IAEvB,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,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC;IAC5B,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,oBAAoB;QACjD,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,SAAS,cAAc,KAAK,CAAC,KAAK,QAAQ,CAClE,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,OAAO,OAAO,KAAK,GAAG,IAAI,CAAC,CAAC;QACrC,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import type { Logger } from \"@tylerbu/cli-api\";\nimport type { Operation } from \"effection\";\nimport type { PolicyName } from \"./policy.js\";\n\nexport type PolicyAction = \"check\" | \"resolve\" | \"handle\";\n\n/**\n * Stores performance data for each handler. Used to collect and display performance stats.\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 function* runWithPerf<T>(\n\tname: string,\n\taction: PolicyAction,\n\tstats: PolicyHandlerPerfStats,\n\trun: () => Operation<T>,\n): Operation<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 = yield* 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} files processed, ` +\n\t\t\t`${stats.count - stats.processed} 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(` ${handler}: ${dur}ms`);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HtmlFileHeaders.d.ts","sourceRoot":"","sources":["../../src/policies/HtmlFileHeaders.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,sBAAsB,EAC3B,MAAM,6CAA6C,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"HtmlFileHeaders.d.ts","sourceRoot":"","sources":["../../src/policies/HtmlFileHeaders.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,sBAAsB,EAC3B,MAAM,6CAA6C,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,eAAe,iEAkB1B,CAAC"}
|
|
@@ -5,13 +5,17 @@ import { defineFileHeaderPolicy, } from "../policyDefiners/defineFileHeaderPolic
|
|
|
5
5
|
*
|
|
6
6
|
* @alpha
|
|
7
7
|
*/
|
|
8
|
-
export const HtmlFileHeaders = defineFileHeaderPolicy(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
export const HtmlFileHeaders = defineFileHeaderPolicy({
|
|
9
|
+
name: "HtmlFileHeaders",
|
|
10
|
+
description: "Ensures HTML files have the configured header comment.",
|
|
11
|
+
config: {
|
|
12
|
+
match: /(^|\/)[^/]+\.[mc]?[jt]sx?$/i,
|
|
13
|
+
lineStart: /<!-- /, // Lines begin with '<!-- '
|
|
14
|
+
lineEnd: / -->\r?\n/, // Lines end with ' -->' followed by CRLF or LF
|
|
15
|
+
replacer: (content, { headerText }) => {
|
|
16
|
+
const newContent = `<!-- ${headerText.replace(newline, ` -->${newline}<!-- `)} -->${newline}${newline}${content}`;
|
|
17
|
+
return newContent;
|
|
18
|
+
},
|
|
15
19
|
},
|
|
16
20
|
});
|
|
17
21
|
//# sourceMappingURL=HtmlFileHeaders.js.map
|
|
@@ -1 +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,EACN,sBAAsB,GAEtB,MAAM,6CAA6C,CAAC;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAC,iBAAiB,EAAE;
|
|
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,EACN,sBAAsB,GAEtB,MAAM,6CAA6C,CAAC;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAC;IACrD,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,wDAAwD;IACrE,MAAM,EAAE;QACP,KAAK,EAAE,6BAA6B;QACpC,SAAS,EAAE,OAAO,EAAE,2BAA2B;QAC/C,OAAO,EAAE,WAAW,EAAE,+CAA+C;QACrE,QAAQ,EAAE,CACT,OAAe,EACf,EAAE,UAAU,EAA0B,EAC7B,EAAE;YACX,MAAM,UAAU,GAAG,QAAQ,UAAU,CAAC,OAAO,CAC5C,OAAO,EACP,OAAO,OAAO,OAAO,CACrB,OAAO,OAAO,GAAG,OAAO,GAAG,OAAO,EAAE,CAAC;YACtC,OAAO,UAAU,CAAC;QACnB,CAAC;KACD;CACD,CAAC,CAAC","sourcesContent":["import { EOL as newline } from \"node:os\";\nimport {\n\tdefineFileHeaderPolicy,\n\ttype FileHeaderPolicyConfig,\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({\n\tname: \"HtmlFileHeaders\",\n\tdescription: \"Ensures HTML files have the configured header comment.\",\n\tconfig: {\n\t\tmatch: /(^|\\/)[^/]+\\.[mc]?[jt]sx?$/i,\n\t\tlineStart: /<!-- /, // Lines begin with '<!-- '\n\t\tlineEnd: / -->\\r?\\n/, // Lines end with ' -->' followed by CRLF or LF\n\t\treplacer: (\n\t\t\tcontent: string,\n\t\t\t{ headerText }: FileHeaderPolicyConfig,\n\t\t): string => {\n\t\t\tconst newContent = `<!-- ${headerText.replace(\n\t\t\t\tnewline,\n\t\t\t\t` -->${newline}<!-- `,\n\t\t\t)} -->${newline}${newline}${content}`;\n\t\t\treturn newContent;\n\t\t},\n\t},\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsTsFileHeaders.d.ts","sourceRoot":"","sources":["../../src/policies/JsTsFileHeaders.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,sBAAsB,EAC3B,MAAM,6CAA6C,CAAC;AAkBrD;;;;GAIG;AACH,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"JsTsFileHeaders.d.ts","sourceRoot":"","sources":["../../src/policies/JsTsFileHeaders.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,sBAAsB,EAC3B,MAAM,6CAA6C,CAAC;AAkBrD;;;;GAIG;AACH,eAAO,MAAM,eAAe,iEAY1B,CAAC"}
|
|
@@ -13,12 +13,16 @@ const jsTsReplacer = (prevContent, { headerText }) => {
|
|
|
13
13
|
*
|
|
14
14
|
* @alpha
|
|
15
15
|
*/
|
|
16
|
-
export const JsTsFileHeaders = defineFileHeaderPolicy(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
export const JsTsFileHeaders = defineFileHeaderPolicy({
|
|
17
|
+
name: "JsTsFileHeaders",
|
|
18
|
+
description: "Ensures JavaScript and TypeScript source files have the configured header comment.",
|
|
19
|
+
config: {
|
|
20
|
+
match: /(^|\/)[^/]+\.[mc]?[jt]sx?$/i,
|
|
21
|
+
headerStart: /(#![^\n]*\r?\n)?\/\*!\r?\n/, // Begins with optional hashbang followed by '/*!'
|
|
22
|
+
lineStart: / \* /, // Subsequent lines begins with ' * '
|
|
23
|
+
lineEnd: /\r?\n/, // Subsequent lines end with CRLF or LF
|
|
24
|
+
headerEnd: / \*\/\r?\n\r?\n/, // Header ends with ' */' on a line by itself, followed by another newline
|
|
25
|
+
replacer: jsTsReplacer,
|
|
26
|
+
},
|
|
23
27
|
});
|
|
24
28
|
//# sourceMappingURL=JsTsFileHeaders.js.map
|
|
@@ -1 +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,EACN,sBAAsB,GAEtB,MAAM,6CAA6C,CAAC;AAErD,MAAM,YAAY,GAAG,CACpB,WAAmB,EACnB,EAAE,UAAU,EAA0B,EAC7B,EAAE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MAAM,EAAE;QACP,KAAK,EAAE,6BAA6B;QACpC,WAAW,EAAE,4BAA4B,EAAE,kDAAkD;QAC7F,SAAS,EAAE,MAAM,EAAE,qCAAqC;QACxD,OAAO,EAAE,OAAO,EAAE,uCAAuC;QACzD,SAAS,EAAE,iBAAiB,EAAE,0EAA0E;QACxG,QAAQ,EAAE,YAAY;KACtB;CACD,CAAC,CAAC","sourcesContent":["import { EOL as newline } from \"node:os\";\nimport {\n\tdefineFileHeaderPolicy,\n\ttype FileHeaderPolicyConfig,\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({\n\tname: \"JsTsFileHeaders\",\n\tdescription:\n\t\t\"Ensures JavaScript and TypeScript source files have the configured header comment.\",\n\tconfig: {\n\t\tmatch: /(^|\\/)[^/]+\\.[mc]?[jt]sx?$/i,\n\t\theaderStart: /(#![^\\n]*\\r?\\n)?\\/\\*!\\r?\\n/, // Begins with optional hashbang followed by '/*!'\n\t\tlineStart: / \\* /, // Subsequent lines begins with ' * '\n\t\tlineEnd: /\\r?\\n/, // Subsequent lines end with CRLF or LF\n\t\theaderEnd: / \\*\\/\\r?\\n\\r?\\n/, // Header ends with ' */' on a line by itself, followed by another newline\n\t\treplacer: jsTsReplacer,\n\t},\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LicenseFileExists.d.ts","sourceRoot":"","sources":["../../src/policies/LicenseFileExists.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,cAAc,CAAC;AAEpE;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACzC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAgBD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,gBAAgB,CAAC,yBAAyB,
|
|
1
|
+
{"version":3,"file":"LicenseFileExists.d.ts","sourceRoot":"","sources":["../../src/policies/LicenseFileExists.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,cAAc,CAAC;AAEpE;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACzC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAgBD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,gBAAgB,CAAC,yBAAyB,CA8BvE,CAAC"}
|
|
@@ -20,23 +20,27 @@ const DEFAULT_LICENSE_NAMES = [
|
|
|
20
20
|
*
|
|
21
21
|
* @alpha
|
|
22
22
|
*/
|
|
23
|
-
export const LicenseFileExists = makePolicyDefinition(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
export const LicenseFileExists = makePolicyDefinition({
|
|
24
|
+
name: "LicenseFileExists",
|
|
25
|
+
description: "Ensures a LICENSE file exists in the repository root for open source projects.",
|
|
26
|
+
// Only trigger on package.json to check once per repository
|
|
27
|
+
match: /^package\.json$/,
|
|
28
|
+
handler: async ({ root, config }) => {
|
|
29
|
+
const acceptedNames = config?.acceptedNames ?? DEFAULT_LICENSE_NAMES;
|
|
30
|
+
// Check if any of the accepted license files exist in the root
|
|
31
|
+
const hasLicenseFile = acceptedNames.some((name) => existsSync(path.join(root, name)));
|
|
32
|
+
if (hasLicenseFile) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
const result = {
|
|
36
|
+
name: LicenseFileExists.name,
|
|
37
|
+
file: ".", // Report against repository root
|
|
38
|
+
autoFixable: false,
|
|
39
|
+
errorMessages: [
|
|
40
|
+
`No LICENSE file found in repository root. Expected one of: ${acceptedNames.join(", ")}`,
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
return result;
|
|
44
|
+
},
|
|
41
45
|
});
|
|
42
46
|
//# sourceMappingURL=LicenseFileExists.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LicenseFileExists.js","sourceRoot":"","sources":["../../src/policies/LicenseFileExists.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAexD;;GAEG;AACH,MAAM,qBAAqB,GAAG;IAC7B,SAAS;IACT,aAAa;IACb,YAAY;IACZ,aAAa;IACb,SAAS;IACT,aAAa;IACb,YAAY;IACZ,aAAa;CACb,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAC7B,oBAAoB,
|
|
1
|
+
{"version":3,"file":"LicenseFileExists.js","sourceRoot":"","sources":["../../src/policies/LicenseFileExists.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAexD;;GAEG;AACH,MAAM,qBAAqB,GAAG;IAC7B,SAAS;IACT,aAAa;IACb,YAAY;IACZ,aAAa;IACb,SAAS;IACT,aAAa;IACb,YAAY;IACZ,aAAa;CACb,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAC7B,oBAAoB,CAAC;IACpB,IAAI,EAAE,mBAAmB;IACzB,WAAW,EACV,gFAAgF;IACjF,4DAA4D;IAC5D,KAAK,EAAE,iBAAiB;IACxB,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QACnC,MAAM,aAAa,GAAG,MAAM,EAAE,aAAa,IAAI,qBAAqB,CAAC;QAErE,+DAA+D;QAC/D,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAClD,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CACjC,CAAC;QAEF,IAAI,cAAc,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,MAAM,GAAkB;YAC7B,IAAI,EAAE,iBAAiB,CAAC,IAAI;YAC5B,IAAI,EAAE,GAAG,EAAE,iCAAiC;YAC5C,WAAW,EAAE,KAAK;YAClB,aAAa,EAAE;gBACd,8DAA8D,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;aACxF;SACD,CAAC;QAEF,OAAO,MAAM,CAAC;IACf,CAAC;CACD,CAAC,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport path from \"pathe\";\nimport { makePolicyDefinition } from \"../makePolicy.js\";\nimport type { PolicyDefinition, PolicyFailure } from \"../policy.js\";\n\n/**\n * Policy settings for the LicenseFileExists repo policy.\n *\n * @alpha\n */\nexport interface LicenseFileExistsSettings {\n\t/**\n\t * Array of acceptable license file names. Defaults to common variations.\n\t */\n\tacceptedNames?: string[];\n}\n\n/**\n * Default license file names to check for.\n */\nconst DEFAULT_LICENSE_NAMES = [\n\t\"LICENSE\",\n\t\"LICENSE.txt\",\n\t\"LICENSE.md\",\n\t\"LICENSE.rst\",\n\t\"LICENCE\",\n\t\"LICENCE.txt\",\n\t\"LICENCE.md\",\n\t\"LICENCE.rst\",\n];\n\n/**\n * A repo policy that checks that a LICENSE file exists in the repository root.\n * This is essential for open source projects to clarify usage rights and obligations.\n *\n * @alpha\n */\nexport const LicenseFileExists: PolicyDefinition<LicenseFileExistsSettings> =\n\tmakePolicyDefinition({\n\t\tname: \"LicenseFileExists\",\n\t\tdescription:\n\t\t\t\"Ensures a LICENSE file exists in the repository root for open source projects.\",\n\t\t// Only trigger on package.json to check once per repository\n\t\tmatch: /^package\\.json$/,\n\t\thandler: async ({ root, config }) => {\n\t\t\tconst acceptedNames = config?.acceptedNames ?? DEFAULT_LICENSE_NAMES;\n\n\t\t\t// Check if any of the accepted license files exist in the root\n\t\t\tconst hasLicenseFile = acceptedNames.some((name) =>\n\t\t\t\texistsSync(path.join(root, name)),\n\t\t\t);\n\n\t\t\tif (hasLicenseFile) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst result: PolicyFailure = {\n\t\t\t\tname: LicenseFileExists.name,\n\t\t\t\tfile: \".\", // Report against repository root\n\t\t\t\tautoFixable: false,\n\t\t\t\terrorMessages: [\n\t\t\t\t\t`No LICENSE file found in repository root. Expected one of: ${acceptedNames.join(\", \")}`,\n\t\t\t\t],\n\t\t\t};\n\n\t\t\treturn result;\n\t\t},\n\t});\n"]}
|
|
@@ -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":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,cAAc,CAAC;AAEpE;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBAiB/B,CAAC"}
|
|
@@ -8,17 +8,21 @@ import { makePolicyDefinition } from "../makePolicy.js";
|
|
|
8
8
|
*
|
|
9
9
|
* @alpha
|
|
10
10
|
*/
|
|
11
|
-
export const NoJsFileExtensions = makePolicyDefinition(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
export const NoJsFileExtensions = makePolicyDefinition({
|
|
12
|
+
name: "NoJsFileExtensions",
|
|
13
|
+
description: "Prevents ambiguous .js files by requiring explicit .mjs or .cjs extensions based on module format.",
|
|
14
|
+
match: /(^|\/)[^/]+\.js$/i,
|
|
15
|
+
// biome-ignore lint/correctness/useYield: no yield needed
|
|
16
|
+
handler: function* ({ file }) {
|
|
17
|
+
return {
|
|
18
|
+
name: NoJsFileExtensions.name,
|
|
19
|
+
file,
|
|
20
|
+
autoFixable: false,
|
|
21
|
+
errorMessages: [
|
|
22
|
+
"JavaScript files should have a .cjs or .mjs file extension based on the module format of the file.",
|
|
23
|
+
],
|
|
24
|
+
manualFix: "Rename the file to have a .cjs or .mjs file extension.",
|
|
25
|
+
};
|
|
26
|
+
},
|
|
23
27
|
});
|
|
24
28
|
//# 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":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAqB,oBAAoB,CAAC;IACxE,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EACV,oGAAoG;IACrG,KAAK,EAAE,mBAAmB;IAC1B,0DAA0D;IAC1D,OAAO,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE;QAC3B,OAAO;YACN,IAAI,EAAE,kBAAkB,CAAC,IAAI;YAC7B,IAAI;YACJ,WAAW,EAAE,KAAK;YAClB,aAAa,EAAE;gBACd,oGAAoG;aACpG;YACD,SAAS,EAAE,wDAAwD;SACnE,CAAC;IACH,CAAC;CACD,CAAC,CAAC","sourcesContent":["import type { Operation } from \"effection\";\nimport { 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\tname: \"NoJsFileExtensions\",\n\tdescription:\n\t\t\"Prevents ambiguous .js files by requiring explicit .mjs or .cjs extensions based on module format.\",\n\tmatch: /(^|\\/)[^/]+\\.js$/i,\n\t// biome-ignore lint/correctness/useYield: no yield needed\n\thandler: function* ({ file }): Operation<PolicyFailure> {\n\t\treturn {\n\t\t\tname: NoJsFileExtensions.name,\n\t\t\tfile,\n\t\t\tautoFixable: false,\n\t\t\terrorMessages: [\n\t\t\t\t\"JavaScript files should have a .cjs or .mjs file extension based on the module format of the file.\",\n\t\t\t],\n\t\t\tmanualFix: \"Rename the file to have a .cjs or .mjs file extension.\",\n\t\t};\n\t},\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoLargeBinaryFiles.d.ts","sourceRoot":"","sources":["../../src/policies/NoLargeBinaryFiles.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,cAAc,CAAC;AAEpE;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE7B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AA2FD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBAAgB,CAAC,0BAA0B,
|
|
1
|
+
{"version":3,"file":"NoLargeBinaryFiles.d.ts","sourceRoot":"","sources":["../../src/policies/NoLargeBinaryFiles.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,cAAc,CAAC;AAEpE;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE7B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AA2FD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBAAgB,CAAC,0BAA0B,CA8CzE,CAAC"}
|
|
@@ -82,39 +82,43 @@ function formatBytes(bytes) {
|
|
|
82
82
|
*
|
|
83
83
|
* @alpha
|
|
84
84
|
*/
|
|
85
|
-
export const NoLargeBinaryFiles = makePolicyDefinition(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
85
|
+
export const NoLargeBinaryFiles = makePolicyDefinition({
|
|
86
|
+
name: "NoLargeBinaryFiles",
|
|
87
|
+
description: "Prevents large binary files from being committed to avoid repository bloat; consider using Git LFS for large assets.",
|
|
88
|
+
// Match all files
|
|
89
|
+
match: /.*/,
|
|
90
|
+
handler: async ({ file, root, config }) => {
|
|
91
|
+
const maxSizeBytes = config?.maxSizeBytes ?? DEFAULT_MAX_SIZE;
|
|
92
|
+
const excludeExtensions = config?.excludeExtensions ?? DEFAULT_EXCLUDE_EXTENSIONS;
|
|
93
|
+
const excludePatterns = config?.excludePatterns ?? [];
|
|
94
|
+
// Skip excluded files
|
|
95
|
+
if (isExcluded(file, excludePatterns, excludeExtensions)) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const filePath = path.resolve(root, file);
|
|
100
|
+
const stats = statSync(filePath);
|
|
101
|
+
// Skip directories
|
|
102
|
+
if (stats.isDirectory()) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (stats.size > maxSizeBytes) {
|
|
106
|
+
const result = {
|
|
107
|
+
name: NoLargeBinaryFiles.name,
|
|
108
|
+
file,
|
|
109
|
+
autoFixable: false,
|
|
110
|
+
errorMessages: [
|
|
111
|
+
`File is too large: ${formatBytes(stats.size)} (max: ${formatBytes(maxSizeBytes)}). Consider using Git LFS or removing the file.`,
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
100
116
|
return true;
|
|
101
117
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
file,
|
|
106
|
-
autoFixable: false,
|
|
107
|
-
errorMessages: [
|
|
108
|
-
`File is too large: ${formatBytes(stats.size)} (max: ${formatBytes(maxSizeBytes)}). Consider using Git LFS or removing the file.`,
|
|
109
|
-
],
|
|
110
|
-
};
|
|
111
|
-
return result;
|
|
118
|
+
catch (_error) {
|
|
119
|
+
// File doesn't exist or can't be accessed, skip it
|
|
120
|
+
return true;
|
|
112
121
|
}
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
catch (_error) {
|
|
116
|
-
// File doesn't exist or can't be accessed, skip it
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
122
|
+
},
|
|
119
123
|
});
|
|
120
124
|
//# sourceMappingURL=NoLargeBinaryFiles.js.map
|
|
@@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EAAE,CAAC;QAEtD,sBAAsB;QACtB,IAAI,UAAU,CAAC,IAAI,EAAE,eAAe,EAAE,iBAAiB,CAAC,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC;QACb,CAAC;QAED,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAEjC,mBAAmB;YACnB,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC;YACb,CAAC;YAED,IAAI,KAAK,CAAC,IAAI,GAAG,YAAY,EAAE,CAAC;gBAC/B,MAAM,MAAM,GAAkB;oBAC7B,IAAI,EAAE,kBAAkB,CAAC,IAAI;oBAC7B,IAAI;oBACJ,WAAW,EAAE,KAAK;oBAClB,aAAa,EAAE;wBACd,sBAAsB,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,WAAW,CAAC,YAAY,CAAC,iDAAiD;qBACjI;iBACD,CAAC;gBAEF,OAAO,MAAM,CAAC;YACf,CAAC;YAED,OAAO,IAAI,CAAC;QACb,CAAC;QAAC,OAAO,MAAe,EAAE,CAAC;YAC1B,mDAAmD;YACnD,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;CACD,CAAC,CAAC","sourcesContent":["import { statSync } from \"node:fs\";\nimport path from \"pathe\";\nimport { makePolicyDefinition } from \"../makePolicy.js\";\nimport type { PolicyDefinition, PolicyFailure } from \"../policy.js\";\n\n/**\n * Policy settings for the NoLargeBinaryFiles repo policy.\n *\n * @alpha\n */\nexport interface NoLargeBinaryFilesSettings {\n\t/**\n\t * Maximum file size in bytes. Defaults to 10MB.\n\t */\n\tmaxSizeBytes?: number;\n\n\t/**\n\t * File extensions to exclude from size checking.\n\t * Useful for known large files that should be allowed.\n\t */\n\texcludeExtensions?: string[];\n\n\t/**\n\t * File patterns to exclude from size checking.\n\t * Uses glob-style patterns.\n\t */\n\texcludePatterns?: string[];\n}\n\n/**\n * Default maximum file size (10MB in bytes).\n */\nconst DEFAULT_MAX_SIZE = 10 * 1024 * 1024;\n\n/**\n * Default file extensions that are typically safe to exclude from size limits.\n */\nconst DEFAULT_EXCLUDE_EXTENSIONS = [\n\t\".md\",\n\t\".txt\",\n\t\".json\",\n\t\".js\",\n\t\".ts\",\n\t\".jsx\",\n\t\".tsx\",\n\t\".css\",\n\t\".scss\",\n\t\".sass\",\n\t\".less\",\n\t\".html\",\n\t\".xml\",\n\t\".yml\",\n\t\".yaml\",\n\t\".toml\",\n\t\".ini\",\n\t\".conf\",\n\t\".config\",\n];\n\n/**\n * Convert a glob pattern to a regex pattern by escaping special characters\n * and converting * to .* for wildcard matching.\n */\nfunction globToRegex(pattern: string): RegExp {\n\t// Escape all regex special characters except *\n\tconst escaped = pattern.replace(/[.+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\t// Convert * to .* for wildcard matching\n\tconst regexPattern = escaped.replace(/\\*/g, \".*\");\n\treturn new RegExp(`^${regexPattern}$`);\n}\n\n/**\n * Check if a file matches any of the exclude patterns.\n */\nfunction isExcluded(\n\tfilePath: string,\n\texcludePatterns: string[],\n\texcludeExtensions: string[],\n): boolean {\n\tconst ext = path.extname(filePath).toLowerCase();\n\n\t// Check extensions\n\tif (excludeExtensions.includes(ext)) {\n\t\treturn true;\n\t}\n\n\t// Check patterns (simple glob-like matching)\n\tfor (const pattern of excludePatterns) {\n\t\tif (pattern.includes(\"*\")) {\n\t\t\tconst regex = globToRegex(pattern);\n\t\t\tif (regex.test(filePath)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} else if (filePath.includes(pattern)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Format bytes in a human-readable format.\n */\nfunction formatBytes(bytes: number): string {\n\tif (bytes === 0) {\n\t\treturn \"0 B\";\n\t}\n\tconst k = 1024;\n\tconst sizes = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\"];\n\tconst i = Math.min(\n\t\tMath.floor(Math.log(bytes) / Math.log(k)),\n\t\tsizes.length - 1,\n\t);\n\tconst formatted = (bytes / k ** i).toFixed(1);\n\treturn `${formatted} ${sizes[i]}`;\n}\n\n/**\n * A repo policy that prevents large binary files from being committed to the repository.\n * Large files can bloat the repository and slow down clones. Consider using Git LFS for large assets.\n *\n * @alpha\n */\nexport const NoLargeBinaryFiles: PolicyDefinition<NoLargeBinaryFilesSettings> =\n\tmakePolicyDefinition({\n\t\tname: \"NoLargeBinaryFiles\",\n\t\tdescription:\n\t\t\t\"Prevents large binary files from being committed to avoid repository bloat; consider using Git LFS for large assets.\",\n\t\t// Match all files\n\t\tmatch: /.*/,\n\t\thandler: async ({ file, root, config }) => {\n\t\t\tconst maxSizeBytes = config?.maxSizeBytes ?? DEFAULT_MAX_SIZE;\n\t\t\tconst excludeExtensions =\n\t\t\t\tconfig?.excludeExtensions ?? DEFAULT_EXCLUDE_EXTENSIONS;\n\t\t\tconst excludePatterns = config?.excludePatterns ?? [];\n\n\t\t\t// Skip excluded files\n\t\t\tif (isExcluded(file, excludePatterns, excludeExtensions)) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst filePath = path.resolve(root, file);\n\t\t\t\tconst stats = statSync(filePath);\n\n\t\t\t\t// Skip directories\n\t\t\t\tif (stats.isDirectory()) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tif (stats.size > maxSizeBytes) {\n\t\t\t\t\tconst result: PolicyFailure = {\n\t\t\t\t\t\tname: NoLargeBinaryFiles.name,\n\t\t\t\t\t\tfile,\n\t\t\t\t\t\tautoFixable: false,\n\t\t\t\t\t\terrorMessages: [\n\t\t\t\t\t\t\t`File is too large: ${formatBytes(stats.size)} (max: ${formatBytes(maxSizeBytes)}). Consider using Git LFS or removing the file.`,\n\t\t\t\t\t\t],\n\t\t\t\t\t};\n\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t} catch (_error: unknown) {\n\t\t\t\t// File doesn't exist or can't be accessed, skip it\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoPrivateWorkspaceDependencies.d.ts","sourceRoot":"","sources":["../../src/policies/NoPrivateWorkspaceDependencies.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NoPrivateWorkspaceDependencies.d.ts","sourceRoot":"","sources":["../../src/policies/NoPrivateWorkspaceDependencies.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,MAAM,WAAW,sCAAsC;IACtD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAC/B;AA6ED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,8BAA8B,6FAyEzC,CAAC"}
|