@marktiderman/genesis-cli 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -0
- package/app.plugin.js +4 -0
- package/dist/cli.js +166 -86
- package/dist/cli.js.map +1 -1
- package/dist/config-Ci-_Ue-1.d.ts +200 -0
- package/dist/doctor.d.ts +12 -173
- package/dist/doctor.js +73 -6
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +59 -0
- package/dist/expo.js +157 -0
- package/dist/expo.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +94 -58
- package/dist/index.js.map +1 -1
- package/dist/scaffolder.d.ts +3 -2
- package/dist/scaffolder.js +18 -49
- package/dist/scaffolder.js.map +1 -1
- package/dist/vite.js +72 -5
- package/dist/vite.js.map +1 -1
- package/package.json +27 -8
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for `genesis doctor` and its rule plugins.
|
|
3
|
+
*/
|
|
4
|
+
type Level = "error" | "warn";
|
|
5
|
+
/** A rule's configured level: a level, or `"off"` to drop its findings. */
|
|
6
|
+
type RuleSetting = Level | "off";
|
|
7
|
+
/** One problem the doctor found. */
|
|
8
|
+
interface Finding {
|
|
9
|
+
/** The rule that produced it, e.g. `raw-tag` or a pattern/plugin rule id. */
|
|
10
|
+
rule: string;
|
|
11
|
+
level: Level;
|
|
12
|
+
/** Path relative to the app root, POSIX separators. */
|
|
13
|
+
file: string;
|
|
14
|
+
/** 1-based line, or 0 when the finding is about the whole file. */
|
|
15
|
+
line: number;
|
|
16
|
+
message: string;
|
|
17
|
+
/**
|
|
18
|
+
* What the finding is about (a tag, token, export name, import specifier).
|
|
19
|
+
* An `allow` entry's `match` is compared against it.
|
|
20
|
+
*/
|
|
21
|
+
subject?: string;
|
|
22
|
+
}
|
|
23
|
+
/** What a rule or plugin passes to `report`. `level` defaults to `"error"`. */
|
|
24
|
+
interface FindingInput {
|
|
25
|
+
rule: string;
|
|
26
|
+
level?: Level;
|
|
27
|
+
file: string;
|
|
28
|
+
line?: number;
|
|
29
|
+
message: string;
|
|
30
|
+
subject?: string;
|
|
31
|
+
}
|
|
32
|
+
/** A justified exception. `reason` is required: an exception nobody can explain is a bug. */
|
|
33
|
+
interface AllowEntry {
|
|
34
|
+
rule: string;
|
|
35
|
+
/** Glob relative to the app root. Omit to allow in every file. */
|
|
36
|
+
file?: string;
|
|
37
|
+
/** Exact subject (tag, token, export name, import specifier). Omit to allow any. */
|
|
38
|
+
match?: string;
|
|
39
|
+
reason: string;
|
|
40
|
+
}
|
|
41
|
+
/** A declarative check: which files it covers and the pattern they must (not) contain. */
|
|
42
|
+
interface PatternRule {
|
|
43
|
+
id: string;
|
|
44
|
+
/** `guide` documents a convention and is never checked. Default `error`. */
|
|
45
|
+
level?: Level | "guide";
|
|
46
|
+
/** Globs the rule applies to. Required unless the level is `guide`. */
|
|
47
|
+
files?: string[];
|
|
48
|
+
exclude?: string[];
|
|
49
|
+
/** Regular expression that must not appear (multiline). Prefix `(?i)` for case-insensitive. */
|
|
50
|
+
forbid?: string;
|
|
51
|
+
/** Regular expression every matching file must contain. */
|
|
52
|
+
require?: string;
|
|
53
|
+
/** Regular expression every matching file's path must fit. */
|
|
54
|
+
path?: string;
|
|
55
|
+
message?: string;
|
|
56
|
+
}
|
|
57
|
+
/** A plugin entry in config: a module path, or `[path, options]`. */
|
|
58
|
+
type PluginSpec = string | [string, unknown];
|
|
59
|
+
/** The `doctor` block of genesis.config.json (or package.json `genesis.doctor`). */
|
|
60
|
+
interface DoctorConfig {
|
|
61
|
+
/** Folders to scan, relative to the app root. Default `["src"]`. */
|
|
62
|
+
src?: string[];
|
|
63
|
+
/** File extensions to scan. Default `.ts .tsx .js .jsx .mts .cts .css`. */
|
|
64
|
+
extensions?: string[];
|
|
65
|
+
/** Extra globs to skip, on top of the defaults (tests, fixtures, `.d.ts`, `*.gen.*`). */
|
|
66
|
+
ignore?: string[];
|
|
67
|
+
/** The component package. Default `@marktiderman/genesis-ui`. */
|
|
68
|
+
uiPackage?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Theme stylesheet(s) whose custom properties are the defined tokens: one
|
|
71
|
+
* or a list of package specifiers (`@scope/pkg/path.css`) or app-relative
|
|
72
|
+
* paths. Default: every `.css` in the design system's `dist/themes/`
|
|
73
|
+
* (genesis.css and the Tailwind v4 bridge genesis-tailwind4.css), plus
|
|
74
|
+
* genesis-ui's styles.
|
|
75
|
+
*/
|
|
76
|
+
themeCss?: string | string[];
|
|
77
|
+
/**
|
|
78
|
+
* App files whose custom-property declarations also count as defined
|
|
79
|
+
* tokens (a brand bridge). Default: every scanned `.css` file.
|
|
80
|
+
*/
|
|
81
|
+
tokenFiles?: string[];
|
|
82
|
+
/** Token prefixes never reported as undefined. Default `--tw-`, `--radix-`. */
|
|
83
|
+
ignoreTokenPrefixes?: string[];
|
|
84
|
+
/** Extra raw-tag → component mappings (`{ "img": "Avatar" }`), or `false` to stop checking a tag. */
|
|
85
|
+
rawTags?: Record<string, string | false>;
|
|
86
|
+
/** Extra import specifiers to forbid: regular expression → message. Added to the defaults. */
|
|
87
|
+
forbiddenImports?: Record<string, string>;
|
|
88
|
+
/** Folders that must not exist (local design-system primitives). Default `["src/components/ui"]`. */
|
|
89
|
+
localPrimitiveDirs?: string[];
|
|
90
|
+
/** Per-rule level overrides, e.g. `{ "raw-color": "warn", "palette-color": "off" }`. */
|
|
91
|
+
rules?: Record<string, RuleSetting>;
|
|
92
|
+
/** Justified exceptions. */
|
|
93
|
+
allow?: AllowEntry[];
|
|
94
|
+
/** Declarative app rules. */
|
|
95
|
+
patterns?: PatternRule[];
|
|
96
|
+
/** A markdown file of pattern rules (`### rule-id` blocks of `- key: value` lines). */
|
|
97
|
+
rulesDoc?: string;
|
|
98
|
+
/** Rule modules, resolved relative to the config file. */
|
|
99
|
+
plugins?: PluginSpec[];
|
|
100
|
+
/** Commands `--build` runs, in order. Default: the app's `typecheck` then `build` scripts. */
|
|
101
|
+
build?: string[];
|
|
102
|
+
}
|
|
103
|
+
/** Facts read from the installed Genesis packages. Nothing here is hardcoded. */
|
|
104
|
+
interface GenesisFacts {
|
|
105
|
+
uiPackage: string;
|
|
106
|
+
uiVersion: string;
|
|
107
|
+
/** Every name exported from the component package (all subpaths). */
|
|
108
|
+
exports: ReadonlySet<string>;
|
|
109
|
+
/** Exported values (not types): what an app could shadow. */
|
|
110
|
+
values: ReadonlySet<string>;
|
|
111
|
+
/** Exported components, sorted. */
|
|
112
|
+
components: readonly string[];
|
|
113
|
+
/** Custom properties the theme stylesheets define. */
|
|
114
|
+
tokens: ReadonlySet<string>;
|
|
115
|
+
/** Raw HTML tag → the Genesis component that replaces it. */
|
|
116
|
+
rawTags: ReadonlyMap<string, string>;
|
|
117
|
+
/** Tailwind palette color names (red, slate, …). */
|
|
118
|
+
palette: readonly string[];
|
|
119
|
+
}
|
|
120
|
+
/** One scanned file. */
|
|
121
|
+
interface SourceFile {
|
|
122
|
+
/** Path relative to the app root, POSIX separators. */
|
|
123
|
+
path: string;
|
|
124
|
+
absolutePath: string;
|
|
125
|
+
/** Extension including the dot, e.g. `.tsx`. */
|
|
126
|
+
ext: string;
|
|
127
|
+
/** Raw contents. */
|
|
128
|
+
text: string;
|
|
129
|
+
/** Contents with comments blanked out (line numbers preserved). */
|
|
130
|
+
code: string;
|
|
131
|
+
}
|
|
132
|
+
/** What a plugin's `check` receives. */
|
|
133
|
+
interface DoctorContext {
|
|
134
|
+
root: string;
|
|
135
|
+
files: readonly SourceFile[];
|
|
136
|
+
genesis: GenesisFacts;
|
|
137
|
+
config: DoctorConfig;
|
|
138
|
+
/** Record a finding. Config `rules` levels and `allow` entries apply afterwards. */
|
|
139
|
+
report(finding: FindingInput): void;
|
|
140
|
+
}
|
|
141
|
+
/** A rule module. Default-export one, an array, or a factory that takes the config options. */
|
|
142
|
+
interface DoctorPlugin {
|
|
143
|
+
name: string;
|
|
144
|
+
check(context: DoctorContext): void | Promise<void>;
|
|
145
|
+
}
|
|
146
|
+
interface DoctorResult {
|
|
147
|
+
ok: boolean;
|
|
148
|
+
root: string;
|
|
149
|
+
genesis: GenesisFacts;
|
|
150
|
+
findings: Finding[];
|
|
151
|
+
/** Genesis components no scanned file imports. */
|
|
152
|
+
unused: string[];
|
|
153
|
+
/** Pattern rules plus plugins that ran. */
|
|
154
|
+
ruleCount: number;
|
|
155
|
+
errors: number;
|
|
156
|
+
warnings: number;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** A genesis.config.json that can't be read or has a block of the wrong shape. */
|
|
160
|
+
declare class GenesisConfigError extends Error {
|
|
161
|
+
name: string;
|
|
162
|
+
}
|
|
163
|
+
declare class DoctorConfigError extends GenesisConfigError {
|
|
164
|
+
name: string;
|
|
165
|
+
}
|
|
166
|
+
/** The `links` block: the web hosts (and optional path prefixes) the app opens as universal / app links. */
|
|
167
|
+
interface GenesisLinks {
|
|
168
|
+
/** Bare host names, such as `example.com` or `app.example.com`: no scheme, path or port. */
|
|
169
|
+
hosts: string[];
|
|
170
|
+
/** Path prefixes the app handles, each starting with `/`. Default: every path. */
|
|
171
|
+
paths?: string[];
|
|
172
|
+
/** Also add `webcredentials:` domains (password autofill). Default true. */
|
|
173
|
+
webcredentials?: boolean;
|
|
174
|
+
}
|
|
175
|
+
/** genesis.config.json, parsed, with its shared blocks validated. */
|
|
176
|
+
interface GenesisConfigFile {
|
|
177
|
+
/** The whole parsed file, for blocks other readers own (`doctor`, `features`). */
|
|
178
|
+
raw: Record<string, unknown>;
|
|
179
|
+
links?: GenesisLinks;
|
|
180
|
+
}
|
|
181
|
+
interface LoadedConfig {
|
|
182
|
+
config: DoctorConfig;
|
|
183
|
+
/** The file it came from, or null when no config exists (defaults apply). */
|
|
184
|
+
file: string | null;
|
|
185
|
+
/** Folder that relative plugin paths resolve against. */
|
|
186
|
+
dir: string;
|
|
187
|
+
}
|
|
188
|
+
declare function loadConfig(root: string, configPath?: string): LoadedConfig;
|
|
189
|
+
/**
|
|
190
|
+
* Reads `<root>/genesis.config.json` and validates its shared blocks (today:
|
|
191
|
+
* `links`). Returns null when the file doesn't exist; throws a
|
|
192
|
+
* GenesisConfigError naming the file when it isn't valid.
|
|
193
|
+
*/
|
|
194
|
+
declare function readGenesisConfig(root: string): GenesisConfigFile | null;
|
|
195
|
+
/** Check the `links` block, so a typo'd host fails the build instead of shipping links that never open. */
|
|
196
|
+
declare function validateLinks(raw: unknown, source?: string): GenesisLinks;
|
|
197
|
+
/** Check the shape, so a typo fails loudly instead of silently disabling a check. */
|
|
198
|
+
declare function validateConfig(raw: unknown, source?: string): DoctorConfig;
|
|
199
|
+
|
|
200
|
+
export { type AllowEntry as A, type DoctorConfig as D, type Finding as F, type GenesisLinks as G, type Level as L, type PatternRule as P, type RuleSetting as R, type SourceFile as S, GenesisConfigError as a, DoctorConfigError as b, type DoctorContext as c, type DoctorPlugin as d, type DoctorResult as e, type GenesisConfigFile as f, type GenesisFacts as g, type FindingInput as h, type PluginSpec as i, validateConfig as j, loadConfig as l, readGenesisConfig as r, validateLinks as v };
|
package/dist/doctor.d.ts
CHANGED
|
@@ -1,174 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
type Level = "error" | "warn";
|
|
5
|
-
/** A rule's configured level: a level, or `"off"` to drop its findings. */
|
|
6
|
-
type RuleSetting = Level | "off";
|
|
7
|
-
/** One problem the doctor found. */
|
|
8
|
-
interface Finding {
|
|
9
|
-
/** The rule that produced it, e.g. `raw-tag` or a pattern/plugin rule id. */
|
|
10
|
-
rule: string;
|
|
11
|
-
level: Level;
|
|
12
|
-
/** Path relative to the app root, POSIX separators. */
|
|
13
|
-
file: string;
|
|
14
|
-
/** 1-based line, or 0 when the finding is about the whole file. */
|
|
15
|
-
line: number;
|
|
16
|
-
message: string;
|
|
17
|
-
/**
|
|
18
|
-
* What the finding is about (a tag, token, export name, import specifier).
|
|
19
|
-
* An `allow` entry's `match` is compared against it.
|
|
20
|
-
*/
|
|
21
|
-
subject?: string;
|
|
22
|
-
}
|
|
23
|
-
/** What a rule or plugin passes to `report`. `level` defaults to `"error"`. */
|
|
24
|
-
interface FindingInput {
|
|
25
|
-
rule: string;
|
|
26
|
-
level?: Level;
|
|
27
|
-
file: string;
|
|
28
|
-
line?: number;
|
|
29
|
-
message: string;
|
|
30
|
-
subject?: string;
|
|
31
|
-
}
|
|
32
|
-
/** A justified exception. `reason` is required: an exception nobody can explain is a bug. */
|
|
33
|
-
interface AllowEntry {
|
|
34
|
-
rule: string;
|
|
35
|
-
/** Glob relative to the app root. Omit to allow in every file. */
|
|
36
|
-
file?: string;
|
|
37
|
-
/** Exact subject (tag, token, export name, import specifier). Omit to allow any. */
|
|
38
|
-
match?: string;
|
|
39
|
-
reason: string;
|
|
40
|
-
}
|
|
41
|
-
/** A declarative check: which files it covers and the pattern they must (not) contain. */
|
|
42
|
-
interface PatternRule {
|
|
43
|
-
id: string;
|
|
44
|
-
/** `guide` documents a convention and is never checked. Default `error`. */
|
|
45
|
-
level?: Level | "guide";
|
|
46
|
-
/** Globs the rule applies to. Required unless the level is `guide`. */
|
|
47
|
-
files?: string[];
|
|
48
|
-
exclude?: string[];
|
|
49
|
-
/** Regular expression that must not appear (multiline). Prefix `(?i)` for case-insensitive. */
|
|
50
|
-
forbid?: string;
|
|
51
|
-
/** Regular expression every matching file must contain. */
|
|
52
|
-
require?: string;
|
|
53
|
-
/** Regular expression every matching file's path must fit. */
|
|
54
|
-
path?: string;
|
|
55
|
-
message?: string;
|
|
56
|
-
}
|
|
57
|
-
/** A plugin entry in config: a module path, or `[path, options]`. */
|
|
58
|
-
type PluginSpec = string | [string, unknown];
|
|
59
|
-
/** The `doctor` block of genesis.config.json (or package.json `genesis.doctor`). */
|
|
60
|
-
interface DoctorConfig {
|
|
61
|
-
/** Folders to scan, relative to the app root. Default `["src"]`. */
|
|
62
|
-
src?: string[];
|
|
63
|
-
/** File extensions to scan. Default `.ts .tsx .js .jsx .mts .cts .css`. */
|
|
64
|
-
extensions?: string[];
|
|
65
|
-
/** Extra globs to skip, on top of the defaults (tests, fixtures, `.d.ts`, `*.gen.*`). */
|
|
66
|
-
ignore?: string[];
|
|
67
|
-
/** The component package. Default `@marktiderman/genesis-ui`. */
|
|
68
|
-
uiPackage?: string;
|
|
69
|
-
/**
|
|
70
|
-
* Theme stylesheet(s) whose custom properties are the defined tokens: one
|
|
71
|
-
* or a list of package specifiers (`@scope/pkg/path.css`) or app-relative
|
|
72
|
-
* paths. Default: every `.css` in the design system's `dist/themes/`
|
|
73
|
-
* (genesis.css and the Tailwind v4 bridge genesis-tailwind4.css), plus
|
|
74
|
-
* genesis-ui's styles.
|
|
75
|
-
*/
|
|
76
|
-
themeCss?: string | string[];
|
|
77
|
-
/**
|
|
78
|
-
* App files whose custom-property declarations also count as defined
|
|
79
|
-
* tokens (a brand bridge). Default: every scanned `.css` file.
|
|
80
|
-
*/
|
|
81
|
-
tokenFiles?: string[];
|
|
82
|
-
/** Token prefixes never reported as undefined. Default `--tw-`, `--radix-`. */
|
|
83
|
-
ignoreTokenPrefixes?: string[];
|
|
84
|
-
/** Extra raw-tag → component mappings (`{ "img": "Avatar" }`), or `false` to stop checking a tag. */
|
|
85
|
-
rawTags?: Record<string, string | false>;
|
|
86
|
-
/** Extra import specifiers to forbid: regular expression → message. Added to the defaults. */
|
|
87
|
-
forbiddenImports?: Record<string, string>;
|
|
88
|
-
/** Folders that must not exist (local design-system primitives). Default `["src/components/ui"]`. */
|
|
89
|
-
localPrimitiveDirs?: string[];
|
|
90
|
-
/** Per-rule level overrides, e.g. `{ "raw-color": "warn", "palette-color": "off" }`. */
|
|
91
|
-
rules?: Record<string, RuleSetting>;
|
|
92
|
-
/** Justified exceptions. */
|
|
93
|
-
allow?: AllowEntry[];
|
|
94
|
-
/** Declarative app rules. */
|
|
95
|
-
patterns?: PatternRule[];
|
|
96
|
-
/** A markdown file of pattern rules (`### rule-id` blocks of `- key: value` lines). */
|
|
97
|
-
rulesDoc?: string;
|
|
98
|
-
/** Rule modules, resolved relative to the config file. */
|
|
99
|
-
plugins?: PluginSpec[];
|
|
100
|
-
/** Commands `--build` runs, in order. Default: the app's `typecheck` then `build` scripts. */
|
|
101
|
-
build?: string[];
|
|
102
|
-
}
|
|
103
|
-
/** Facts read from the installed Genesis packages. Nothing here is hardcoded. */
|
|
104
|
-
interface GenesisFacts {
|
|
105
|
-
uiPackage: string;
|
|
106
|
-
uiVersion: string;
|
|
107
|
-
/** Every name exported from the component package (all subpaths). */
|
|
108
|
-
exports: ReadonlySet<string>;
|
|
109
|
-
/** Exported values (not types): what an app could shadow. */
|
|
110
|
-
values: ReadonlySet<string>;
|
|
111
|
-
/** Exported components, sorted. */
|
|
112
|
-
components: readonly string[];
|
|
113
|
-
/** Custom properties the theme stylesheets define. */
|
|
114
|
-
tokens: ReadonlySet<string>;
|
|
115
|
-
/** Raw HTML tag → the Genesis component that replaces it. */
|
|
116
|
-
rawTags: ReadonlyMap<string, string>;
|
|
117
|
-
/** Tailwind palette color names (red, slate, …). */
|
|
118
|
-
palette: readonly string[];
|
|
119
|
-
}
|
|
120
|
-
/** One scanned file. */
|
|
121
|
-
interface SourceFile {
|
|
122
|
-
/** Path relative to the app root, POSIX separators. */
|
|
123
|
-
path: string;
|
|
124
|
-
absolutePath: string;
|
|
125
|
-
/** Extension including the dot, e.g. `.tsx`. */
|
|
126
|
-
ext: string;
|
|
127
|
-
/** Raw contents. */
|
|
128
|
-
text: string;
|
|
129
|
-
/** Contents with comments blanked out (line numbers preserved). */
|
|
130
|
-
code: string;
|
|
131
|
-
}
|
|
132
|
-
/** What a plugin's `check` receives. */
|
|
133
|
-
interface DoctorContext {
|
|
134
|
-
root: string;
|
|
135
|
-
files: readonly SourceFile[];
|
|
136
|
-
genesis: GenesisFacts;
|
|
137
|
-
config: DoctorConfig;
|
|
138
|
-
/** Record a finding. Config `rules` levels and `allow` entries apply afterwards. */
|
|
139
|
-
report(finding: FindingInput): void;
|
|
140
|
-
}
|
|
141
|
-
/** A rule module. Default-export one, an array, or a factory that takes the config options. */
|
|
142
|
-
interface DoctorPlugin {
|
|
143
|
-
name: string;
|
|
144
|
-
check(context: DoctorContext): void | Promise<void>;
|
|
145
|
-
}
|
|
146
|
-
interface DoctorResult {
|
|
147
|
-
ok: boolean;
|
|
148
|
-
root: string;
|
|
149
|
-
genesis: GenesisFacts;
|
|
150
|
-
findings: Finding[];
|
|
151
|
-
/** Genesis components no scanned file imports. */
|
|
152
|
-
unused: string[];
|
|
153
|
-
/** Pattern rules plus plugins that ran. */
|
|
154
|
-
ruleCount: number;
|
|
155
|
-
errors: number;
|
|
156
|
-
warnings: number;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
declare class DoctorConfigError extends Error {
|
|
160
|
-
name: string;
|
|
161
|
-
}
|
|
162
|
-
interface LoadedConfig {
|
|
163
|
-
config: DoctorConfig;
|
|
164
|
-
/** The file it came from, or null when no config exists (defaults apply). */
|
|
165
|
-
file: string | null;
|
|
166
|
-
/** Folder that relative plugin paths resolve against. */
|
|
167
|
-
dir: string;
|
|
168
|
-
}
|
|
169
|
-
declare function loadConfig(root: string, configPath?: string): LoadedConfig;
|
|
170
|
-
/** Check the shape, so a typo fails loudly instead of silently disabling a check. */
|
|
171
|
-
declare function validateConfig(raw: unknown, source?: string): DoctorConfig;
|
|
1
|
+
import { D as DoctorConfig, g as GenesisFacts, P as PatternRule, d as DoctorPlugin, e as DoctorResult, F as Finding } from './config-Ci-_Ue-1.js';
|
|
2
|
+
export { A as AllowEntry, b as DoctorConfigError, c as DoctorContext, h as FindingInput, a as GenesisConfigError, f as GenesisConfigFile, G as GenesisLinks, L as Level, i as PluginSpec, R as RuleSetting, S as SourceFile, l as loadConfig, r as readGenesisConfig, j as validateConfig, v as validateLinks } from './config-Ci-_Ue-1.js';
|
|
172
3
|
|
|
173
4
|
/** The installed folder of `name`, looking in node_modules from `from` upward (works with hoisting and pnpm). */
|
|
174
5
|
declare function findPackageDir(from: string, name: string): string | null;
|
|
@@ -182,7 +13,7 @@ declare function parseRulesMarkdown(markdown: string): PatternRule[];
|
|
|
182
13
|
declare function defineDoctorPlugin(plugin: DoctorPlugin): DoctorPlugin;
|
|
183
14
|
|
|
184
15
|
/** Ids of the built-in rules, for `rules` overrides and `allow` entries. */
|
|
185
|
-
declare const BUILTIN_RULES: readonly ["local-primitives", "starter-leftover", "forbidden-import", "raw-tag", "palette-color", "arbitrary-color", "raw-color", "undefined-token", "shadowed-export"];
|
|
16
|
+
declare const BUILTIN_RULES: readonly ["local-primitives", "starter-leftover", "forbidden-import", "raw-tag", "palette-color", "arbitrary-color", "raw-color", "undefined-token", "shadowed-export", "version-skew"];
|
|
186
17
|
|
|
187
18
|
/**
|
|
188
19
|
* Minimal globs for config: `*` matches within a folder, `**` across folders,
|
|
@@ -190,6 +21,14 @@ declare const BUILTIN_RULES: readonly ["local-primitives", "starter-leftover", "
|
|
|
190
21
|
*/
|
|
191
22
|
declare function globToRegExp(glob: string): RegExp;
|
|
192
23
|
|
|
24
|
+
/** The shape of the umbrella's `dist/versions.json`. */
|
|
25
|
+
interface ReleaseManifest {
|
|
26
|
+
version: string;
|
|
27
|
+
packages: Record<string, string>;
|
|
28
|
+
}
|
|
29
|
+
/** The installed umbrella's manifest, or null when there's no umbrella or no manifest. */
|
|
30
|
+
declare function readReleaseManifest(root: string): ReleaseManifest | null;
|
|
31
|
+
|
|
193
32
|
interface RunDoctorOptions {
|
|
194
33
|
/** The app root. Default `process.cwd()`. */
|
|
195
34
|
root?: string;
|
|
@@ -229,4 +68,4 @@ declare function genesisSummary(g: GenesisFacts): {
|
|
|
229
68
|
palette: readonly string[];
|
|
230
69
|
};
|
|
231
70
|
|
|
232
|
-
export {
|
|
71
|
+
export { BUILTIN_RULES, DoctorConfig, DoctorPlugin, DoctorResult, Finding, GenesisFacts, PatternRule, type ReleaseManifest, type RunDoctorOptions, defineDoctorPlugin, findPackageDir, formatReport, genesisSummary, globToRegExp, loadGenesis, parseExportNames, parseRulesMarkdown, readReleaseManifest, runDoctor, toJson };
|
package/dist/doctor.js
CHANGED
|
@@ -45,7 +45,10 @@ ${String(r.stderr ?? "").trim().split("\n").slice(-20).join("\n")}` : "";
|
|
|
45
45
|
}
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
|
-
var
|
|
48
|
+
var GenesisConfigError = class extends Error {
|
|
49
|
+
name = "GenesisConfigError";
|
|
50
|
+
};
|
|
51
|
+
var DoctorConfigError = class extends GenesisConfigError {
|
|
49
52
|
name = "DoctorConfigError";
|
|
50
53
|
};
|
|
51
54
|
var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build"];
|
|
@@ -75,7 +78,8 @@ function loadConfig(root, configPath) {
|
|
|
75
78
|
}
|
|
76
79
|
const own = path3.join(root, "genesis.config.json");
|
|
77
80
|
if (existsSync(own)) {
|
|
78
|
-
|
|
81
|
+
const block = readGenesisConfig(root)?.raw.doctor;
|
|
82
|
+
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
79
83
|
}
|
|
80
84
|
const pkg = path3.join(root, "package.json");
|
|
81
85
|
if (existsSync(pkg)) {
|
|
@@ -91,6 +95,43 @@ function readJson(file) {
|
|
|
91
95
|
throw new DoctorConfigError(`${file} is not valid JSON: ${err.message}`);
|
|
92
96
|
}
|
|
93
97
|
}
|
|
98
|
+
function readGenesisConfig(root) {
|
|
99
|
+
const file = path3.join(root, "genesis.config.json");
|
|
100
|
+
if (!existsSync(file)) return null;
|
|
101
|
+
const raw = readJson(file);
|
|
102
|
+
if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
103
|
+
const links = raw.links === void 0 ? void 0 : validateLinks(raw.links, file);
|
|
104
|
+
return links ? { raw, links } : { raw };
|
|
105
|
+
}
|
|
106
|
+
var LINK_KEYS = /* @__PURE__ */ new Set(["hosts", "paths", "webcredentials"]);
|
|
107
|
+
var HOST = /^(?=.{1,253}$)(\*\.)?([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
|
|
108
|
+
function validateLinks(raw, source = "config") {
|
|
109
|
+
const fail = (msg) => {
|
|
110
|
+
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
111
|
+
};
|
|
112
|
+
if (!isObject(raw)) fail(`"links" must be an object`);
|
|
113
|
+
const c = raw;
|
|
114
|
+
for (const key of Object.keys(c)) if (!LINK_KEYS.has(key)) fail(`links: unknown setting "${key}"`);
|
|
115
|
+
if (!isStringList(c.hosts) || c.hosts.length === 0) fail(`links.hosts must be a non-empty list of host names`);
|
|
116
|
+
for (const host of c.hosts) {
|
|
117
|
+
if (!HOST.test(host)) {
|
|
118
|
+
fail(`links.hosts: "${host}" is not a bare lower-case host name (no scheme, path or port), e.g. "example.com"`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (c.paths !== void 0) {
|
|
122
|
+
if (!isStringList(c.paths)) fail(`links.paths must be a list of path prefixes`);
|
|
123
|
+
for (const p of c.paths) {
|
|
124
|
+
if (!p.startsWith("/") || /[\s?#*]/.test(p)) {
|
|
125
|
+
fail(`links.paths: "${p}" must start with "/" and hold no spaces, "?", "#" or "*"`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (c.webcredentials !== void 0 && typeof c.webcredentials !== "boolean") fail(`links.webcredentials must be true or false`);
|
|
130
|
+
const links = { hosts: [...new Set(c.hosts)] };
|
|
131
|
+
if (c.paths !== void 0) links.paths = [...new Set(c.paths)];
|
|
132
|
+
if (c.webcredentials !== void 0) links.webcredentials = c.webcredentials;
|
|
133
|
+
return links;
|
|
134
|
+
}
|
|
94
135
|
function validateConfig(raw, source = "config") {
|
|
95
136
|
const fail = (msg) => {
|
|
96
137
|
throw new DoctorConfigError(`${source}: ${msg}`);
|
|
@@ -195,7 +236,7 @@ function globToRegExp(glob) {
|
|
|
195
236
|
}
|
|
196
237
|
function globMatcher(globs) {
|
|
197
238
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
198
|
-
return (
|
|
239
|
+
return (path10) => res.some((re) => re.test(path10));
|
|
199
240
|
}
|
|
200
241
|
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
201
242
|
var DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
|
|
@@ -751,7 +792,8 @@ var BUILTIN_RULES = [
|
|
|
751
792
|
"arbitrary-color",
|
|
752
793
|
"raw-color",
|
|
753
794
|
"undefined-token",
|
|
754
|
-
"shadowed-export"
|
|
795
|
+
"shadowed-export",
|
|
796
|
+
"version-skew"
|
|
755
797
|
];
|
|
756
798
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
757
799
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -897,6 +939,30 @@ function unusedComponents(ctx) {
|
|
|
897
939
|
}
|
|
898
940
|
return ctx.genesis.components.filter((c) => !used.has(c));
|
|
899
941
|
}
|
|
942
|
+
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
943
|
+
function readReleaseManifest(root) {
|
|
944
|
+
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
945
|
+
const file = dir && path3.join(dir, "dist", "versions.json");
|
|
946
|
+
if (!file || !existsSync(file)) return null;
|
|
947
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
948
|
+
}
|
|
949
|
+
function checkVersionSkew(ctx) {
|
|
950
|
+
const manifest = readReleaseManifest(ctx.root);
|
|
951
|
+
if (!manifest) return;
|
|
952
|
+
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
953
|
+
const dir = findPackageDir(ctx.root, name);
|
|
954
|
+
if (!dir) continue;
|
|
955
|
+
const have = JSON.parse(readFileSync(path3.join(dir, "package.json"), "utf8")).version;
|
|
956
|
+
if (have === want) continue;
|
|
957
|
+
ctx.report({
|
|
958
|
+
rule: "version-skew",
|
|
959
|
+
level: "warn",
|
|
960
|
+
file: "package.json",
|
|
961
|
+
subject: name,
|
|
962
|
+
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
}
|
|
900
966
|
|
|
901
967
|
// src/doctor/index.ts
|
|
902
968
|
async function runDoctor(options = {}) {
|
|
@@ -919,7 +985,8 @@ async function runDoctor(options = {}) {
|
|
|
919
985
|
{ name: "raw-tags", check: checkRawTags },
|
|
920
986
|
{ name: "colors", check: checkColors },
|
|
921
987
|
{ name: "tokens", check: checkTokens },
|
|
922
|
-
{ name: "shadowed-exports", check: checkShadowedExports }
|
|
988
|
+
{ name: "shadowed-exports", check: checkShadowedExports },
|
|
989
|
+
{ name: "version-skew", check: checkVersionSkew }
|
|
923
990
|
];
|
|
924
991
|
for (const plugin of [...builtins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
925
992
|
try {
|
|
@@ -1016,6 +1083,6 @@ function genesisSummary(g) {
|
|
|
1016
1083
|
};
|
|
1017
1084
|
}
|
|
1018
1085
|
|
|
1019
|
-
export { BUILTIN_RULES, DoctorConfigError, defineDoctorPlugin, findPackageDir, formatReport, genesisSummary, globToRegExp, loadConfig, loadGenesis, parseExportNames, parseRulesMarkdown, runDoctor, toJson, validateConfig };
|
|
1086
|
+
export { BUILTIN_RULES, DoctorConfigError, GenesisConfigError, defineDoctorPlugin, findPackageDir, formatReport, genesisSummary, globToRegExp, loadConfig, loadGenesis, parseExportNames, parseRulesMarkdown, readGenesisConfig, readReleaseManifest, runDoctor, toJson, validateConfig, validateLinks };
|
|
1020
1087
|
//# sourceMappingURL=doctor.js.map
|
|
1021
1088
|
//# sourceMappingURL=doctor.js.map
|