repopo 0.2.2 → 0.3.1
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 +40 -0
- package/README.md +20 -5
- package/esm/baseCommand.d.ts +52 -0
- package/esm/baseCommand.d.ts.map +1 -0
- package/esm/baseCommand.js +87 -0
- package/esm/baseCommand.js.map +1 -0
- package/esm/commands/check.d.ts +7 -11
- package/esm/commands/check.d.ts.map +1 -1
- package/esm/commands/check.js +20 -150
- package/esm/commands/check.js.map +1 -1
- package/esm/commands/list.d.ts +13 -0
- package/esm/commands/list.d.ts.map +1 -0
- package/esm/commands/list.js +19 -0
- package/esm/commands/list.js.map +1 -0
- package/esm/config.d.ts +9 -9
- package/esm/config.d.ts.map +1 -1
- package/esm/config.js +7 -1
- package/esm/config.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/perf.d.ts +12 -0
- package/esm/perf.d.ts.map +1 -0
- package/esm/perf.js +31 -0
- package/esm/perf.js.map +1 -0
- package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
- package/esm/policies/PackageJsonProperties.js +2 -1
- package/esm/policies/PackageJsonProperties.js.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.js +2 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
- package/esm/policies/PackageJsonSortedPolicy.d.ts.map +1 -1
- package/esm/policies/PackageJsonSortedPolicy.js +2 -1
- package/esm/policies/PackageJsonSortedPolicy.js.map +1 -1
- package/esm/policy.d.ts +17 -0
- package/esm/policy.d.ts.map +1 -1
- package/esm/policy.js +0 -12
- package/esm/policy.js.map +1 -1
- package/oclif.manifest.json +65 -32
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/commands/check.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GAAG,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport { EOL as newline } from \"node:os\";\nimport path from \"node:path\";\nimport { Flags } from \"@oclif/core\";\nimport { StringBuilder } from \"@rushstack/node-core-library\";\nimport { GitCommand, RegExpFlag, findGitRoot } from \"@tylerbu/cli-api\";\nimport chalk from \"chalk\";\nimport { type CosmiconfigResult, cosmiconfig } from \"cosmiconfig\";\nimport { DefaultPolicyConfig, type PolicyConfig } from \"../config.js\";\nimport {\n\tDefaultPolicies,\n\ttype PolicyName,\n\ttype RepoPolicy,\n\tisPolicyFixResult,\n} from \"../policy.js\";\n\ntype PolicyAction = \"handle\" | \"resolve\";\n\ntype ExcludedPolicyFileMap = Map<PolicyName, RegExp[]>; // Record<PolicyName, RegExp[]>\n\n/**\n * A convenience interface used to pass commonly used parameters to functions in this file.\n */\ninterface CheckPolicyCommandContext {\n\t/**\n\t * A regular expression used to filter selected files.\n\t */\n\tpathRegex: RegExp;\n\n\t/**\n\t * A list of regular expressions used to exclude files from all handlers.\n\t */\n\texcludeFiles: RegExp[];\n\n\t/**\n\t * A list of handlers to apply to selected files.\n\t */\n\tpolicies: RepoPolicy[];\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 * The repo context.\n\t */\n\t// context: Context;\n}\n\n/**\n * Stores performance data for each handler. Used to collect and display performance stats.\n */\nconst handlerPerformanceData = new Map<PolicyAction, Map<string, number>>();\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 extends GitCommand<\n\ttypeof CheckPolicy & {\n\t\targs: typeof GitCommand.args;\n\t\tflags: typeof GitCommand.flags;\n\t},\n\tPolicyConfig\n> {\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\tpolicy: RegExpFlag({\n\t\t\tdescription:\n\t\t\t\t\"Filter policies to apply by <regex>. Only policies with a name matching the regex will be applied.\",\n\t\t\trequired: false,\n\t\t\tchar: \"d\",\n\t\t}),\n\t\texcludePolicy: Flags.string({\n\t\t\tchar: \"D\",\n\t\t\tdescription:\n\t\t\t\t\"Exclude policies by name. Can be specified multiple times to exclude multiple policies.\",\n\t\t\texclusive: [\"policy\"],\n\t\t\tmultiple: true,\n\t\t}),\n\t\tpath: RegExpFlag({\n\t\t\tdescription: \"Filter file paths by <regex>.\",\n\t\t\trequired: false,\n\t\t\tchar: \"p\",\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...GitCommand.flags,\n\t} as const;\n\n\tprivate processed = 0;\n\tprivate count = 0;\n\t// private policies: RepoPolicy[] | undefined;\n\tprivate commandContext: CheckPolicyCommandContext | undefined;\n\n\tpublic override get defaultConfig() {\n\t\treturn DefaultPolicyConfig;\n\t}\n\n\tprotected override async loadConfig(): Promise<PolicyConfig> {\n\t\tconst gitRoot = await findGitRoot();\n\t\t// this.configPath ??= this.config.configDir; // path.join(this.config.configDir, \"config.ts\");\n\t\tconst explorer = cosmiconfig(this.config.bin, {\n\t\t\tsearchStrategy: \"global\",\n\t\t});\n\t\tthis.verbose(`Looking for '${this.config.bin}' config at '${gitRoot}'`);\n\t\tconst config: CosmiconfigResult = await explorer.search(gitRoot);\n\t\tif (config?.config !== undefined) {\n\t\t\tthis.verbose(`Found config at ${config.filepath}`);\n\t\t}\n\t\tif (config?.config === undefined) {\n\t\t\tthis.warning(\"No config found; using defaults.\");\n\t\t}\n\t\tconst finalConfig: PolicyConfig = config?.config ?? this.defaultConfig;\n\t\tif (finalConfig.includeDefaultPolicies === true) {\n\t\t\tfinalConfig.policies ??= [];\n\t\t\tfinalConfig.policies.push(...DefaultPolicies);\n\t\t}\n\n\t\treturn finalConfig;\n\t}\n\n\tpublic override async init(): Promise<void> {\n\t\tawait super.init();\n\n\t\tlet policies =\n\t\t\tthis.commandConfig?.policies?.filter((h) => {\n\t\t\t\tif (\n\t\t\t\t\tthis.flags.excludePolicy === undefined ||\n\t\t\t\t\tthis.flags.excludePolicy.length === 0\n\t\t\t\t) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconst shouldRun = this.flags.excludePolicy?.includes(h.name) === false;\n\t\t\t\tif (!shouldRun) {\n\t\t\t\t\tthis.info(`Disabled policy: ${h.name}`);\n\t\t\t\t}\n\t\t\t\treturn shouldRun;\n\t\t\t}) ?? [];\n\n\t\t// const pathRegex: RegExp =\n\t\t// \tthis.flags.path === undefined ? /.?/ : new RegExp(this.flags.path, \"i\");\n\n\t\tif (this.flags.policy !== undefined) {\n\t\t\tthis.info(`Filtering handlers by regex: ${this.flags.policy}`);\n\t\t\tpolicies = policies?.filter((h) => this.flags.policy?.test(h.name));\n\t\t}\n\n\t\tconst pathRegex = this.flags.path ?? /.?/;\n\t\tif (this.flags.path !== undefined) {\n\t\t\tthis.info(`Filtering file paths by regex: ${pathRegex}`);\n\t\t}\n\n\t\tif (this.flags.fix) {\n\t\t\tthis.info(\"Resolving errors if possible.\");\n\t\t}\n\n\t\tconst excludeFiles: RegExp[] =\n\t\t\tthis.commandConfig?.excludeFiles?.map((e) => toRegExp(e)) ?? [];\n\n\t\tconst excludePoliciesForFilesRaw =\n\t\t\tthis.commandConfig?.excludePoliciesForFiles;\n\n\t\tconst excludePoliciesForFiles: ExcludedPolicyFileMap = new Map();\n\t\tif (excludePoliciesForFilesRaw) {\n\t\t\tfor (const [policyName, filters] of Object.entries(\n\t\t\t\texcludePoliciesForFilesRaw,\n\t\t\t)) {\n\t\t\t\tconst regexes = filters.map((e) => toRegExp(e));\n\t\t\t\texcludePoliciesForFiles.set(policyName, regexes);\n\t\t\t}\n\t\t}\n\n\t\tconst gitRoot = await findGitRoot();\n\t\tthis.commandContext = {\n\t\t\tpathRegex,\n\t\t\texcludeFiles,\n\t\t\tpolicies,\n\t\t\texcludePoliciesForFiles,\n\t\t\tgitRoot,\n\t\t};\n\t}\n\n\tpublic override async run(): Promise<void> {\n\t\t// list the handlers then exit\n\t\t// if (this.flags.listHandlers) {\n\t\t// \tfor (const h of handlersToRun) {\n\t\t// \t\tthis.log(`${h.name}\\nresolver: ${h.resolver !== undefined}\\n`);\n\t\t// \t}\n\t\t// \tthis.log(`${handlersToRun.length} TOTAL POLICY HANDLERS`);\n\t\t// \tthis.exit(0);\n\t\t// }\n\n\t\tconst policies = this.commandConfig?.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\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t// const rawExclusions: string[] =\n\t\t// \tthis.flags.exclusions === undefined\n\t\t// \t\t? manifest.policy?.exclusions\n\t\t// \t\t: await readJson(this.flags.exclusions);\n\n\t\t// const exclusions: RegExp[] = rawExclusions.map((e) => new RegExp(e, \"i\"));\n\n\t\t// const rawHandlerExclusions = manifest?.policy?.handlerExclusions;\n\n\t\t// const handlerExclusions: ExcludedPolicyFileMap = {};\n\t\t// if (rawHandlerExclusions) {\n\t\t// \tfor (const rule of Object.keys(rawHandlerExclusions)) {\n\t\t// \t\thandlerExclusions[rule] = rawHandlerExclusions[rule].map(\n\t\t// \t\t\t(e) => new RegExp(e, \"i\"),\n\t\t// \t\t);\n\t\t// \t}\n\t\t// }\n\n\t\tconst filePathsToCheck: string[] = [];\n\t\t// const context = await this.getContext();\n\t\t// const gitRoot = context.repo.resolvedRoot;\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\t// const repo = new Repository({ baseDir: gitRoot });\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\tif (this.commandContext === undefined) {\n\t\t\tthis.error(\"Command context was undefined - fatal error.\", {\n\t\t\t\texit: 100,\n\t\t\t});\n\t\t}\n\n\t\tawait this.executePolicy(filePathsToCheck, this.commandContext);\n\t}\n\n\tprivate async executePolicy(\n\t\tpathsToCheck: string[],\n\t\tcommandContext: CheckPolicyCommandContext,\n\t): Promise<void> {\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\tthis.logStats();\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: CheckPolicyCommandContext,\n\t): Promise<void> {\n\t\tconst {\n\t\t\t// context,\n\t\t\tpolicies,\n\t\t\texcludePoliciesForFiles,\n\t\t\tgitRoot,\n\t\t} = 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\tawait Promise.all(\n\t\t\tpolicies\n\t\t\t\t.filter((handler) => handler.match.test(relPath))\n\t\t\t\t// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>\n\t\t\t\t.map(async (policy): Promise<void> => {\n\t\t\t\t\t// doing exclusion per handler\n\t\t\t\t\tconst exclusions = excludePoliciesForFiles.get(policy.name);\n\t\t\t\t\tif (\n\t\t\t\t\t\texclusions !== undefined &&\n\t\t\t\t\t\t!exclusions.every((regex) => !regex.test(relPath))\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.verbose(`Excluded from '${policy.name}' policy: ${relPath}`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst result = await runWithPerf(policy.name, \"handle\", async () =>\n\t\t\t\t\t\tpolicy.handler({\n\t\t\t\t\t\t\tfile: relPath,\n\t\t\t\t\t\t\troot: gitRoot,\n\t\t\t\t\t\t\tresolve: this.flags.fix,\n\t\t\t\t\t\t\tconfig: this.commandConfig?.policySettings?.[policy.name],\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\n\t\t\t\t\tif (result === true) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst messages = new StringBuilder();\n\t\t\t\t\tif (isPolicyFixResult(result)) {\n\t\t\t\t\t\tif (result.resolved) {\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\t`Resolved ${policy.name} policy failure for file: ${result.file}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\t`Error when trying to fix ${policy.name} policy failure in ${result.file}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// result must be a PolicyFailureResult; check if there is a standalone resolver.\n\t\t\t\t\t\tconst { resolver } = policy;\n\n\t\t\t\t\t\tif (this.flags.fix && resolver !== undefined) {\n\t\t\t\t\t\t\t// Resolve the failure\n\t\t\t\t\t\t\tmessages.append(`${newline}attempting to resolve: ${relPath}`);\n\t\t\t\t\t\t\tconst resolveResult = await runWithPerf(\n\t\t\t\t\t\t\t\tpolicy.name,\n\t\t\t\t\t\t\t\t\"resolve\",\n\t\t\t\t\t\t\t\tasync () => resolver({ file: relPath, root: gitRoot }),\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tresolveResult.errorMessage !== undefined &&\n\t\t\t\t\t\t\t\tresolveResult.errorMessage !== \"\"\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tmessages.append(newline + resolveResult.errorMessage);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!resolveResult.resolved) {\n\t\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// No resolver, or fix is false, so we're in the full failure case.\n\t\t\t\t\t\t\tconst autoFixable = result.autoFixable\n\t\t\t\t\t\t\t\t? chalk.green(\" (autofixable)\")\n\t\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\t`'${policy.name}' policy failure${autoFixable}: ${result.file}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\tresult.errorMessage === undefined\n\t\t\t\t\t\t\t\t\t? \"\"\n\t\t\t\t\t\t\t\t\t: `${newline}${result.errorMessage}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif ((process.exitCode ?? 0) === 0) {\n\t\t\t\t\t\tthis.info(messages.toString());\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.warning(messages.toString());\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t);\n\t}\n\n\tprivate logStats(): void {\n\t\tthis.log(\n\t\t\t`Statistics: ${this.processed} processed, ${\n\t\t\t\tthis.count - this.processed\n\t\t\t} excluded, ${this.count} total`,\n\t\t);\n\t\tfor (const [action, handlerPerf] of handlerPerformanceData.entries()) {\n\t\t\tthis.log(`Performance for \"${action}\":`);\n\t\t\tfor (const [handler, dur] of handlerPerf.entries()) {\n\t\t\t\tthis.log(`\\t${handler}: ${dur}ms`);\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\tprivate async checkOrExcludeFile(\n\t\tinputPath: string,\n\t\tcommandContext: CheckPolicyCommandContext,\n\t): Promise<void> {\n\t\tconst { excludeFiles: exclusions, gitRoot, pathRegex } = commandContext;\n\n\t\tconst filePath = path.join(gitRoot, inputPath).trim().replace(/\\\\/g, \"/\");\n\n\t\tif (!(pathRegex.test(inputPath) && fs.existsSync(filePath))) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.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(`Error routing ${filePath} to handler: ${error}`);\n\t\t}\n\n\t\tthis.processed++;\n\t}\n}\n\nasync function runWithPerf<T>(\n\tname: string,\n\taction: PolicyAction,\n\trun: () => Promise<T>,\n): Promise<T> {\n\tconst actionMap =\n\t\thandlerPerformanceData.get(action) ?? new Map<string, number>();\n\tlet dur = actionMap.get(name) ?? 0;\n\n\tconst start = Date.now();\n\tconst result = await run();\n\tdur += Date.now() - start;\n\n\tactionMap.set(name, dur);\n\thandlerPerformanceData.set(action, actionMap);\n\treturn result;\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 (stdin.isTTY) {\n\t\t\tresolve(\"\");\n\t\t}\n\t});\n}\n\nfunction toRegExp(input: string | RegExp): RegExp {\n\tif (typeof input === \"string\") {\n\t\treturn new RegExp(input, \"i\");\n\t}\n\treturn input;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EACN,iBAAiB,GAEjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,OAAO,WAKX,SAAQ,iBAAoB;IAC7B,MAAM,CAAmB,OAAO,GAC/B,6DAA6D,CAAC;IAE/D,MAAM,CAAmB,KAAK,GAAG;QAChC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC;YAClB,OAAO,EAAE,CAAC,SAAS,CAAC;YACpB,WAAW,EAAE,yBAAyB;YACtC,QAAQ,EAAE,KAAK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M,IAAI,KAAK,CAAC,iBAAiB,QAAQ,gBAAgB,KAAK,EAAE,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,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 fs from \"node:fs\";\nimport { EOL as newline } from \"node:os\";\nimport path from \"node:path\";\nimport { Flags } from \"@oclif/core\";\nimport { StringBuilder } from \"@rushstack/node-core-library\";\nimport chalk from \"chalk\";\n\nimport {\n\tBaseRepopoCommand,\n\ttype PolicyCommandContext,\n} from \"../baseCommand.js\";\nimport { DefaultPolicyConfig } from \"../config.js\";\nimport { logStats, runWithPerf } from \"../perf.js\";\nimport { 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\tprivate processed = 0;\n\tprivate count = 0;\n\n\tpublic override defaultConfig = DefaultPolicyConfig;\n\n\tpublic override async init(): Promise<void> {\n\t\tawait super.init();\n\n\t\tif (this.flags.fix) {\n\t\t\tthis.info(\"Resolving errors if possible.\");\n\t\t}\n\t}\n\n\tpublic override async run(): Promise<void> {\n\t\t// list the handlers then exit\n\t\tconst config = await this.loadConfig();\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\ttry {\n\t\t\tconst context = this.getContext();\n\t\t\tawait this.executePolicy(filePathsToCheck, context);\n\t\t} catch (error) {\n\t\t\tthis.error(`Command context was undefined - fatal error: ${error}`, {\n\t\t\t\texit: 100,\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async executePolicy(\n\t\tpathsToCheck: string[],\n\t\tcommandContext: PolicyCommandContext,\n\t): Promise<void> {\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\tlogStats(commandContext.perfStats, this);\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: PolicyCommandContext,\n\t): Promise<void> {\n\t\tconst { policies, excludePoliciesForFiles, gitRoot, perfStats } =\n\t\t\tcommandContext;\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\t\tconst config = await this.loadConfig();\n\n\t\tawait Promise.all(\n\t\t\tpolicies\n\t\t\t\t.filter((handler) => handler.match.test(relPath))\n\t\t\t\t// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>\n\t\t\t\t.map(async (policy): Promise<void> => {\n\t\t\t\t\t// doing exclusion per handler\n\t\t\t\t\tconst exclusions = excludePoliciesForFiles.get(policy.name);\n\t\t\t\t\tif (\n\t\t\t\t\t\texclusions !== undefined &&\n\t\t\t\t\t\t!exclusions.every((regex) => !regex.test(relPath))\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.verbose(`Excluded from '${policy.name}' policy: ${relPath}`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst result = await runWithPerf(\n\t\t\t\t\t\tpolicy.name,\n\t\t\t\t\t\t\"handle\",\n\t\t\t\t\t\tperfStats,\n\t\t\t\t\t\tasync () =>\n\t\t\t\t\t\t\tpolicy.handler({\n\t\t\t\t\t\t\t\tfile: relPath,\n\t\t\t\t\t\t\t\troot: gitRoot,\n\t\t\t\t\t\t\t\tresolve: this.flags.fix,\n\t\t\t\t\t\t\t\tconfig: config?.policySettings?.[policy.name],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\n\t\t\t\t\tif (result === true) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst messages = new StringBuilder();\n\t\t\t\t\tif (isPolicyFixResult(result)) {\n\t\t\t\t\t\tif (result.resolved) {\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\t`Resolved ${policy.name} policy failure for file: ${result.file}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\t`Error when trying to fix ${policy.name} policy failure in ${result.file}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// result must be a PolicyFailureResult; check if there is a standalone resolver.\n\t\t\t\t\t\tconst { resolver } = policy;\n\n\t\t\t\t\t\tif (this.flags.fix && resolver !== undefined) {\n\t\t\t\t\t\t\t// Resolve the failure\n\t\t\t\t\t\t\tmessages.append(`${newline}attempting to resolve: ${relPath}`);\n\t\t\t\t\t\t\tconst resolveResult = await runWithPerf(\n\t\t\t\t\t\t\t\tpolicy.name,\n\t\t\t\t\t\t\t\t\"resolve\",\n\t\t\t\t\t\t\t\tperfStats,\n\t\t\t\t\t\t\t\tasync () => resolver({ file: relPath, root: gitRoot }),\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tresolveResult.errorMessage !== undefined &&\n\t\t\t\t\t\t\t\tresolveResult.errorMessage !== \"\"\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tmessages.append(newline + resolveResult.errorMessage);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!resolveResult.resolved) {\n\t\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// No resolver, or fix is false, so we're in the full failure case.\n\t\t\t\t\t\t\tconst autoFixable = result.autoFixable\n\t\t\t\t\t\t\t\t? chalk.green(\" (autofixable)\")\n\t\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\t`'${policy.name}' policy failure${autoFixable}: ${result.file}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tmessages.append(\n\t\t\t\t\t\t\t\tresult.errorMessage === undefined\n\t\t\t\t\t\t\t\t\t? \"\"\n\t\t\t\t\t\t\t\t\t: `${newline}${result.errorMessage}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif ((process.exitCode ?? 0) === 0) {\n\t\t\t\t\t\tthis.info(messages.toString());\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.warning(messages.toString());\n\t\t\t\t\t}\n\t\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\tprivate async checkOrExcludeFile(\n\t\tinputPath: string,\n\t\tcommandContext: PolicyCommandContext,\n\t): Promise<void> {\n\t\tconst { excludeFiles: exclusions, gitRoot, pathRegex } = commandContext;\n\n\t\tconst filePath = path.join(gitRoot, inputPath).trim().replace(/\\\\/g, \"/\");\n\n\t\tif (!(pathRegex.test(inputPath) && fs.existsSync(filePath))) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.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(`Error routing ${filePath} to handler: ${error}`);\n\t\t}\n\n\t\tthis.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 (stdin.isTTY) {\n\t\t\tresolve(\"\");\n\t\t}\n\t});\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseRepopoCommand } from "../baseCommand.js";
|
|
2
|
+
import type { RepoPolicy } from "../policy.js";
|
|
3
|
+
/**
|
|
4
|
+
* This command lists all the policies configured to run.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ListCommand<T extends typeof BaseRepopoCommand & {
|
|
7
|
+
args: typeof ListCommand.args;
|
|
8
|
+
flags: typeof ListCommand.flags;
|
|
9
|
+
}> extends BaseRepopoCommand<T> {
|
|
10
|
+
static readonly summary = "Lists the policies configured to run.";
|
|
11
|
+
run(): Promise<RepoPolicy[]>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;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,gBAAyB,OAAO,2CAA2C;IAGrD,GAAG,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;CAUlD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { BaseRepopoCommand } from "../baseCommand.js";
|
|
3
|
+
/**
|
|
4
|
+
* This command lists all the policies configured to run.
|
|
5
|
+
*/
|
|
6
|
+
export class ListCommand extends BaseRepopoCommand {
|
|
7
|
+
static summary = "Lists the policies configured to run.";
|
|
8
|
+
// biome-ignore lint/suspicious/useAwait: inherited method
|
|
9
|
+
async run() {
|
|
10
|
+
const { policies } = this.getContext();
|
|
11
|
+
// list the handlers then exit
|
|
12
|
+
this.log(`${policies.length} POLICIES ENABLED`);
|
|
13
|
+
for (const h of policies) {
|
|
14
|
+
this.log(`${chalk.bold(h.name)} (auto-fix: ${h.resolver !== undefined})`);
|
|
15
|
+
}
|
|
16
|
+
return policies;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;GAEG;AACH,MAAM,OAAO,WAKX,SAAQ,iBAAoB;IAC7B,MAAM,CAAmB,OAAO,GAAG,uCAAuC,CAAC;IAE3E,0DAA0D;IAC1C,KAAK,CAAC,GAAG;QACxB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAEvC,8BAA8B;QAC9B,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,mBAAmB,CAAC,CAAC;QAChD,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,QAAQ,KAAK,SAAS,GAAG,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC","sourcesContent":["import chalk from \"chalk\";\n\nimport { BaseRepopoCommand } from \"../baseCommand.js\";\nimport type { RepoPolicy } 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\tstatic override readonly summary = \"Lists the policies configured to run.\";\n\n\t// biome-ignore lint/suspicious/useAwait: inherited method\n\tpublic override async run(): Promise<RepoPolicy[]> {\n\t\tconst { policies } = this.getContext();\n\n\t\t// list the handlers then exit\n\t\tthis.log(`${policies.length} POLICIES ENABLED`);\n\t\tfor (const h of policies) {\n\t\t\tthis.log(`${chalk.bold(h.name)} (auto-fix: ${h.resolver !== undefined})`);\n\t\t}\n\t\treturn policies;\n\t}\n}\n"]}
|
package/esm/config.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { RequireAtLeastOne, SetOptional } from "type-fest";
|
|
2
1
|
import type { PackageJsonPropertiesSettings } from "./policies/PackageJsonProperties.js";
|
|
3
|
-
import type
|
|
2
|
+
import { type PolicyName, type RepoPolicy } from "./policy.js";
|
|
4
3
|
/**
|
|
5
4
|
* @alpha
|
|
6
5
|
*/
|
|
@@ -10,11 +9,14 @@ export type PerPolicySettings = ({
|
|
|
10
9
|
/**
|
|
11
10
|
* @alpha
|
|
12
11
|
*/
|
|
13
|
-
export interface
|
|
12
|
+
export interface PolicyConfig {
|
|
13
|
+
/**
|
|
14
|
+
* An array of policies that are enabled. If this is `undefined`, then all {@link DefaultPolicies} will be enabled.
|
|
15
|
+
*/
|
|
14
16
|
policies?: RepoPolicy[];
|
|
15
17
|
/**
|
|
16
|
-
* An array of strings/regular expressions.
|
|
17
|
-
* policy.
|
|
18
|
+
* An array of strings/regular expressions. File paths that match any of these expressions will be completely excluded
|
|
19
|
+
* from policy.
|
|
18
20
|
*/
|
|
19
21
|
excludeFiles?: (string | RegExp)[];
|
|
20
22
|
/**
|
|
@@ -22,14 +24,12 @@ export interface OptionalPolicyConfig {
|
|
|
22
24
|
* exclude that rule from being checked.
|
|
23
25
|
*/
|
|
24
26
|
excludePoliciesForFiles?: Record<PolicyName, (string | RegExp)[]>;
|
|
25
|
-
includeDefaultPolicies?: boolean;
|
|
26
27
|
policySettings?: PerPolicySettings | undefined;
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
|
-
*
|
|
30
|
+
* The default config applied when no config is found.
|
|
30
31
|
*
|
|
31
32
|
* @alpha
|
|
32
33
|
*/
|
|
33
|
-
export
|
|
34
|
-
export declare const DefaultPolicyConfig: SetOptional<Required<PolicyConfig>, "policies" | "policySettings">;
|
|
34
|
+
export declare const DefaultPolicyConfig: PolicyConfig;
|
|
35
35
|
//# sourceMappingURL=config.d.ts.map
|
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,6BAA6B,EAAE,MAAM,qCAAqC,CAAC;AACzF,OAAO,EAAmB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAC1B,CAAC;IACD,qBAAqB,EAAE,6BAA6B,CAAC;CACpD,GAAG,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,GAChC,SAAS,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;OAEG;IACH,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IAExB;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAEnC;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IAElE,cAAc,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAC/C;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAIjC,CAAC"}
|
package/esm/config.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import { DefaultPolicies } from "./policy.js";
|
|
2
|
+
/**
|
|
3
|
+
* The default config applied when no config is found.
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
6
|
+
*/
|
|
1
7
|
export const DefaultPolicyConfig = {
|
|
8
|
+
policies: DefaultPolicies,
|
|
2
9
|
excludeFiles: [],
|
|
3
10
|
excludePoliciesForFiles: {},
|
|
4
|
-
includeDefaultPolicies: true,
|
|
5
11
|
};
|
|
6
12
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAoC,MAAM,aAAa,CAAC;AAmChF;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAiB;IAChD,QAAQ,EAAE,eAAe;IACzB,YAAY,EAAE,EAAE;IAChB,uBAAuB,EAAE,EAAE;CAC3B,CAAC","sourcesContent":["import type { PackageJsonPropertiesSettings } from \"./policies/PackageJsonProperties.js\";\nimport { DefaultPolicies, type PolicyName, type RepoPolicy } from \"./policy.js\";\n\n/**\n * @alpha\n */\nexport type PerPolicySettings =\n\t| ({\n\t\t\tPackageJsonProperties: PackageJsonPropertiesSettings;\n\t } & Record<PolicyName, unknown>)\n\t| undefined;\n\n/**\n * @alpha\n */\nexport interface PolicyConfig {\n\t/**\n\t * An array of policies that are enabled. If this is `undefined`, then all {@link DefaultPolicies} will be enabled.\n\t */\n\tpolicies?: RepoPolicy[];\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\t/**\n\t * An object with a policy name as keys that map to an array of strings/regular expressions to\n\t * exclude that rule from being checked.\n\t */\n\texcludePoliciesForFiles?: Record<PolicyName, (string | RegExp)[]>;\n\n\tpolicySettings?: PerPolicySettings | undefined;\n}\n\n/**\n * The default config applied when no config is found.\n *\n * @alpha\n */\nexport const DefaultPolicyConfig: PolicyConfig = {\n\tpolicies: DefaultPolicies,\n\texcludeFiles: [],\n\texcludePoliciesForFiles: {},\n};\n"]}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { run } from "@oclif/core";
|
|
2
2
|
export type { PolicyFailure, PolicyFixResult, PolicyFunctionArguments, PolicyHandler, PolicyName, PolicyStandaloneResolver, RepoPolicy, } from "./policy.js";
|
|
3
3
|
export { DefaultPolicies } from "./policy.js";
|
|
4
|
-
export type { PolicyConfig,
|
|
4
|
+
export type { PolicyConfig, PerPolicySettings, } from "./config.js";
|
|
5
5
|
export type { PackageJsonPropertiesSettings, PackageJsonProperty, } from "./policies/PackageJsonProperties.js";
|
|
6
6
|
//# 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;AAElC,YAAY,EACX,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,UAAU,EACV,wBAAwB,EACxB,UAAU,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EACX,YAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,YAAY,EACX,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,UAAU,EACV,wBAAwB,EACxB,UAAU,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EACX,YAAY,EACZ,iBAAiB,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EACX,6BAA6B,EAC7B,mBAAmB,GACnB,MAAM,qCAAqC,CAAC"}
|
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;AAWlC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { run } from \"@oclif/core\";\n\nexport type {\n\tPolicyFailure,\n\tPolicyFixResult,\n\tPolicyFunctionArguments,\n\tPolicyHandler,\n\tPolicyName,\n\tPolicyStandaloneResolver,\n\tRepoPolicy,\n} from \"./policy.js\";\nexport { DefaultPolicies } from \"./policy.js\";\nexport type {\n\tPolicyConfig,\n\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAWlC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { run } from \"@oclif/core\";\n\nexport type {\n\tPolicyFailure,\n\tPolicyFixResult,\n\tPolicyFunctionArguments,\n\tPolicyHandler,\n\tPolicyName,\n\tPolicyStandaloneResolver,\n\tRepoPolicy,\n} from \"./policy.js\";\nexport { DefaultPolicies } from \"./policy.js\";\nexport type {\n\tPolicyConfig,\n\tPerPolicySettings,\n} from \"./config.js\";\nexport type {\n\tPackageJsonPropertiesSettings,\n\tPackageJsonProperty,\n} from \"./policies/PackageJsonProperties.js\";\n"]}
|
package/esm/perf.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Logger } from "@tylerbu/cli-api";
|
|
2
|
+
import type { PolicyName } from "./policy.js";
|
|
3
|
+
export type PolicyAction = "handle" | "resolve";
|
|
4
|
+
export interface PolicyHandlerPerfStats {
|
|
5
|
+
count: number;
|
|
6
|
+
processed: number;
|
|
7
|
+
data: Map<PolicyAction, Map<PolicyName, number>>;
|
|
8
|
+
}
|
|
9
|
+
export declare function newPerfStats(): PolicyHandlerPerfStats;
|
|
10
|
+
export declare function runWithPerf<T>(name: string, action: PolicyAction, stats: PolicyHandlerPerfStats, run: () => Promise<T>): Promise<T>;
|
|
11
|
+
export declare function logStats(stats: PolicyHandlerPerfStats, log: Logger): void;
|
|
12
|
+
//# sourceMappingURL=perf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perf.d.ts","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,CAAC;AAOhD,MAAM,WAAW,sBAAsB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;CACjD;AAED,wBAAgB,YAAY,IAAI,sBAAsB,CAMrD;AAED,wBAAsB,WAAW,CAAC,CAAC,EAClC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,sBAAsB,EAC7B,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAWZ;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,sBAAsB,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAYzE"}
|
package/esm/perf.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stores performance data for each handler. Used to collect and display performance stats.
|
|
3
|
+
*/
|
|
4
|
+
const handlerPerformanceData = new Map();
|
|
5
|
+
export function newPerfStats() {
|
|
6
|
+
return {
|
|
7
|
+
count: 0,
|
|
8
|
+
processed: 0,
|
|
9
|
+
data: new Map(),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export async function runWithPerf(name, action, stats, run) {
|
|
13
|
+
const actionMap = stats.data.get(action) ?? new Map();
|
|
14
|
+
let dur = actionMap.get(name) ?? 0;
|
|
15
|
+
const start = Date.now();
|
|
16
|
+
const result = await run();
|
|
17
|
+
dur += Date.now() - start;
|
|
18
|
+
actionMap.set(name, dur);
|
|
19
|
+
stats.data.set(action, actionMap);
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
export function logStats(stats, log) {
|
|
23
|
+
log.log(`Statistics: ${stats.processed} processed, ${stats.count - stats.processed} excluded, ${stats.count} total`);
|
|
24
|
+
for (const [action, handlerPerf] of handlerPerformanceData.entries()) {
|
|
25
|
+
log.log(`Performance for "${action}":`);
|
|
26
|
+
for (const [handler, dur] of handlerPerf.entries()) {
|
|
27
|
+
log.log(`\t${handler}: ${dur}ms`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|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O,EAAE,EAAE,CAAC;QACtE,GAAG,CAAC,GAAG,CAAC,oBAAoB,MAAM,IAAI,CAAC,CAAC;QACxC,KAAK,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;YACpD,GAAG,CAAC,GAAG,CAAC,KAAK,OAAO,KAAK,GAAG,IAAI,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import type { Logger } from \"@tylerbu/cli-api\";\nimport type { PolicyName } from \"./policy.js\";\n\nexport type PolicyAction = \"handle\" | \"resolve\";\n\n/**\n * Stores performance data for each handler. Used to collect and display performance stats.\n */\nconst handlerPerformanceData = new Map<PolicyAction, Map<PolicyName, number>>();\n\nexport interface PolicyHandlerPerfStats {\n\tcount: number;\n\tprocessed: number;\n\tdata: Map<PolicyAction, Map<PolicyName, number>>;\n}\n\nexport function newPerfStats(): PolicyHandlerPerfStats {\n\treturn {\n\t\tcount: 0,\n\t\tprocessed: 0,\n\t\tdata: new Map<PolicyAction, Map<PolicyName, number>>(),\n\t};\n}\n\nexport async function runWithPerf<T>(\n\tname: string,\n\taction: PolicyAction,\n\tstats: PolicyHandlerPerfStats,\n\trun: () => Promise<T>,\n): Promise<T> {\n\tconst actionMap = stats.data.get(action) ?? new Map<string, number>();\n\tlet dur = actionMap.get(name) ?? 0;\n\n\tconst start = Date.now();\n\tconst result = await run();\n\tdur += Date.now() - start;\n\n\tactionMap.set(name, dur);\n\tstats.data.set(action, actionMap);\n\treturn result;\n}\n\nexport function logStats(stats: PolicyHandlerPerfStats, log: Logger): void {\n\tlog.log(\n\t\t`Statistics: ${stats.processed} processed, ${\n\t\t\tstats.count - stats.processed\n\t\t} excluded, ${stats.count} total`,\n\t);\n\tfor (const [action, handlerPerf] of handlerPerformanceData.entries()) {\n\t\tlog.log(`Performance for \"${action}\":`);\n\t\tfor (const [handler, dur] of handlerPerf.entries()) {\n\t\t\tlog.log(`\\t${handler}: ${dur}ms`);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJsonProperties.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PackageJsonProperties.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAkC,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAEzC;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC7C;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;CAC9C;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,UAAU,CAAC,6BAA6B,CAkD1E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJsonProperties.js","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PackageJsonProperties.js","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC;AAqB9D;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GACjC;IACC,IAAI,EAAE,uBAAuB;IAC7B,KAAK,EAAE,sBAAsB;IAC7B,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;QAC5C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,UAAU,GAAkB;YACjC,IAAI,EAAE,qBAAqB,CAAC,IAAI;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port jsonfile from \"jsonfile\";\nconst { writeFile: writeJson, readFile: readJson } = jsonfile;\n\nimport type { PolicyFailure, PolicyFixResult, RepoPolicy } from \"../policy.js\";\n\n/**\n * @alpha\n */\nexport type PackageJsonProperty = string;\n\n/**\n * Policy settings for the PackageJsonProperties repo policy.\n *\n * @alpha\n */\nexport interface PackageJsonPropertiesSettings {\n\t/**\n\t * Sets a package.json property to the string value provided. The string value will be used verbatim.\n\t */\n\tverbatim: Record<PackageJsonProperty, string>;\n}\n\n/**\n * A RepoPolicy that checks that package.json properties in packages match expected values.\n */\nexport const PackageJsonProperties: RepoPolicy<PackageJsonPropertiesSettings> =\n\t{\n\t\tname: \"PackageJsonProperties\",\n\t\tmatch: /(^|\\/)package\\.json/i,\n\t\thandler: async ({ file, config, resolve }) => {\n\t\t\tif (config === undefined) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst failResult: PolicyFailure = {\n\t\t\t\tname: PackageJsonProperties.name,\n\t\t\t\tfile,\n\t\t\t\tautoFixable: true,\n\t\t\t};\n\n\t\t\tconst { verbatim } = config;\n\t\t\tconst json = (await readJson(file)) as PackageJson;\n\t\t\tconst messages: string[] = [];\n\n\t\t\tfor (const [propName, value] of Object.entries(verbatim)) {\n\t\t\t\tif (json[propName] !== value) {\n\t\t\t\t\tmessages.push(\n\t\t\t\t\t\t`Incorrect package.json field value for '${propName}'. Expected '${value}', got '${json[propName]}'.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (messages.length > 0) {\n\t\t\t\tif (resolve) {\n\t\t\t\t\tconst fixResult: PolicyFixResult = {\n\t\t\t\t\t\t...failResult,\n\t\t\t\t\t\tresolved: false,\n\t\t\t\t\t};\n\n\t\t\t\t\tfor (const [propName, value] of Object.entries(verbatim)) {\n\t\t\t\t\t\tjson[propName] = value;\n\t\t\t\t\t}\n\t\t\t\t\tawait writeJson(file, json, { spaces: \"\\t\" });\n\n\t\t\t\t\tfixResult.resolved = true;\n\t\t\t\t\treturn fixResult;\n\t\t\t\t}\n\n\t\t\t\t// There were errors, and we're not resolving them, so return a fail result\n\t\t\t\tfailResult.errorMessage = messages.join(\"\\n\");\n\t\t\t\treturn failResult;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t},\n\t};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJsonRepoDirectoryProperty.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PackageJsonRepoDirectoryProperty.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAkC,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/E;;;GAGG;AACH,eAAO,MAAM,gCAAgC,EAAE,UA2C9C,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { updatePackageJsonFile } from "@fluidframework/build-tools";
|
|
4
|
-
import
|
|
4
|
+
import jsonfile from "jsonfile";
|
|
5
|
+
const { readFile: readJson } = jsonfile;
|
|
5
6
|
/**
|
|
6
7
|
* A RepoPolicy that checks that the repository.directory property in package.json is set correctly. If the repository
|
|
7
8
|
* field is a string instead of an object the package will be ignored.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJsonRepoDirectoryProperty.js","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"PackageJsonRepoDirectoryProperty.js","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings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SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC;oBAC3B,CAAC;oBAAC,OAAO,KAAc,EAAE,CAAC;wBACzB,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;wBAC3B,SAAS,CAAC,YAAY,GAAG,GAAI,KAAe,CAAC,OAAO,KAClD,KAAe,CAAC,KAClB,EAAE,CAAC;oBACJ,CAAC;oBACD,OAAO,SAAS,CAAC;gBAClB,CAAC;gBACD,UAAU,CAAC,YAAY,GAAG,kDAAkD,cAAc,WAAW,GAAG,CAAC,UAAU,CAAC,SAAS,GAAG,CAAC;gBACjI,OAAO,UAAU,CAAC;YACnB,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport path from \"node:path\";\nimport { updatePackageJsonFile } from \"@fluidframework/build-tools\";\nimport type { PackageJson } from \"type-fest\";\n\nimport jsonfile from \"jsonfile\";\nconst { readFile: readJson } = jsonfile;\n\nimport type { PolicyFailure, PolicyFixResult, RepoPolicy } from \"../policy.js\";\n\n/**\n * A RepoPolicy that checks that the repository.directory property in package.json is set correctly. If the repository\n * field is a string instead of an object the package will be ignored.\n */\nexport const PackageJsonRepoDirectoryProperty: RepoPolicy = {\n\tname: \"PackageJsonRepoDirectoryProperty\",\n\tmatch: /(^|\\/)package\\.json/i,\n\thandler: async ({ file, root, resolve }) => {\n\t\tconst failResult: PolicyFailure = {\n\t\t\tname: PackageJsonRepoDirectoryProperty.name,\n\t\t\tfile,\n\t\t\tautoFixable: true,\n\t\t};\n\n\t\tconst fixResult: PolicyFixResult = {\n\t\t\t...failResult,\n\t\t\tresolved: false,\n\t\t};\n\n\t\tconst pkg = (await readJson(file)) as PackageJson;\n\t\tconst pkgDir = path.dirname(file);\n\t\tconst relativePkgDir = path.relative(root, pkgDir);\n\n\t\tif (typeof pkg.repository === \"object\") {\n\t\t\tif (pkg.repository.directory !== relativePkgDir) {\n\t\t\t\tif (resolve) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tupdatePackageJsonFile(file, (json) => {\n\t\t\t\t\t\t\tassert(typeof json.repository === \"object\");\n\t\t\t\t\t\t\tjson.repository.directory = relativePkgDir;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tfixResult.resolved = true;\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tfixResult.resolved = false;\n\t\t\t\t\t\tfixResult.errorMessage = `${(error as Error).message}\\n${\n\t\t\t\t\t\t\t(error as Error).stack\n\t\t\t\t\t\t}`;\n\t\t\t\t\t}\n\t\t\t\t\treturn fixResult;\n\t\t\t\t}\n\t\t\t\tfailResult.errorMessage = `repository.directory value is wrong. Expected '${relativePkgDir}', got '${pkg.repository.directory}'`;\n\t\t\t\treturn failResult;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t},\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJsonSortedPolicy.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonSortedPolicy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PackageJsonSortedPolicy.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonSortedPolicy.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAkC,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,UAwCrC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { updatePackageJsonFile } from "@tylerbu/cli-api";
|
|
2
|
-
import { readJson } from "fs-extra/esm";
|
|
3
2
|
import { sortPackageJson } from "sort-package-json";
|
|
3
|
+
import jsonfile from "jsonfile";
|
|
4
|
+
const { readFile: readJson } = jsonfile;
|
|
4
5
|
/**
|
|
5
6
|
* A repo policy that checks if package.json files in the repo are sorted using sort-package-json.
|
|
6
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJsonSortedPolicy.js","sourceRoot":"","sources":["../../src/policies/PackageJsonSortedPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"PackageJsonSortedPolicy.js","sourceRoot":"","sources":["../../src/policies/PackageJsonSortedPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC;AAIxC;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAe;IAClD,IAAI,EAAE,yBAAyB;IAC/B,KAAK,EAAE,sBAAsB;IAC7B,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;QACpC,MAAM,IAAI,GAAgB,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAErE,IAAI,QAAQ,EAAE,CAAC;YACd,OAAO,IAAI,CAAC;QACb,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACb,IAAI,CAAC;gBACJ,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBAClE,MAAM,MAAM,GAAoB;oBAC/B,IAAI,EAAE,uBAAuB,CAAC,IAAI;oBAClC,IAAI;oBACJ,QAAQ,EAAE,IAAI;iBACd,CAAC;gBACF,OAAO,MAAM,CAAC;YACf,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACzB,MAAM,MAAM,GAAoB;oBAC/B,IAAI,EAAE,uBAAuB,CAAC,IAAI;oBAClC,IAAI;oBACJ,QAAQ,EAAE,KAAK;oBACf,WAAW,EAAE,IAAI;oBACjB,YAAY,EAAG,KAAe,CAAC,OAAO;iBACtC,CAAC;gBACF,OAAO,MAAM,CAAC;YACf,CAAC;QACF,CAAC;aAAM,CAAC;YACP,MAAM,MAAM,GAAkB;gBAC7B,IAAI,EAAE,uBAAuB,CAAC,IAAI;gBAClC,IAAI;gBACJ,WAAW,EAAE,IAAI;aACjB,CAAC;YACF,OAAO,MAAM,CAAC;QACf,CAAC;IACF,CAAC;CACD,CAAC","sourcesContent":["import { updatePackageJsonFile } from \"@tylerbu/cli-api\";\nimport { sortPackageJson } from \"sort-package-json\";\nimport type { PackageJson } from \"type-fest\";\n\nimport jsonfile from \"jsonfile\";\nconst { readFile: readJson } = jsonfile;\n\nimport type { PolicyFailure, PolicyFixResult, RepoPolicy } from \"../policy.js\";\n\n/**\n * A repo policy that checks if package.json files in the repo are sorted using sort-package-json.\n */\nexport const PackageJsonSortedPolicy: RepoPolicy = {\n\tname: \"PackageJsonSortedPolicy\",\n\tmatch: /(^|\\/)package\\.json/i,\n\thandler: async ({ file, resolve }) => {\n\t\tconst json: PackageJson = await readJson(file);\n\t\tconst sortedJson = sortPackageJson(json);\n\t\tconst isSorted = JSON.stringify(sortedJson) === JSON.stringify(json);\n\n\t\tif (isSorted) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (resolve) {\n\t\t\ttry {\n\t\t\t\tawait updatePackageJsonFile(file, (json) => json, { sort: true });\n\t\t\t\tconst result: PolicyFixResult = {\n\t\t\t\t\tname: PackageJsonSortedPolicy.name,\n\t\t\t\t\tfile,\n\t\t\t\t\tresolved: true,\n\t\t\t\t};\n\t\t\t\treturn result;\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst result: PolicyFixResult = {\n\t\t\t\t\tname: PackageJsonSortedPolicy.name,\n\t\t\t\t\tfile,\n\t\t\t\t\tresolved: false,\n\t\t\t\t\tautoFixable: true,\n\t\t\t\t\terrorMessage: (error as Error).message,\n\t\t\t\t};\n\t\t\t\treturn result;\n\t\t\t}\n\t\t} else {\n\t\t\tconst result: PolicyFailure = {\n\t\t\t\tname: PackageJsonSortedPolicy.name,\n\t\t\t\tfile,\n\t\t\t\tautoFixable: true,\n\t\t\t};\n\t\t\treturn result;\n\t\t}\n\t},\n};\n"]}
|
package/esm/policy.d.ts
CHANGED
|
@@ -83,15 +83,32 @@ export declare class RepoPolicyClass implements RepoPolicy {
|
|
|
83
83
|
* @alpha
|
|
84
84
|
*/
|
|
85
85
|
export interface PolicyFailure {
|
|
86
|
+
/**
|
|
87
|
+
* Name of the policy that failed.
|
|
88
|
+
*/
|
|
86
89
|
name: PolicyName;
|
|
90
|
+
/**
|
|
91
|
+
* Path to the file that failed the policy.
|
|
92
|
+
*/
|
|
87
93
|
file: string;
|
|
94
|
+
/**
|
|
95
|
+
* Set to `true` if the policy can be fixed automatically.
|
|
96
|
+
*/
|
|
88
97
|
autoFixable?: boolean | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* An optional error message accompanying the failure.
|
|
100
|
+
*/
|
|
89
101
|
errorMessage?: string | undefined;
|
|
90
102
|
}
|
|
91
103
|
/**
|
|
104
|
+
* The result of an automatic fix for a failing policy.
|
|
105
|
+
*
|
|
92
106
|
* @alpha
|
|
93
107
|
*/
|
|
94
108
|
export interface PolicyFixResult extends PolicyFailure {
|
|
109
|
+
/**
|
|
110
|
+
* Set to true if the failure was resolved by the automated fixer.
|
|
111
|
+
*/
|
|
95
112
|
resolved: boolean;
|
|
96
113
|
}
|
|
97
114
|
export declare function isPolicyFixResult(toCheck: any): toCheck is PolicyFixResult;
|
package/esm/policy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"m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IAE1B;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,wBAAwB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;CACnD;AAED,qBAAa,eAAgB,YAAW,UAAU;aAWhC,IAAI,EAAE,MAAM;aACZ,KAAK,EAAE,MAAM;IACtB,OAAO,EAAE,aAAa;IACtB,QAAQ,CAAC,EAAE,wBAAwB;WAb7B,gBAAgB,CAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,aAAa,EACtB,QAAQ,CAAC,EAAE,wBAAwB,GACjC,eAAe;gBAKD,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACtB,OAAO,EAAE,aAAa,EACtB,QAAQ,CAAC,EAAE,wBAAwB,YAAA;CAI3C;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC7B;;OAEG;IACH,IAAI,EAAE,UAAU,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAElC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACrD;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;CAClB;AAGD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,IAAI,eAAe,CAK1E;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,UAAU,EAMvC,CAAC"}
|
package/esm/policy.js
CHANGED
|
@@ -26,18 +26,6 @@ export function isPolicyFixResult(toCheck) {
|
|
|
26
26
|
}
|
|
27
27
|
return "resolved" in toCheck;
|
|
28
28
|
}
|
|
29
|
-
// export const commonMatchPatterns = {
|
|
30
|
-
// "package.json": /(^|\/)package\.json/i,
|
|
31
|
-
// } as const;
|
|
32
|
-
// export function createPackageJsonPolicy(
|
|
33
|
-
// props: Omit<RepoPolicy, "match">,
|
|
34
|
-
// ): RepoPolicy {
|
|
35
|
-
// const newPolicy: RepoPolicy = {
|
|
36
|
-
// ...props,
|
|
37
|
-
// match: commonMatchPatterns["package.json"],
|
|
38
|
-
// };
|
|
39
|
-
// return newPolicy;
|
|
40
|
-
// }
|
|
41
29
|
/**
|
|
42
30
|
* Default policies included with repopo.
|
|
43
31
|
*
|
package/esm/policy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AA+F5D,MAAM,OAAO,eAAe;IAWV;IACA;IACT;IACA;IAbD,MAAM,CAAC,gBAAgB,CAC7B,IAAY,EACZ,KAAa,EACb,OAAsB,EACtB,QAAmC;QAEnC,OAAO,IAAI,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAED,YACiB,IAAY,EACZ,KAAa,EACtB,OAAsB,EACtB,QAAmC;QAH1B,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAQ;QACtB,YAAO,GAAP,OAAO,CAAe;QACtB,aAAQ,GAAR,QAAQ,CAA2B;QAE1C,QAAQ;IACT,CAAC;CACD;
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AA+F5D,MAAM,OAAO,eAAe;IAWV;IACA;IACT;IACA;IAbD,MAAM,CAAC,gBAAgB,CAC7B,IAAY,EACZ,KAAa,EACb,OAAsB,EACtB,QAAmC;QAEnC,OAAO,IAAI,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAED,YACiB,IAAY,EACZ,KAAa,EACtB,OAAsB,EACtB,QAAmC;QAH1B,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAQ;QACtB,YAAO,GAAP,OAAO,CAAe;QACtB,aAAQ,GAAR,QAAQ,CAA2B;QAE1C,QAAQ;IACT,CAAC;CACD;AAyCD,yDAAyD;AACzD,MAAM,UAAU,iBAAiB,CAAC,OAAY;IAC7C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,UAAU,IAAI,OAAO,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAiB;IAC5C,kBAAkB;IAClB,gCAAgC;IAChC,qBAAqB;IACrB,uBAAuB;IACvB,aAAa;CACb,CAAC","sourcesContent":["import { NoJsFileExtensions } from \"./policies/NoJsFileExtensions.js\";\nimport { PackageJsonProperties } from \"./policies/PackageJsonProperties.js\";\nimport { PackageJsonRepoDirectoryProperty } from \"./policies/PackageJsonRepoDirectoryProperty.js\";\nimport { PackageJsonSortedPolicy } from \"./policies/PackageJsonSortedPolicy.js\";\nimport { SortTsconfigs } from \"./policies/SortTsconfigs.js\";\n\n/**\n * A type representing a policy name.\n *\n * @alpha\n */\nexport type PolicyName = string;\n\n/**\n * @alpha\n */\nexport interface PolicyFunctionArguments<C = unknown | undefined> {\n\tfile: string;\n\troot: string;\n\tresolve: boolean;\n\tconfig?: C;\n}\n\n/**\n * A policy handler is a function that is called to check policy against a file.\n *\n * @alpha\n */\nexport type PolicyHandler<C = unknown | undefined> = (\n\targs: PolicyFunctionArguments<C>,\n) => Promise<true | PolicyFailure | PolicyFixResult>;\n\n// export type PolicyCheckOnly = (\n// \tfile: string,\n// \troot: string,\n// ) => Promise<true | PolicyFailure | PolicyFixResult>;\n\n/**\n * A standalone function that can be called to resolve a policy failure.\n *\n * @alpha\n */\nexport type PolicyStandaloneResolver<C = unknown | undefined> = (\n\targs: Omit<PolicyFunctionArguments<C>, \"resolve\">,\n) => PolicyFixResult;\n\n// function isPolicyHandler(input: PolicyHandler | PolicyCheckOnly): input is PolicyHandler\n\n/**\n * A RepoPolicy checks and applies policies to files in the repository.\n *\n * Each policy has a name and a match regex for matching which files it should apply to. Every file in th repo is\n * enumerated and if it matches the regex for a policy, that policy is applied.\n *\n * Each policy includes a handler function that checks a file against the policy and can optionally resolve any problems\n * (automated resolutions depend on the policy implementation).\n *\n * @typeParam C - type of configuration object used by the policy\n *\n * @alpha\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: TODO - figure out if this can work with unknown or in another typesafe manner\nexport interface RepoPolicy<C = any | undefined> {\n\t/**\n\t * The name of the policy; displayed in UI and used in settings.\n\t */\n\tname: PolicyName;\n\n\t/**\n\t * A more detailed description of the policy and its intended function.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * A regular expression that is used to match files in the repo.\n\t */\n\tmatch: RegExp;\n\n\t/**\n\t * A handler function that checks if a file is compliant with the policy.\n\t *\n\t * @param file - Repo-relative path to the file to check.\n\t * @param root - Absolute path to the root of the repo.\n\t * @param resolve - If true, automated policy fixes will be applied. Not all policies support automated fixes.\n\t * @returns True if the file passed the policy; otherwise a PolicyFailure object will be returned.\n\t */\n\thandler: PolicyHandler<C>;\n\n\t/**\n\t * A resolver function that can be used to automatically address the policy violation.\n\t *\n\t * @param file - Repo-relative path to the file to check.\n\t * @param root - Absolute path to the root of the repo.\n\t * @returns true if the file passed the policy; otherwise a PolicyFailure object will be returned.\n\t */\n\tresolver?: PolicyStandaloneResolver<C> | undefined;\n}\n\nexport class RepoPolicyClass implements RepoPolicy {\n\tpublic static createRepoPolicy(\n\t\tname: string,\n\t\tmatch: RegExp,\n\t\thandler: PolicyHandler,\n\t\tresolver?: PolicyStandaloneResolver,\n\t): RepoPolicyClass {\n\t\treturn new RepoPolicyClass(name, match, handler, resolver);\n\t}\n\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly match: RegExp,\n\t\tpublic handler: PolicyHandler,\n\t\tpublic resolver?: PolicyStandaloneResolver,\n\t) {\n\t\t// empty\n\t}\n}\n\n/**\n * A policy failure.\n *\n * @alpha\n */\nexport interface PolicyFailure {\n\t/**\n\t * Name of the policy that failed.\n\t */\n\tname: PolicyName;\n\n\t/**\n\t * Path to the file that failed the policy.\n\t */\n\tfile: string;\n\n\t/**\n\t * Set to `true` if the policy can be fixed automatically.\n\t */\n\tautoFixable?: boolean | undefined;\n\n\t/**\n\t * An optional error message accompanying the failure.\n\t */\n\terrorMessage?: string | undefined;\n}\n\n/**\n * The result of an automatic fix for a failing policy.\n *\n * @alpha\n */\nexport interface PolicyFixResult extends PolicyFailure {\n\t/**\n\t * Set to true if the failure was resolved by the automated fixer.\n\t */\n\tresolved: boolean;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: type guard\nexport function isPolicyFixResult(toCheck: any): toCheck is PolicyFixResult {\n\tif (typeof toCheck !== \"object\") {\n\t\treturn false;\n\t}\n\treturn \"resolved\" in toCheck;\n}\n\n/**\n * Default policies included with repopo.\n *\n * @alpha\n */\nexport const DefaultPolicies: RepoPolicy[] = [\n\tNoJsFileExtensions,\n\tPackageJsonRepoDirectoryProperty,\n\tPackageJsonProperties,\n\tPackageJsonSortedPolicy,\n\tSortTsconfigs,\n];\n"]}
|