@efolusi/meridian-guard 1.21.2
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/LICENSE +21 -0
- package/README.md +54 -0
- package/bin/meridian-guard.js +7 -0
- package/package.json +40 -0
- package/src/cli.mjs +55 -0
- package/src/generated/meridian-rules.json +1902 -0
- package/src/index.mjs +2 -0
- package/src/reporter.mjs +26 -0
- package/src/rules.mjs +37 -0
- package/src/scanner.mjs +266 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Efolusi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Meridian Guard
|
|
2
|
+
|
|
3
|
+
Install the public CLI as a development dependency:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install --save-dev @efolusi/meridian-guard
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Meridian Guard validates React source against Meridian's component, icon,
|
|
10
|
+
token, deprecation, and accessibility contracts. It is deterministic: the CLI
|
|
11
|
+
does not upload source or call an AI model.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npx @efolusi/meridian-guard src
|
|
17
|
+
npx @efolusi/meridian-guard src pages --format json
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Guard exits `0` when no diagnostics are found, `1` when a contract violation is
|
|
21
|
+
found, and `2` for CLI or runtime failures. Directories are scanned recursively;
|
|
22
|
+
common dependency, framework-output, build, and coverage directories are
|
|
23
|
+
ignored (`node_modules`, `.next`, `.turbo`, `.open-next`, `.wrangler`, `dist`,
|
|
24
|
+
`build`, `coverage`, and their equivalents). Symbolic links are not followed,
|
|
25
|
+
keeping a scan inside the requested source tree and safely skipping broken links.
|
|
26
|
+
Test/spec fixtures and minified vendor scripts are also excluded because they are
|
|
27
|
+
not shipped interface source.
|
|
28
|
+
|
|
29
|
+
## Rules
|
|
30
|
+
|
|
31
|
+
| Rule | Severity | Contract |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| `MDG000` | error | Source must parse before it can be validated. |
|
|
34
|
+
| `MDG001` | error | Imported Meridian components must exist. |
|
|
35
|
+
| `MDG002` | error | Static `Icon` and `IconButton` names must exist. |
|
|
36
|
+
| `MDG003` | warning | Inline and CSS-in-JS colors use semantic tokens, not hex. |
|
|
37
|
+
| `MDG004` | warning | Deprecated props migrate to their canonical replacement. |
|
|
38
|
+
| `MDG005` | error | Required accessible names and dialog titles are present. |
|
|
39
|
+
| `MDG006` | error | Referenced Meridian radius tokens must exist in the generated token contract. |
|
|
40
|
+
|
|
41
|
+
Dynamic icon names cannot be proven statically and are left to the application.
|
|
42
|
+
Guard currently validates Meridian imports from the umbrella package and its
|
|
43
|
+
documented deep-import paths.
|
|
44
|
+
|
|
45
|
+
## Developing
|
|
46
|
+
|
|
47
|
+
The contract at `src/generated/meridian-rules.json` is generated from Meridian's
|
|
48
|
+
manifest, component declarations, tokens, and SVG directory. Regenerate it with:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
node scripts/build_guard_rules.mjs
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Do not edit the generated file manually.
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@efolusi/meridian-guard",
|
|
3
|
+
"version": "1.21.2",
|
|
4
|
+
"description": "Static compliance checks for React applications built with the Meridian design system.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://meridian.efolusi.com",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/efolusi/meridian.git",
|
|
10
|
+
"directory": "packages/guard"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=20.10"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"meridian-guard": "bin/meridian-guard.js"
|
|
18
|
+
},
|
|
19
|
+
"main": "./src/index.mjs",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./src/index.mjs",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"bin",
|
|
26
|
+
"src",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@babel/parser": "^7.28.0"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"design-system",
|
|
35
|
+
"accessibility",
|
|
36
|
+
"lint",
|
|
37
|
+
"meridian",
|
|
38
|
+
"react"
|
|
39
|
+
]
|
|
40
|
+
}
|
package/src/cli.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { guard } from './scanner.mjs';
|
|
3
|
+
import { formatJson, formatPretty } from './reporter.mjs';
|
|
4
|
+
|
|
5
|
+
const HELP = `Meridian Guard — validate React code against Meridian contracts
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
meridian-guard [path ...] [--format pretty|json]
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
--format <name> Output format: pretty (default) or json
|
|
12
|
+
--help Show this help
|
|
13
|
+
--version Show the Guard rule-pack version
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
function parseArgs(argv) {
|
|
17
|
+
const paths = [];
|
|
18
|
+
let format = 'pretty';
|
|
19
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
20
|
+
const arg = argv[index];
|
|
21
|
+
if (arg === '--help' || arg === '-h') return { help: true, paths, format };
|
|
22
|
+
if (arg === '--version' || arg === '-v') return { version: true, paths, format };
|
|
23
|
+
if (arg === '--format') {
|
|
24
|
+
format = argv[index + 1];
|
|
25
|
+
index += 1;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (arg.startsWith('--format=')) {
|
|
29
|
+
format = arg.slice('--format='.length);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (arg.startsWith('-')) throw new Error(`unknown option ${arg}`);
|
|
33
|
+
paths.push(arg);
|
|
34
|
+
}
|
|
35
|
+
if (!['pretty', 'json'].includes(format)) throw new Error(`unknown format ${format}`);
|
|
36
|
+
return { paths, format };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function main(argv, io = process) {
|
|
40
|
+
const options = parseArgs(argv);
|
|
41
|
+
if (options.help) {
|
|
42
|
+
io.stdout.write(HELP);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const { default: contracts } = await import('./generated/meridian-rules.json', { with: { type: 'json' } });
|
|
46
|
+
if (options.version) {
|
|
47
|
+
io.stdout.write(`${contracts.version}\n`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const cwd = process.cwd();
|
|
51
|
+
const targets = (options.paths.length ? options.paths : ['.']).map(target => path.resolve(cwd, target));
|
|
52
|
+
const result = await guard(targets, { contracts });
|
|
53
|
+
io.stdout.write(options.format === 'json' ? formatJson(result) : formatPretty(result, cwd));
|
|
54
|
+
if (result.diagnostics.length > 0) io.exitCode = 1;
|
|
55
|
+
}
|