@webpieces/code-rules 0.2.127 → 0.3.129
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 +4 -3
- package/src/cli.d.ts +1 -0
- package/src/cli.js +1 -0
- package/src/cli.js.map +1 -1
- package/src/from-shared-config.d.ts +2 -2
- package/src/from-shared-config.js +2 -4
- package/src/from-shared-config.js.map +1 -1
- package/src/wp-ci.d.ts +17 -0
- package/src/wp-ci.js +111 -0
- package/src/wp-ci.js.map +1 -0
- package/bin/wp-validate-code.js +0 -15
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/code-rules",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.129",
|
|
4
4
|
"description": "Standalone code validation rules extracted from architecture-validators, no Nx dependency required",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"bin": {
|
|
8
|
-
"wp-validate-code": "./
|
|
8
|
+
"wp-validate-code": "./src/cli.js",
|
|
9
|
+
"wp-ci": "./src/wp-ci.js"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"src/**/*",
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
"directory": "packages/tooling/code-rules"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@webpieces/rules-config": "0.
|
|
23
|
+
"@webpieces/rules-config": "0.3.129"
|
|
23
24
|
},
|
|
24
25
|
"publishConfig": {
|
|
25
26
|
"access": "public"
|
package/src/cli.d.ts
CHANGED
package/src/cli.js
CHANGED
package/src/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/cli.ts"],"names":[],"mappings":";;;;AACA,0DAAqD;AACrD,6DAA6D;AAC7D,4EAA8C;AAE9C,KAAK,UAAU,IAAI;IACf,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACpC,MAAM,MAAM,GAAG,IAAA,yBAAU,EAAC,aAAa,CAAC,CAAC;IACzC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACrB,OAAO,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,MAAM,OAAO,GAAG,IAAA,0CAAqB,EAAC,MAAM,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,MAAM,IAAA,uBAAe,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,IAAI,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { loadConfig } from '@webpieces/rules-config';\nimport { toValidateCodeOptions } from './from-shared-config';\nimport runValidateCode from './validate-code';\n\nasync function main(): Promise<void> {\n const workspaceRoot = process.cwd();\n const shared = loadConfig(workspaceRoot);\n if (!shared.configPath) {\n console.error('No webpieces.config.json found');\n process.exit(1);\n }\n const options = toValidateCodeOptions(shared);\n const result = await runValidateCode(options, workspaceRoot);\n process.exit(result.success ? 0 : 1);\n}\n\nmain();\n"]}
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
* no-unmanaged-exceptions -> noUnmanagedExceptions
|
|
21
21
|
* no-direct-api-in-resolver -> noDirectApiInResolver
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
* downstream executor short-circuits
|
|
23
|
+
* On/off is driven entirely by `mode`: a `mode:'OFF'` entry flows straight
|
|
24
|
+
* through to the downstream executor, which short-circuits on it.
|
|
25
25
|
*/
|
|
26
26
|
import type { ResolvedConfig } from '@webpieces/rules-config';
|
|
27
27
|
import type { ValidateCodeOptions } from './validate-code';
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* no-unmanaged-exceptions -> noUnmanagedExceptions
|
|
22
22
|
* no-direct-api-in-resolver -> noDirectApiInResolver
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
* downstream executor short-circuits
|
|
24
|
+
* On/off is driven entirely by `mode`: a `mode:'OFF'` entry flows straight
|
|
25
|
+
* through to the downstream executor, which short-circuits on it.
|
|
26
26
|
*/
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
exports.toValidateCodeOptions = toValidateCodeOptions;
|
|
@@ -38,8 +38,6 @@ function opt(rule, key) {
|
|
|
38
38
|
function modeOrOff(rule) {
|
|
39
39
|
if (!rule)
|
|
40
40
|
return undefined;
|
|
41
|
-
if (rule.enabled === false)
|
|
42
|
-
return 'OFF';
|
|
43
41
|
const mode = rule.options['mode'];
|
|
44
42
|
return mode ?? undefined;
|
|
45
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"from-shared-config.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/from-shared-config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;
|
|
1
|
+
{"version":3,"file":"from-shared-config.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/from-shared-config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;AAmBH,sDAyEC;AAvFD,oFAAoF;AACpF,SAAS,GAAG,CAAI,IAAoC,EAAE,GAAW;IAC7D,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,OAAO,KA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2B,CAAC,EAAE,gBAAgB,CAAC;YAC9E,wBAAwB,EAAE,GAAG,CAAS,CAAC,CAAC,2BAA2B,CAAC,EAAE,0BAA0B,CAAC;YACjG,YAAY,EAAE,GAAG,CAAW,CAAC,CAAC,2BAA2B,CAAC,EAAE,cAAc,CAAC;SAC9E;KACJ,CAAC;AACN,CAAC","sourcesContent":["/**\n * Adapter: map @webpieces/rules-config ResolvedConfig -> legacy ValidateCodeOptions.\n *\n * We don't want to rewrite the 11 sub-executors in this PR, so this file\n * takes the shared webpieces.config.json entries (kebab-case rule names)\n * and reconstructs the camelCase ValidateCodeOptions shape the executor\n * already understands.\n *\n * Mapping of canonical kebab-case rule name -> ValidateCodeOptions field:\n * max-method-lines -> methodMaxLimit\n * max-file-lines -> fileMaxLimit\n * require-return-type -> requireReturnType\n * no-inline-type-literals -> noInlineTypeLiterals\n * no-any-unknown -> noAnyUnknown\n * no-implicit-any -> noImplicitAny\n * validate-dtos -> validateDtos\n * prisma-converter -> prismaConverter\n * no-destructure -> noDestructure\n * catch-error-pattern -> catchErrorPattern\n * no-unmanaged-exceptions -> noUnmanagedExceptions\n * no-direct-api-in-resolver -> noDirectApiInResolver\n *\n * On/off is driven entirely by `mode`: a `mode:'OFF'` entry flows straight\n * through to the downstream executor, which short-circuits on it.\n */\n\nimport type { ResolvedConfig, ResolvedRuleConfig } from '@webpieces/rules-config';\nimport type { ValidateCodeOptions } from './validate-code';\n\n// webpieces-disable no-any-unknown -- coerces opaque option values pulled from JSON\nfunction opt<T>(rule: ResolvedRuleConfig | undefined, key: string): T | undefined {\n if (!rule) return undefined;\n const value = rule.options[key];\n if (value === undefined) return undefined;\n return value as T;\n}\n\nfunction modeOrOff<T extends string>(rule: ResolvedRuleConfig | undefined): T | undefined {\n if (!rule) return undefined;\n const mode = rule.options['mode'];\n return (mode as T) ?? undefined;\n}\n\nexport function toValidateCodeOptions(shared: ResolvedConfig): ValidateCodeOptions {\n const r = (name: string): ResolvedRuleConfig | undefined => shared.rules.get(name);\n\n return {\n methodMaxLimit: {\n limit: opt<number>(r('max-method-lines'), 'limit'),\n mode: modeOrOff(r('max-method-lines')),\n disableAllowed: opt<boolean>(r('max-method-lines'), 'disableAllowed'),\n ignoreModifiedUntilEpoch: opt<number>(r('max-method-lines'), 'ignoreModifiedUntilEpoch'),\n },\n fileMaxLimit: {\n limit: opt<number>(r('max-file-lines'), 'limit'),\n mode: modeOrOff(r('max-file-lines')),\n disableAllowed: opt<boolean>(r('max-file-lines'), 'disableAllowed'),\n ignoreModifiedUntilEpoch: opt<number>(r('max-file-lines'), 'ignoreModifiedUntilEpoch'),\n },\n requireReturnType: {\n mode: modeOrOff(r('require-return-type')),\n disableAllowed: opt<boolean>(r('require-return-type'), 'disableAllowed'),\n ignoreModifiedUntilEpoch: opt<number>(r('require-return-type'), 'ignoreModifiedUntilEpoch'),\n },\n noInlineTypeLiterals: {\n mode: modeOrOff(r('no-inline-type-literals')),\n disableAllowed: opt<boolean>(r('no-inline-type-literals'), 'disableAllowed'),\n ignoreModifiedUntilEpoch: opt<number>(r('no-inline-type-literals'), 'ignoreModifiedUntilEpoch'),\n },\n noAnyUnknown: {\n mode: modeOrOff(r('no-any-unknown')),\n disableAllowed: opt<boolean>(r('no-any-unknown'), 'disableAllowed'),\n ignoreModifiedUntilEpoch: opt<number>(r('no-any-unknown'), 'ignoreModifiedUntilEpoch'),\n },\n noImplicitAny: {\n mode: modeOrOff(r('no-implicit-any')),\n disableAllowed: opt<boolean>(r('no-implicit-any'), 'disableAllowed'),\n ignoreModifiedUntilEpoch: opt<number>(r('no-implicit-any'), 'ignoreModifiedUntilEpoch'),\n },\n validateDtos: {\n mode: modeOrOff(r('validate-dtos')),\n disableAllowed: opt<boolean>(r('validate-dtos'), 'disableAllowed'),\n prismaSchemaPath: opt<string>(r('validate-dtos'), 'prismaSchemaPath'),\n dtoSourcePaths: opt<string[]>(r('validate-dtos'), 'dtoSourcePaths'),\n ignoreModifiedUntilEpoch: opt<number>(r('validate-dtos'), 'ignoreModifiedUntilEpoch'),\n },\n prismaConverter: {\n mode: modeOrOff(r('prisma-converter')),\n disableAllowed: opt<boolean>(r('prisma-converter'), 'disableAllowed'),\n schemaPath: opt<string>(r('prisma-converter'), 'schemaPath'),\n convertersPaths: opt<string[]>(r('prisma-converter'), 'convertersPaths'),\n enforcePaths: opt<string[]>(r('prisma-converter'), 'enforcePaths'),\n ignoreModifiedUntilEpoch: opt<number>(r('prisma-converter'), 'ignoreModifiedUntilEpoch'),\n },\n noDestructure: {\n mode: modeOrOff(r('no-destructure')),\n disableAllowed: opt<boolean>(r('no-destructure'), 'disableAllowed'),\n ignoreModifiedUntilEpoch: opt<number>(r('no-destructure'), 'ignoreModifiedUntilEpoch'),\n },\n catchErrorPattern: {\n mode: modeOrOff(r('catch-error-pattern')),\n disableAllowed: opt<boolean>(r('catch-error-pattern'), 'disableAllowed'),\n ignoreModifiedUntilEpoch: opt<number>(r('catch-error-pattern'), 'ignoreModifiedUntilEpoch'),\n },\n noUnmanagedExceptions: {\n mode: modeOrOff(r('no-unmanaged-exceptions')),\n disableAllowed: opt<boolean>(r('no-unmanaged-exceptions'), 'disableAllowed'),\n ignoreModifiedUntilEpoch: opt<number>(r('no-unmanaged-exceptions'), 'ignoreModifiedUntilEpoch'),\n },\n noDirectApiInResolver: {\n mode: modeOrOff(r('no-direct-api-in-resolver')),\n disableAllowed: opt<boolean>(r('no-direct-api-in-resolver'), 'disableAllowed'),\n ignoreModifiedUntilEpoch: opt<number>(r('no-direct-api-in-resolver'), 'ignoreModifiedUntilEpoch'),\n enforcePaths: opt<string[]>(r('no-direct-api-in-resolver'), 'enforcePaths'),\n },\n };\n}\n"]}
|
package/src/wp-ci.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* wp-ci — the universal webpieces CI entrypoint.
|
|
4
|
+
*
|
|
5
|
+
* Works in BOTH an Nx monorepo and a plain (non-Nx) repo, because the detection of
|
|
6
|
+
* "are we even in Nx?" cannot live inside an Nx executor (by the time an executor runs,
|
|
7
|
+
* Nx is already running). Dispatch:
|
|
8
|
+
*
|
|
9
|
+
* - no nx.json (non-Nx repo) -> run the standalone code validators, succeed.
|
|
10
|
+
* - nx.json present, plugin NOT in it -> fail with the exact install command.
|
|
11
|
+
* - nx.json present, plugin registered -> run validators (incl. the wiring guard),
|
|
12
|
+
* then `nx affected --target=ci`.
|
|
13
|
+
*
|
|
14
|
+
* Repos reference this as a bin (`"webpieces:ci": "wp-ci"`) so the logic is versioned in
|
|
15
|
+
* the npm package instead of copy-pasted into each repo's package.json (which drifts).
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
package/src/wp-ci.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* wp-ci — the universal webpieces CI entrypoint.
|
|
5
|
+
*
|
|
6
|
+
* Works in BOTH an Nx monorepo and a plain (non-Nx) repo, because the detection of
|
|
7
|
+
* "are we even in Nx?" cannot live inside an Nx executor (by the time an executor runs,
|
|
8
|
+
* Nx is already running). Dispatch:
|
|
9
|
+
*
|
|
10
|
+
* - no nx.json (non-Nx repo) -> run the standalone code validators, succeed.
|
|
11
|
+
* - nx.json present, plugin NOT in it -> fail with the exact install command.
|
|
12
|
+
* - nx.json present, plugin registered -> run validators (incl. the wiring guard),
|
|
13
|
+
* then `nx affected --target=ci`.
|
|
14
|
+
*
|
|
15
|
+
* Repos reference this as a bin (`"webpieces:ci": "wp-ci"`) so the logic is versioned in
|
|
16
|
+
* the npm package instead of copy-pasted into each repo's package.json (which drifts).
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const child_process_1 = require("child_process");
|
|
21
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
22
|
+
const path = tslib_1.__importStar(require("path"));
|
|
23
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
24
|
+
const from_shared_config_1 = require("./from-shared-config");
|
|
25
|
+
const validate_code_1 = tslib_1.__importDefault(require("./validate-code"));
|
|
26
|
+
const NX_PLUGIN_NAME = '@webpieces/nx-webpieces-rules';
|
|
27
|
+
function findUp(filename, startDir) {
|
|
28
|
+
let dir = startDir;
|
|
29
|
+
while (true) {
|
|
30
|
+
const candidate = path.join(dir, filename);
|
|
31
|
+
if (fs.existsSync(candidate))
|
|
32
|
+
return candidate;
|
|
33
|
+
const parent = path.dirname(dir);
|
|
34
|
+
if (parent === dir)
|
|
35
|
+
return null;
|
|
36
|
+
dir = parent;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function pluginEntryMatches(entry) {
|
|
40
|
+
if (typeof entry === 'string')
|
|
41
|
+
return entry === NX_PLUGIN_NAME;
|
|
42
|
+
return entry.plugin === NX_PLUGIN_NAME;
|
|
43
|
+
}
|
|
44
|
+
function isPluginRegistered(nxJsonPath) {
|
|
45
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
46
|
+
try {
|
|
47
|
+
const raw = fs.readFileSync(nxJsonPath, 'utf8');
|
|
48
|
+
const parsed = JSON.parse(raw);
|
|
49
|
+
const plugins = parsed.plugins ?? [];
|
|
50
|
+
return plugins.some((entry) => pluginEntryMatches(entry));
|
|
51
|
+
// webpieces-disable catch-error-pattern -- malformed nx.json should report as "not registered" with guidance
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
//const error = toError(err); -- malformed nx.json reports as "not registered"
|
|
55
|
+
void err;
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function nxBin(root) {
|
|
60
|
+
const local = path.join(root, 'node_modules', '.bin', 'nx');
|
|
61
|
+
return fs.existsSync(local) ? local : 'nx';
|
|
62
|
+
}
|
|
63
|
+
function runNx(root, args) {
|
|
64
|
+
const result = (0, child_process_1.spawnSync)(nxBin(root), args, { stdio: 'inherit', cwd: root });
|
|
65
|
+
if (typeof result.status === 'number')
|
|
66
|
+
return result.status;
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
async function runStandalone(cwd) {
|
|
70
|
+
const shared = (0, rules_config_1.loadConfig)(cwd);
|
|
71
|
+
if (!shared.configPath) {
|
|
72
|
+
console.log('ℹ️ Not an Nx repo and no webpieces.config.json found — nothing to validate.');
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
console.log('ℹ️ Not an Nx repo — running standalone webpieces code validators.\n');
|
|
76
|
+
const options = (0, from_shared_config_1.toValidateCodeOptions)(shared);
|
|
77
|
+
const result = await (0, validate_code_1.default)(options, cwd);
|
|
78
|
+
return result.success ? 0 : 1;
|
|
79
|
+
}
|
|
80
|
+
function reportPluginMissing() {
|
|
81
|
+
console.error('\n❌ This is an Nx monorepo but the webpieces Nx plugin is not installed.\n');
|
|
82
|
+
console.error(' Install it so the validators run during CI:\n');
|
|
83
|
+
console.error(` nx add ${NX_PLUGIN_NAME}\n`);
|
|
84
|
+
console.error(' (or add it manually to the "plugins" array in nx.json).\n');
|
|
85
|
+
}
|
|
86
|
+
async function main() {
|
|
87
|
+
const cwd = process.cwd();
|
|
88
|
+
const passthrough = process.argv.slice(2);
|
|
89
|
+
const nxJsonPath = findUp('nx.json', cwd);
|
|
90
|
+
if (!nxJsonPath) {
|
|
91
|
+
const code = await runStandalone(cwd);
|
|
92
|
+
process.exit(code);
|
|
93
|
+
}
|
|
94
|
+
const root = path.dirname(nxJsonPath);
|
|
95
|
+
if (!isPluginRegistered(nxJsonPath)) {
|
|
96
|
+
reportPluginMissing();
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
// Run the architecture + code validators first (this also runs the wiring guard,
|
|
100
|
+
// which fails loudly if nx.json no longer wires validators into the build).
|
|
101
|
+
if (fs.existsSync(path.join(root, 'architecture'))) {
|
|
102
|
+
const validateCode = runNx(root, ['run', 'architecture:validate-complete']);
|
|
103
|
+
if (validateCode !== 0)
|
|
104
|
+
process.exit(validateCode);
|
|
105
|
+
}
|
|
106
|
+
// Then the Gradle-style ci composite (lint + build + test) across affected projects.
|
|
107
|
+
const ciCode = runNx(root, ['affected', '--target=ci', ...passthrough]);
|
|
108
|
+
process.exit(ciCode);
|
|
109
|
+
}
|
|
110
|
+
void main();
|
|
111
|
+
//# sourceMappingURL=wp-ci.js.map
|
package/src/wp-ci.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wp-ci.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/wp-ci.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;;;GAcG;;;AAEH,iDAA0C;AAC1C,+CAAyB;AACzB,mDAA6B;AAE7B,0DAAqD;AACrD,6DAA6D;AAC7D,4EAA8C;AAE9C,MAAM,cAAc,GAAG,+BAA+B,CAAC;AAYvD,SAAS,MAAM,CAAC,QAAgB,EAAE,QAAgB;IAC9C,IAAI,GAAG,GAAG,QAAQ,CAAC;IACnB,OAAO,IAAI,EAAE,CAAC;QACV,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC3C,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,MAAM,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QAChC,GAAG,GAAG,MAAM,CAAC;IACjB,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAoB;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,KAAK,cAAc,CAAC;IAC/D,OAAO,KAAK,CAAC,MAAM,KAAK,cAAc,CAAC;AAC3C,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAkB;IAC1C,8DAA8D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AC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;QACjD,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,gCAAgC,CAAC,CAAC,CAAC;QAC5E,IAAI,YAAY,KAAK,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvD,CAAC;IAED,qFAAqF;IACrF,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,aAAa,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC;IACxE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED,KAAK,IAAI,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * wp-ci — the universal webpieces CI entrypoint.\n *\n * Works in BOTH an Nx monorepo and a plain (non-Nx) repo, because the detection of\n * \"are we even in Nx?\" cannot live inside an Nx executor (by the time an executor runs,\n * Nx is already running). Dispatch:\n *\n * - no nx.json (non-Nx repo) -> run the standalone code validators, succeed.\n * - nx.json present, plugin NOT in it -> fail with the exact install command.\n * - nx.json present, plugin registered -> run validators (incl. the wiring guard),\n * then `nx affected --target=ci`.\n *\n * Repos reference this as a bin (`\"webpieces:ci\": \"wp-ci\"`) so the logic is versioned in\n * the npm package instead of copy-pasted into each repo's package.json (which drifts).\n */\n\nimport { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport { loadConfig } from '@webpieces/rules-config';\nimport { toValidateCodeOptions } from './from-shared-config';\nimport runValidateCode from './validate-code';\n\nconst NX_PLUGIN_NAME = '@webpieces/nx-webpieces-rules';\n\ninterface NxPluginObject {\n plugin?: string;\n}\n\ntype NxPluginEntry = string | NxPluginObject;\n\ninterface RawNxJson {\n plugins?: NxPluginEntry[];\n}\n\nfunction findUp(filename: string, startDir: string): string | null {\n let dir = startDir;\n while (true) {\n const candidate = path.join(dir, filename);\n if (fs.existsSync(candidate)) return candidate;\n const parent = path.dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n}\n\nfunction pluginEntryMatches(entry: NxPluginEntry): boolean {\n if (typeof entry === 'string') return entry === NX_PLUGIN_NAME;\n return entry.plugin === NX_PLUGIN_NAME;\n}\n\nfunction isPluginRegistered(nxJsonPath: string): boolean {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const raw = fs.readFileSync(nxJsonPath, 'utf8');\n const parsed = JSON.parse(raw) as RawNxJson;\n const plugins = parsed.plugins ?? [];\n return plugins.some((entry: NxPluginEntry) => pluginEntryMatches(entry));\n // webpieces-disable catch-error-pattern -- malformed nx.json should report as \"not registered\" with guidance\n } catch (err: unknown) {\n //const error = toError(err); -- malformed nx.json reports as \"not registered\"\n void err;\n return false;\n }\n}\n\nfunction nxBin(root: string): string {\n const local = path.join(root, 'node_modules', '.bin', 'nx');\n return fs.existsSync(local) ? local : 'nx';\n}\n\nfunction runNx(root: string, args: string[]): number {\n const result = spawnSync(nxBin(root), args, { stdio: 'inherit', cwd: root });\n if (typeof result.status === 'number') return result.status;\n return 1;\n}\n\nasync function runStandalone(cwd: string): Promise<number> {\n const shared = loadConfig(cwd);\n if (!shared.configPath) {\n console.log('ℹ️ Not an Nx repo and no webpieces.config.json found — nothing to validate.');\n return 0;\n }\n console.log('ℹ️ Not an Nx repo — running standalone webpieces code validators.\\n');\n const options = toValidateCodeOptions(shared);\n const result = await runValidateCode(options, cwd);\n return result.success ? 0 : 1;\n}\n\nfunction reportPluginMissing(): void {\n console.error('\\n❌ This is an Nx monorepo but the webpieces Nx plugin is not installed.\\n');\n console.error(' Install it so the validators run during CI:\\n');\n console.error(` nx add ${NX_PLUGIN_NAME}\\n`);\n console.error(' (or add it manually to the \"plugins\" array in nx.json).\\n');\n}\n\nasync function main(): Promise<void> {\n const cwd = process.cwd();\n const passthrough = process.argv.slice(2);\n\n const nxJsonPath = findUp('nx.json', cwd);\n if (!nxJsonPath) {\n const code = await runStandalone(cwd);\n process.exit(code);\n }\n\n const root = path.dirname(nxJsonPath);\n if (!isPluginRegistered(nxJsonPath)) {\n reportPluginMissing();\n process.exit(1);\n }\n\n // Run the architecture + code validators first (this also runs the wiring guard,\n // which fails loudly if nx.json no longer wires validators into the build).\n if (fs.existsSync(path.join(root, 'architecture'))) {\n const validateCode = runNx(root, ['run', 'architecture:validate-complete']);\n if (validateCode !== 0) process.exit(validateCode);\n }\n\n // Then the Gradle-style ci composite (lint + build + test) across affected projects.\n const ciCode = runNx(root, ['affected', '--target=ci', ...passthrough]);\n process.exit(ciCode);\n}\n\nvoid main();\n"]}
|
package/bin/wp-validate-code.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Plain JS shim — delegates to compiled TypeScript.
|
|
3
|
-
// Must NOT be converted to TypeScript (needs to exist pre-build for pnpm bin symlinks).
|
|
4
|
-
'use strict';
|
|
5
|
-
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const compiled = path.join(__dirname, '..', 'src', 'cli.js');
|
|
9
|
-
|
|
10
|
-
if (fs.existsSync(compiled)) {
|
|
11
|
-
require(compiled);
|
|
12
|
-
} else {
|
|
13
|
-
console.error(' [code-rules] Package not built yet. Run the build first, or install from npm.');
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|