@yearofthedan/warp 0.2.0 → 0.3.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 +9 -8
- package/dist/analysis/imports.d.ts +3 -1
- package/dist/analysis/imports.js +5 -1
- package/dist/analysis/typescript.js +2 -1
- package/dist/app/check.js +2 -1
- package/dist/app/checkModel.js +1 -1
- package/dist/app/load.js +12 -12
- package/dist/builtins/advice.d.ts +8 -0
- package/dist/builtins/advice.js +42 -0
- package/dist/builtins/dependency-direction/dependencyDirection.js +32 -15
- package/dist/builtins/index.js +2 -0
- package/dist/builtins/module-externals/moduleExternals.js +10 -9
- package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.js +16 -5
- package/dist/builtins/place.js +5 -3
- package/dist/builtins/unresolved-import/unresolvedImport.d.ts +2 -0
- package/dist/builtins/unresolved-import/unresolvedImport.js +15 -0
- package/dist/builtins/unused-declaration/declarations.js +1 -1
- package/dist/builtins/unused-declaration/empty.js +16 -9
- package/dist/builtins/unused-declaration/grants.js +8 -11
- package/dist/builtins/unused-declaration/surfaces.js +11 -19
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/model/archetype/builder.d.ts +11 -11
- package/dist/model/archetype/builder.js +14 -21
- package/dist/model/archetype/data.d.ts +19 -13
- package/dist/model/archetype/draft.d.ts +2 -9
- package/dist/model/archetype/draft.js +48 -59
- package/dist/model/archetype/fixes.d.ts +37 -0
- package/dist/model/archetype/fixes.js +234 -0
- package/dist/model/archetype/reach.js +34 -80
- package/dist/model/archetype/references.d.ts +1 -1
- package/dist/model/archetype/references.js +13 -28
- package/dist/model/archetype/requirements.js +3 -6
- package/dist/model/archetype/resolve.d.ts +2 -3
- package/dist/model/archetype/resolve.js +85 -67
- package/dist/model/archetype/rulesets.js +0 -7
- package/dist/model/archetype/settings.js +4 -19
- package/dist/model/facts.d.ts +6 -0
- package/dist/reporters/model.js +8 -9
- package/package.json +1 -1
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { verdicts } from './reach.js';
|
|
2
|
+
const ancestors = function* (module) {
|
|
3
|
+
for (let at = module.parent; at; at = at.parent)
|
|
4
|
+
yield at;
|
|
5
|
+
};
|
|
6
|
+
const lineage = (module) => [module, ...ancestors(module)];
|
|
7
|
+
export const namedArchetype = (config, name) => config.archetypes[name].inline ? namedArchetype(config, name.slice(0, name.lastIndexOf('.'))) : name;
|
|
8
|
+
const withArchetype = (config, name, change) => ({
|
|
9
|
+
...config,
|
|
10
|
+
archetypes: { ...config.archetypes, [name]: change(config.archetypes[name]) },
|
|
11
|
+
});
|
|
12
|
+
const withModule = (config, archetype, name, change) => withArchetype(config, archetype, (data) => ({
|
|
13
|
+
...data,
|
|
14
|
+
modules: data.modules.map((module) => (module.name === name ? change(module) : module)),
|
|
15
|
+
}));
|
|
16
|
+
const declarationSite = (config, module) => {
|
|
17
|
+
const holder = module.parent;
|
|
18
|
+
const archetype = holder.archetype;
|
|
19
|
+
const declared = config.archetypes[archetype].modules;
|
|
20
|
+
const index = declared.findIndex((data) => data.name === module.name);
|
|
21
|
+
return {
|
|
22
|
+
label: `the using of ${archetype}.${module.name}`,
|
|
23
|
+
holder,
|
|
24
|
+
add: (from, ref) => withModule(from, archetype, module.name, (data) => ({ ...data, using: [...data.using, ref] })),
|
|
25
|
+
visible: new Set(declared.slice(0, index).map((data) => data.name)),
|
|
26
|
+
self: module.name,
|
|
27
|
+
tests: module.kind === 'test',
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const kitSite = (config, at) => {
|
|
31
|
+
const archetype = at.archetype;
|
|
32
|
+
return {
|
|
33
|
+
label: `the testUsing of ${archetype}`,
|
|
34
|
+
holder: at,
|
|
35
|
+
add: (from, ref) => withArchetype(from, archetype, (data) => ({ ...data, testUsing: [...(data.testUsing ?? []), ref] })),
|
|
36
|
+
visible: new Set(config.archetypes[archetype].modules.map((data) => data.name)),
|
|
37
|
+
tests: true,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export const sitesOf = (config, model, file) => {
|
|
41
|
+
const module = model.moduleOf(file);
|
|
42
|
+
if (!module || module.looseFiles.includes(file))
|
|
43
|
+
return [];
|
|
44
|
+
if (module.kind === 'test')
|
|
45
|
+
return [declarationSite(config, module), ...lineage(module.parent).map((at) => kitSite(config, at))];
|
|
46
|
+
const owners = module.kind === 'files' ? [module, module.parent] : [module];
|
|
47
|
+
return owners.filter((owner) => owner.parent).map((owner) => declarationSite(config, owner));
|
|
48
|
+
};
|
|
49
|
+
const surfacesOf = (exposes) => exposes?.kind === 'surfaces' ? Object.keys(exposes.surfaces) : [];
|
|
50
|
+
const moduleRefs = (config, module) => {
|
|
51
|
+
const surfaces = module.kind === 'dir' ? surfacesOf(config.archetypes[module.archetype].exposes) : [];
|
|
52
|
+
const name = module.name;
|
|
53
|
+
return [
|
|
54
|
+
...surfaces.map((surface) => ({ kind: 'module', module: name, surface })),
|
|
55
|
+
{ kind: 'module', module: name },
|
|
56
|
+
];
|
|
57
|
+
};
|
|
58
|
+
const requiredRefs = (config, name, requirement) => {
|
|
59
|
+
const surfaces = requirement.kind === 'archetype' ? surfacesOf(config.archetypes[requirement.archetype].exposes) : [];
|
|
60
|
+
return [...surfaces.map((surface) => ({ kind: 'required', name, surface })), { kind: 'required', name }];
|
|
61
|
+
};
|
|
62
|
+
const allowed = ({ model, from, to }, config) => verdicts(config, model).verdict(from, to).allowed;
|
|
63
|
+
const targetLineage = ({ model, to }) => lineage(model.moduleOf(to));
|
|
64
|
+
const sameDeclaration = (a, b) => a.parent === b.parent && a.name === b.name;
|
|
65
|
+
const reachable = (search) => {
|
|
66
|
+
const importer = lineage(search.model.moduleOf(search.from));
|
|
67
|
+
return targetLineage(search).filter((module) => !importer.some((own) => sameDeclaration(own, module)));
|
|
68
|
+
};
|
|
69
|
+
const nameable = (site, module) => module.parent === site.holder && module.name !== site.self && (site.tests || module.kind !== 'test');
|
|
70
|
+
const usingChanges = function* (search, config) {
|
|
71
|
+
const targets = reachable(search);
|
|
72
|
+
for (const site of sitesOf(config, search.model, search.from)) {
|
|
73
|
+
const own = targets.filter((module) => nameable(site, module) && site.visible.has(module.name));
|
|
74
|
+
const named = namedArchetype(config, site.holder.archetype);
|
|
75
|
+
const required = Object.entries(config.archetypes[named].requires).flatMap(([name, requirement]) => requiredRefs(config, name, requirement));
|
|
76
|
+
for (const ref of [...own.flatMap((module) => moduleRefs(config, module)), ...required])
|
|
77
|
+
yield [{ fix: { kind: 'using', site: site.label, ref }, config: site.add(config, ref) }];
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const declareChanges = function* (search, config) {
|
|
81
|
+
const targets = reachable(search);
|
|
82
|
+
for (const site of sitesOf(config, search.model, search.from))
|
|
83
|
+
for (const module of targets.filter((candidate) => nameable(site, candidate) && !site.visible.has(candidate.name))) {
|
|
84
|
+
const declared = declare(config, site, module);
|
|
85
|
+
if (!declared)
|
|
86
|
+
continue;
|
|
87
|
+
for (const ref of moduleRefs(declared.config, module))
|
|
88
|
+
yield [declared, { fix: { kind: 'using', site: site.label, ref }, config: site.add(declared.config, ref) }];
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const declare = (config, site, module) => {
|
|
92
|
+
if (site.self === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
const archetype = site.holder.archetype;
|
|
95
|
+
const modules = config.archetypes[archetype].modules;
|
|
96
|
+
const moved = modules.find((data) => data.name === module.name);
|
|
97
|
+
const sees = moved.using.every((ref) => ref.kind !== 'module' || site.visible.has(ref.module));
|
|
98
|
+
if (!sees)
|
|
99
|
+
return undefined;
|
|
100
|
+
const rest = modules.filter((data) => data !== moved);
|
|
101
|
+
const at = rest.findIndex((data) => data.name === site.self);
|
|
102
|
+
return {
|
|
103
|
+
fix: { kind: 'declare', archetype, module: module.name, above: site.self },
|
|
104
|
+
config: withArchetype(config, archetype, (data) => ({
|
|
105
|
+
...data,
|
|
106
|
+
modules: [...rest.slice(0, at), moved, ...rest.slice(at)],
|
|
107
|
+
})),
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const providedEverywhere = (config, model, archetype, name) => model.modules
|
|
111
|
+
.filter((module) => module.archetype !== undefined && namedArchetype(config, module.archetype) === archetype)
|
|
112
|
+
.every((module) => [...ancestors(module)].some((at) => config.archetypes[at.archetype].provides[name]));
|
|
113
|
+
const requireChanges = function* (search, config) {
|
|
114
|
+
const targets = reachable(search);
|
|
115
|
+
for (const site of sitesOf(config, search.model, search.from))
|
|
116
|
+
for (const provider of ancestors(site.holder))
|
|
117
|
+
for (const module of targets.filter((target) => target.parent === provider && target.kind !== 'test')) {
|
|
118
|
+
const changes = requirement(search, config, site, provider, module);
|
|
119
|
+
if (changes)
|
|
120
|
+
yield changes;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const requirement = (search, config, site, provider, module) => {
|
|
124
|
+
const archetype = namedArchetype(config, site.holder.archetype);
|
|
125
|
+
const name = module.name;
|
|
126
|
+
const providing = config.archetypes[provider.archetype].provides[name];
|
|
127
|
+
if (config.archetypes[archetype].requires[name] || (providing && providing.module !== name))
|
|
128
|
+
return undefined;
|
|
129
|
+
const required = withArchetype(withArchetype(config, archetype, (data) => ({
|
|
130
|
+
...data,
|
|
131
|
+
requires: { ...data.requires, [name]: { kind: module.kind === 'dir' ? 'dir' : 'files' } },
|
|
132
|
+
})), provider.archetype, (data) => ({ ...data, provides: { ...data.provides, [name]: { kind: 'module', module: name } } }));
|
|
133
|
+
if (!providedEverywhere(required, search.model, archetype, name))
|
|
134
|
+
return undefined;
|
|
135
|
+
const ref = { kind: 'required', name };
|
|
136
|
+
return [
|
|
137
|
+
{ fix: { kind: 'require', archetype, name, provider: provider.archetype, module: name }, config: required },
|
|
138
|
+
{ fix: { kind: 'using', site: site.label, ref }, config: site.add(required, ref) },
|
|
139
|
+
];
|
|
140
|
+
};
|
|
141
|
+
const relative = (module, file) => module.dir === '' ? file : file.slice(module.dir.length + 1);
|
|
142
|
+
const exposeChange = (search, config, hiddenBy) => {
|
|
143
|
+
if (hiddenBy.kind !== 'dir')
|
|
144
|
+
return exposeFilesModule(search, config, hiddenBy);
|
|
145
|
+
const archetype = hiddenBy.archetype;
|
|
146
|
+
const exposes = config.archetypes[archetype].exposes;
|
|
147
|
+
const child = targetLineage(search).find((module) => module.parent === hiddenBy);
|
|
148
|
+
if (exposes?.kind === 'surfaces') {
|
|
149
|
+
if (!child)
|
|
150
|
+
return undefined;
|
|
151
|
+
const ref = { kind: 'module', module: child.name };
|
|
152
|
+
const surfaces = { ...exposes.surfaces, [child.name]: [...(exposes.surfaces[child.name] ?? []), ref] };
|
|
153
|
+
return {
|
|
154
|
+
fix: { kind: 'expose', archetype, ref },
|
|
155
|
+
config: withArchetype(config, archetype, (data) => ({ ...data, exposes: { kind: 'surfaces', surfaces } })),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (exposes?.kind === 'all' || exposes?.entry || child?.kind === 'test')
|
|
159
|
+
return undefined;
|
|
160
|
+
const pattern = relative(hiddenBy, search.to);
|
|
161
|
+
const opened = { kind: 'files', patterns: [...(exposes?.patterns ?? []), pattern] };
|
|
162
|
+
return {
|
|
163
|
+
fix: { kind: 'expose-file', archetype, pattern },
|
|
164
|
+
config: withArchetype(config, archetype, (data) => ({ ...data, exposes: opened })),
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
const exposeFilesModule = (search, config, hiddenBy) => {
|
|
168
|
+
const archetype = hiddenBy.parent.archetype;
|
|
169
|
+
const declared = config.archetypes[archetype].modules.find((data) => data.name === hiddenBy.name);
|
|
170
|
+
if (declared?.kind === 'dir')
|
|
171
|
+
return undefined;
|
|
172
|
+
const exposes = declared.exposes;
|
|
173
|
+
if (exposes?.kind === 'all')
|
|
174
|
+
return undefined;
|
|
175
|
+
const pattern = relative(hiddenBy, search.to);
|
|
176
|
+
return {
|
|
177
|
+
fix: { kind: 'expose-file', archetype: `${archetype}.${hiddenBy.name}`, pattern },
|
|
178
|
+
config: withModule(config, archetype, hiddenBy.name, (data) => ({
|
|
179
|
+
...data,
|
|
180
|
+
exposes: { kind: 'files', patterns: [...(exposes?.patterns ?? []), pattern] },
|
|
181
|
+
})),
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
const subtree = (module) => [module, ...module.children.flatMap(subtree)];
|
|
185
|
+
const reaches = (config, model, from, to) => {
|
|
186
|
+
const judge = verdicts(config, model);
|
|
187
|
+
const files = new Set(subtree(to).flatMap((module) => module.files));
|
|
188
|
+
return subtree(from).some((module) => {
|
|
189
|
+
const file = module.files[0];
|
|
190
|
+
return file !== undefined && judge.reach(file).some((grant) => [...grant.files].some((to) => files.has(to)));
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
const topOf = (module, under) => {
|
|
194
|
+
let at = module;
|
|
195
|
+
while (at.parent && at.parent !== under)
|
|
196
|
+
at = at.parent;
|
|
197
|
+
return at;
|
|
198
|
+
};
|
|
199
|
+
const loops = ({ model, from, to }, config) => {
|
|
200
|
+
if (model.isTest(from))
|
|
201
|
+
return false;
|
|
202
|
+
const source = model.moduleOf(from);
|
|
203
|
+
const target = model.moduleOf(to);
|
|
204
|
+
const common = [...lineage(source)].find((module) => lineage(target).includes(module));
|
|
205
|
+
if (!common || common === source || common === target)
|
|
206
|
+
return false;
|
|
207
|
+
return reaches(config, model, topOf(target, common), topOf(source, common));
|
|
208
|
+
};
|
|
209
|
+
const search = (state, config, fixes) => {
|
|
210
|
+
const verdict = verdicts(config, state.model).verdict(state.from, state.to);
|
|
211
|
+
if (verdict.allowed)
|
|
212
|
+
return fixes;
|
|
213
|
+
if (verdict.reason === 'private') {
|
|
214
|
+
const change = exposeChange(state, config, verdict.hiddenBy);
|
|
215
|
+
return change && search(state, change.config, [...fixes, change.fix]);
|
|
216
|
+
}
|
|
217
|
+
for (const candidates of [usingChanges, declareChanges, requireChanges])
|
|
218
|
+
for (const changes of candidates(state, config)) {
|
|
219
|
+
const changed = changes.at(-1).config;
|
|
220
|
+
if (allowed(state, changed) && !loops(state, changed))
|
|
221
|
+
return [...fixes, ...changes.map((change) => change.fix)];
|
|
222
|
+
}
|
|
223
|
+
const hidden = hiddenOnTheWay(state, config);
|
|
224
|
+
const change = hidden && exposeChange(state, config, hidden);
|
|
225
|
+
return change && search(state, change.config, [...fixes, change.fix]);
|
|
226
|
+
};
|
|
227
|
+
const hiddenOnTheWay = ({ model, from, to }, config) => {
|
|
228
|
+
const judge = verdicts(config, model);
|
|
229
|
+
const above = lineage(model.moduleOf(from));
|
|
230
|
+
return lineage(model.moduleOf(to))
|
|
231
|
+
.filter((module) => !above.includes(module))
|
|
232
|
+
.find((module) => !judge.surface(module).has(to));
|
|
233
|
+
};
|
|
234
|
+
export const fixesFor = (config, model, from, to) => search({ model, from, to }, config, []);
|
|
@@ -28,6 +28,8 @@ const exposes = ({ config }, module) => {
|
|
|
28
28
|
if (module.kind === 'dir')
|
|
29
29
|
return config.archetypes[module.archetype].exposes;
|
|
30
30
|
const declared = declarationOf(config, module);
|
|
31
|
+
if (declared?.kind === 'test')
|
|
32
|
+
return declared.exposes ?? { kind: 'all' };
|
|
31
33
|
return declared?.kind === 'files' ? declared.exposes : undefined;
|
|
32
34
|
};
|
|
33
35
|
const surface = (state, module, name) => {
|
|
@@ -47,7 +49,10 @@ const exposed = (state, module, name) => {
|
|
|
47
49
|
const refs = name === undefined ? Object.values(declared.surfaces).flat() : (declared.surfaces[name] ?? []);
|
|
48
50
|
return union(refs.map((ref) => resolve(state, module, ref)));
|
|
49
51
|
}
|
|
50
|
-
const all = union([
|
|
52
|
+
const all = union([
|
|
53
|
+
new Set(module.files),
|
|
54
|
+
...module.children.filter((child) => child.kind !== 'test').map((child) => surface(state, child)),
|
|
55
|
+
]);
|
|
51
56
|
if (declared.kind === 'all')
|
|
52
57
|
return all;
|
|
53
58
|
const patterns = declared.patterns.flatMap((pattern) => fillPattern(pattern, module.captures) ?? []);
|
|
@@ -91,93 +96,46 @@ const reach = (state, file) => {
|
|
|
91
96
|
const module = state.model.moduleOf(file);
|
|
92
97
|
if (!module || module.looseFiles.includes(file))
|
|
93
98
|
return undefined;
|
|
94
|
-
if (state.model.isTest(file))
|
|
95
|
-
return testReach(state, module);
|
|
96
99
|
let found = state.reaches.get(module.id);
|
|
97
100
|
if (!found) {
|
|
98
|
-
|
|
99
|
-
{ owner: `own module ${module.id}`, files: new Set(module.files) },
|
|
100
|
-
...module.children
|
|
101
|
-
.filter((child) => !child.test)
|
|
102
|
-
.map((child) => ({ owner: module.id, ref: child.id, files: surface(state, child) })),
|
|
103
|
-
...using(state, module),
|
|
104
|
-
];
|
|
105
|
-
if (module.kind === 'files')
|
|
106
|
-
granted.push(...using(state, module.parent));
|
|
107
|
-
found = granted;
|
|
101
|
+
found = module.kind === 'test' ? testReach(state, module) : productionReach(state, module);
|
|
108
102
|
state.reaches.set(module.id, found);
|
|
109
103
|
}
|
|
110
104
|
return found;
|
|
111
105
|
};
|
|
106
|
+
const productionReach = (state, module) => [
|
|
107
|
+
{ owner: `own module ${module.id}`, files: new Set(module.files) },
|
|
108
|
+
...module.children
|
|
109
|
+
.filter((child) => child.kind !== 'test')
|
|
110
|
+
.map((child) => ({ owner: module.id, ref: child.id, files: surface(state, child) })),
|
|
111
|
+
...using(state, module),
|
|
112
|
+
...(module.kind === 'files' ? using(state, module.parent) : []),
|
|
113
|
+
];
|
|
112
114
|
const testReach = (state, module) => {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
let found = state.reaches.get(key);
|
|
116
|
-
if (!found) {
|
|
117
|
-
found = owner.kind === 'dir' ? folderTests(state, owner) : filesTests(state, owner);
|
|
118
|
-
state.reaches.set(key, found);
|
|
119
|
-
}
|
|
120
|
-
return found;
|
|
121
|
-
};
|
|
122
|
-
const folderTests = (state, owner) => {
|
|
123
|
-
const by = `tests of ${owner.id}`;
|
|
124
|
-
const own = owner.children.filter((child) => child.kind === 'files');
|
|
115
|
+
const holder = module.parent;
|
|
116
|
+
const own = holder.children.filter((child) => child.kind === 'files');
|
|
125
117
|
return [
|
|
118
|
+
{ owner: `own module ${module.id}`, files: new Set(module.files) },
|
|
126
119
|
{
|
|
127
|
-
owner:
|
|
128
|
-
|
|
120
|
+
owner: module.id,
|
|
121
|
+
ref: holder.id,
|
|
122
|
+
files: union([new Set(holder.files), ...own.map((child) => new Set(child.files))]),
|
|
129
123
|
},
|
|
130
|
-
...
|
|
124
|
+
...holder.children
|
|
131
125
|
.filter((child) => child.kind === 'dir')
|
|
132
|
-
.map((child) => ({ owner:
|
|
133
|
-
...
|
|
134
|
-
...own.
|
|
135
|
-
...
|
|
136
|
-
...[...ancestors(
|
|
126
|
+
.map((child) => ({ owner: holder.id, ref: child.id, files: surface(state, child) })),
|
|
127
|
+
...using(state, holder),
|
|
128
|
+
...own.flatMap((child) => using(state, child)),
|
|
129
|
+
...using(state, module),
|
|
130
|
+
...[holder, ...ancestors(holder)].flatMap((at) => testKit(state, at)),
|
|
137
131
|
];
|
|
138
132
|
};
|
|
139
|
-
const
|
|
140
|
-
const by = `tests of ${owner.id}`;
|
|
141
|
-
const folder = owner.parent;
|
|
142
|
-
const declared = declarationOf(state.config, owner);
|
|
143
|
-
const tests = declared?.kind === 'files' ? declared.tests : undefined;
|
|
144
|
-
return [
|
|
145
|
-
{ owner: by, files: new Set([...owner.files, ...owner.tests]) },
|
|
146
|
-
...using(state, owner),
|
|
147
|
-
...using(state, folder),
|
|
148
|
-
...(tests ? grants(state, folder, by, tests.using) : []),
|
|
149
|
-
...[folder, ...ancestors(folder)].flatMap((above) => layer(state, above, by)),
|
|
150
|
-
];
|
|
151
|
-
};
|
|
152
|
-
const layerOf = ({ config }, module) => module.archetype === undefined ? undefined : config.archetypes[module.archetype].tests;
|
|
153
|
-
const layerUsing = (state, holder, at, by) => grants(state, holder, by, layerOf(state, at)?.using ?? []);
|
|
154
|
-
const layer = (state, above, by) => {
|
|
155
|
-
const tests = above.children.filter((child) => child.test).map((child) => new Set(child.files));
|
|
156
|
-
return [
|
|
157
|
-
...(tests.length > 0 ? [{ owner: by, ref: `${above.id} tests`, files: union(tests) }] : []),
|
|
158
|
-
...layerUsing(state, above, above, by),
|
|
159
|
-
];
|
|
160
|
-
};
|
|
161
|
-
const testSurface = (state, module) => {
|
|
162
|
-
const exposes = layerOf(state, module)?.exposes;
|
|
163
|
-
if (!exposes)
|
|
164
|
-
return none;
|
|
165
|
-
const testModules = module.children.filter((child) => child.test);
|
|
166
|
-
if (exposes.kind !== 'surfaces')
|
|
167
|
-
return union([
|
|
168
|
-
...testModules.map((child) => new Set(child.files)),
|
|
169
|
-
...module.children.filter((child) => child.kind === 'dir').map((child) => testSurface(state, child)),
|
|
170
|
-
]);
|
|
171
|
-
const named = new Set(Object.values(exposes.surfaces)
|
|
172
|
-
.flat()
|
|
173
|
-
.flatMap((ref) => (ref.kind === 'module' ? [`tests.${ref.module}`] : [])));
|
|
174
|
-
return union(testModules.filter((child) => named.has(child.name)).map((child) => new Set(child.files)));
|
|
175
|
-
};
|
|
133
|
+
const testKit = (state, at) => grants(state, at, `${at.archetype}.testUsing`, state.config.archetypes[at.archetype].testUsing ?? []);
|
|
176
134
|
const using = (state, module) => {
|
|
177
135
|
const declared = declarationOf(state.config, module);
|
|
178
136
|
if (!declared)
|
|
179
137
|
return [];
|
|
180
|
-
const owner = module.kind === '
|
|
138
|
+
const owner = module.kind === 'dir' ? `${module.parent.archetype}.${declared.name}` : declared.name;
|
|
181
139
|
return grants(state, module.parent, owner, declared.using);
|
|
182
140
|
};
|
|
183
141
|
const verdict = (state, from, to) => {
|
|
@@ -185,25 +143,21 @@ const verdict = (state, from, to) => {
|
|
|
185
143
|
const target = state.model.moduleOf(to);
|
|
186
144
|
if (!granted || !target)
|
|
187
145
|
return undefined;
|
|
146
|
+
if (state.model.isTest(to) && !state.model.isTest(from))
|
|
147
|
+
return { allowed: false, reason: 'test' };
|
|
188
148
|
const grant = granted.find((candidate) => candidate.files.has(to));
|
|
189
149
|
if (grant)
|
|
190
150
|
return { allowed: true, grant };
|
|
191
|
-
if (state.model.isTest(to) && !state.model.isTest(from))
|
|
192
|
-
return { allowed: false, reason: 'test' };
|
|
193
151
|
return { allowed: false, ...refusal(state, state.model.moduleOf(from), target, from, to) };
|
|
194
152
|
};
|
|
195
153
|
const refusal = (state, source, target, from, to) => {
|
|
196
154
|
const above = new Set(ancestors(source));
|
|
197
155
|
if (above.has(target))
|
|
198
156
|
return { reason: 'above' };
|
|
199
|
-
if (target.kind
|
|
157
|
+
if (target.kind !== 'dir' && target.parent !== source.parent && above.has(target.parent))
|
|
200
158
|
return { reason: 'above' };
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
for (let at = start; !above.has(at) && at !== source; at = at.parent) {
|
|
204
|
-
const open = tested ? union([surface(state, at), testSurface(state, at)]) : surface(state, at);
|
|
205
|
-
if (!open.has(to))
|
|
159
|
+
for (let at = target; !above.has(at) && at !== source; at = at.parent)
|
|
160
|
+
if (!surface(state, at).has(to))
|
|
206
161
|
return { reason: 'private', hiddenBy: at };
|
|
207
|
-
}
|
|
208
162
|
return { reason: 'not-in-using' };
|
|
209
163
|
};
|
|
@@ -8,6 +8,6 @@ export interface Check {
|
|
|
8
8
|
exposesOf: (archetype: string) => DraftExposes | undefined;
|
|
9
9
|
}
|
|
10
10
|
export declare const show: (ref: RefData) => string;
|
|
11
|
-
export declare const resolveDraft: (check: Check, { data: archetype, modules, exposes, provides,
|
|
11
|
+
export declare const resolveDraft: (check: Check, { data: archetype, modules, exposes, provides, testUsing }: Draft) => void;
|
|
12
12
|
export declare const toRules: (check: Check, value: unknown, where: string) => RuleSettingsData | undefined;
|
|
13
13
|
export declare const exposesText: (exposes: DraftExposes | ExposesData | undefined) => string;
|
|
@@ -4,55 +4,36 @@ import { isName, isRecord, list } from './shared.js';
|
|
|
4
4
|
export const show = (ref) => ref.kind === 'package'
|
|
5
5
|
? `pkg('${ref.pattern}')`
|
|
6
6
|
: `${ref.kind === 'required' ? `required.${ref.name}` : ref.module}${ref.surface === undefined ? '' : `.${ref.surface}`}`;
|
|
7
|
-
export const resolveDraft = (check, { data: archetype, modules, exposes, provides,
|
|
7
|
+
export const resolveDraft = (check, { data: archetype, modules, exposes, provides, testUsing }) => {
|
|
8
|
+
const every = ['module', 'required', 'package'];
|
|
8
9
|
for (const [index, module] of modules.entries()) {
|
|
9
10
|
const scope = {
|
|
10
11
|
archetype,
|
|
11
12
|
visible: index,
|
|
12
|
-
kinds:
|
|
13
|
+
kinds: every,
|
|
13
14
|
refused: '',
|
|
15
|
+
tests: module.data.kind === 'test',
|
|
14
16
|
module: module.data.name,
|
|
15
17
|
};
|
|
16
18
|
const where = `${archetype.name}.${module.data.name}`;
|
|
17
19
|
module.data.using.push(...module.using.map((value) => toRef(check, value, `${where} uses`, scope)));
|
|
18
|
-
if (module.tests && module.data.kind === 'files')
|
|
19
|
-
module.data.tests = testLayer(check, `${where}.tests`, archetype, module.tests, scope);
|
|
20
20
|
}
|
|
21
21
|
const own = {
|
|
22
22
|
archetype,
|
|
23
23
|
visible: archetype.modules.length,
|
|
24
24
|
kinds: ['module'],
|
|
25
25
|
refused: 'exposes and provides name the archetype’s own modules',
|
|
26
|
+
tests: true,
|
|
26
27
|
};
|
|
27
28
|
if (exposes)
|
|
28
29
|
archetype.exposes = exposesData(check, archetype.name, exposes, own);
|
|
29
30
|
for (const [name, value] of Object.entries(provides)) {
|
|
30
|
-
const scope = { ...own, whole: true };
|
|
31
|
+
const scope = { ...own, whole: true, tests: false };
|
|
31
32
|
archetype.provides[name] = toRef(check, value, `${archetype.name} provides ${name} as`, scope);
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
kinds: ['module', 'required', 'package'],
|
|
37
|
-
refused: '',
|
|
38
|
-
module: 'tests',
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
const testLayer = (check, where, holder, tests, scope) => {
|
|
42
|
-
const modules = tests.modules.map((module) => module.data);
|
|
43
|
-
const layer = { ...holder, name: where, modules, provides: {} };
|
|
44
|
-
const own = {
|
|
45
|
-
archetype: layer,
|
|
46
|
-
visible: modules.length,
|
|
47
|
-
kinds: ['module'],
|
|
48
|
-
refused: 'exposes names the layer’s own test modules',
|
|
49
|
-
};
|
|
50
|
-
return {
|
|
51
|
-
...(tests.locator ? { locator: tests.locator } : {}),
|
|
52
|
-
modules,
|
|
53
|
-
using: tests.using.map((value) => toRef(check, value, `${where} uses`, scope)),
|
|
54
|
-
...(tests.exposes ? { exposes: exposesData(check, where, tests.exposes, own) } : {}),
|
|
55
|
-
};
|
|
34
|
+
const kit = { ...own, kinds: every, refused: '' };
|
|
35
|
+
if (testUsing.length > 0)
|
|
36
|
+
archetype.testUsing = testUsing.map((value) => toRef(check, value, `${archetype.name} testUsing`, kit));
|
|
56
37
|
};
|
|
57
38
|
const exposesData = (check, name, exposes, scope) => exposes.kind !== 'surfaces'
|
|
58
39
|
? exposes
|
|
@@ -129,6 +110,10 @@ const moduleProblem = (check, name, surface, scope) => {
|
|
|
129
110
|
if (surface !== undefined && scope.whole)
|
|
130
111
|
return 'name the whole module, without a surface';
|
|
131
112
|
const module = scope.archetype.modules[index];
|
|
113
|
+
if (module.kind === 'test')
|
|
114
|
+
return scope.tests
|
|
115
|
+
? exposedProblem(name, undefined, module.exposes ?? { kind: 'all' }, surface)
|
|
116
|
+
: `${name} is a test module, which only test modules and testUsing may name`;
|
|
132
117
|
if (module.kind === 'files')
|
|
133
118
|
return exposedProblem(name, undefined, module.exposes, surface);
|
|
134
119
|
return exposedProblem(name, archetypeText(scope.archetype, module), check.exposesOf(module.archetype), surface);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { recordedAs } from './builder.js';
|
|
2
2
|
const usedRequirements = (drafts) => new Set(drafts
|
|
3
|
-
.flatMap((draft) => [
|
|
4
|
-
...draft.modules.flatMap((module) => [...module.using, ...(module.tests?.using ?? [])]),
|
|
5
|
-
...(draft.tests?.using ?? []),
|
|
6
|
-
])
|
|
3
|
+
.flatMap((draft) => [...draft.modules.flatMap((module) => module.using), ...draft.testUsing])
|
|
7
4
|
.map((value) => recordedAs(value, 'ref'))
|
|
8
5
|
.map((ref) => ref?.kind === 'required' && ref.name));
|
|
9
6
|
export const checkUnused = (drafts, fail) => {
|
|
@@ -59,8 +56,8 @@ const answer = (state, at, archetype, name, requirement, provider) => {
|
|
|
59
56
|
}
|
|
60
57
|
};
|
|
61
58
|
const moduleText = (state, module) => {
|
|
62
|
-
if (module.kind
|
|
63
|
-
return
|
|
59
|
+
if (module.kind !== 'dir')
|
|
60
|
+
return `a ${module.kind} module`;
|
|
64
61
|
return state.archetypes[module.archetype].inline ? 'a dir module' : `modules of ${module.archetype}`;
|
|
65
62
|
};
|
|
66
63
|
const requirementText = (requirement) => requirement.kind === 'archetype' ? `modules of ${requirement.archetype}` : `${requirement.kind}()`;
|
|
@@ -6,7 +6,7 @@ export interface Folders {
|
|
|
6
6
|
export interface ModuleView {
|
|
7
7
|
id: string;
|
|
8
8
|
name?: string;
|
|
9
|
-
kind: 'dir' | 'files';
|
|
9
|
+
kind: 'dir' | 'files' | 'test';
|
|
10
10
|
dir: string;
|
|
11
11
|
archetype?: string;
|
|
12
12
|
captures: Record<string, string>;
|
|
@@ -14,8 +14,6 @@ export interface ModuleView {
|
|
|
14
14
|
children: ModuleView[];
|
|
15
15
|
files: string[];
|
|
16
16
|
looseFiles: string[];
|
|
17
|
-
tests: string[];
|
|
18
|
-
test?: true;
|
|
19
17
|
}
|
|
20
18
|
export interface Model {
|
|
21
19
|
root: ModuleView;
|
|
@@ -24,6 +22,7 @@ export interface Model {
|
|
|
24
22
|
isTest(file: string): boolean;
|
|
25
23
|
}
|
|
26
24
|
export declare const declarationOf: (config: ConfigData, module: ModuleView) => ModuleData | undefined;
|
|
25
|
+
export declare const rootId = "(root)";
|
|
27
26
|
export declare const fillPattern: (pattern: string, captures: Record<string, string>) => string | undefined;
|
|
28
27
|
export declare const resolveModel: (config: ConfigData, folders: Folders, files: readonly string[]) => Model;
|
|
29
28
|
export declare const specificity: (pattern: string) => number;
|