@yearofthedan/warp 0.2.0 → 0.4.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.
Files changed (54) hide show
  1. package/README.md +24 -25
  2. package/dist/analysis/imports.d.ts +3 -1
  3. package/dist/analysis/imports.js +5 -1
  4. package/dist/analysis/typescript.js +2 -1
  5. package/dist/app/check.d.ts +3 -1
  6. package/dist/app/check.js +5 -3
  7. package/dist/app/checkModel.js +1 -1
  8. package/dist/app/configLines.d.ts +5 -0
  9. package/dist/app/configLines.js +24 -0
  10. package/dist/app/load.d.ts +2 -2
  11. package/dist/app/load.js +31 -43
  12. package/dist/builtins/advice.d.ts +8 -0
  13. package/dist/builtins/advice.js +42 -0
  14. package/dist/builtins/dependency-direction/dependencyDirection.js +33 -16
  15. package/dist/builtins/index.js +2 -0
  16. package/dist/builtins/module-externals/moduleExternals.js +11 -9
  17. package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.js +16 -5
  18. package/dist/builtins/place.js +5 -3
  19. package/dist/builtins/unresolved-import/unresolvedImport.d.ts +2 -0
  20. package/dist/builtins/unresolved-import/unresolvedImport.js +15 -0
  21. package/dist/builtins/unused-declaration/declarations.js +1 -1
  22. package/dist/builtins/unused-declaration/empty.js +19 -11
  23. package/dist/builtins/unused-declaration/grants.js +22 -15
  24. package/dist/builtins/unused-declaration/surfaces.js +24 -22
  25. package/dist/cli.js +14 -11
  26. package/dist/config/loadConfig.d.ts +7 -1
  27. package/dist/config/loadConfig.js +83 -12
  28. package/dist/index.d.ts +0 -1
  29. package/dist/index.js +0 -1
  30. package/dist/model/archetype/data.d.ts +25 -29
  31. package/dist/model/archetype/data.js +1 -1
  32. package/dist/model/archetype/fixes.d.ts +35 -0
  33. package/dist/model/archetype/fixes.js +265 -0
  34. package/dist/model/archetype/language.d.ts +16 -0
  35. package/dist/model/archetype/language.js +419 -0
  36. package/dist/model/archetype/reach.d.ts +8 -3
  37. package/dist/model/archetype/reach.js +142 -122
  38. package/dist/model/archetype/references.d.ts +11 -5
  39. package/dist/model/archetype/references.js +58 -132
  40. package/dist/model/archetype/requirements.d.ts +3 -3
  41. package/dist/model/archetype/requirements.js +65 -61
  42. package/dist/model/archetype/resolve.d.ts +3 -3
  43. package/dist/model/archetype/resolve.js +64 -77
  44. package/dist/model/archetype/rulesets.d.ts +2 -1
  45. package/dist/model/archetype/rulesets.js +72 -49
  46. package/dist/model/archetype/settings.js +4 -19
  47. package/dist/model/facts.d.ts +6 -0
  48. package/dist/reporters/model.js +9 -9
  49. package/dist/rules/registry.js +1 -1
  50. package/package.json +3 -2
  51. package/dist/model/archetype/builder.d.ts +0 -183
  52. package/dist/model/archetype/builder.js +0 -85
  53. package/dist/model/archetype/draft.d.ts +0 -37
  54. package/dist/model/archetype/draft.js +0 -275
