repopo 0.5.0 → 0.7.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 +87 -0
- package/README.md +3 -5
- package/THIRD-PARTY-LICENSES.txt +6 -6
- package/esm/baseCommand.d.ts.map +1 -1
- package/esm/baseCommand.js +7 -9
- package/esm/baseCommand.js.map +1 -1
- package/esm/commands/check.d.ts +17 -6
- package/esm/commands/check.d.ts.map +1 -1
- package/esm/commands/check.js +162 -110
- package/esm/commands/check.js.map +1 -1
- package/esm/commands/list.d.ts.map +1 -1
- package/esm/commands/list.js +0 -1
- package/esm/commands/list.js.map +1 -1
- package/esm/config.d.ts +4 -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 +3 -3
- package/esm/context.d.ts.map +1 -1
- package/esm/context.js.map +1 -1
- 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 -11
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -9
- 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/policies/HtmlFileHeaders.d.ts +2 -2
- package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
- package/esm/policies/HtmlFileHeaders.js +2 -2
- package/esm/policies/HtmlFileHeaders.js.map +1 -1
- package/esm/policies/JsTsFileHeaders.d.ts +2 -2
- package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
- package/esm/policies/JsTsFileHeaders.js +2 -2
- package/esm/policies/JsTsFileHeaders.js.map +1 -1
- package/esm/policies/LicenseFileExists.d.ts +20 -0
- package/esm/policies/LicenseFileExists.d.ts.map +1 -0
- package/esm/policies/LicenseFileExists.js +40 -0
- package/esm/policies/LicenseFileExists.js.map +1 -0
- package/esm/policies/NoJsFileExtensions.d.ts +2 -2
- package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
- package/esm/policies/NoJsFileExtensions.js +11 -15
- package/esm/policies/NoJsFileExtensions.js.map +1 -1
- package/esm/policies/NoLargeBinaryFiles.d.ts +30 -0
- package/esm/policies/NoLargeBinaryFiles.d.ts.map +1 -0
- package/esm/policies/NoLargeBinaryFiles.js +118 -0
- package/esm/policies/NoLargeBinaryFiles.js.map +1 -0
- package/esm/policies/PackageJsonProperties.d.ts +1 -1
- package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
- package/esm/policies/PackageJsonProperties.js +3 -3
- package/esm/policies/PackageJsonProperties.js.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.js +24 -25
- package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
- package/esm/policies/PackageJsonSorted.d.ts +1 -1
- package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
- package/esm/policies/PackageJsonSorted.js +3 -2
- package/esm/policies/PackageJsonSorted.js.map +1 -1
- package/esm/policies/PackageScripts.d.ts +25 -2
- package/esm/policies/PackageScripts.d.ts.map +1 -1
- package/esm/policies/PackageScripts.js +47 -10
- package/esm/policies/PackageScripts.js.map +1 -1
- package/esm/policies/RequiredGitignorePatterns.d.ts +24 -0
- package/esm/policies/RequiredGitignorePatterns.d.ts.map +1 -0
- package/esm/policies/RequiredGitignorePatterns.js +166 -0
- package/esm/policies/RequiredGitignorePatterns.js.map +1 -0
- package/esm/policies.d.ts +8 -3
- package/esm/policies.d.ts.map +1 -1
- package/esm/policies.js +8 -3
- package/esm/policies.js.map +1 -1
- package/esm/policy.d.ts +40 -13
- package/esm/policy.d.ts.map +1 -1
- package/esm/policy.js +18 -7
- package/esm/policy.js.map +1 -1
- package/esm/{policyGenerators/generateFileHeaderPolicy.d.ts → policyDefiners/defineFileHeaderPolicy.d.ts} +4 -4
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -0
- package/esm/{policyGenerators/generateFileHeaderPolicy.js → policyDefiners/defineFileHeaderPolicy.js} +3 -3
- 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/{policyGenerators/generatePackagePolicy.js → policyDefiners/definePackagePolicy.js} +2 -2
- package/esm/policyDefiners/definePackagePolicy.js.map +1 -0
- package/esm/tsdoc-metadata.json +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +36 -31
- package/esm/policyGenerators/generateFileHeaderPolicy.d.ts.map +0 -1
- package/esm/policyGenerators/generateFileHeaderPolicy.js.map +0 -1
- package/esm/policyGenerators/generatePackagePolicy.d.ts +0 -9
- package/esm/policyGenerators/generatePackagePolicy.d.ts.map +0 -1
- package/esm/policyGenerators/generatePackagePolicy.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAmB,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAElE;;;;;;;;GAQG;AACH,MAAM,OAAO,WAKX,SAAQ,iBAAoB;I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,EAAE,cAAc,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CACd,iBAAiB,QAAQ,gBAAgB,KAAK,aAAc,KAAe,CAAC,KAAK,EAAE,CACnF,CAAC;QACH,CAAC;QAED,SAAS,CAAC,SAAS,EAAE,CAAC;IACvB,CAAC;;AAGF,KAAK,UAAU,SAAS;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAE1B,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YAC1B,IAAI,IAAI,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO,CAAC,EAAE,CAAC,CAAC;QACb,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { EOL as newline } from \"node:os\";\nimport { Flags } from \"@oclif/core\";\nimport { StringBuilder } from \"@rushstack/node-core-library\";\nimport path from \"pathe\";\nimport chalk from \"picocolors\";\n\nimport { BaseRepopoCommand } from \"../baseCommand.js\";\nimport type { RepopoCommandContext } from \"../context.js\";\nimport { logStats, runWithPerf } from \"../perf.js\";\nimport { type RepoPolicy, isPolicyFixResult } from \"../policy.js\";\n\n/**\n * This tool enforces policies across the code base via a series of handler functions. The handler functions are\n * associated with a regular expression, and all files matching that expression are passed to the handler function.\n *\n * By default, the list of files to check comes from `git ls-files. You can also pipe in file names from stdin. For\n * example:\n *\n * `git ls-files -co --exclude-standard --full-name | repopo check --stdin --verbose`\n */\nexport class CheckPolicy<\n\tT extends typeof BaseRepopoCommand & {\n\t\targs: typeof CheckPolicy.args;\n\t\tflags: typeof CheckPolicy.flags;\n\t},\n> extends BaseRepopoCommand<T> {\n\tstatic override readonly summary =\n\t\t\"Checks and applies policies to the files in the repository.\";\n\n\tstatic override readonly flags = {\n\t\tfix: Flags.boolean({\n\t\t\taliases: [\"resolve\"],\n\t\t\tdescription: \"Fix errors if possible.\",\n\t\t\trequired: false,\n\t\t\tchar: \"f\",\n\t\t}),\n\t\tstdin: Flags.boolean({\n\t\t\tdescription: \"Read list of files from stdin.\",\n\t\t\trequired: false,\n\t\t}),\n\t\t...BaseRepopoCommand.flags,\n\t} as const;\n\n\tpublic override async run(): Promise<void> {\n\t\tif (this.flags.fix) {\n\t\t\tthis.info(\"Resolving errors if possible.\");\n\t\t}\n\n\t\tconst config = this.commandConfig;\n\t\tconst policies = config?.policies ?? [];\n\t\tthis.verbose(`${policies.length} policies loaded.`);\n\t\tfor (const h of policies) {\n\t\t\tthis.verbose(h.name);\n\t\t}\n\n\t\tconst filePathsToCheck: string[] = [];\n\n\t\tif (this.flags.stdin) {\n\t\t\tconst stdInput = await readStdin();\n\n\t\t\tif (stdInput !== undefined) {\n\t\t\t\tfilePathsToCheck.push(...stdInput.split(\"\\n\"));\n\t\t\t}\n\t\t} else {\n\t\t\tconst gitFiles =\n\t\t\t\t(await this.git.raw(\n\t\t\t\t\t\"ls-files\",\n\t\t\t\t\t\"-co\",\n\t\t\t\t\t\"--exclude-standard\",\n\t\t\t\t\t\"--full-name\",\n\t\t\t\t)) ?? \"\";\n\n\t\t\tfilePathsToCheck.push(...gitFiles.split(\"\\n\"));\n\t\t}\n\n\t\tawait this.executeAllPolicies(filePathsToCheck);\n\t}\n\n\tprivate async executeAllPolicies(pathsToCheck: string[]): Promise<void> {\n\t\tconst commandContext: RepopoCommandContext = await this.getContext();\n\n\t\ttry {\n\t\t\tfor (const pathToCheck of pathsToCheck) {\n\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\tawait this.checkOrExcludeFile(pathToCheck, commandContext);\n\t\t\t}\n\t\t} finally {\n\t\t\tif (!this.flags.quiet) {\n\t\t\t\tlogStats(commandContext.perfStats, this);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Routes files to their handlers and resolvers by regex testing their full paths. If a file fails a policy that has a\n\t * resolver, the resolver will be invoked as well. Synchronizes the output, exit codes, and resolve\n\t * decision for all handlers.\n\t */\n\tprivate async routeToHandlers(\n\t\tfile: string,\n\t\tcommandContext: RepopoCommandContext,\n\t): Promise<void> {\n\t\tconst { policies, gitRoot } = commandContext;\n\n\t\t// Use the repo-relative path so that regexes that specify string start (^) will match repo paths.\n\t\t// Replace \\ in result with / in case OS is Windows.\n\t\tconst relPath = path.relative(gitRoot, file).replace(/\\\\/g, \"/\");\n\n\t\tconst filteredPolicies = policies.filter((handler) =>\n\t\t\thandler.match.test(relPath),\n\t\t);\n\n\t\tconst resultsP: Promise<void>[] = [];\n\n\t\tfor (const policy of filteredPolicies) {\n\t\t\tresultsP.push(this.runPolicyOnFile(relPath, policy));\n\t\t}\n\n\t\tawait Promise.all(resultsP);\n\t}\n\n\t// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: FIXME\n\tprivate async runPolicyOnFile(\n\t\trelPath: string,\n\t\t// policies: RepoPolicy[],\n\t\tpolicy: RepoPolicy,\n\t): Promise<void> {\n\t\tconst context = await this.getContext();\n\t\tconst { excludePoliciesForFiles, perfStats, gitRoot } = context;\n\n\t\t// doing exclusion per handler\n\t\tconst exclusions = excludePoliciesForFiles.get(policy.name);\n\t\tif (\n\t\t\texclusions !== undefined &&\n\t\t\t!exclusions.every((regex) => !regex.test(relPath))\n\t\t) {\n\t\t\tthis.verbose(`Excluded from '${policy.name}' policy: ${relPath}`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst result = await runWithPerf(\n\t\t\tpolicy.name,\n\t\t\t\"handle\",\n\t\t\tperfStats,\n\t\t\tasync () =>\n\t\t\t\tpolicy.handler({\n\t\t\t\t\tfile: relPath,\n\t\t\t\t\troot: gitRoot,\n\t\t\t\t\tresolve: this.flags.fix,\n\t\t\t\t\tconfig: this.commandConfig?.perPolicyConfig?.[\n\t\t\t\t\t\tpolicy.name\n\t\t\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: FIXME\n\t\t\t\t\t] as any,\n\t\t\t\t}),\n\t\t);\n\n\t\tif (result === true) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst messages = new StringBuilder();\n\t\tif (isPolicyFixResult(result)) {\n\t\t\tif (result.resolved) {\n\t\t\t\tmessages.append(\n\t\t\t\t\t`Resolved ${policy.name} policy failure for file: ${result.file}`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tmessages.append(\n\t\t\t\t\t`Error when trying to fix ${policy.name} policy failure in ${result.file}`,\n\t\t\t\t);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t} else {\n\t\t\t// result must be a PolicyFailureResult; check if there is a standalone resolver.\n\t\t\tconst { resolver } = policy;\n\n\t\t\tif (this.flags.fix && resolver !== undefined) {\n\t\t\t\t// Resolve the failure\n\t\t\t\tmessages.append(`${newline}attempting to resolve: ${relPath}`);\n\t\t\t\tconst resolveResult = await runWithPerf(\n\t\t\t\t\tpolicy.name,\n\t\t\t\t\t\"resolve\",\n\t\t\t\t\tperfStats,\n\t\t\t\t\tasync () => resolver({ file: relPath, root: gitRoot }),\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\tresolveResult.errorMessage !== undefined &&\n\t\t\t\t\tresolveResult.errorMessage !== \"\"\n\t\t\t\t) {\n\t\t\t\t\tmessages.append(newline + resolveResult.errorMessage);\n\t\t\t\t}\n\n\t\t\t\tif (!resolveResult.resolved) {\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No resolver, or fix is false, so we're in the full failure case.\n\t\t\t\tconst autoFixable = result.autoFixable\n\t\t\t\t\t? chalk.green(\" (autofixable)\")\n\t\t\t\t\t: \"\";\n\t\t\t\tmessages.append(\n\t\t\t\t\t`'${chalk.bold(policy.name)}' policy failure${autoFixable}: ${result.file}`,\n\t\t\t\t);\n\t\t\t\tmessages.append(\n\t\t\t\t\tresult.errorMessage === undefined\n\t\t\t\t\t\t? \"\"\n\t\t\t\t\t\t: `${newline}\\t${result.errorMessage}`,\n\t\t\t\t);\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t}\n\t\t}\n\n\t\tif ((process.exitCode ?? 0) === 0) {\n\t\t\tthis.info(messages.toString());\n\t\t} else {\n\t\t\tthis.warning(messages.toString());\n\t\t}\n\t}\n\n\t/**\n\t * Given a string that represents a path to a file in the repo, determines if the file should be checked, and if so,\n\t * routes the file to the appropriate handlers.\n\t */\n\tprivate async checkOrExcludeFile(\n\t\tinputPath: string,\n\t\tcommandContext: RepopoCommandContext,\n\t): Promise<void> {\n\t\tconst { excludeFiles: exclusions, gitRoot, perfStats } = commandContext;\n\n\t\tconst filePath = path.join(gitRoot, inputPath).trim().replace(/\\\\/g, \"/\");\n\n\t\tperfStats.count++;\n\t\tif (!exclusions.every((value) => !value.test(inputPath))) {\n\t\t\tthis.verbose(`Excluded all handlers: ${inputPath}`);\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.routeToHandlers(filePath, commandContext);\n\t\t} catch (error: unknown) {\n\t\t\tthrow new Error(\n\t\t\t\t`Error routing ${filePath} to handler: ${error}\\nStack:\\n${(error as Error).stack}`,\n\t\t\t);\n\t\t}\n\n\t\tperfStats.processed++;\n\t}\n}\n\nasync function readStdin(): Promise<string> {\n\treturn new Promise((resolve) => {\n\t\tconst stdin = process.stdin;\n\t\tstdin.setEncoding(\"utf8\");\n\n\t\tlet data = \"\";\n\t\tstdin.on(\"data\", (chunk) => {\n\t\t\tdata += chunk;\n\t\t});\n\n\t\tstdin.on(\"end\", () => {\n\t\t\tresolve(data);\n\t\t});\n\n\t\tif (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CACd,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,WAAW,KAAK,MAAM,CAAC,IAAI,EAAE,CAC3E,CAAC;QACF,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YACzB,QAAQ,CAAC,MAAM,CAAC,GAAG,OAAO,KAAK,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACtB,CAAC;IACO,WAAW,CAAC,QAAuB;QAC1C,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnC,CAAC;IACF,CAAC","sourcesContent":["import { EOL as newline } from \"node:os\";\nimport process from \"node:process\";\nimport { Flags } from \"@oclif/core\";\nimport { StringBuilder } from \"@rushstack/node-core-library\";\nimport chalk from \"picocolors\";\nimport { BaseRepopoCommand } from \"../baseCommand.js\";\nimport type { RepopoCommandContext } from \"../context.js\";\nimport { logStats, type PolicyHandlerPerfStats, runWithPerf } from \"../perf.js\";\nimport {\n\tisPolicyFixResult,\n\ttype PolicyFailure,\n\ttype PolicyFixResult,\n\ttype PolicyHandlerResult,\n\ttype PolicyInstance,\n\ttype PolicyStandaloneResolver,\n} from \"../policy.js\";\n\nasync function readStdin(): Promise<string> {\n\treturn new Promise((resolve) => {\n\t\tconst stdin = process.stdin;\n\t\tstdin.setEncoding(\"utf8\");\n\n\t\tlet data = \"\";\n\t\tstdin.on(\"data\", (chunk) => {\n\t\t\tdata += chunk;\n\t\t});\n\n\t\tstdin.on(\"end\", () => {\n\t\t\tresolve(data);\n\t\t});\n\n\t\tif (stdin.isTTY) {\n\t\t\tresolve(\"\");\n\t\t}\n\t});\n}\n\n/**\n * This tool enforces policies across the code base via a series of handler functions. The handler functions are\n * associated with a regular expression, and all files matching that expression are passed to the handler function.\n *\n * By default, the list of files to check comes from `git ls-files. You can also pipe in file names from stdin. For\n * example:\n *\n * `git ls-files -co --exclude-standard --full-name | repopo check --stdin --verbose`\n */\nexport class CheckPolicy<\n\tT extends typeof BaseRepopoCommand & {\n\t\targs: typeof CheckPolicy.args;\n\t\tflags: typeof CheckPolicy.flags;\n\t},\n> extends BaseRepopoCommand<T> {\n\tpublic static override readonly summary =\n\t\t\"Checks and applies policies to the files in the repository.\";\n\n\tpublic static override readonly flags = {\n\t\tfix: Flags.boolean({\n\t\t\taliases: [\"resolve\"],\n\t\t\tdescription: \"Fix errors if possible.\",\n\t\t\trequired: false,\n\t\t\tchar: \"f\",\n\t\t}),\n\t\tstdin: Flags.boolean({\n\t\t\tdescription: \"Read list of files from stdin.\",\n\t\t\trequired: false,\n\t\t}),\n\t\t...BaseRepopoCommand.flags,\n\t} as const;\n\n\tpublic override async run(): Promise<void> {\n\t\tif (this.flags.fix) {\n\t\t\tthis.info(\"Resolving errors if possible.\");\n\t\t}\n\n\t\tconst config = this.commandConfig;\n\t\tconst policies = config?.policies ?? [];\n\t\tthis.verbose(`${policies.length} policies loaded.`);\n\t\tfor (const h of policies) {\n\t\t\tthis.verbose(h.name);\n\t\t}\n\n\t\tconst filePathsToCheck: string[] = [];\n\n\t\tif (this.flags.stdin) {\n\t\t\tconst stdInput = await readStdin();\n\n\t\t\tif (stdInput !== undefined) {\n\t\t\t\tfilePathsToCheck.push(\n\t\t\t\t\t...stdInput\n\t\t\t\t\t\t.replace(\n\t\t\t\t\t\t\t// normalize slashes in case they're windows paths\n\t\t\t\t\t\t\t/\\\\/g,\n\t\t\t\t\t\t\t\"/\",\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.split(\"\\n\"),\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tconst gitFiles =\n\t\t\t\t(await this.git.raw(\n\t\t\t\t\t\"ls-files\",\n\t\t\t\t\t// include staged files and untracked files\n\t\t\t\t\t\"-co\",\n\t\t\t\t\t// exclude gitignored files and other standard ignore rules\n\t\t\t\t\t\"--exclude-standard\",\n\t\t\t\t\t// Outputs paths relative to the root of the repository, regardless of the current working directory.\n\t\t\t\t\t\"--full-name\",\n\t\t\t\t)) ?? \"\";\n\n\t\t\tfilePathsToCheck.push(\n\t\t\t\t...gitFiles\n\t\t\t\t\t.replace(\n\t\t\t\t\t\t// normalize slashes in case they're windows paths\n\t\t\t\t\t\t/\\\\/g,\n\t\t\t\t\t\t\"/\",\n\t\t\t\t\t)\n\t\t\t\t\t.split(\"\\n\"),\n\t\t\t);\n\t\t}\n\n\t\tconst context: RepopoCommandContext = await this.getContext();\n\n\t\tawait this.checkAllFiles(filePathsToCheck, context);\n\t}\n\n\t/**\n\t * Executes all policies against the provided paths.\n\t *\n\t * @param pathsToCheck - All paths that should be checked. Paths should be relative to the repository root.\n\t * @param context - The context.\n\t */\n\tprivate async checkAllFiles(\n\t\tpathsToCheck: string[],\n\t\tcontext: RepopoCommandContext,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tfor (const pathToCheck of pathsToCheck) {\n\t\t\t\tawait this.checkOrExcludeFile(pathToCheck, context);\n\t\t\t}\n\t\t} finally {\n\t\t\tif (!this.flags.quiet) {\n\t\t\t\tlogStats(context.perfStats, this);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Given a string that represents a path to a file in the repo, determines if the file should be checked, and if so,\n\t * routes the file to the appropriate handlers.\n\t *\n\t * @param relPath - A git repo-relative path to a file.\n\t */\n\tprivate async checkOrExcludeFile(\n\t\trelPath: string,\n\t\tcontext: RepopoCommandContext,\n\t): Promise<void> {\n\t\tconst { perfStats } = context;\n\t\tperfStats.count++;\n\n\t\ttry {\n\t\t\tconst wasProcessed = await this.routeToPolicies(relPath, context);\n\t\t\tif (wasProcessed) {\n\t\t\t\tperfStats.processed++;\n\t\t\t}\n\t\t} catch (error: unknown) {\n\t\t\tthrow new Error(\n\t\t\t\t`Error routing ${relPath} to handler: ${error}\\nStack:\\n${(error as Error).stack}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async routeToPolicies(\n\t\trelPath: string,\n\t\tcontext: RepopoCommandContext,\n\t): Promise<boolean> {\n\t\tconst { policies, excludeFromAll } = context;\n\n\t\t// Check exclusions\n\t\tif (excludeFromAll.some((regex) => regex.test(relPath))) {\n\t\t\tthis.verbose(`Excluded all handlers: ${relPath}`);\n\t\t\treturn false; // File was excluded from all policies\n\t\t}\n\n\t\t// Run all matching policies\n\t\tconst matchingPolicies = policies.filter((policy) =>\n\t\t\tpolicy.match.test(relPath),\n\t\t);\n\n\t\t// for(const policy of matchingPolicies) {\n\t\t// \tbars.addFile(policy.name,\n\t\t// }\n\n\t\t// If no policies match this file, it's still considered processed\n\t\t// (we examined it and determined no policies apply)\n\t\tif (matchingPolicies.length === 0) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst results = await Promise.all(\n\t\t\tmatchingPolicies.map(async (policy) => {\n\t\t\t\treturn await this.runPolicyOnFile(relPath, policy, context);\n\t\t\t}),\n\t\t);\n\n\t\t// File is considered processed if at least one policy ran on it\n\t\t// If all matching policies excluded it, count as excluded\n\t\treturn results.some((ran) => ran);\n\t}\n\n\tprivate async runPolicyOnFile(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tcontext: RepopoCommandContext,\n\t): Promise<boolean> {\n\t\tconst { excludePoliciesForFiles, perfStats, gitRoot } = context;\n\n\t\t// Check if the policy is excluded for the file\n\t\tif (this.isPolicyExcluded(relPath, policy, excludePoliciesForFiles)) {\n\t\t\tthis.verbose(`Excluded from '${policy.name}' policy: ${relPath}`);\n\t\t\treturn false; // Policy didn't run on this file\n\t\t}\n\n\t\ttry {\n\t\t\t// Execute the policy handler\n\t\t\tconst result = await this.executePolicyHandler(\n\t\t\t\trelPath,\n\t\t\t\tpolicy,\n\t\t\t\tperfStats,\n\t\t\t\tgitRoot,\n\t\t\t);\n\n\t\t\t// Handle the result of the policy execution\n\t\t\tawait this.handlePolicyResult(\n\t\t\t\tresult,\n\t\t\t\trelPath,\n\t\t\t\tpolicy,\n\t\t\t\tperfStats,\n\t\t\t\tgitRoot,\n\t\t\t);\n\t\t} catch (error: unknown) {\n\t\t\t// Log and rethrow the error for higher-level handling\n\t\t\tthis.error(\n\t\t\t\t`Error executing policy '${policy.name}' for file '${relPath}': ${error}`,\n\t\t\t);\n\t\t}\n\n\t\treturn true; // Policy ran (successfully or with error)\n\t}\n\n\tprivate isPolicyExcluded(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\texcludePoliciesForFiles: Map<string, RegExp[]>,\n\t): boolean {\n\t\treturn (\n\t\t\texcludePoliciesForFiles\n\t\t\t\t.get(policy.name)\n\t\t\t\t?.some((regex) => regex.test(relPath)) ?? false\n\t\t);\n\t}\n\n\tprivate async executePolicyHandler(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Promise<PolicyHandlerResult> {\n\t\ttry {\n\t\t\treturn await runWithPerf(policy.name, \"handle\", perfStats, () =>\n\t\t\t\tpolicy.handler({\n\t\t\t\t\tfile: relPath,\n\t\t\t\t\troot: gitRoot,\n\t\t\t\t\tresolve: this.flags.fix,\n\t\t\t\t\tconfig: policy.config,\n\t\t\t\t}),\n\t\t\t);\n\t\t} catch (error: unknown) {\n\t\t\tthis.error(\n\t\t\t\t`Error in policy handler '${policy.name}' for file '${relPath}': ${error}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async handlePolicyResult(\n\t\tresult: PolicyHandlerResult,\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Promise<void> {\n\t\tif (result === true) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (isPolicyFixResult(result)) {\n\t\t\tthis.handleFixResult(result, policy);\n\t\t} else {\n\t\t\tawait this.handleFailureResult(\n\t\t\t\tresult,\n\t\t\t\trelPath,\n\t\t\t\tpolicy,\n\t\t\t\tperfStats,\n\t\t\t\tgitRoot,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate handleFixResult(\n\t\tresult: PolicyFixResult,\n\t\tpolicy: PolicyInstance,\n\t): void {\n\t\tconst messages = new StringBuilder();\n\n\t\tif (result.resolved) {\n\t\t\tmessages.append(\n\t\t\t\t`Resolved ${policy.name} policy failure for file: ${result.file}`,\n\t\t\t);\n\t\t} else {\n\t\t\tmessages.append(\n\t\t\t\t`Error fixing ${policy.name} policy failure in ${result.file}`,\n\t\t\t);\n\t\t\tprocess.exitCode = 1;\n\t\t}\n\n\t\tthis.logMessages(messages);\n\t}\n\n\tprivate async handleFailureResult(\n\t\tresult: PolicyFailure,\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t): Promise<void> {\n\t\tconst messages = new StringBuilder();\n\n\t\tif (this.flags.fix && policy.resolver) {\n\t\t\tawait this.attemptResolution(\n\t\t\t\trelPath,\n\t\t\t\tpolicy,\n\t\t\t\tpolicy.resolver,\n\t\t\t\tperfStats,\n\t\t\t\tgitRoot,\n\t\t\t\tmessages,\n\t\t\t);\n\t\t} else {\n\t\t\tthis.logPolicyFailure(result, policy, messages);\n\t\t}\n\n\t\tthis.logMessages(messages);\n\t}\n\n\tprivate async attemptResolution(\n\t\trelPath: string,\n\t\tpolicy: PolicyInstance,\n\t\tresolver: PolicyStandaloneResolver,\n\t\tperfStats: PolicyHandlerPerfStats,\n\t\tgitRoot: string,\n\t\tmessages: StringBuilder,\n\t): Promise<void> {\n\t\tmessages.append(`${newline}Attempting to resolve: ${relPath}`);\n\t\tconst resolveResult = await runWithPerf(\n\t\t\tpolicy.name,\n\t\t\t\"resolve\",\n\t\t\tperfStats,\n\t\t\t() => resolver({ file: relPath, root: gitRoot }),\n\t\t);\n\n\t\tif (!resolveResult.resolved) {\n\t\t\tprocess.exitCode = 1;\n\t\t}\n\n\t\tif (resolveResult.errorMessage) {\n\t\t\tmessages.append(newline + resolveResult.errorMessage);\n\t\t}\n\t}\n\n\tprivate logPolicyFailure(\n\t\tresult: PolicyFailure,\n\t\tpolicy: PolicyInstance,\n\t\tmessages: StringBuilder,\n\t): void {\n\t\tconst autoFixable = result.autoFixable ? chalk.green(\" (autofixable)\") : \"\";\n\t\tmessages.append(\n\t\t\t`'${chalk.bold(policy.name)}' policy failure${autoFixable}: ${result.file}`,\n\t\t);\n\t\tif (result.errorMessage) {\n\t\t\tmessages.append(`${newline}\\t${result.errorMessage}`);\n\t\t}\n\t\tprocess.exitCode = 1;\n\t}\n\tprivate logMessages(messages: StringBuilder): void {\n\t\tif ((process.exitCode ?? 0) === 0) {\n\t\t\tthis.info(messages.toString());\n\t\t} else {\n\t\t\tthis.warning(messages.toString());\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;GAEG;AACH,qBAAa,WAAW,CACvB,CAAC,SAAS,OAAO,iBAAiB,GAAG;IACpC,IAAI,EAAE,OAAO,WAAW,CAAC,IAAI,CAAC;IAC9B,KAAK,EAAE,OAAO,WAAW,CAAC,KAAK,CAAC;CAChC,CACA,SAAQ,iBAAiB,CAAC,CAAC,CAAC;IAC7B,
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;GAEG;AACH,qBAAa,WAAW,CACvB,CAAC,SAAS,OAAO,iBAAiB,GAAG;IACpC,IAAI,EAAE,OAAO,WAAW,CAAC,IAAI,CAAC;IAC9B,KAAK,EAAE,OAAO,WAAW,CAAC,KAAK,CAAC;CAChC,CACA,SAAQ,iBAAiB,CAAC,CAAC,CAAC;IAC7B,gBAAgC,OAAO,2CACE;IAEnB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ1C"}
|
package/esm/commands/list.js
CHANGED
|
@@ -5,7 +5,6 @@ import { DefaultPolicies } from "../policy.js";
|
|
|
5
5
|
*/
|
|
6
6
|
export class ListCommand extends BaseRepopoCommand {
|
|
7
7
|
static summary = "Lists the policies configured to run.";
|
|
8
|
-
// biome-ignore lint/suspicious/useAwait: overridden method
|
|
9
8
|
async run() {
|
|
10
9
|
const policies = this.commandConfig?.policies ?? DefaultPolicies;
|
|
11
10
|
// list the handlers then exit
|
package/esm/commands/list.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,WAKX,SAAQ,iBAAoB;
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,WAKX,SAAQ,iBAAoB;IACtB,MAAM,CAAmB,OAAO,GACtC,uCAAuC,CAAC;IAEzB,KAAK,CAAC,GAAG;QACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,EAAE,QAAQ,IAAI,eAAe,CAAC;QACjE,8BAA8B;QAC9B,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,wBAAwB,CAAC,CAAC;IACtD,CAAC","sourcesContent":["import { BaseRepopoCommand } from \"../baseCommand.js\";\nimport { DefaultPolicies } from \"../policy.js\";\n\n/**\n * This command lists all the policies configured to run.\n */\nexport class ListCommand<\n\tT extends typeof BaseRepopoCommand & {\n\t\targs: typeof ListCommand.args;\n\t\tflags: typeof ListCommand.flags;\n\t},\n> extends BaseRepopoCommand<T> {\n\tpublic static override readonly summary =\n\t\t\"Lists the policies configured to run.\";\n\n\tpublic override async run(): Promise<void> {\n\t\tconst policies = this.commandConfig?.policies ?? DefaultPolicies;\n\t\t// list the handlers then exit\n\t\tfor (const h of policies) {\n\t\t\tthis.log(`${h.name}\\nresolver: ${h.resolver !== undefined}\\n`);\n\t\t}\n\t\tthis.log(`${policies.length} TOTAL POLICY HANDLERS`);\n\t}\n}\n"]}
|
package/esm/config.d.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { type
|
|
3
|
-
/**
|
|
4
|
-
* @alpha
|
|
5
|
-
*/
|
|
6
|
-
export type PerPolicySettings = ({
|
|
7
|
-
PackageJsonProperties: PackageJsonPropertiesSettings;
|
|
8
|
-
} & Record<PolicyName, unknown>) | undefined;
|
|
1
|
+
import type { PolicyCreator } from "./generators.js";
|
|
2
|
+
import { type PolicyInstance } from "./policy.js";
|
|
9
3
|
/**
|
|
10
4
|
* @alpha
|
|
11
5
|
*/
|
|
6
|
+
export type PolicyList = PolicyCreator[];
|
|
12
7
|
/**
|
|
13
8
|
* @alpha
|
|
14
9
|
*/
|
|
@@ -18,18 +13,12 @@ export interface RepopoConfig {
|
|
|
18
13
|
*
|
|
19
14
|
* See `DefaultPolicies` for the policies that will be enabled by default if this is `undefined`.
|
|
20
15
|
*/
|
|
21
|
-
policies?:
|
|
16
|
+
policies?: PolicyInstance<any>[];
|
|
22
17
|
/**
|
|
23
18
|
* An array of strings/regular expressions. File paths that match any of these expressions will be completely excluded
|
|
24
19
|
* from policy.
|
|
25
20
|
*/
|
|
26
21
|
excludeFiles?: (string | RegExp)[];
|
|
27
|
-
/**
|
|
28
|
-
* An object with a policy name as keys that map to an array of strings/regular expressions to
|
|
29
|
-
* exclude that rule from being checked.
|
|
30
|
-
*/
|
|
31
|
-
excludePoliciesForFiles?: Record<PolicyName, (string | RegExp)[]>;
|
|
32
|
-
perPolicyConfig?: PerPolicySettings | undefined;
|
|
33
22
|
}
|
|
34
23
|
/**
|
|
35
24
|
* The default config applied when no config is found.
|
package/esm/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;OAIG;IAEH,QAAQ,CAAC,EAAE,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;IAEjC;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CACnC;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAIjC,CAAC"}
|
package/esm/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { makePolicy } from "./makePolicy.js";
|
|
1
2
|
import { DefaultPolicies } from "./policy.js";
|
|
2
3
|
/**
|
|
3
4
|
* The default config applied when no config is found.
|
|
@@ -5,8 +6,8 @@ import { DefaultPolicies } from "./policy.js";
|
|
|
5
6
|
* @alpha
|
|
6
7
|
*/
|
|
7
8
|
export const DefaultPolicyConfig = {
|
|
8
|
-
policies: DefaultPolicies,
|
|
9
|
+
policies: DefaultPolicies.map((p) => makePolicy(p)),
|
|
9
10
|
excludeFiles: [],
|
|
10
|
-
excludePoliciesForFiles: {},
|
|
11
|
+
// excludePoliciesForFiles: {},
|
|
11
12
|
};
|
|
12
13
|
//# sourceMappingURL=config.js.map
|
package/esm/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAuB,MAAM,aAAa,CAAC;AA0BnE;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAiB;IAChD,QAAQ,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACnD,YAAY,EAAE,EAAE;IAChB,+BAA+B;CAC/B,CAAC","sourcesContent":["import type { PolicyCreator } from \"./generators.js\";\nimport { makePolicy } from \"./makePolicy.js\";\nimport { DefaultPolicies, type PolicyInstance } from \"./policy.js\";\n\n/**\n * @alpha\n */\nexport type PolicyList = PolicyCreator[];\n\n/**\n * @alpha\n */\nexport interface RepopoConfig {\n\t/**\n\t * An array of policies that are enabled.\n\t *\n\t * See `DefaultPolicies` for the policies that will be enabled by default if this is `undefined`.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: FIXME\n\tpolicies?: PolicyInstance<any>[];\n\n\t/**\n\t * An array of strings/regular expressions. File paths that match any of these expressions will be completely excluded\n\t * from policy.\n\t */\n\texcludeFiles?: (string | RegExp)[];\n}\n\n/**\n * The default config applied when no config is found.\n *\n * @alpha\n */\nexport const DefaultPolicyConfig: RepopoConfig = {\n\tpolicies: DefaultPolicies.map((p) => makePolicy(p)),\n\texcludeFiles: [],\n\t// excludePoliciesForFiles: {},\n};\n"]}
|
package/esm/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PolicyHandlerPerfStats } from "./perf.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { PolicyInstance, PolicyName } from "./policy.js";
|
|
3
3
|
export type ExcludedPolicyFileMap = Map<PolicyName, RegExp[]>;
|
|
4
4
|
/**
|
|
5
5
|
* Contextual data available to all Repopo commands.
|
|
@@ -8,11 +8,11 @@ export interface RepopoCommandContext {
|
|
|
8
8
|
/**
|
|
9
9
|
* A list of regular expressions used to exclude files from all handlers.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
excludeFromAll: RegExp[];
|
|
12
12
|
/**
|
|
13
13
|
* A list of handlers to apply to selected files.
|
|
14
14
|
*/
|
|
15
|
-
policies:
|
|
15
|
+
policies: PolicyInstance[];
|
|
16
16
|
/**
|
|
17
17
|
* A per-handler list of regular expressions used to exclude files from specific handlers.
|
|
18
18
|
*/
|
package/esm/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,MAAM,qBAAqB,GAAG,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,cAAc,EAAE,MAAM,EAAE,CAAC;IAEzB;;OAEG;IACH,QAAQ,EAAE,cAAc,EAAE,CAAC;IAE3B;;OAEG;IACH,uBAAuB,EAAE,qBAAqB,CAAC;IAE/C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,sBAAsB,CAAC;CAClC"}
|
package/esm/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"","sourcesContent":["import type { PolicyHandlerPerfStats } from \"./perf.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"","sourcesContent":["import type { PolicyHandlerPerfStats } from \"./perf.js\";\nimport type { PolicyInstance, PolicyName } from \"./policy.js\";\n\nexport type ExcludedPolicyFileMap = Map<PolicyName, RegExp[]>;\n\n/**\n * Contextual data available to all Repopo commands.\n */\nexport interface RepopoCommandContext {\n\t/**\n\t * A list of regular expressions used to exclude files from all handlers.\n\t */\n\texcludeFromAll: RegExp[];\n\n\t/**\n\t * A list of handlers to apply to selected files.\n\t */\n\tpolicies: PolicyInstance[];\n\n\t/**\n\t * A per-handler list of regular expressions used to exclude files from specific handlers.\n\t */\n\texcludePoliciesForFiles: ExcludedPolicyFileMap;\n\n\t/**\n\t * Path to the root of the git repo.\n\t */\n\tgitRoot: string;\n\n\t/**\n\t * Stores performance data for each handler. Used to collect and display performance stats.\n\t */\n\tperfStats: PolicyHandlerPerfStats;\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PolicyDefinition } from "./policy.js";
|
|
2
|
+
/**
|
|
3
|
+
* The definition of a free function that returns a RepoPolicy.
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
6
|
+
*/
|
|
7
|
+
export type PolicyCreatorFunction<C = undefined> = (args: PolicyDefinition<C>) => PolicyDefinition<C>;
|
|
8
|
+
/**
|
|
9
|
+
* The definition of a constructor function that returns a RepoPolicy.
|
|
10
|
+
*
|
|
11
|
+
* @alpha
|
|
12
|
+
*/
|
|
13
|
+
export type PolicyCreatorConstructor<C = undefined> = new (args: PolicyDefinition<C>) => PolicyDefinition<C>;
|
|
14
|
+
/**
|
|
15
|
+
* A PolicyCreator is a function that can be used to generate a {@link PolicyDefinition}. The function can be a free function
|
|
16
|
+
* or a constructor that creates a class implementing the {@link PolicyDefinition} interface.
|
|
17
|
+
*
|
|
18
|
+
* @alpha
|
|
19
|
+
*/
|
|
20
|
+
export type PolicyCreator = PolicyCreatorConstructor | PolicyCreatorFunction;
|
|
21
|
+
//# sourceMappingURL=generators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,SAAS,IAAI,CAClD,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,KACrB,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAEzB;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,GAAG,SAAS,IAAI,KACrD,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,KACrB,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAEzB;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,wBAAwB,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators.js","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"","sourcesContent":["import type { PolicyDefinition } from \"./policy.js\";\n\n/**\n * The definition of a free function that returns a RepoPolicy.\n *\n * @alpha\n */\nexport type PolicyCreatorFunction<C = undefined> = (\n\targs: PolicyDefinition<C>,\n) => PolicyDefinition<C>;\n\n/**\n * The definition of a constructor function that returns a RepoPolicy.\n *\n * @alpha\n */\nexport type PolicyCreatorConstructor<C = undefined> = new (\n\targs: PolicyDefinition<C>,\n) => PolicyDefinition<C>;\n\n/**\n * A PolicyCreator is a function that can be used to generate a {@link PolicyDefinition}. The function can be a free function\n * or a constructor that creates a class implementing the {@link PolicyDefinition} interface.\n *\n * @alpha\n */\nexport type PolicyCreator = PolicyCreatorConstructor | PolicyCreatorFunction;\n"]}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
export { run } from "@oclif/core";
|
|
2
|
-
export type {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { PackageJsonRepoDirectoryProperty } from "./policies/PackageJsonRepoDirectoryProperty.js";
|
|
8
|
-
export { PackageJsonSorted } from "./policies/PackageJsonSorted.js";
|
|
9
|
-
export { PackageScripts } from "./policies/PackageScripts.js";
|
|
10
|
-
export type { PerPolicySettings, RepopoConfig, } from "./config.js";
|
|
11
|
-
export { generatePackagePolicy } from "./policyGenerators/generatePackagePolicy.js";
|
|
12
|
-
export { generateFileHeaderPolicy, type FileHeaderGeneratorConfig, type FileHeaderPolicyConfig, } from "./policyGenerators/generateFileHeaderPolicy.js";
|
|
2
|
+
export type { RepopoConfig, } from "./config.js";
|
|
3
|
+
export { makePolicy } from "./makePolicy.js";
|
|
4
|
+
export type { PolicyDefinition, PolicyFailure, PolicyFixResult, PolicyFunctionArguments, PolicyHandler, PolicyHandlerResult, PolicyInstance, PolicyInstanceSettings, PolicyName, PolicyStandaloneResolver, } from "./policy.js";
|
|
5
|
+
export { defineFileHeaderPolicy as generateFileHeaderPolicy, type FileHeaderGeneratorConfig, type FileHeaderPolicyConfig, } from "./policyDefiners/defineFileHeaderPolicy.js";
|
|
6
|
+
export { definePackagePolicy as generatePackagePolicy, type PackageJsonHandler, } from "./policyDefiners/definePackagePolicy.js";
|
|
13
7
|
//# 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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,YAAY,EAEX,YAAY,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,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,sBAAsB,IAAI,wBAAwB,EAClD,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,GAC3B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,mBAAmB,IAAI,qBAAqB,EAC5C,KAAK,kBAAkB,GACvB,MAAM,yCAAyC,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
export { run } from "@oclif/core";
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export { PackageJsonProperties, } from "./policies/PackageJsonProperties.js";
|
|
6
|
-
export { PackageJsonRepoDirectoryProperty } from "./policies/PackageJsonRepoDirectoryProperty.js";
|
|
7
|
-
export { PackageJsonSorted } from "./policies/PackageJsonSorted.js";
|
|
8
|
-
export { PackageScripts } from "./policies/PackageScripts.js";
|
|
9
|
-
export { generatePackagePolicy } from "./policyGenerators/generatePackagePolicy.js";
|
|
10
|
-
export { generateFileHeaderPolicy, } from "./policyGenerators/generateFileHeaderPolicy.js";
|
|
2
|
+
export { makePolicy } from "./makePolicy.js";
|
|
3
|
+
export { defineFileHeaderPolicy as generateFileHeaderPolicy, } from "./policyDefiners/defineFileHeaderPolicy.js";
|
|
4
|
+
export { definePackagePolicy as generatePackagePolicy, } from "./policyDefiners/definePackagePolicy.js";
|
|
11
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;AAKlC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAa7C,OAAO,EACN,sBAAsB,IAAI,wBAAwB,GAGlD,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,mBAAmB,IAAI,qBAAqB,GAE5C,MAAM,yCAAyC,CAAC","sourcesContent":["export { run } from \"@oclif/core\";\nexport type {\n\t// PolicyList,\n\tRepopoConfig,\n} from \"./config.js\";\nexport { makePolicy } 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\tdefineFileHeaderPolicy as generateFileHeaderPolicy,\n\ttype FileHeaderGeneratorConfig,\n\ttype FileHeaderPolicyConfig,\n} from \"./policyDefiners/defineFileHeaderPolicy.js\";\nexport {\n\tdefinePackagePolicy as generatePackagePolicy,\n\ttype PackageJsonHandler,\n} from \"./policyDefiners/definePackagePolicy.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"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type FileHeaderPolicyConfig } from "../
|
|
1
|
+
import { type FileHeaderPolicyConfig } from "../policyDefiners/defineFileHeaderPolicy.js";
|
|
2
2
|
/**
|
|
3
3
|
* A RepoPolicy that checks that HTML files have the configured header comment.
|
|
4
4
|
*
|
|
5
5
|
* @alpha
|
|
6
6
|
*/
|
|
7
|
-
export declare const HtmlFileHeaders: import("../policy.js").
|
|
7
|
+
export declare const HtmlFileHeaders: import("../policy.js").PolicyDefinition<FileHeaderPolicyConfig>;
|
|
8
8
|
//# sourceMappingURL=HtmlFileHeaders.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HtmlFileHeaders.d.ts","sourceRoot":"","sources":["../../src/policies/HtmlFileHeaders.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
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,iEAc1B,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { EOL as newline } from "node:os";
|
|
2
|
-
import {
|
|
2
|
+
import { defineFileHeaderPolicy, } from "../policyDefiners/defineFileHeaderPolicy.js";
|
|
3
3
|
/**
|
|
4
4
|
* A RepoPolicy that checks that HTML files have the configured header comment.
|
|
5
5
|
*
|
|
6
6
|
* @alpha
|
|
7
7
|
*/
|
|
8
|
-
export const HtmlFileHeaders =
|
|
8
|
+
export const HtmlFileHeaders = defineFileHeaderPolicy("HtmlFileHeaders", {
|
|
9
9
|
match: /(^|\/)[^/]+\.[mc]?[jt]sx?$/i,
|
|
10
10
|
lineStart: /<!-- /, // Lines begin with '<!-- '
|
|
11
11
|
lineEnd: / -->\r?\n/, // Lines end with ' -->' followed by CRLF or LF
|
|
@@ -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,
|
|
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;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\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(\"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"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type FileHeaderPolicyConfig } from "../
|
|
1
|
+
import { type FileHeaderPolicyConfig } from "../policyDefiners/defineFileHeaderPolicy.js";
|
|
2
2
|
/**
|
|
3
3
|
* A RepoPolicy that checks that JavaScript and TypeScript source files have the configured header comment
|
|
4
4
|
*
|
|
5
5
|
* @alpha
|
|
6
6
|
*/
|
|
7
|
-
export declare const JsTsFileHeaders: import("../policy.js").
|
|
7
|
+
export declare const JsTsFileHeaders: import("../policy.js").PolicyDefinition<FileHeaderPolicyConfig>;
|
|
8
8
|
//# sourceMappingURL=JsTsFileHeaders.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsTsFileHeaders.d.ts","sourceRoot":"","sources":["../../src/policies/JsTsFileHeaders.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
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,iEAO1B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EOL as newline } from "node:os";
|
|
2
|
-
import {
|
|
2
|
+
import { defineFileHeaderPolicy, } from "../policyDefiners/defineFileHeaderPolicy.js";
|
|
3
3
|
const jsTsReplacer = (prevContent, { headerText }) => {
|
|
4
4
|
// prepend header to existing content
|
|
5
5
|
const separator = prevContent.startsWith("\r") || prevContent.startsWith("\n")
|
|
@@ -13,7 +13,7 @@ const jsTsReplacer = (prevContent, { headerText }) => {
|
|
|
13
13
|
*
|
|
14
14
|
* @alpha
|
|
15
15
|
*/
|
|
16
|
-
export const JsTsFileHeaders =
|
|
16
|
+
export const JsTsFileHeaders = defineFileHeaderPolicy("JsTsFileHeaders", {
|
|
17
17
|
match: /(^|\/)[^/]+\.[mc]?[jt]sx?$/i,
|
|
18
18
|
headerStart: /(#![^\n]*\r?\n)?\/\*!\r?\n/, // Begins with optional hashbang followed by '/*!'
|
|
19
19
|
lineStart: / \* /, // Subsequent lines begins with ' * '
|
|
@@ -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,
|
|
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;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\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(\"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"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PolicyDefinition } from "../policy.js";
|
|
2
|
+
/**
|
|
3
|
+
* Policy settings for the LicenseFileExists repo policy.
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
6
|
+
*/
|
|
7
|
+
export interface LicenseFileExistsSettings {
|
|
8
|
+
/**
|
|
9
|
+
* Array of acceptable license file names. Defaults to common variations.
|
|
10
|
+
*/
|
|
11
|
+
acceptedNames?: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A repo policy that checks that a LICENSE file exists in the repository root.
|
|
15
|
+
* This is essential for open source projects to clarify usage rights and obligations.
|
|
16
|
+
*
|
|
17
|
+
* @alpha
|
|
18
|
+
*/
|
|
19
|
+
export declare const LicenseFileExists: PolicyDefinition<LicenseFileExistsSettings>;
|
|
20
|
+
//# sourceMappingURL=LicenseFileExists.d.ts.map
|
|
@@ -0,0 +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,CA0BxE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "pathe";
|
|
3
|
+
import { makePolicyDefinition } from "../makePolicy.js";
|
|
4
|
+
/**
|
|
5
|
+
* Default license file names to check for.
|
|
6
|
+
*/
|
|
7
|
+
const DEFAULT_LICENSE_NAMES = [
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"LICENSE.txt",
|
|
10
|
+
"LICENSE.md",
|
|
11
|
+
"LICENSE.rst",
|
|
12
|
+
"LICENCE",
|
|
13
|
+
"LICENCE.txt",
|
|
14
|
+
"LICENCE.md",
|
|
15
|
+
"LICENCE.rst",
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* A repo policy that checks that a LICENSE file exists in the repository root.
|
|
19
|
+
* This is essential for open source projects to clarify usage rights and obligations.
|
|
20
|
+
*
|
|
21
|
+
* @alpha
|
|
22
|
+
*/
|
|
23
|
+
export const LicenseFileExists = makePolicyDefinition("LicenseFileExists",
|
|
24
|
+
// Only trigger on package.json to check once per repository
|
|
25
|
+
/^package\.json$/, async ({ root, config }) => {
|
|
26
|
+
const acceptedNames = config?.acceptedNames ?? DEFAULT_LICENSE_NAMES;
|
|
27
|
+
// Check if any of the accepted license files exist in the root
|
|
28
|
+
const hasLicenseFile = acceptedNames.some((name) => existsSync(path.join(root, name)));
|
|
29
|
+
if (hasLicenseFile) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const result = {
|
|
33
|
+
name: LicenseFileExists.name,
|
|
34
|
+
file: ".", // Report against repository root
|
|
35
|
+
autoFixable: false,
|
|
36
|
+
errorMessage: `No LICENSE file found in repository root. Expected one of: ${acceptedNames.join(", ")}`,
|
|
37
|
+
};
|
|
38
|
+
return result;
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=LicenseFileExists.js.map
|
|
@@ -0,0 +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,CACnB,mBAAmB;AACnB,4DAA4D;AAC5D,iBAAiB,EACjB,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;IAC1B,MAAM,aAAa,GAAG,MAAM,EAAE,aAAa,IAAI,qBAAqB,CAAC;IAErE,+DAA+D;IAC/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;IAEF,IAAI,cAAc,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,MAAM,GAAkB;QAC7B,IAAI,EAAE,iBAAiB,CAAC,IAAI;QAC5B,IAAI,EAAE,GAAG,EAAE,iCAAiC;QAC5C,WAAW,EAAE,KAAK;QAClB,YAAY,EAAE,8DAA8D,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;KACtG,CAAC;IAEF,OAAO,MAAM,CAAC;AACf,CAAC,CACD,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\t\"LicenseFileExists\",\n\t\t// Only trigger on package.json to check once per repository\n\t\t/^package\\.json$/,\n\t\tasync ({ 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\terrorMessage: `No LICENSE file found in repository root. Expected one of: ${acceptedNames.join(\", \")}`,\n\t\t\t};\n\n\t\t\treturn result;\n\t\t},\n\t);\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
@@ -8,5 +8,5 @@ import type { RepoPolicy } from "../policy.js";
|
|
|
8
8
|
*
|
|
9
9
|
* @alpha
|
|
10
10
|
*/
|
|
11
|
-
export declare const NoJsFileExtensions:
|
|
11
|
+
export declare const NoJsFileExtensions: PolicyDefinition;
|
|
12
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,gBAchC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
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
|
|
@@ -7,19 +8,14 @@
|
|
|
7
8
|
*
|
|
8
9
|
* @alpha
|
|
9
10
|
*/
|
|
10
|
-
export const NoJsFileExtensions = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
errorMessage: "JavaScript files should have a .cjs or .mjs file extension based on the module format of the file. Rename the file accordingly.",
|
|
21
|
-
};
|
|
22
|
-
return result;
|
|
23
|
-
},
|
|
24
|
-
};
|
|
11
|
+
export const NoJsFileExtensions = makePolicyDefinition("NoJsFileExtensions", /(^|\/)[^/]+\.js$/i, async ({ file }) => {
|
|
12
|
+
// Any match is considered a failure.
|
|
13
|
+
const result = {
|
|
14
|
+
name: NoJsFileExtensions.name,
|
|
15
|
+
file,
|
|
16
|
+
autoFixable: false,
|
|
17
|
+
errorMessage: "JavaScript files should have a .cjs or .mjs file extension based on the module format of the file. Rename the file accordingly.",
|
|
18
|
+
};
|
|
19
|
+
return result;
|
|
20
|
+
});
|
|
25
21
|
//# sourceMappingURL=NoJsFileExtensions.js.map
|