@webpieces/webpieces-tooling 0.4.975 → 0.4.977
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/webpieces-tooling",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.977",
|
|
4
4
|
"description": "Complete webpieces tooling installation and the combined OpenClaw hook adapter.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -16,17 +16,17 @@
|
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@webpieces/agent-workflow-rules": "0.4.
|
|
20
|
-
"@webpieces/ai-hook-rules": "0.4.
|
|
21
|
-
"@webpieces/code-rules": "0.4.
|
|
22
|
-
"@webpieces/eslint-rules": "0.4.
|
|
23
|
-
"@webpieces/hook-runtime": "0.4.
|
|
24
|
-
"@webpieces/nx-webpieces-rules": "0.4.
|
|
25
|
-
"@webpieces/pr-gate": "0.4.
|
|
26
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
27
|
-
"@webpieces/rules-config": "0.4.
|
|
28
|
-
"@webpieces/tooling-common": "0.4.
|
|
29
|
-
"@webpieces/rules-sdk": "0.4.
|
|
19
|
+
"@webpieces/agent-workflow-rules": "0.4.977",
|
|
20
|
+
"@webpieces/ai-hook-rules": "0.4.977",
|
|
21
|
+
"@webpieces/code-rules": "0.4.977",
|
|
22
|
+
"@webpieces/eslint-rules": "0.4.977",
|
|
23
|
+
"@webpieces/hook-runtime": "0.4.977",
|
|
24
|
+
"@webpieces/nx-webpieces-rules": "0.4.977",
|
|
25
|
+
"@webpieces/pr-gate": "0.4.977",
|
|
26
|
+
"@webpieces/repo-workflow-core": "0.4.977",
|
|
27
|
+
"@webpieces/rules-config": "0.4.977",
|
|
28
|
+
"@webpieces/tooling-common": "0.4.977",
|
|
29
|
+
"@webpieces/rules-sdk": "0.4.977"
|
|
30
30
|
},
|
|
31
31
|
"author": "Dean Hiller",
|
|
32
32
|
"license": "Apache-2.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
42
|
+
"@webpieces/tooling-testkit": "0.4.977"
|
|
43
43
|
},
|
|
44
44
|
"types": "./src/index.d.ts"
|
|
45
45
|
}
|
|
@@ -54,23 +54,23 @@ class LocalBuildPolicy extends rules_config_1.AbstractRule {
|
|
|
54
54
|
throw this.failure(found);
|
|
55
55
|
}
|
|
56
56
|
/** undefined when the diff base cannot be found, so a diff-scoped mode has nothing to compare against. */
|
|
57
|
-
scan(workspaceRoot) {
|
|
57
|
+
async scan(workspaceRoot) {
|
|
58
58
|
const mode = this.config.mode;
|
|
59
59
|
if (mode === undefined || mode === 'OFF')
|
|
60
60
|
return [];
|
|
61
|
-
const range = this.diffScope.resolveBase(workspaceRoot);
|
|
61
|
+
const range = await this.diffScope.resolveBase(workspaceRoot);
|
|
62
62
|
if (range.base === undefined && mode !== 'RUN_EVERY_TIME') {
|
|
63
63
|
console.log(`\n⏭️ Skipping ${this.name} validation (could not detect base branch)\n`);
|
|
64
64
|
return undefined;
|
|
65
65
|
}
|
|
66
66
|
const base = range.base ?? '';
|
|
67
67
|
const found = [];
|
|
68
|
-
for (const relFile of this.scanScope.files(workspaceRoot, mode, base, range.head, { tsOnly: false })) {
|
|
68
|
+
for (const relFile of await this.scanScope.files(workspaceRoot, mode, base, range.head, { tsOnly: false })) {
|
|
69
69
|
const absFile = path.join(workspaceRoot, relFile);
|
|
70
70
|
if (!this.judge.judges(relFile) || !fs.existsSync(absFile))
|
|
71
71
|
continue;
|
|
72
72
|
const changed = mode === 'NEW_AND_MODIFIED_CODE'
|
|
73
|
-
? this.diffScope.getChangedLineNumbers(this.diffScope.getFileDiff(workspaceRoot, relFile, base, range.head))
|
|
73
|
+
? this.diffScope.getChangedLineNumbers(await this.diffScope.getFileDiff(workspaceRoot, relFile, base, range.head))
|
|
74
74
|
: undefined;
|
|
75
75
|
if (changed !== undefined && changed.size === 0)
|
|
76
76
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-build-policy.js","sourceRoot":"","sources":["../../../../../../packages/tooling/webpieces-tooling/src/local-rules/local-build-policy.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,oDAAsE;AACtE,0DAAgG;AAGhG,yDAAsE;AAEtE,mEAAmE;AACnE,MAAa,mBAAmB;IAEf;IACA;IAFb,YACa,OAAe,EACf,OAAyB;QADzB,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAAO,CAAkB;IACnC,CAAC;CACP;AALD,kDAKC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAa,gBAAiB,SAAQ,2BAA6B;IAM1C;IACA;IACA;IAPJ,KAAK,CAAiB;IACtB,SAAS,GAAG,IAAI,wBAAS,EAAE,CAAC;IAE7C,YACI,MAAuB,EACN,IAAe,EACf,kBAAqC,EACrC,SAAoB;QAErC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAJf,SAAI,GAAJ,IAAI,CAAW;QACf,uBAAkB,GAAlB,kBAAkB,CAAmB;QACrC,cAAS,GAAT,SAAS,CAAW;QAGrC,IAAI,CAAC,KAAK,GAAG,IAAI,iCAAc,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,aAAqB;QAC3B,MAAM,KAAK,GAAG,MAAM,IAAI,4BAAa,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;QACtI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,6BAAiB,CAAC,IAAI,CAAC,CAAC;QAClF,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAyB,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9F,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,0GAA0G;IAClG,IAAI,CAAC,aAAqB;
|
|
1
|
+
{"version":3,"file":"local-build-policy.js","sourceRoot":"","sources":["../../../../../../packages/tooling/webpieces-tooling/src/local-rules/local-build-policy.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,oDAAsE;AACtE,0DAAgG;AAGhG,yDAAsE;AAEtE,mEAAmE;AACnE,MAAa,mBAAmB;IAEf;IACA;IAFb,YACa,OAAe,EACf,OAAyB;QADzB,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAAO,CAAkB;IACnC,CAAC;CACP;AALD,kDAKC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAa,gBAAiB,SAAQ,2BAA6B;IAM1C;IACA;IACA;IAPJ,KAAK,CAAiB;IACtB,SAAS,GAAG,IAAI,wBAAS,EAAE,CAAC;IAE7C,YACI,MAAuB,EACN,IAAe,EACf,kBAAqC,EACrC,SAAoB;QAErC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAJf,SAAI,GAAJ,IAAI,CAAW;QACf,uBAAkB,GAAlB,kBAAkB,CAAmB;QACrC,cAAS,GAAT,SAAS,CAAW;QAGrC,IAAI,CAAC,KAAK,GAAG,IAAI,iCAAc,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,GAAG,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AAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YACjH,8BAA8B,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,CAAC;QAChE,OAAO,IAAI,4BAAa,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxF,CAAC;CACJ;AAtDD,4CAsDC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { BuildPolicy, BuildPolicyResult } from '@webpieces/rules-sdk';\nimport { AbstractRule, DiffScope, RuleFailError, RuleFileScope } from '@webpieces/rules-config';\nimport { ScanScope } from '@webpieces/code-rules';\nimport { LocalRule, LocalRuleConfig } from './local-rule';\nimport { LocalRuleJudge, LocalRuleVerdict } from './local-rule-judge';\n\n/** A verdict located in its workspace-relative file. Data-only. */\nexport class LocatedLocalVerdict {\n constructor(\n readonly relFile: string,\n readonly verdict: LocalRuleVerdict,\n ) {}\n}\n\n/**\n * A local rule at the build gate (`wp-build` / the PR gate, through `validate-code`): the backstop for a\n * repo that does not run the guard hooks. It reads each in-scope file WHOLE and calls the same\n * {@link LocalRuleJudge} the Write/Edit guard calls, so both runners report the same sites at the same lines.\n *\n * The file set follows `mode` exactly as the built-in rules do (`ScanScope`): NEW_AND_MODIFIED_CODE judges\n * only findings on changed lines of changed files, NEW_AND_MODIFIED_FILES every finding in a changed file,\n * MODIFIED_PROJECTS / RUN_EVERY_TIME every file of each touched project / of the repo. The repo's\n * top-level `excludePaths` and the rule's own are applied to that listing; OFF and the epoch and branch\n * switches are checked by `shouldRun()` here and again by the build runner. A failure is ONE thrown\n * `RuleFailError` listing every site, rendered by the build runner.\n *\n * The files come from the {@link ScanScope} it is handed: the gate's (`GateScanScope`, no restriction), or a\n * debug run's (#1330), restricted to `--projects`. Every site found is recorded there too, so a debug run\n * counts them per project exactly as it does for a built-in rule.\n */\nexport class LocalBuildPolicy extends AbstractRule<LocalRuleConfig> implements BuildPolicy {\n private readonly judge: LocalRuleJudge;\n private readonly diffScope = new DiffScope();\n\n constructor(\n config: LocalRuleConfig,\n private readonly rule: LocalRule,\n private readonly globalExcludePaths: readonly string[],\n private readonly scanScope: ScanScope,\n ) {\n super(config, rule.id, rule.id);\n this.judge = new LocalRuleJudge(rule);\n }\n\n async run(workspaceRoot: string): Promise<BuildPolicyResult> {\n const found = await new RuleFileScope().runWithin(this.fileExclusions(this.globalExcludePaths), async () => this.scan(workspaceRoot));\n if (found === undefined || found.length === 0) return new BuildPolicyResult(true);\n this.scanScope.recordSites(this.name, found.map((each: LocatedLocalVerdict) => each.relFile));\n throw this.failure(found);\n }\n\n /** undefined when the diff base cannot be found, so a diff-scoped mode has nothing to compare against. */\n private async scan(workspaceRoot: string): Promise<LocatedLocalVerdict[] | undefined> {\n const mode = this.config.mode;\n if (mode === undefined || mode === 'OFF') return [];\n const range = await this.diffScope.resolveBase(workspaceRoot);\n if (range.base === undefined && mode !== 'RUN_EVERY_TIME') {\n console.log(`\\n⏭️ Skipping ${this.name} validation (could not detect base branch)\\n`);\n return undefined;\n }\n const base = range.base ?? '';\n const found: LocatedLocalVerdict[] = [];\n for (const relFile of await this.scanScope.files(workspaceRoot, mode, base, range.head, { tsOnly: false })) {\n const absFile = path.join(workspaceRoot, relFile);\n if (!this.judge.judges(relFile) || !fs.existsSync(absFile)) continue;\n const changed = mode === 'NEW_AND_MODIFIED_CODE'\n ? this.diffScope.getChangedLineNumbers(await this.diffScope.getFileDiff(workspaceRoot, relFile, base, range.head))\n : undefined;\n if (changed !== undefined && changed.size === 0) continue;\n for (const verdict of this.judge.judge(relFile, fs.readFileSync(absFile, 'utf8'), this.config, changed)) {\n found.push(new LocatedLocalVerdict(relFile, verdict));\n }\n }\n return found;\n }\n\n private failure(found: readonly LocatedLocalVerdict[]): RuleFailError {\n const message =\n `${found.length} site(s) break the repo-local rule ${this.name} — ${this.rule.description}\\n` +\n found.map((each: LocatedLocalVerdict) =>\n ` ${each.relFile}:${each.verdict.line} — ${each.verdict.message}\\n ${each.verdict.snippet}`).join('\\n') +\n `\\n Last resort, per site: ${this.judge.disableComment()}`;\n return new RuleFailError(this.name, message, undefined, undefined, this.rule.cures);\n }\n}\n"]}
|
|
@@ -75,13 +75,13 @@ class LocalBuildDebugRuntime {
|
|
|
75
75
|
const rule = this.pack.ruleFor(request.selection.rule);
|
|
76
76
|
const loaded = (0, rules_config_1.loadAndValidate)(root);
|
|
77
77
|
const config = new LocalRuleConfigs(loaded.rulesConfig).configFor(rule);
|
|
78
|
-
const plan = this.debug.plan(root, new code_rules_1.DebugAsk(rule.id, asked.mode, config.mode ?? 'OFF', rules_sdk_1.MODIFIED_CODE_MODES, asked.projects));
|
|
78
|
+
const plan = await this.debug.plan(root, new code_rules_1.DebugAsk(rule.id, asked.mode, config.mode ?? 'OFF', rules_sdk_1.MODIFIED_CODE_MODES, asked.projects));
|
|
79
79
|
this.debug.printBanner(plan);
|
|
80
80
|
const diffScope = new rules_config_1.DiffScope();
|
|
81
81
|
const scan = new code_rules_1.ScanScope(diffScope, new code_rules_1.ProjectCatalog(diffScope), new code_rules_1.ScanRestriction(plan.projects));
|
|
82
82
|
const policy = new local_build_policy_1.LocalBuildPolicy(this.debug.overridden(config, plan), rule, loaded.excludePaths.paths, scan);
|
|
83
83
|
const ruleSucceeded = await this.runPrintingFailure(policy, root);
|
|
84
|
-
const sites = this.debug.printCounts(root, plan, scan, ruleSucceeded);
|
|
84
|
+
const sites = await this.debug.printCounts(root, plan, scan, ruleSucceeded);
|
|
85
85
|
return new rules_sdk_1.BuildPolicyResult(ruleSucceeded && sites === 0);
|
|
86
86
|
}
|
|
87
87
|
/** The rule's own failure text is printed BEFORE the counts, exactly as a built-in rule's is. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-rule-pack.js","sourceRoot":"","sources":["../../../../../../packages/tooling/webpieces-tooling/src/local-rules/local-rule-pack.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AAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAEO,UAAU,CAAC,IAAe;QAC9B,MAAM,MAAM,GAA6B,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,+BAAmB,CAAC,EAAE,CAAC;QACjH,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,wBAAY,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,qBAAqB,EAAE,CAAC,EAAE,wBAAwB,EAAE,IAAI,EAAE,CAAC,CAAC;QACxH,OAAO,IAAI,+BAAmB,CAC1B,IAAI,CAAC,EAAE,EACP,MAAM,EACN,mCAAuB,EACvB,EAAE,EACF,IAAI,EACJ,OAAO,EACP,IAAI,oBAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,iCAAiC,IAAI,CAAC,EAAE,wBAAwB,CAAC,CACnG,CAAC;IACN,CAAC;CACJ;AApED,sCAoEC","sourcesContent":["import * as path from 'node:path';\nimport {\n BuildDebugRequest,\n BuildDebugRuntime,\n BuildPolicy,\n BuildPolicyResult,\n BuildRuleRuntime,\n ConfigObject,\n FieldDef,\n MODIFIED_CODE_MODES,\n OwnedRuleDefinition,\n PolicyRuntimeRequest,\n RULE_PACK_API_VERSION,\n RULE_SCHEMA_API_VERSION,\n RuleContribution,\n RuleHelp,\n RulePackManifest,\n} from '@webpieces/rules-sdk';\nimport { BASE_RULE_SCHEMA } from '@webpieces/rules-sdk';\nimport { HookPolicyRuntimeRequest, HookRuleRuntime, Rule } from '@webpieces/hook-runtime';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { DiffScope, RuleFailError, loadAndValidate, renderRuleFailForHuman } from '@webpieces/rules-config';\nimport {\n DebugAsk,\n GateScanScope,\n ProjectCatalog,\n RuleDebugRun,\n RunRequestParser,\n ScanRestriction,\n ScanScope,\n} from '@webpieces/code-rules';\nimport { LocalRule, LocalRuleConfig } from './local-rule';\nimport { LocalSourceHookPolicy } from './local-source-hook-policy';\nimport { LocalBuildPolicy } from './local-build-policy';\n\nconst RULE_ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\n\n/** The version a local pack reports: it ships with the repo, never as an npm release. */\nconst LOCAL_PACK_VERSION = '0.0.0-local';\n\n/** Validated owner settings for one local rule, or a refusal naming the owner file to repair. */\nclass LocalRuleConfigs {\n constructor(private readonly configs: Readonly<Record<string, ConfigObject>>) {}\n\n configFor(rule: LocalRule): LocalRuleConfig {\n const config = this.configs[rule.id];\n if (!config)\n throw new InformAiError(`Missing explicit config for local rule ${rule.id}. Add its entry to the rule pack's owner file.`);\n return config as LocalRuleConfig;\n }\n}\n\n/** The source-hook half: one {@link LocalSourceHookPolicy} per rule the runtime request names. */\nclass LocalSourceRuleRuntime implements HookRuleRuntime {\n constructor(private readonly pack: LocalRulePack) {}\n\n create(request: HookPolicyRuntimeRequest): readonly Rule[] {\n const configs = new LocalRuleConfigs(request.configs);\n return request.ruleIds.map((id: string) => {\n const rule = this.pack.ruleFor(id);\n return new LocalSourceHookPolicy(configs.configFor(rule), rule);\n });\n }\n}\n\n/** The build half: one {@link LocalBuildPolicy} per rule the runtime request names. */\nclass LocalBuildRuleRuntime implements BuildRuleRuntime {\n constructor(private readonly pack: LocalRulePack) {}\n\n async create(request: PolicyRuntimeRequest): Promise<readonly BuildPolicy[]> {\n const configs = new LocalRuleConfigs(request.configs);\n return request.ruleIds.map((id: string) => {\n const rule = this.pack.ruleFor(id);\n return new LocalBuildPolicy(configs.configFor(rule), rule, request.excludePaths, new GateScanScope());\n });\n }\n}\n\n/**\n * The one-rule DEBUG run of a local rule (#1330) — `wp-validate-code --rule=<id> --mode=RUN_EVERY_TIME\n * --projects=a,b` — with the same refusals, banner, in-memory override and per-project count a built-in\n * code rule gets ({@link RuleDebugRun}). The rule runs through the same {@link LocalBuildPolicy} the gate\n * runs, so disables, the repo's `excludePaths` and the rule's own apply exactly as they do there; only the\n * mode (when `--mode` is given) and the two escape hatches are overridden, in memory. RUN_EVERY_TIME lists\n * every file in the repo and never consults the diff.\n */\nclass LocalBuildDebugRuntime implements BuildDebugRuntime {\n private readonly debug = new RuleDebugRun();\n\n constructor(private readonly pack: LocalRulePack) {}\n\n async run(request: BuildDebugRequest): Promise<BuildPolicyResult> {\n const root = request.workspaceRoot;\n const asked = new RunRequestParser().parse(request.selection.rule, request.selection.mode, request.selection.projects);\n const rule = this.pack.ruleFor(request.selection.rule);\n const loaded = loadAndValidate(root);\n const config = new LocalRuleConfigs(loaded.rulesConfig as Record<string, ConfigObject>).configFor(rule);\n const plan = this.debug.plan(root, new DebugAsk(rule.id, asked.mode, config.mode ?? 'OFF', MODIFIED_CODE_MODES, asked.projects));\n this.debug.printBanner(plan);\n const diffScope = new DiffScope();\n const scan = new ScanScope(diffScope, new ProjectCatalog(diffScope), new ScanRestriction(plan.projects));\n const policy = new LocalBuildPolicy(this.debug.overridden(config, plan), rule, loaded.excludePaths.paths, scan);\n const ruleSucceeded = await this.runPrintingFailure(policy, root);\n const sites = this.debug.printCounts(root, plan, scan, ruleSucceeded);\n return new BuildPolicyResult(ruleSucceeded && sites === 0);\n }\n\n /** The rule's own failure text is printed BEFORE the counts, exactly as a built-in rule's is. */\n private async runPrintingFailure(policy: LocalBuildPolicy, root: string): Promise<boolean> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- the policy's RuleFailError IS the debug run's report; anything else propagates\n try {\n return (await policy.run(root)).success;\n // webpieces-disable no-any-unknown -- a thrown value is narrowed to the policy's RuleFailError, anything else is rethrown\n } catch (err: unknown) {\n const error = toError(err);\n if (!(error instanceof RuleFailError)) throw error;\n console.error(renderRuleFailForHuman(error));\n return false;\n }\n }\n}\n\n/**\n * A repo's OWN rule pack (#1314) — the sixth owner beside webpieces' five, built from {@link LocalRule}s.\n *\n * One module both declares the pack and implements it. It exports the four names the framework loads —\n * `rulePackManifest`, `sourceRuleRuntime`, `buildRuleRuntime` and `buildDebugRuntime` (the one-rule\n * `wp-validate-code --rule=<id>` debug run, #1330) — and every rule is contributed to BOTH runners, the\n * Write/Edit source guard and the build gate, so there is no when-to-run setting:\n *\n * ```ts\n * // webpieces-rules/local-rules.ts\n * import { LocalRulePack } from '@webpieces/webpieces-tooling/local-rules';\n * import { NoTodoCommentRule } from './no-todo-comment';\n *\n * const pack = new LocalRulePack('local-rules', __filename, [new NoTodoCommentRule()]);\n * export const rulePackManifest = pack.rulePackManifest;\n * export const sourceRuleRuntime = pack.sourceRuleRuntime;\n * export const buildRuleRuntime = pack.buildRuleRuntime;\n * export const buildDebugRuntime = pack.buildDebugRuntime;\n * ```\n *\n * declared in `webpieces.config.json` like any pack, with its own owner file:\n * `{ \"package\": \"./webpieces-rules/local-rules.ts\", \"config\": \".webpieces-config/rules/local.json\" }`.\n * A `.ts` module is transpiled in memory when it is loaded; there is no build step.\n *\n * Each rule's schema is its `settings` plus a required `mode` (the scope vocabulary built-in diff rules\n * use); the registry adds the framework-owned fields. Nothing has a default: a missing entry or value fails\n * the config load naming the owner file and the seed to paste.\n */\nexport class LocalRulePack {\n readonly rulePackManifest: RulePackManifest;\n readonly sourceRuleRuntime: HookRuleRuntime;\n readonly buildRuleRuntime: BuildRuleRuntime;\n readonly buildDebugRuntime: BuildDebugRuntime;\n private readonly rules = new Map<string, LocalRule>();\n\n /**\n * @param packageName the pack's owner name — how the registry and every refusal name it.\n * @param moduleFile the declaring module's own `__filename`: both runtimes are loaded from it.\n * @param rules the pack's rules; ids must be unique kebab-case and not collide with any other pack's.\n */\n constructor(packageName: string, moduleFile: string, rules: readonly LocalRule[]) {\n if (!packageName.trim()) throw new InformAiError('A LocalRulePack needs a nonempty package name, e.g. \"local-rules\".');\n if (!path.isAbsolute(moduleFile))\n throw new InformAiError(`LocalRulePack ${packageName} needs its module's absolute path. Pass __filename as the second argument.`);\n if (rules.length === 0) throw new InformAiError(`LocalRulePack ${packageName} has no rules. Add at least one LocalRule.`);\n for (const rule of rules) this.add(packageName, rule);\n this.rulePackManifest = new RulePackManifest(\n packageName,\n LOCAL_PACK_VERSION,\n RULE_PACK_API_VERSION,\n rules.map((rule: LocalRule) => this.definition(rule)),\n rules.flatMap((rule: LocalRule) => [\n new RuleContribution(rule.id, packageName, 'source-hook', moduleFile),\n new RuleContribution(rule.id, packageName, 'build', moduleFile),\n ]),\n [],\n [],\n );\n this.sourceRuleRuntime = new LocalSourceRuleRuntime(this);\n this.buildRuleRuntime = new LocalBuildRuleRuntime(this);\n this.buildDebugRuntime = new LocalBuildDebugRuntime(this);\n }\n\n /** The rule registered under `id`; the runtimes only ever ask for ids this pack's manifest declares. */\n ruleFor(id: string): LocalRule {\n const rule = this.rules.get(id);\n if (!rule) throw new InformAiError(`Local rule pack has no rule ${id}. Repair its rule list.`);\n return rule;\n }\n\n private add(packageName: string, rule: LocalRule): void {\n if (!RULE_ID.test(rule.id))\n throw new InformAiError(`Local rule id \"${rule.id}\" in ${packageName} must be kebab-case (e.g. no-todo-comment).`);\n if (this.rules.has(rule.id)) throw new InformAiError(`Local rule ${rule.id} is declared twice in ${packageName}. Keep one.`);\n for (const key of Object.keys(rule.settings)) {\n if (key === 'mode' || Object.hasOwn(BASE_RULE_SCHEMA, key))\n throw new InformAiError(\n `Local rule ${rule.id} declares the framework-owned setting \"${key}\". Delete it from settings; every local rule gets mode, ${Object.keys(BASE_RULE_SCHEMA).join(', ')}.`,\n );\n }\n this.rules.set(rule.id, rule);\n }\n\n private definition(rule: LocalRule): OwnedRuleDefinition {\n const schema: Record<string, FieldDef> = { ...rule.settings, mode: new FieldDef('string', MODIFIED_CODE_MODES) };\n const seed = Object.assign(new ConfigObject(), rule.seed, { turnOffRuleUntilEpoch: 0, turnOffRuleWhileOnBranch: null });\n return new OwnedRuleDefinition(\n rule.id,\n schema,\n RULE_SCHEMA_API_VERSION,\n {},\n seed,\n 'rules',\n new RuleHelp(rule.description, `Fix the reported site, or set ${rule.id}.mode in {configFile}.`),\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"local-rule-pack.js","sourceRoot":"","sources":["../../../../../../packages/tooling/webpieces-tooling/src/local-rules/local-rule-pack.ts"],"names":[],"mappings":";;;;AAAA,wDAAkC;AAClC,oDAgB8B;AAC9B,oDAAwD;AAExD,8DAA0D;AAC1D,iEAA6D;AAC7D,0DAA4G;AAC5G,sDAQ+B;AAE/B,yEAAmE;AACnE,6DAAwD;AAExD,MAAM,OAAO,GAAG,iCAAiC,CAAC;AAElD,yFAAyF;AACzF,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAEzC,iGAAiG;AACjG,MAAM,gBAAgB;IACW;IAA7B,YAA6B,OAA+C;QAA/C,YAAO,GAAP,OAAO,CAAwC;IAAG,CAAC;IAEhF,SAAS,CAAC,IAAe;QACrB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,MAAM;YACP,MAAM,IAAI,8BAAa,CAAC,0CAA0C,IAAI,CAAC,EAAE,gDAAgD,CAAC,CAAC;QAC/H,OAAO,MAAyB,CAAC;IACrC,CAAC;CACJ;AAED,kGAAkG;AAClG,MAAM,sBAAsB;IACK;IAA7B,YAA6B,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;IAAG,CAAC;IAEpD,MAAM,CAAC,OAAiC;QACpC,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtD,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAU,EAAE,EAAE;YACtC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACnC,OAAO,IAAI,gDAAqB,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,uFAAuF;A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AAM,CAAC,IAAI,CAAC,4BAAgB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC3K,CAAC;QACV,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAEO,UAAU,CAAC,IAAe;QAC9B,MAAM,MAAM,GAA6B,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,+BAAmB,CAAC,EAAE,CAAC;QACjH,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,wBAAY,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,qBAAqB,EAAE,CAAC,EAAE,wBAAwB,EAAE,IAAI,EAAE,CAAC,CAAC;QACxH,OAAO,IAAI,+BAAmB,CAC1B,IAAI,CAAC,EAAE,EACP,MAAM,EACN,mCAAuB,EACvB,EAAE,EACF,IAAI,EACJ,OAAO,EACP,IAAI,oBAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,iCAAiC,IAAI,CAAC,EAAE,wBAAwB,CAAC,CACnG,CAAC;IACN,CAAC;CACJ;AApED,sCAoEC","sourcesContent":["import * as path from 'node:path';\nimport {\n BuildDebugRequest,\n BuildDebugRuntime,\n BuildPolicy,\n BuildPolicyResult,\n BuildRuleRuntime,\n ConfigObject,\n FieldDef,\n MODIFIED_CODE_MODES,\n OwnedRuleDefinition,\n PolicyRuntimeRequest,\n RULE_PACK_API_VERSION,\n RULE_SCHEMA_API_VERSION,\n RuleContribution,\n RuleHelp,\n RulePackManifest,\n} from '@webpieces/rules-sdk';\nimport { BASE_RULE_SCHEMA } from '@webpieces/rules-sdk';\nimport { HookPolicyRuntimeRequest, HookRuleRuntime, Rule } from '@webpieces/hook-runtime';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { DiffScope, RuleFailError, loadAndValidate, renderRuleFailForHuman } from '@webpieces/rules-config';\nimport {\n DebugAsk,\n GateScanScope,\n ProjectCatalog,\n RuleDebugRun,\n RunRequestParser,\n ScanRestriction,\n ScanScope,\n} from '@webpieces/code-rules';\nimport { LocalRule, LocalRuleConfig } from './local-rule';\nimport { LocalSourceHookPolicy } from './local-source-hook-policy';\nimport { LocalBuildPolicy } from './local-build-policy';\n\nconst RULE_ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\n\n/** The version a local pack reports: it ships with the repo, never as an npm release. */\nconst LOCAL_PACK_VERSION = '0.0.0-local';\n\n/** Validated owner settings for one local rule, or a refusal naming the owner file to repair. */\nclass LocalRuleConfigs {\n constructor(private readonly configs: Readonly<Record<string, ConfigObject>>) {}\n\n configFor(rule: LocalRule): LocalRuleConfig {\n const config = this.configs[rule.id];\n if (!config)\n throw new InformAiError(`Missing explicit config for local rule ${rule.id}. Add its entry to the rule pack's owner file.`);\n return config as LocalRuleConfig;\n }\n}\n\n/** The source-hook half: one {@link LocalSourceHookPolicy} per rule the runtime request names. */\nclass LocalSourceRuleRuntime implements HookRuleRuntime {\n constructor(private readonly pack: LocalRulePack) {}\n\n create(request: HookPolicyRuntimeRequest): readonly Rule[] {\n const configs = new LocalRuleConfigs(request.configs);\n return request.ruleIds.map((id: string) => {\n const rule = this.pack.ruleFor(id);\n return new LocalSourceHookPolicy(configs.configFor(rule), rule);\n });\n }\n}\n\n/** The build half: one {@link LocalBuildPolicy} per rule the runtime request names. */\nclass LocalBuildRuleRuntime implements BuildRuleRuntime {\n constructor(private readonly pack: LocalRulePack) {}\n\n async create(request: PolicyRuntimeRequest): Promise<readonly BuildPolicy[]> {\n const configs = new LocalRuleConfigs(request.configs);\n return request.ruleIds.map((id: string) => {\n const rule = this.pack.ruleFor(id);\n return new LocalBuildPolicy(configs.configFor(rule), rule, request.excludePaths, new GateScanScope());\n });\n }\n}\n\n/**\n * The one-rule DEBUG run of a local rule (#1330) — `wp-validate-code --rule=<id> --mode=RUN_EVERY_TIME\n * --projects=a,b` — with the same refusals, banner, in-memory override and per-project count a built-in\n * code rule gets ({@link RuleDebugRun}). The rule runs through the same {@link LocalBuildPolicy} the gate\n * runs, so disables, the repo's `excludePaths` and the rule's own apply exactly as they do there; only the\n * mode (when `--mode` is given) and the two escape hatches are overridden, in memory. RUN_EVERY_TIME lists\n * every file in the repo and never consults the diff.\n */\nclass LocalBuildDebugRuntime implements BuildDebugRuntime {\n private readonly debug = new RuleDebugRun();\n\n constructor(private readonly pack: LocalRulePack) {}\n\n async run(request: BuildDebugRequest): Promise<BuildPolicyResult> {\n const root = request.workspaceRoot;\n const asked = new RunRequestParser().parse(request.selection.rule, request.selection.mode, request.selection.projects);\n const rule = this.pack.ruleFor(request.selection.rule);\n const loaded = loadAndValidate(root);\n const config = new LocalRuleConfigs(loaded.rulesConfig as Record<string, ConfigObject>).configFor(rule);\n const plan = await this.debug.plan(root, new DebugAsk(rule.id, asked.mode, config.mode ?? 'OFF', MODIFIED_CODE_MODES, asked.projects));\n this.debug.printBanner(plan);\n const diffScope = new DiffScope();\n const scan = new ScanScope(diffScope, new ProjectCatalog(diffScope), new ScanRestriction(plan.projects));\n const policy = new LocalBuildPolicy(this.debug.overridden(config, plan), rule, loaded.excludePaths.paths, scan);\n const ruleSucceeded = await this.runPrintingFailure(policy, root);\n const sites = await this.debug.printCounts(root, plan, scan, ruleSucceeded);\n return new BuildPolicyResult(ruleSucceeded && sites === 0);\n }\n\n /** The rule's own failure text is printed BEFORE the counts, exactly as a built-in rule's is. */\n private async runPrintingFailure(policy: LocalBuildPolicy, root: string): Promise<boolean> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- the policy's RuleFailError IS the debug run's report; anything else propagates\n try {\n return (await policy.run(root)).success;\n // webpieces-disable no-any-unknown -- a thrown value is narrowed to the policy's RuleFailError, anything else is rethrown\n } catch (err: unknown) {\n const error = toError(err);\n if (!(error instanceof RuleFailError)) throw error;\n console.error(renderRuleFailForHuman(error));\n return false;\n }\n }\n}\n\n/**\n * A repo's OWN rule pack (#1314) — the sixth owner beside webpieces' five, built from {@link LocalRule}s.\n *\n * One module both declares the pack and implements it. It exports the four names the framework loads —\n * `rulePackManifest`, `sourceRuleRuntime`, `buildRuleRuntime` and `buildDebugRuntime` (the one-rule\n * `wp-validate-code --rule=<id>` debug run, #1330) — and every rule is contributed to BOTH runners, the\n * Write/Edit source guard and the build gate, so there is no when-to-run setting:\n *\n * ```ts\n * // webpieces-rules/local-rules.ts\n * import { LocalRulePack } from '@webpieces/webpieces-tooling/local-rules';\n * import { NoTodoCommentRule } from './no-todo-comment';\n *\n * const pack = new LocalRulePack('local-rules', __filename, [new NoTodoCommentRule()]);\n * export const rulePackManifest = pack.rulePackManifest;\n * export const sourceRuleRuntime = pack.sourceRuleRuntime;\n * export const buildRuleRuntime = pack.buildRuleRuntime;\n * export const buildDebugRuntime = pack.buildDebugRuntime;\n * ```\n *\n * declared in `webpieces.config.json` like any pack, with its own owner file:\n * `{ \"package\": \"./webpieces-rules/local-rules.ts\", \"config\": \".webpieces-config/rules/local.json\" }`.\n * A `.ts` module is transpiled in memory when it is loaded; there is no build step.\n *\n * Each rule's schema is its `settings` plus a required `mode` (the scope vocabulary built-in diff rules\n * use); the registry adds the framework-owned fields. Nothing has a default: a missing entry or value fails\n * the config load naming the owner file and the seed to paste.\n */\nexport class LocalRulePack {\n readonly rulePackManifest: RulePackManifest;\n readonly sourceRuleRuntime: HookRuleRuntime;\n readonly buildRuleRuntime: BuildRuleRuntime;\n readonly buildDebugRuntime: BuildDebugRuntime;\n private readonly rules = new Map<string, LocalRule>();\n\n /**\n * @param packageName the pack's owner name — how the registry and every refusal name it.\n * @param moduleFile the declaring module's own `__filename`: both runtimes are loaded from it.\n * @param rules the pack's rules; ids must be unique kebab-case and not collide with any other pack's.\n */\n constructor(packageName: string, moduleFile: string, rules: readonly LocalRule[]) {\n if (!packageName.trim()) throw new InformAiError('A LocalRulePack needs a nonempty package name, e.g. \"local-rules\".');\n if (!path.isAbsolute(moduleFile))\n throw new InformAiError(`LocalRulePack ${packageName} needs its module's absolute path. Pass __filename as the second argument.`);\n if (rules.length === 0) throw new InformAiError(`LocalRulePack ${packageName} has no rules. Add at least one LocalRule.`);\n for (const rule of rules) this.add(packageName, rule);\n this.rulePackManifest = new RulePackManifest(\n packageName,\n LOCAL_PACK_VERSION,\n RULE_PACK_API_VERSION,\n rules.map((rule: LocalRule) => this.definition(rule)),\n rules.flatMap((rule: LocalRule) => [\n new RuleContribution(rule.id, packageName, 'source-hook', moduleFile),\n new RuleContribution(rule.id, packageName, 'build', moduleFile),\n ]),\n [],\n [],\n );\n this.sourceRuleRuntime = new LocalSourceRuleRuntime(this);\n this.buildRuleRuntime = new LocalBuildRuleRuntime(this);\n this.buildDebugRuntime = new LocalBuildDebugRuntime(this);\n }\n\n /** The rule registered under `id`; the runtimes only ever ask for ids this pack's manifest declares. */\n ruleFor(id: string): LocalRule {\n const rule = this.rules.get(id);\n if (!rule) throw new InformAiError(`Local rule pack has no rule ${id}. Repair its rule list.`);\n return rule;\n }\n\n private add(packageName: string, rule: LocalRule): void {\n if (!RULE_ID.test(rule.id))\n throw new InformAiError(`Local rule id \"${rule.id}\" in ${packageName} must be kebab-case (e.g. no-todo-comment).`);\n if (this.rules.has(rule.id)) throw new InformAiError(`Local rule ${rule.id} is declared twice in ${packageName}. Keep one.`);\n for (const key of Object.keys(rule.settings)) {\n if (key === 'mode' || Object.hasOwn(BASE_RULE_SCHEMA, key))\n throw new InformAiError(\n `Local rule ${rule.id} declares the framework-owned setting \"${key}\". Delete it from settings; every local rule gets mode, ${Object.keys(BASE_RULE_SCHEMA).join(', ')}.`,\n );\n }\n this.rules.set(rule.id, rule);\n }\n\n private definition(rule: LocalRule): OwnedRuleDefinition {\n const schema: Record<string, FieldDef> = { ...rule.settings, mode: new FieldDef('string', MODIFIED_CODE_MODES) };\n const seed = Object.assign(new ConfigObject(), rule.seed, { turnOffRuleUntilEpoch: 0, turnOffRuleWhileOnBranch: null });\n return new OwnedRuleDefinition(\n rule.id,\n schema,\n RULE_SCHEMA_API_VERSION,\n {},\n seed,\n 'rules',\n new RuleHelp(rule.description, `Fix the reported site, or set ${rule.id}.mode in {configFile}.`),\n );\n }\n}\n"]}
|