@@ -0,0 +1,419 @@
1
+ import { isName, isRecord, list } from './shared.js';
2
+ export const rootName = 'root';
3
+ const moduleKeys = ['description', 'dir', 'files', 'entry', 'archetype', 'dependencies', 'exposes', 'modules', 'test'];
4
+ const archetypeKeys = ['description', 'marker', 'requires', 'entry', 'exposes', 'modules', 'test'];
5
+ const rootKeys = ['description', 'modules', 'test'];
6
+ const testKeys = ['requires', 'dependencies', 'provides', 'exposes', 'modules'];
7
+ const kindOf = new Map([
8
+ [archetypeKeys, 'an archetype'],
9
+ [rootKeys, 'the root'],
10
+ [testKeys, 'a test block'],
11
+ ]);
12
+ const testModuleKeys = ['description', 'dir', 'files', 'archetype', 'dependencies', 'exposes', 'modules'];
13
+ export const parseStructure = (root, archetypes, fail) => {
14
+ const defs = archetypes === undefined ? {} : isRecord(archetypes) ? archetypes : {};
15
+ if (archetypes !== undefined && !isRecord(archetypes))
16
+ fail('archetypes: expected archetypes by name');
17
+ const state = { defs, archetypes: {}, pending: [], fail };
18
+ if (Object.hasOwn(defs, rootName))
19
+ fail(`archetypes.${rootName}: root is the repository; name the archetype otherwise`);
20
+ for (const [name, def] of Object.entries(defs)) {
21
+ if (!isName(name) || name.includes('.'))
22
+ fail(`archetypes: a name has no dots, not '${name}'`);
23
+ archetype(state, name, record(state, `archetypes.${name}`, def), { keys: archetypeKeys });
24
+ }
25
+ if (!isRecord(root))
26
+ fail('root: expected the repository, root: { modules: ... }');
27
+ else
28
+ archetype(state, rootName, root, { keys: rootKeys });
29
+ return { root: rootName, archetypes: state.archetypes, pending: state.pending };
30
+ };
31
+ const record = (state, where, value) => {
32
+ if (isRecord(value))
33
+ return value;
34
+ state.fail(`${where}: expected a mapping`);
35
+ return {};
36
+ };
37
+ const checkKeys = (state, where, def, keys) => {
38
+ for (const key of Object.keys(def).filter((key) => !keys.includes(key)))
39
+ state.fail(`${where}: unknown key ${key}; ${kindOf.get(keys) ?? 'a module'} takes ${keys.join(', ')}`);
40
+ };
41
+ const strings = (state, where, value) => {
42
+ if (value === undefined)
43
+ return [];
44
+ const items = Array.isArray(value) ? value : [value];
45
+ if (!items.every(isName))
46
+ state.fail(`${where}: expected a name or a list of names`);
47
+ return items.filter(isName);
48
+ };
49
+ const description = (state, where, value) => {
50
+ if (value === undefined)
51
+ return {};
52
+ if (typeof value !== 'string')
53
+ state.fail(`${where}.description: expected a string`);
54
+ return typeof value === 'string' ? { description: value } : {};
55
+ };
56
+ const archetype = (state, name, def, options) => {
57
+ const where = options.parent ? `${options.parent.archetype}.${name.slice(name.lastIndexOf('.') + 1)}` : name;
58
+ if (!options.parent)
59
+ checkKeys(state, where, def, options.keys);
60
+ const test = testBlock(state, where, def.test);
61
+ const modules = def.modules === undefined ? {} : record(state, `${where}.modules`, def.modules);
62
+ const testModules = test.modules === undefined ? {} : record(state, `${where}.test.modules`, test.modules);
63
+ const data = options.parent ? inlineData(state, name, where, test) : namedData(state, name, def, test);
64
+ if (options.test)
65
+ data.test = true;
66
+ const scope = {
67
+ archetype: name,
68
+ names: new Set([...Object.keys(modules), ...Object.keys(testModules), ...filesTestNames(modules)]),
69
+ ...(options.parent ? { parent: options.parent } : {}),
70
+ inputs: options.parent?.inputs ?? new Set(data.requires),
71
+ testInputs: options.parent?.testInputs ?? new Set(data.testRequires),
72
+ };
73
+ state.archetypes[name] = data;
74
+ const build = options.test ? testModule : productionModule;
75
+ for (const [module, raw] of Object.entries(modules))
76
+ data.modules.push(...build(state, scope, module, raw));
77
+ for (const [module, raw] of Object.entries(testModules))
78
+ data.modules.push(...testModule(state, scope, module, raw));
79
+ const exposed = exposes(state, scope, `${where}.exposes`, def.exposes, def.entry, true, options.test === true);
80
+ if (exposed)
81
+ data.exposes = exposed;
82
+ Object.assign(data, testSurfaces(state, scope, where, test, options.test === true));
83
+ return data;
84
+ };
85
+ const namedData = (state, name, def, test) => {
86
+ const testRequires = strings(state, `${name}.test.requires`, test.requires);
87
+ return {
88
+ name,
89
+ ...description(state, name, def.description),
90
+ requires: strings(state, `${name}.requires`, def.requires),
91
+ ...(testRequires.length > 0 ? { testRequires } : {}),
92
+ ...marker(state, name, def.marker),
93
+ modules: [],
94
+ };
95
+ };
96
+ const inlineData = (state, name, where, test) => {
97
+ if (test.requires !== undefined)
98
+ state.fail(`${where}.test.requires: only an archetype requires; its modules see what it requires`);
99
+ return { name, inline: true, requires: [], modules: [] };
100
+ };
101
+ const testBlock = (state, where, value) => {
102
+ if (value === undefined)
103
+ return {};
104
+ if (!isRecord(value)) {
105
+ state.fail(`${where}.test: expected a test block`);
106
+ return {};
107
+ }
108
+ for (const key of Object.keys(value).filter((key) => !testKeys.includes(key)))
109
+ state.fail(`${where}.test: unknown key ${key}; a test block takes ${testKeys.join(', ')}`);
110
+ if (value.dependencies !== undefined)
111
+ state.fail(`${where}.test.dependencies: fills an archetype's test.requires, where a module uses one`);
112
+ return value;
113
+ };
114
+ const filesTestNames = (modules) => Object.entries(modules).flatMap(([module, raw]) => isRecord(raw) && raw.files !== undefined && isRecord(raw.test) && isRecord(raw.test.modules)
115
+ ? Object.keys(raw.test.modules).map((inner) => `${module}.${inner}`)
116
+ : []);
117
+ const marker = (state, where, value) => {
118
+ if (value === undefined)
119
+ return {};
120
+ if (isName(value))
121
+ return { identify: { marker: value } };
122
+ state.fail(`${where}.marker: expected a file pattern, such as '{name}.dom.ts'`);
123
+ return {};
124
+ };
125
+ const testSurfaces = (state, scope, where, test, isTest) => {
126
+ const data = {};
127
+ if (test.exposes !== undefined) {
128
+ if (isTest)
129
+ state.fail(`${where}.test.exposes: ${where} is test code; what it exposes is for tests already`);
130
+ else
131
+ data.testExposes = surfaces(state, scope, `${where}.test.exposes`, test.exposes, true);
132
+ }
133
+ if (test.provides !== undefined) {
134
+ if (isTest)
135
+ state.fail(`${where}.test.provides: ${where} is test code; give its modules dependencies`);
136
+ else
137
+ data.testUsing = references(state, scope, `${where}.test.provides`, test.provides, true);
138
+ }
139
+ return data;
140
+ };
141
+ const nameProblem = (name) => !isName(name) || name.includes('.');
142
+ const productionModule = (state, scope, name, raw) => {
143
+ const where = `${scope.archetype}.${name}`;
144
+ const def = record(state, where, raw);
145
+ if (nameProblem(name))
146
+ state.fail(`${scope.archetype}: a module's name has no dots, not '${name}'`);
147
+ checkKeys(state, where, def, moduleKeys);
148
+ const inner = { ...scope, own: name };
149
+ if (def.archetype !== undefined)
150
+ return [instance(state, inner, name, def, false)];
151
+ if (def.dir !== undefined && def.files !== undefined)
152
+ state.fail(`${where}: a module has dir or files, not both`);
153
+ if (def.dir !== undefined)
154
+ return [inlineDir(state, inner, name, def, false)];
155
+ if (def.files === undefined) {
156
+ state.fail(`${where}: expected dir, files or an archetype`);
157
+ return [];
158
+ }
159
+ return filesModule(state, inner, name, def);
160
+ };
161
+ const testModule = (state, scope, name, raw) => {
162
+ const where = `${scope.archetype}.${name}`;
163
+ const def = record(state, where, raw);
164
+ if (nameProblem(name))
165
+ state.fail(`${scope.archetype}: a module's name has no dots, not '${name}'`);
166
+ checkKeys(state, where, def, testModuleKeys);
167
+ const inner = { ...scope, own: name };
168
+ if (def.archetype !== undefined)
169
+ return [instance(state, inner, name, def, true)];
170
+ if (def.dir !== undefined && def.files !== undefined)
171
+ state.fail(`${where}: a module has dir or files, not both`);
172
+ if (def.dir !== undefined)
173
+ return [inlineDir(state, inner, name, def, true)];
174
+ return [testFiles(state, inner, name, def)];
175
+ };
176
+ const testFiles = (state, scope, name, def, of) => {
177
+ const where = `${scope.archetype}.${name}`;
178
+ if (def.modules !== undefined)
179
+ state.fail(`${where}: a files module has no modules; use dir for a folder of them`);
180
+ const exposed = exposes(state, scope, `${where}.exposes`, def.exposes, undefined, false, true);
181
+ return {
182
+ kind: 'test',
183
+ name,
184
+ patterns: patterns(state, `${where}.files`, def.files),
185
+ ...(of === undefined ? {} : { of }),
186
+ using: references(state, scope, `${where}.dependencies`, def.dependencies, true),
187
+ ...(exposed && exposed.kind !== 'surfaces' ? { exposes: exposed } : {}),
188
+ ...description(state, where, def.description),
189
+ };
190
+ };
191
+ const patterns = (state, where, value) => {
192
+ const found = strings(state, where, value);
193
+ if (found.length === 0)
194
+ state.fail(`${where}: expected a file pattern or a list of them`);
195
+ return found;
196
+ };
197
+ const dirPaths = (state, where, value) => patterns(state, where, value).map((path) => {
198
+ const segments = path.split('/');
199
+ if (segments.some((segment) => segment === '' || segment === '.' || segment === '..' || segment === '**'))
200
+ state.fail(`${where}: a dir is folder names or '*', a whole segment each, not '${path}'`);
201
+ if (segments.filter((segment) => segment === '*').length > 1)
202
+ state.fail(`${where}: one '*' per dir, which names each instance {name}; '${path}' has more`);
203
+ return segments.map((segment) => (segment === '*' ? '{name}' : segment)).join('/');
204
+ });
205
+ const instance = (state, scope, name, def, test) => {
206
+ const where = `${scope.archetype}.${name}`;
207
+ const named = String(def.archetype);
208
+ if (!Object.hasOwn(state.defs, named))
209
+ state.fail(`${where}.archetype: no archetype called ${named}`);
210
+ if (def.dir === undefined)
211
+ state.fail(`${where}: an archetype makes a folder module; give it a dir`);
212
+ for (const key of ['files', 'entry', 'exposes', 'modules'].filter((key) => def[key] !== undefined))
213
+ state.fail(`${where}.${key}: ${named} defines what is inside; declare ${key} there`);
214
+ const own = bindings(state, scope, `${where}.dependencies`, def.dependencies, test);
215
+ const testBlock = isRecord(def.test) ? def.test : {};
216
+ for (const key of Object.keys(testBlock).filter((key) => key !== 'dependencies'))
217
+ state.fail(`${where}.test.${key}: ${named} defines its test code; declare ${key} there`);
218
+ const tests = bindings(state, scope, `${where}.test.dependencies`, testBlock.dependencies, true);
219
+ return {
220
+ kind: 'dir',
221
+ name,
222
+ paths: def.dir === undefined ? [] : dirPaths(state, `${where}.dir`, def.dir),
223
+ archetype: named,
224
+ ...(test ? { test: true } : {}),
225
+ using: Object.values(own),
226
+ ...(Object.keys(own).length > 0 ? { inputs: own } : {}),
227
+ ...(Object.keys(tests).length > 0 ? { testInputs: tests } : {}),
228
+ ...description(state, where, def.description),
229
+ };
230
+ };
231
+ const inlineDir = (state, scope, name, def, test) => {
232
+ const where = `${scope.archetype}.${name}`;
233
+ const inner = `${scope.archetype}.${name}`;
234
+ if (isRecord(def.test) && def.test.dependencies !== undefined)
235
+ state.fail(`${where}.test.dependencies: fills an archetype's test.requires; ${name} has no archetype`);
236
+ archetype(state, inner, def, { keys: moduleKeys, parent: scope, test });
237
+ return {
238
+ kind: 'dir',
239
+ name,
240
+ paths: dirPaths(state, `${where}.dir`, def.dir),
241
+ archetype: inner,
242
+ ...(test ? { test: true } : {}),
243
+ using: references(state, scope, `${where}.dependencies`, def.dependencies, test),
244
+ ...description(state, where, def.description),
245
+ };
246
+ };
247
+ const filesModule = (state, scope, name, def) => {
248
+ const where = `${scope.archetype}.${name}`;
249
+ for (const key of ['modules', 'entry'].filter((key) => def[key] !== undefined))
250
+ state.fail(`${where}.${key}: a files module has no modules; use dir for a folder of them`);
251
+ const exposed = exposes(state, scope, `${where}.exposes`, def.exposes, undefined, false, false);
252
+ const module = {
253
+ kind: 'files',
254
+ name,
255
+ patterns: patterns(state, `${where}.files`, def.files),
256
+ using: references(state, scope, `${where}.dependencies`, def.dependencies, false),
257
+ ...(exposed && exposed.kind !== 'surfaces' ? { exposes: exposed } : {}),
258
+ ...description(state, where, def.description),
259
+ };
260
+ const test = isRecord(def.test) ? def.test : {};
261
+ for (const key of Object.keys(test).filter((key) => key !== 'modules'))
262
+ state.fail(`${where}.test.${key}: a files module's test block holds its test modules only`);
263
+ const tests = test.modules === undefined ? {} : record(state, `${where}.test.modules`, test.modules);
264
+ const lifted = Object.entries(tests).map(([inner, raw]) => {
265
+ const testDef = record(state, `${where}.test.modules.${inner}`, raw);
266
+ checkKeys(state, `${where}.test.modules.${inner}`, testDef, testModuleKeys);
267
+ if (testDef.dir !== undefined || testDef.archetype !== undefined)
268
+ state.fail(`${where}.test.modules.${inner}: a files module's tests are files; use files`);
269
+ return testFiles(state, { ...scope, own: `${name}.${inner}` }, `${name}.${inner}`, testDef, name);
270
+ });
271
+ return [module, ...lifted];
272
+ };
273
+ const entries = (state, where, value) => {
274
+ if (value === undefined)
275
+ return [];
276
+ if (Array.isArray(value)) {
277
+ if (!value.every(isName))
278
+ state.fail(`${where}: expected names, such as [domain, ports.projectStore, npm:x]`);
279
+ return value.filter(isName).map((entry) => [keyOf(entry), entry]);
280
+ }
281
+ if (isRecord(value)) {
282
+ const found = Object.entries(value).filter((entry) => isName(entry[1]));
283
+ if (found.length !== Object.keys(value).length)
284
+ state.fail(`${where}: expected a name for each key`);
285
+ return found;
286
+ }
287
+ state.fail(`${where}: expected a list of names, or a map from name to name`);
288
+ return [];
289
+ };
290
+ const keyOf = (entry) => {
291
+ const prefix = /^(npm|node|virtual):/.exec(entry);
292
+ return prefix ? entry : entry.slice(entry.lastIndexOf('.') + 1);
293
+ };
294
+ const references = (state, scope, where, value, tests) => entries(state, where, value).flatMap(([, entry]) => {
295
+ const ref = resolveName(state, scope, entry, tests, where);
296
+ return ref ? [ref] : [];
297
+ });
298
+ const bindings = (state, scope, where, value, tests) => {
299
+ const bound = {};
300
+ for (const [key, entry] of entries(state, where, value)) {
301
+ if (Object.hasOwn(bound, key))
302
+ state.fail(`${where}: two entries are named ${key}; rename one with a map`);
303
+ const ref = resolveName(state, scope, entry, tests, where);
304
+ if (ref)
305
+ bound[key] = ref;
306
+ }
307
+ return bound;
308
+ };
309
+ const packageOf = (entry) => {
310
+ if (entry.startsWith('npm:'))
311
+ return { kind: 'package', pattern: entry.slice(4) };
312
+ if (entry.startsWith('node:') || entry.startsWith('virtual:'))
313
+ return { kind: 'package', pattern: entry };
314
+ return undefined;
315
+ };
316
+ const resolveName = (state, scope, entry, tests, where) => {
317
+ const pkg = packageOf(entry);
318
+ if (pkg)
319
+ return pkg.pattern === '' || pkg.pattern === 'virtual:' ? fail(state, where, entry, 'a package has a name') : pkg;
320
+ const [head, ...rest] = entry.split('.');
321
+ const top = head === 'top';
322
+ const parts = top ? rest : [head, ...rest];
323
+ if (parts.length === 0 || parts.length > 2 || !parts.every(isName))
324
+ return fail(state, where, entry, 'a name is a module, a module and one of its surfaces, or an input');
325
+ const [module, surface] = parts;
326
+ const name = { module, ...(surface === undefined ? {} : { surface }), top, tests, where, entry };
327
+ const named = moduleRef(state, scope, name);
328
+ if (named !== undefined)
329
+ return named ?? undefined;
330
+ return inputRef(state, scope, name) ?? outOfScope(state, scope, name);
331
+ };
332
+ const levelsOf = (scope) => {
333
+ const levels = [];
334
+ for (let at = scope; at; at = at.parent)
335
+ levels.push(at);
336
+ return levels;
337
+ };
338
+ const searchedFrom = (scope, top) => {
339
+ const levels = levelsOf(scope);
340
+ return top ? [levels.at(-1)] : levels;
341
+ };
342
+ const moduleRef = (state, scope, name) => {
343
+ const found = searchedFrom(scope, name.top).find((level) => level.names.has(name.module));
344
+ if (!found)
345
+ return undefined;
346
+ if (found === scope && name.module === scope.own && !name.top) {
347
+ fail(state, name.where, name.entry, `a module reaches its own files already`);
348
+ return null;
349
+ }
350
+ const up = levelsOf(scope).indexOf(found);
351
+ const ref = {
352
+ kind: 'module',
353
+ module: name.module,
354
+ ...(name.surface === undefined ? {} : { surface: name.surface }),
355
+ ...(up > 0 ? { up } : {}),
356
+ };
357
+ state.pending.push({ ref, where: name.where, archetype: found.archetype, tests: name.tests });
358
+ return ref;
359
+ };
360
+ const inputRef = (state, scope, name) => {
361
+ const isInput = scope.inputs.has(name.module) || (name.tests && scope.testInputs.has(name.module));
362
+ if (name.top || !isInput)
363
+ return undefined;
364
+ const ref = {
365
+ kind: 'required',
366
+ name: name.module,
367
+ ...(name.surface === undefined ? {} : { surface: name.surface }),
368
+ };
369
+ state.pending.push({ ref, where: name.where, archetype: scope.archetype, tests: name.tests });
370
+ return ref;
371
+ };
372
+ const outOfScope = (state, scope, { module, top, tests, where, entry }) => {
373
+ const inputs = top ? [] : [...scope.inputs, ...(tests ? scope.testInputs : [])];
374
+ const names = searchedFrom(scope, top).flatMap((level) => [...level.names].filter((name) => level !== scope || name !== scope.own));
375
+ const inScope = [...new Set([...names, ...inputs])];
376
+ const testInput = !tests && scope.testInputs.has(module) ? `; ${module} is a test input, which only test code may name` : '';
377
+ return fail(state, where, entry, `no module or input called ${module} here${testInput}; in scope: ${list(inScope.sort(), 'nothing')}`);
378
+ };
379
+ const fail = (state, where, entry, problem) => {
380
+ state.fail(`${where}: '${entry}': ${problem}`);
381
+ return undefined;
382
+ };
383
+ const exposes = (state, scope, where, value, entry, surfacesAllowed, tests) => {
384
+ if (entry !== undefined) {
385
+ if (value !== undefined)
386
+ state.fail(`${where}: an entry is the module's whole surface; give it entry or exposes`);
387
+ return { kind: 'files', patterns: patterns(state, where.replace(/exposes$/, 'entry'), entry), entry: true };
388
+ }
389
+ if (value === undefined)
390
+ return undefined;
391
+ if (value === 'all')
392
+ return { kind: 'all' };
393
+ if (isRecord(value) && Object.keys(value).length === 1 && value.files !== undefined)
394
+ return { kind: 'files', patterns: patterns(state, `${where}.files`, value.files) };
395
+ if (Array.isArray(value) && surfacesAllowed)
396
+ return { kind: 'surfaces', surfaces: surfaces(state, scope, where, value, tests) };
397
+ state.fail(`${where}: expected all, ${surfacesAllowed ? 'a list of its modules, ' : ''}or { files: [...] }`);
398
+ return undefined;
399
+ };
400
+ const surfaces = (state, scope, where, value, tests) => {
401
+ if (!Array.isArray(value)) {
402
+ state.fail(`${where}: expected a list of its modules, such as [render] or [ui.dsl]`);
403
+ return {};
404
+ }
405
+ const own = { archetype: scope.archetype, names: scope.names, inputs: new Set(), testInputs: new Set() };
406
+ const result = {};
407
+ for (const [key, entry] of entries(state, where, value)) {
408
+ if (Object.hasOwn(result, key))
409
+ state.fail(`${where}: offers '${key}' twice; rename the module at its source`);
410
+ const ref = resolveName(state, own, entry, tests, where);
411
+ if (ref?.kind === 'package')
412
+ state.fail(`${where}: '${entry}': exposes names the module's own modules`);
413
+ else if (ref) {
414
+ state.pending.at(-1).surface = true;
415
+ result[key] = [ref];
416
+ }
417
+ }
418
+ return result;
419
+ };
@@ -6,6 +6,7 @@ export interface Grant {
6
6
  files: ReadonlySet<string>;
7
7
  package?: string;
8
8
  declared?: RefData;
9
+ via?: readonly RefData[];
9
10
  }
10
11
  export declare const grantText: ({ owner, ref }: Grant) => string;
11
12
  export type Refusal = {
@@ -14,10 +15,11 @@ export type Refusal = {
14
15
  } | {
15
16
  reason: 'above';
16
17
  } | {
17
- reason: 'not-in-using';
18
+ reason: 'not-in-dependencies';
18
19
  } | {
19
20
  reason: 'test';
20
21
  };
22
+ export type View = 'production' | 'test';
21
23
  export type Verdict = {
22
24
  allowed: true;
23
25
  grant: Grant;
@@ -27,9 +29,12 @@ export type Verdict = {
27
29
  export interface Verdicts {
28
30
  reach(file: string): readonly Grant[] | undefined;
29
31
  exposes(module: ModuleView): ExposesData | undefined;
30
- surface(module: ModuleView, name?: string): ReadonlySet<string>;
32
+ surface(module: ModuleView, name?: string, view?: View): ReadonlySet<string>;
31
33
  verdict(from: string, to: string): Verdict | undefined;
32
- files(module: ModuleView, ref: RefData): ReadonlySet<string>;
34
+ files(module: ModuleView, ref: RefData, view?: View): ReadonlySet<string>;
33
35
  describe(module: ModuleView, ref: RefData): string;
34
36
  }
35
37
  export declare const verdicts: (config: ConfigData, model: Model) => Verdicts;
38
+ export declare const instanceOf: (state: {
39
+ config: ConfigData;
40
+ }, holder: ModuleView) => ModuleView;