@starci/eslint-grammar-offset-pop 0.22.0 → 0.24.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/CHANGELOG.md +12 -0
- package/package.json +6 -5
- package/runtime/bundle.json +2 -51
- package/runtime/engine/by-code-unit.mjs +0 -12
- package/runtime/engine/config.mjs +0 -461
- package/runtime/engine/invalid-config.mjs +0 -15
- package/runtime/engine/model-config.mjs +0 -112
- package/runtime/engine/orca-config.mjs +0 -34
- package/runtime/engine/plain-object.mjs +0 -5
- package/runtime/engine/release-config.mjs +0 -32
- package/runtime/engine/removed-vocabulary.mjs +0 -27
- package/runtime/engine/resources-config.mjs +0 -59
- package/runtime/engine/runtime-root.mjs +0 -138
- package/runtime/engine/secrets.mjs +0 -202
- package/runtime/engine/sonar-config.mjs +0 -24
- package/runtime/engine/yaml.mjs +0 -161
- package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
- package/runtime/knowledge/hfs/slots.yaml +0 -2783
- package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
- package/runtime/modules/models/registry.yaml +0 -221
- package/runtime/modules/models/runtimes.yaml +0 -556
- package/runtime/modules/models/tiers.yaml +0 -66
- package/runtime/scripts/hfs/allows.mjs +0 -77
- package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
- package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
- package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
- package/runtime/scripts/hfs/edition-slots.mjs +0 -80
- package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
- package/runtime/scripts/hfs/param-names.mjs +0 -13
- package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
- package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
- package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
- package/runtime/scripts/hfs/slot-classify.mjs +0 -69
- package/runtime/scripts/hfs/slot-errors.mjs +0 -12
- package/runtime/scripts/hfs/slot-imports.mjs +0 -98
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
- package/runtime/scripts/hfs/slot-match.mjs +0 -164
- package/runtime/scripts/hfs/slot-path.mjs +0 -6
- package/runtime/scripts/hfs/slot-required.mjs +0 -95
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
- package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
- package/runtime/scripts/hfs/slots.mjs +0 -306
- package/runtime/scripts/hfs/view.mjs +0 -180
- package/runtime/scripts/lib/glob.mjs +0 -32
- package/runtime/scripts/lib/i18n.mjs +0 -82
- package/runtime/scripts/lib/json-clone.mjs +0 -70
- package/runtime/scripts/lib/list.mjs +0 -26
- package/runtime/scripts/lib/path-key.mjs +0 -124
- package/runtime/scripts/lib/regex.mjs +0 -3
- package/runtime/scripts/lib/yaml-cached.mjs +0 -14
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
// slot-app-view.mjs - the resolver of a whole app: a root path is answered by the scope of the app root, a path below a side folder
|
|
2
|
-
// (be/, fe/) by that side's scope with the side prefixed back onto every path and root it returns. Only the declared `reads` cross sides.
|
|
3
|
-
// slots.mjs builds the scopes (`root` and `sides`, each a resolver of one scope) and hands them to appResolver.
|
|
4
|
-
import { APP_SCOPE, isSide, PROFILES } from './slot-manifest-shape.mjs';
|
|
5
|
-
import { cleanSlotPath } from './slot-path.mjs';
|
|
6
|
-
/** True for the view of a whole app (profile app), the one resolveRepoDeclaration builds with both sides. */
|
|
7
|
-
export const isAppRepo = (repo) => repo.sides !== undefined;
|
|
8
|
-
/** { side, rest } when `p` lies below a side folder, else null. */
|
|
9
|
-
function splitSide(input) {
|
|
10
|
-
const p = cleanSlotPath(input);
|
|
11
|
-
const slash = p.indexOf('/');
|
|
12
|
-
const head = slash < 0 ? p : p.slice(0, slash);
|
|
13
|
-
return isSide(head) && slash > 0 ? { side: head, rest: p.slice(slash + 1) } : null;
|
|
14
|
-
}
|
|
15
|
-
const under = (side, rel) => (rel ? `${side}/${rel}` : side);
|
|
16
|
-
function prefixed(side, c) {
|
|
17
|
-
return {
|
|
18
|
-
...c,
|
|
19
|
-
path: under(side, c.path),
|
|
20
|
-
side,
|
|
21
|
-
...(c.root !== undefined ? { root: under(side, c.root) } : {}),
|
|
22
|
-
...(c.nearest ? { nearest: { ...c.nearest, matchedPrefix: under(side, c.nearest.matchedPrefix), matchedDepth: c.nearest.matchedDepth + 1 } } : {}),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function classifyApp({ root, sides }, input) {
|
|
26
|
-
const at = splitSide(input);
|
|
27
|
-
return at ? prefixed(at.side, sides[at.side].classifyPath(at.rest)) : root.classifyPath(input);
|
|
28
|
-
}
|
|
29
|
-
function ownerApp({ root, sides }, input) {
|
|
30
|
-
const at = splitSide(input);
|
|
31
|
-
if (!at)
|
|
32
|
-
return root.ownerOf(input);
|
|
33
|
-
const owner = sides[at.side].ownerOf(at.rest);
|
|
34
|
-
return owner ? { ...owner, root: under(at.side, owner.root), side: at.side } : null;
|
|
35
|
-
}
|
|
36
|
-
/** Whether `toPath`, of the other side, lies below a path `fromSide` declares it reads. */
|
|
37
|
-
const readsPath = (repo, fromSide, toPath) => repo.sides[fromSide].reads.some((read) => `${cleanSlotPath(toPath)}/`.startsWith(read));
|
|
38
|
-
/** The verdict of an import from a side file to a path of the other side (or of the app root, `toSide` null): allowed only through a declared read. */
|
|
39
|
-
function sideCrossing(repo, fromSide, toSide, toPath) {
|
|
40
|
-
return readsPath(repo, fromSide, toPath)
|
|
41
|
-
? { allowed: true, reason: 'sideRead', fromSide, toSide }
|
|
42
|
-
: { allowed: false, reason: 'crossSide', fromSide, toSide, reads: repo.sides[fromSide].reads };
|
|
43
|
-
}
|
|
44
|
-
function importAllowedApp({ repo, root, sides }, fromPath, toPath) {
|
|
45
|
-
const from = splitSide(fromPath);
|
|
46
|
-
const to = splitSide(toPath);
|
|
47
|
-
// A side file may read an app-root path (db/types/) only through a declared read, exactly as it reads the other side.
|
|
48
|
-
if (from && from.side !== to?.side)
|
|
49
|
-
return sideCrossing(repo, from.side, to?.side ?? null, toPath);
|
|
50
|
-
if (from && to)
|
|
51
|
-
return sides[from.side].importAllowed(from.rest, to.rest);
|
|
52
|
-
return root.importAllowed(fromPath, toPath);
|
|
53
|
-
}
|
|
54
|
-
function requiredPathsApp({ root, sides }) {
|
|
55
|
-
const own = root.requiredPaths();
|
|
56
|
-
const paths = [...own.paths];
|
|
57
|
-
const minimums = [...own.minimums];
|
|
58
|
-
for (const side of PROFILES) {
|
|
59
|
-
const required = sides[side].requiredPaths();
|
|
60
|
-
paths.push(...required.paths.map((entry) => ({ ...entry, path: under(side, entry.path), side })));
|
|
61
|
-
minimums.push(...required.minimums.map((entry) => ({ ...entry, side })));
|
|
62
|
-
}
|
|
63
|
-
return { paths, minimums };
|
|
64
|
-
}
|
|
65
|
-
function slotEnabledApp({ root, sides }, slot) {
|
|
66
|
-
if (slot.profiles.includes(APP_SCOPE))
|
|
67
|
-
return root.slotEnabled(slot);
|
|
68
|
-
return PROFILES.some((side) => slot.profiles.includes(side) && sides[side].slotEnabled(slot));
|
|
69
|
-
}
|
|
70
|
-
/** The resolver of the app `repo`: `root` answers its root paths and `sides[side]` the paths below that side's folder. */
|
|
71
|
-
export function appResolver(repo, root, sides) {
|
|
72
|
-
const view = { repo, root, sides };
|
|
73
|
-
const allSlots = [...new Map([...root.slots(), ...PROFILES.flatMap((side) => sides[side].slots())].map((s) => [s.id, s])).values()];
|
|
74
|
-
const byId = new Map(allSlots.map((s) => [s.id, s]));
|
|
75
|
-
const classifyPath = (input) => classifyApp(view, input);
|
|
76
|
-
return Object.freeze({
|
|
77
|
-
repo,
|
|
78
|
-
sides: Object.freeze(sides),
|
|
79
|
-
/** The side of a path (be, fe) or null for a root path. */
|
|
80
|
-
sideOf: (input) => splitSide(input)?.side ?? null,
|
|
81
|
-
slot: (id) => byId.get(id) ?? null,
|
|
82
|
-
slots: () => allSlots,
|
|
83
|
-
slotEnabled: (slot) => slotEnabledApp(view, slot),
|
|
84
|
-
classifyPath,
|
|
85
|
-
slotOf: (p) => { const c = classifyPath(p); return c.slot ? byId.get(c.slot) : null; },
|
|
86
|
-
ownerOf: (input) => ownerApp(view, input),
|
|
87
|
-
tierOf: (input) => { const at = splitSide(input); return at ? sides[at.side].tierOf(at.rest) : root.tierOf(input); },
|
|
88
|
-
importAllowed: (fromPath, toPath) => importAllowedApp(view, fromPath, toPath),
|
|
89
|
-
requiredFiles: (input) => { const at = splitSide(input); return at ? sides[at.side].requiredFiles(at.rest).map((p) => under(at.side, p)) : root.requiredFiles(input); },
|
|
90
|
-
requiredPaths: () => requiredPathsApp(view),
|
|
91
|
-
trackingOf: (p) => classifyPath(p).tracking ?? null,
|
|
92
|
-
isTracked: (p) => classifyPath(p).tracking === 'tracked',
|
|
93
|
-
// The root has no tier and no rule parameters of its own; each side has them (sides.<side>.ruleParams()).
|
|
94
|
-
ruleParams: () => null,
|
|
95
|
-
allowedImports: () => null,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// slot-classify.mjs - what slot of one scope (the app root or one side) owns a path: its status, owner unit, tier, folder kind and role.
|
|
2
|
-
// A scope is {manifest, repo, profile, edition, slots, byId, variants, appKind} built once by slots.mjs; every function here reads it.
|
|
3
|
-
import { globExpression } from '../lib/glob.mjs';
|
|
4
|
-
import { declaredSlotEnabled } from './declaration-slots.mjs';
|
|
5
|
-
import { bestMatch, fillVars, matchVariants, nearestSlot } from './slot-match.mjs';
|
|
6
|
-
import { cleanSlotPath } from './slot-path.mjs';
|
|
7
|
-
/** Whether the repository of the scope holds the slot. */
|
|
8
|
-
export function slotEnabled(scope, slot) {
|
|
9
|
-
// A provider slot is gated by its provider in every edition: litePresence may lift it to required, but it still
|
|
10
|
-
// exists for this repository only while a connection declares the provider.
|
|
11
|
-
if (slot.provider !== undefined)
|
|
12
|
-
return declaredSlotEnabled(slot, scope.repo);
|
|
13
|
-
if (slot.presence !== 'opt-in')
|
|
14
|
-
return true;
|
|
15
|
-
return declaredSlotEnabled(slot, scope.repo);
|
|
16
|
-
}
|
|
17
|
-
/** The folder kind of a file in its slot, from a named layer or kind folder. */
|
|
18
|
-
function kindOf({ variant, slot, root }, p) {
|
|
19
|
-
const names = [...(slot.layers ?? []), ...(slot.kinds ?? [])];
|
|
20
|
-
if (!names.length)
|
|
21
|
-
return null;
|
|
22
|
-
const literal = variant.segments.find((segment) => names.includes(segment));
|
|
23
|
-
if (literal)
|
|
24
|
-
return literal;
|
|
25
|
-
const below = root ? p.slice(root.length + 1) : p;
|
|
26
|
-
return below.split('/').slice(0, -1).find((segment) => names.includes(segment)) ?? null;
|
|
27
|
-
}
|
|
28
|
-
/** The role of a file in its slot: the entry of `roles` whose file name (variables filled from the path, `*` a wildcard inside the name) matches the file's name. */
|
|
29
|
-
function roleOf(slot, bindings, p) {
|
|
30
|
-
const name = p.split('/').pop();
|
|
31
|
-
for (const [role, file] of Object.entries(slot.roles ?? {}))
|
|
32
|
-
if (globExpression(fillVars(file, bindings)).test(name))
|
|
33
|
-
return role;
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* status: owned | forbidden (external slot) | not-enabled (opt-in slot the repository did not declare) | ambiguous
|
|
38
|
-
* (two slots of equal specificity; a manifest gap) | no-slot (code HFS_SLOT_UNDECLARED, with the nearest slot).
|
|
39
|
-
*/
|
|
40
|
-
export function classifyIn(scope, input) {
|
|
41
|
-
const p = cleanSlotPath(input);
|
|
42
|
-
const { hit, ambiguous } = bestMatch(matchVariants(scope, p));
|
|
43
|
-
if (ambiguous.length)
|
|
44
|
-
return { path: p, status: 'ambiguous', candidates: ambiguous };
|
|
45
|
-
if (!hit)
|
|
46
|
-
return { path: p, status: 'no-slot', code: 'HFS_SLOT_UNDECLARED', nearest: nearestSlot(scope.variants, p) };
|
|
47
|
-
const { slot, root, bindings } = hit;
|
|
48
|
-
const status = (slot.presence === 'forbidden' && 'forbidden') || (slotEnabled(scope, slot) ? 'owned' : 'not-enabled');
|
|
49
|
-
const kind = kindOf(hit, p);
|
|
50
|
-
const role = roleOf(slot, bindings, p);
|
|
51
|
-
return { path: p, status, slot: slot.id, root, bindings, ...(kind ? { kind } : {}), ...(role ? { role } : {}), presence: slot.presence, tracking: slot.tracked, ...(status === 'forbidden' ? { goesTo: slot.goesTo } : {}) };
|
|
52
|
-
}
|
|
53
|
-
/** The owner unit of `p`: the most specific owner slot instance containing it (a slot's own root when it owns nothing). */
|
|
54
|
-
export function ownerIn(scope, input) {
|
|
55
|
-
const p = cleanSlotPath(input);
|
|
56
|
-
const { hit } = bestMatch(matchVariants(scope, p, (s) => s.owner === true));
|
|
57
|
-
return hit ? { slot: hit.slot.id, root: hit.root, bindings: hit.bindings } : null;
|
|
58
|
-
}
|
|
59
|
-
/** The tier of `p` in the direction matrix: its slot's tier, the owner's for an inheriting slot, none for an untiered one; null when no slot owns it. */
|
|
60
|
-
export function tierIn(scope, input) {
|
|
61
|
-
const c = classifyIn(scope, input);
|
|
62
|
-
if (!c.slot)
|
|
63
|
-
return null;
|
|
64
|
-
const tier = scope.byId.get(c.slot).tier;
|
|
65
|
-
if (tier !== 'inherit')
|
|
66
|
-
return tier;
|
|
67
|
-
const owner = ownerIn(scope, input);
|
|
68
|
-
return owner ? scope.byId.get(owner.slot).tier : 'none';
|
|
69
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// slot-errors.mjs - the shared refusal type for HFS manifest and declaration loaders.
|
|
2
|
-
export class HfsSlotsError extends Error {
|
|
3
|
-
code;
|
|
4
|
-
details;
|
|
5
|
-
constructor(code, message, details = {}) {
|
|
6
|
-
super(`${code}: ${message}`);
|
|
7
|
-
this.name = 'HfsSlotsError';
|
|
8
|
-
this.code = code;
|
|
9
|
-
this.details = details;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export const fail = (code, message, details) => { throw new HfsSlotsError(code, message, details); };
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// slot-imports.mjs - whether one file of a scope (the app root or one side) may import another: the tier direction matrix, the
|
|
2
|
-
// owner units, the layer order and the public entry of an owner. Cycles are a graph property of the architecture check, not of one edge.
|
|
3
|
-
import { RUNTIME_KIND } from './manifest-shape.mjs';
|
|
4
|
-
import { classifyIn, ownerIn, tierIn } from './slot-classify.mjs';
|
|
5
|
-
import { braceVariants, globExpression } from '../lib/glob.mjs';
|
|
6
|
-
const isEntryFile = (name) => name === 'index.ts' || name === 'index.tsx';
|
|
7
|
-
function declaredEntry(slot, relative) {
|
|
8
|
-
return (slot.entries ?? []).some((entry) => braceVariants(entry).some((pattern) => globExpression(pattern).test(relative)));
|
|
9
|
-
}
|
|
10
|
-
function unownedPathProblem(from, to) {
|
|
11
|
-
for (const side of [from, to]) {
|
|
12
|
-
if (side.status === 'no-slot')
|
|
13
|
-
return { allowed: false, reason: 'unowned', code: side.code, path: side.path, nearest: side.nearest };
|
|
14
|
-
}
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
function unavailableSlotProblem(from, to) {
|
|
18
|
-
for (const side of [from, to]) {
|
|
19
|
-
if (side.status !== 'owned')
|
|
20
|
-
return { allowed: false, reason: `slot${side.status[0].toUpperCase()}${side.status.slice(1).replace(/-(.)/g, (_, c) => c.toUpperCase())}`, path: side.path, slot: side.slot };
|
|
21
|
-
}
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
function sameOwnerUnit(side, owner) {
|
|
25
|
-
return owner ? `${owner.slot}:${owner.root}` : `${side.slot}:${side.root}`;
|
|
26
|
-
}
|
|
27
|
-
const layerIndex = (slot, root) => (slot.layers ? slot.layers.findIndex((layer) => root.split('/').includes(layer)) : -1);
|
|
28
|
-
function lowerLayerProblem({ manifest, profile, byId }, from, to, fromTier, toTier, fromOwner, toOwner) {
|
|
29
|
-
if (manifest.tiers[profile][fromTier].lowerLayerOnly && fromTier === toTier) {
|
|
30
|
-
const fromSlot = byId.get((fromOwner ?? from).slot);
|
|
31
|
-
const a = layerIndex(fromSlot, fromOwner?.root ?? from.root);
|
|
32
|
-
const b = layerIndex(byId.get((toOwner ?? to).slot), toOwner?.root ?? to.root);
|
|
33
|
-
if (a >= 0 && b >= 0 && b <= a)
|
|
34
|
-
return { allowed: false, reason: 'layerOrder', fromLayer: fromSlot.layers[a], toLayer: fromSlot.layers[b] };
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
function privateEntryProblem({ repo, byId }, to, toOwner) {
|
|
39
|
-
if (toOwner && repo.kind !== RUNTIME_KIND) {
|
|
40
|
-
const relative = to.path === toOwner.root ? '' : to.path.slice(toOwner.root.length + 1);
|
|
41
|
-
const ownerSlot = byId.get(toOwner.slot);
|
|
42
|
-
const entry = isEntryFile(relative) || declaredEntry(byId.get(to.slot), to.path.slice(to.root.length + 1)) || (ownerSlot.tier === 'package' && relative === 'src/index.ts') || (ownerSlot.tier === 'app' && relative === 'app.module.ts');
|
|
43
|
-
if (!entry)
|
|
44
|
-
return { allowed: false, reason: 'notPublicEntry', owner: toOwner.root, path: to.path };
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
function tierImportProblem(scope, from, to, fromTier, toTier) {
|
|
49
|
-
const { mayImport, mayImportKinds, mayImportSlots } = scope.manifest.tiers[scope.profile][fromTier] ?? {};
|
|
50
|
-
if (!mayImport?.includes(toTier))
|
|
51
|
-
return { allowed: false, reason: 'tierDirection', fromTier, toTier, mayImport: mayImport ?? [] };
|
|
52
|
-
const kindRestriction = mayImportKinds?.[toTier];
|
|
53
|
-
if (kindRestriction && (!kindRestriction.from.includes(from.kind) || !kindRestriction.to.includes(to.kind)))
|
|
54
|
-
return { allowed: false, reason: 'tierDirection', fromTier, toTier, mayImport, kindRestriction, fromKind: from.kind ?? null, toKind: to.kind ?? null };
|
|
55
|
-
const slotRestriction = mayImportSlots?.[toTier];
|
|
56
|
-
if (slotRestriction && !slotRestriction.from.includes(from.slot))
|
|
57
|
-
return { allowed: false, reason: 'tierDirection', fromTier, toTier, mayImport, slotRestriction, fromSlot: from.slot };
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Whether `fromPath` may import `toPath`: {allowed, reason, ...}. Reasons: sameOwner, untiered, crossApp,
|
|
62
|
-
* tierDirection, layerOrder, notPublicEntry, allowed, slotForbidden, slotNotEnabled, slotAmbiguous, and unowned (HFS_SLOT_UNDECLARED for the path no slot owns).
|
|
63
|
-
* Cycles are a graph property and belong to the architecture check, not to one edge.
|
|
64
|
-
*/
|
|
65
|
-
export function importAllowedIn(scope, fromPath, toPath) {
|
|
66
|
-
const fromClassified = classifyIn(scope, fromPath);
|
|
67
|
-
const toClassified = classifyIn(scope, toPath);
|
|
68
|
-
const unowned = unownedPathProblem(fromClassified, toClassified);
|
|
69
|
-
if (unowned)
|
|
70
|
-
return unowned;
|
|
71
|
-
const unavailable = unavailableSlotProblem(fromClassified, toClassified);
|
|
72
|
-
if (unavailable)
|
|
73
|
-
return unavailable;
|
|
74
|
-
// reason: unavailableSlotProblem answers for every status but owned, so both paths are placed from here on
|
|
75
|
-
const from = fromClassified;
|
|
76
|
-
const to = toClassified;
|
|
77
|
-
const fromTier = tierIn(scope, from.path);
|
|
78
|
-
const toTier = tierIn(scope, to.path);
|
|
79
|
-
if (fromTier === 'none' || toTier === 'none')
|
|
80
|
-
return { allowed: true, reason: 'untiered' };
|
|
81
|
-
if (from.bindings.app !== undefined && to.bindings.app !== undefined && from.bindings.app !== to.bindings.app)
|
|
82
|
-
return { allowed: false, reason: 'crossApp', from: from.bindings.app, to: to.bindings.app };
|
|
83
|
-
const fromOwner = ownerIn(scope, from.path);
|
|
84
|
-
const toOwner = ownerIn(scope, to.path);
|
|
85
|
-
if (sameOwnerUnit(from, fromOwner) === sameOwnerUnit(to, toOwner))
|
|
86
|
-
return { allowed: true, reason: 'sameOwner' };
|
|
87
|
-
const tierProblem = tierImportProblem(scope, from, to, fromTier, toTier);
|
|
88
|
-
if (tierProblem)
|
|
89
|
-
return tierProblem;
|
|
90
|
-
const layerProblem = lowerLayerProblem(scope, from, to, fromTier, toTier, fromOwner, toOwner);
|
|
91
|
-
if (layerProblem)
|
|
92
|
-
return layerProblem;
|
|
93
|
-
// A runtime owner is imported file by file (crossOwner of knowledge/hfs/runtime-slots.yaml): no public entry.
|
|
94
|
-
const privateEntry = privateEntryProblem(scope, to, toOwner);
|
|
95
|
-
if (privateEntry)
|
|
96
|
-
return privateEntry;
|
|
97
|
-
return { allowed: true, reason: 'allowed', fromTier, toTier };
|
|
98
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { isPlainObject } from '../../engine/plain-object.mjs';
|
|
2
|
-
import { byCodeUnit } from '../lib/list.mjs';
|
|
3
|
-
import { ruleParamsProblems } from './rule-params-shape.mjs';
|
|
4
|
-
import { APP_KIND, EDITIONS, MANIFEST_KINDS, NAME, PRESENCE, RUNTIME_KIND, SEMVER, TESTS, TRACKED, manifestKind, runtimeShapeProblems, slotProblems, tierMapProblems } from './manifest-shape.mjs';
|
|
5
|
-
export const PROFILES = ['be', 'fe'];
|
|
6
|
-
/** Whether `value` names a side of an app. */
|
|
7
|
-
export const isSide = (value) => PROFILES.includes(value);
|
|
8
|
-
export const APP_SCOPE = 'app';
|
|
9
|
-
export const SCOPES = [APP_SCOPE, ...PROFILES];
|
|
10
|
-
/** Shape problems of a parsed manifest, in the words of modules/schemas/hfs-slots.schema.yaml. */
|
|
11
|
-
function checkCoreManifestFields(m, bad) {
|
|
12
|
-
const allowed = new Set(['schema', 'kind', 'version', 'versioning', 'presenceValues', 'trackedValues', 'testValues', 'editions', 'sides', 'appKinds', 'triggerKinds', 'tiers', 'ruleParams', 'crossOwner', 'crossApp', 'slots', 'consumers', 'naming']);
|
|
13
|
-
for (const key of Object.keys(m))
|
|
14
|
-
if (!allowed.has(key))
|
|
15
|
-
bad.push(`unknown top-level key ${key}`);
|
|
16
|
-
if (!/^starci\/hfs-slots@\d+$/.test(String(m.schema)))
|
|
17
|
-
bad.push('schema must be starci/hfs-slots@<major>');
|
|
18
|
-
if (!SEMVER.test(String(m.version)))
|
|
19
|
-
bad.push('version must be MAJOR.MINOR.PATCH');
|
|
20
|
-
if (!isPlainObject(m.versioning) || !['patch', 'minor', 'major', 'pins'].every((k) => typeof m.versioning[k] === 'string'))
|
|
21
|
-
bad.push('versioning needs patch, minor, major and pins text');
|
|
22
|
-
if (JSON.stringify(m.presenceValues) !== JSON.stringify(PRESENCE))
|
|
23
|
-
bad.push(`presenceValues must be ${PRESENCE.join(', ')}`);
|
|
24
|
-
if (JSON.stringify(m.trackedValues) !== JSON.stringify(TRACKED))
|
|
25
|
-
bad.push(`trackedValues must be ${TRACKED.join(', ')}`);
|
|
26
|
-
if (JSON.stringify(m.testValues) !== JSON.stringify(TESTS))
|
|
27
|
-
bad.push(`testValues must be ${TESTS.join(', ')}`);
|
|
28
|
-
if (JSON.stringify(m.editions) !== JSON.stringify(EDITIONS))
|
|
29
|
-
bad.push(`editions must be ${EDITIONS.join(', ')}`);
|
|
30
|
-
}
|
|
31
|
-
function checkSideShapes(m, bad) {
|
|
32
|
-
if (!isPlainObject(m.sides) || Object.keys(m.sides).sort(byCodeUnit).join() !== PROFILES.join())
|
|
33
|
-
bad.push('sides must be a map with exactly be and fe');
|
|
34
|
-
else
|
|
35
|
-
for (const side of PROFILES) {
|
|
36
|
-
const def = m.sides[side];
|
|
37
|
-
if (!isPlainObject(def) || Object.keys(def).join() !== 'reads' || !Array.isArray(def.reads) || !def.reads.every((r) => typeof r === 'string' && /^[a-z][a-z0-9-]*\/([^/]+\/)+$/.test(r)) || new Set(def.reads).size !== def.reads.length)
|
|
38
|
-
bad.push(`sides.${side} must be {reads: [unique <owner>/<dir>/ paths]}`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function checkTriggerKinds(m, bad) {
|
|
42
|
-
if (m.triggerKinds !== undefined && (!Array.isArray(m.triggerKinds) || !m.triggerKinds.length || !m.triggerKinds.every((k) => NAME.test(String(k))) || new Set(m.triggerKinds).size !== m.triggerKinds.length))
|
|
43
|
-
bad.push('triggerKinds must be a non-empty list of unique names');
|
|
44
|
-
}
|
|
45
|
-
function checkProfileMaps(m, bad) {
|
|
46
|
-
for (const key of ['appKinds', 'tiers']) {
|
|
47
|
-
if (!isPlainObject(m[key])) {
|
|
48
|
-
bad.push(`${key} must be a map with be and fe`);
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
for (const extra of Object.keys(m[key]))
|
|
52
|
-
if (!isSide(extra) && !(key === 'tiers' && extra === COMPONENT_LIBRARY))
|
|
53
|
-
bad.push(`${key}.${extra} is not a profile`);
|
|
54
|
-
for (const profile of PROFILES)
|
|
55
|
-
if (!(profile in m[key]))
|
|
56
|
-
bad.push(`${key}.${profile} is missing`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/** The tier matrix of a component library (packages/grammar), beside the be and fe profiles: tiers.grammar. */
|
|
60
|
-
const COMPONENT_LIBRARY = 'grammar';
|
|
61
|
-
function checkComponentLibraryTiers(m, bad) {
|
|
62
|
-
const tiers = m.tiers?.[COMPONENT_LIBRARY];
|
|
63
|
-
if (tiers === undefined)
|
|
64
|
-
return;
|
|
65
|
-
bad.push(...tierMapProblems(COMPONENT_LIBRARY, tiers));
|
|
66
|
-
if (!isPlainObject(tiers))
|
|
67
|
-
return;
|
|
68
|
-
for (const [tier, def] of Object.entries(tiers))
|
|
69
|
-
for (const target of def?.mayImport ?? [])
|
|
70
|
-
if (!(target in tiers))
|
|
71
|
-
bad.push(`tiers.${COMPONENT_LIBRARY}.${tier}.mayImport names ${target}, which is not a ${COMPONENT_LIBRARY} tier`);
|
|
72
|
-
}
|
|
73
|
-
function checkAppKindAndTierShapes(m, bad) {
|
|
74
|
-
for (const profile of PROFILES) {
|
|
75
|
-
const kinds = m.appKinds?.[profile];
|
|
76
|
-
if (kinds !== undefined && (!Array.isArray(kinds) || !kinds.length || !kinds.every((k) => NAME.test(String(k))) || new Set(kinds).size !== kinds.length))
|
|
77
|
-
bad.push(`appKinds.${profile} must be a non-empty list of unique names`);
|
|
78
|
-
const tiers = m.tiers?.[profile];
|
|
79
|
-
if (tiers === undefined)
|
|
80
|
-
continue;
|
|
81
|
-
bad.push(...tierMapProblems(profile, tiers));
|
|
82
|
-
}
|
|
83
|
-
checkComponentLibraryTiers(m, bad);
|
|
84
|
-
}
|
|
85
|
-
function checkSlotShapes(m, bad) {
|
|
86
|
-
if (!Array.isArray(m.slots) || !m.slots.length) {
|
|
87
|
-
bad.push('slots must be a non-empty list');
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
const logicRoles = Array.isArray(m.ruleParams?.be?.logicRoles) ? m.ruleParams.be.logicRoles : [];
|
|
91
|
-
m.slots.forEach((slot, index) => bad.push(...slotProblems(slot, index, APP_KIND, { appScope: APP_SCOPE, scopes: SCOPES, logicRoles })));
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
export function manifestShapeProblems(m) {
|
|
95
|
-
const bad = [];
|
|
96
|
-
if (!isPlainObject(m))
|
|
97
|
-
return ['the manifest is not a map'];
|
|
98
|
-
if (!MANIFEST_KINDS.includes(manifestKind(m)))
|
|
99
|
-
return [`kind must be one of ${MANIFEST_KINDS.join(', ')}`];
|
|
100
|
-
if (manifestKind(m) === RUNTIME_KIND)
|
|
101
|
-
return runtimeShapeProblems(m);
|
|
102
|
-
checkCoreManifestFields(m, bad);
|
|
103
|
-
checkSideShapes(m, bad);
|
|
104
|
-
checkTriggerKinds(m, bad);
|
|
105
|
-
checkProfileMaps(m, bad);
|
|
106
|
-
checkAppKindAndTierShapes(m, bad);
|
|
107
|
-
bad.push(...ruleParamsProblems(m));
|
|
108
|
-
if (!checkSlotShapes(m, bad))
|
|
109
|
-
return bad;
|
|
110
|
-
return bad;
|
|
111
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
// slot-match.mjs - the slot path patterns of the HFS manifest compiled to regular expressions, and the matching of a path against them:
|
|
2
|
-
// the variants that match it, the most specific one, and the nearest slot of an unknown path. Pure; slot-classify.mjs asks it.
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { braceVariants } from '../lib/glob.mjs';
|
|
5
|
-
import { captureNames } from '../lib/i18n.mjs';
|
|
6
|
-
const VAR = /<([A-Za-z][A-Za-z0-9-]*)>/g;
|
|
7
|
-
export const varsOf = (text) => captureNames(text, VAR);
|
|
8
|
-
const hasWildcard = (segment) => /[*?]/.test(segment);
|
|
9
|
-
/** `text` with the `<name>` variables filled from `bindings` (an unbound one stays as written). */
|
|
10
|
-
export function fillVars(text, bindings) {
|
|
11
|
-
const bound = (whole, name) => bindings[name] ?? whole;
|
|
12
|
-
return `${text}`.replace(VAR, bound);
|
|
13
|
-
}
|
|
14
|
-
/** Weight of one pattern segment: literal 4, literal mixed with a variable 3, a bare variable 2, a wildcard 1, `**` 0. */
|
|
15
|
-
function segmentWeight(segment) {
|
|
16
|
-
if (segment === '**')
|
|
17
|
-
return 0;
|
|
18
|
-
if (hasWildcard(segment))
|
|
19
|
-
return 1;
|
|
20
|
-
if (/^<[^>]+>$/.test(segment))
|
|
21
|
-
return 2;
|
|
22
|
-
if (segment.includes('<'))
|
|
23
|
-
return 3;
|
|
24
|
-
return 4;
|
|
25
|
-
}
|
|
26
|
-
/** The RegExp source of one pattern segment (no separators); variables capture, and are listed in `names`. */
|
|
27
|
-
function segmentSource(segment, names) {
|
|
28
|
-
let source = '', variableEnd = -1;
|
|
29
|
-
for (let i = 0; i < segment.length; i += 1) {
|
|
30
|
-
const c = segment[i];
|
|
31
|
-
if (i <= variableEnd)
|
|
32
|
-
continue;
|
|
33
|
-
if (c === '<') {
|
|
34
|
-
variableEnd = segment.indexOf('>', i);
|
|
35
|
-
names.push(segment.slice(i + 1, variableEnd));
|
|
36
|
-
source += '([^/]+?)';
|
|
37
|
-
}
|
|
38
|
-
else if (c === '*')
|
|
39
|
-
source += '[^/]*';
|
|
40
|
-
else if (c === '?')
|
|
41
|
-
source += '[^/]';
|
|
42
|
-
else
|
|
43
|
-
source += /[.+^${}()|[\]\\]/.test(c) ? `\\${c}` : c;
|
|
44
|
-
}
|
|
45
|
-
return source;
|
|
46
|
-
}
|
|
47
|
-
/** One brace-free pattern compiled: `dir` patterns (trailing /) own everything below their root. */
|
|
48
|
-
export function compileVariant(slot, pattern) {
|
|
49
|
-
const dir = pattern.endsWith('/');
|
|
50
|
-
const body = dir ? pattern.slice(0, -1) : pattern;
|
|
51
|
-
const segments = body.split('/');
|
|
52
|
-
const names = [];
|
|
53
|
-
let source = '';
|
|
54
|
-
segments.forEach((segment, index) => {
|
|
55
|
-
const last = index === segments.length - 1;
|
|
56
|
-
if (segment === '**')
|
|
57
|
-
source += last ? '.*' : '(?:.*/)?';
|
|
58
|
-
else
|
|
59
|
-
source += segmentSource(segment, names) + (last ? '' : '/');
|
|
60
|
-
});
|
|
61
|
-
return {
|
|
62
|
-
slot,
|
|
63
|
-
pattern,
|
|
64
|
-
dir,
|
|
65
|
-
segments,
|
|
66
|
-
names,
|
|
67
|
-
score: segments.reduce((sum, s) => sum + segmentWeight(s), 0),
|
|
68
|
-
wildcards: segments.filter(hasWildcard).length,
|
|
69
|
-
regex: new RegExp(`^(${source})${dir ? '(?:/.*)?' : ''}$`),
|
|
70
|
-
segmentRegexes: segments.map((s) => (s === '**' ? null : new RegExp(`^${segmentSource(s, [])}$`))),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
export const variantsOf = (slot) => braceVariants(slot.path).map((pattern) => compileVariant(slot, pattern));
|
|
74
|
-
const levenshtein = (a, b) => {
|
|
75
|
-
const row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
76
|
-
for (let i = 1; i <= a.length; i += 1) {
|
|
77
|
-
let prev = row[0];
|
|
78
|
-
row[0] = i;
|
|
79
|
-
for (let j = 1; j <= b.length; j += 1) {
|
|
80
|
-
const held = row[j];
|
|
81
|
-
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
82
|
-
prev = held;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return row[b.length];
|
|
86
|
-
};
|
|
87
|
-
/** The match of `p` against one variant: its slot, root and bindings, or null (not matching, filtered out, or an app-kind slot of another kind). */
|
|
88
|
-
function matchVariant(variant, p, only, appKind) {
|
|
89
|
-
if (only && !only(variant.slot))
|
|
90
|
-
return null;
|
|
91
|
-
const m = variant.regex.exec(p);
|
|
92
|
-
if (!m)
|
|
93
|
-
return null;
|
|
94
|
-
const bindings = {};
|
|
95
|
-
variant.names.forEach((name, i) => { bindings[name] = m[i + 2]; });
|
|
96
|
-
if (variant.slot.appKind !== undefined && appKind.get(bindings.app) !== variant.slot.appKind)
|
|
97
|
-
return null;
|
|
98
|
-
const root = variant.dir ? m[1] : path.posix.dirname(m[1]);
|
|
99
|
-
return { variant, slot: variant.slot, root: root === '.' ? '' : root, bindings };
|
|
100
|
-
}
|
|
101
|
-
/** Every variant matching `p`, with its root and bindings, minus app-kind slots of another kind, the most specific first. */
|
|
102
|
-
export function matchVariants({ variants, appKind }, p, only) {
|
|
103
|
-
const found = [];
|
|
104
|
-
for (const variant of variants) {
|
|
105
|
-
const hit = matchVariant(variant, p, only, appKind);
|
|
106
|
-
if (hit)
|
|
107
|
-
found.push(hit);
|
|
108
|
-
}
|
|
109
|
-
return found.sort((a, b) => b.variant.score - a.variant.score || a.variant.wildcards - b.variant.wildcards);
|
|
110
|
-
}
|
|
111
|
-
/** The single most specific match of a sorted list: {hit, ambiguous}; two slots of equal specificity are ambiguous. */
|
|
112
|
-
export function bestMatch(found) {
|
|
113
|
-
if (!found.length)
|
|
114
|
-
return { hit: null, ambiguous: [] };
|
|
115
|
-
const first = found[0];
|
|
116
|
-
const top = found.filter((f) => f.variant.score === first.variant.score && f.variant.wildcards === first.variant.wildcards);
|
|
117
|
-
const distinct = [...new Set(top.map((f) => f.slot.id))];
|
|
118
|
-
return distinct.length > 1 ? { hit: null, ambiguous: distinct } : { hit: top[0], ambiguous: [] };
|
|
119
|
-
}
|
|
120
|
-
/** How many leading segments of `parts` a variant accepts. */
|
|
121
|
-
function acceptedDepth(variant, parts) {
|
|
122
|
-
let depth = 0;
|
|
123
|
-
while (depth < parts.length && depth < variant.segments.length) {
|
|
124
|
-
const rx = variant.segmentRegexes[depth];
|
|
125
|
-
if (rx === null || !rx.test(parts[depth]))
|
|
126
|
-
break;
|
|
127
|
-
depth += 1;
|
|
128
|
-
}
|
|
129
|
-
return depth;
|
|
130
|
-
}
|
|
131
|
-
/** Whether `cand` is nearer to the path than `winner`: deeper, then closer in shape, then in spelling, then more specific. */
|
|
132
|
-
function nearerCandidate(cand, winner) {
|
|
133
|
-
if (!winner)
|
|
134
|
-
return true;
|
|
135
|
-
if (cand.depth !== winner.depth)
|
|
136
|
-
return cand.depth > winner.depth;
|
|
137
|
-
if (cand.shape !== winner.shape)
|
|
138
|
-
return cand.shape < winner.shape;
|
|
139
|
-
if (cand.distance !== winner.distance)
|
|
140
|
-
return cand.distance < winner.distance;
|
|
141
|
-
return cand.variant.score > winner.variant.score;
|
|
142
|
-
}
|
|
143
|
-
/** The leading segments of `p` a variant accepts, and how far it got; how the nearest slot of an unknown path is found. */
|
|
144
|
-
export function nearestSlot(variants, p) {
|
|
145
|
-
const parts = p.split('/');
|
|
146
|
-
let winner = null;
|
|
147
|
-
for (const variant of variants) {
|
|
148
|
-
const depth = acceptedDepth(variant, parts);
|
|
149
|
-
const expected = variant.segments[depth] ?? '';
|
|
150
|
-
const distance = levenshtein(parts[depth] ?? '', expected.replace(VAR, ''));
|
|
151
|
-
const cand = { variant, depth, shape: Math.abs(variant.segments.length - parts.length), distance };
|
|
152
|
-
if (nearerCandidate(cand, winner))
|
|
153
|
-
winner = cand;
|
|
154
|
-
}
|
|
155
|
-
if (!winner)
|
|
156
|
-
return null;
|
|
157
|
-
return {
|
|
158
|
-
slot: winner.variant.slot.id,
|
|
159
|
-
pattern: winner.variant.pattern,
|
|
160
|
-
matchedDepth: winner.depth,
|
|
161
|
-
matchedPrefix: parts.slice(0, winner.depth).join('/'),
|
|
162
|
-
expectedNext: winner.variant.segments[winner.depth] ?? null,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// slot-path.mjs - normalize a slot-relative path for resolver comparisons.
|
|
2
|
-
import { posixPath } from '../lib/path-key.mjs';
|
|
3
|
-
const SLASH = '/';
|
|
4
|
-
const END = '$';
|
|
5
|
-
const TRAILING_SLASHES = new RegExp(`${SLASH}+${END}`);
|
|
6
|
-
export const cleanSlotPath = (value) => posixPath(value).replace(TRAILING_SLASHES, '');
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
// slot-required.mjs - what a scope (the app root or one side) must contain, without walking it: the files an instance of a slot
|
|
2
|
-
// requires, and the paths and minimum instance counts of every required slot. A scope is the one slots.mjs builds.
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { braceVariants } from '../lib/glob.mjs';
|
|
5
|
-
import { classifyIn, slotEnabled } from './slot-classify.mjs';
|
|
6
|
-
import { fillVars, varsOf } from './slot-match.mjs';
|
|
7
|
-
/** A populated fe.modules instance needs its index.ts only when it contains TypeScript, including nested files. */
|
|
8
|
-
export function requiredFileApplies(slotId, target, files) {
|
|
9
|
-
if (!/^fe\.modules(?:\.|$)/u.test(slotId) || path.posix.basename(target) !== 'index.ts')
|
|
10
|
-
return true;
|
|
11
|
-
const prefix = `${path.posix.dirname(target)}/`;
|
|
12
|
-
let populated = false;
|
|
13
|
-
for (const file of files) {
|
|
14
|
-
if (!file.startsWith(prefix))
|
|
15
|
-
continue;
|
|
16
|
-
populated = true;
|
|
17
|
-
if (/\.tsx?$/u.test(file))
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
return !populated;
|
|
21
|
-
}
|
|
22
|
-
/** One `requires` entry of a slot placed under `root`: a leading / makes it repository-relative, the variables are filled from `bindings`. */
|
|
23
|
-
function requiredEntry(entry, bindings, root) {
|
|
24
|
-
const rooted = entry.startsWith('/');
|
|
25
|
-
const filled = fillVars(rooted ? entry.slice(1) : entry, bindings);
|
|
26
|
-
return rooted || !root || root === '.' ? filled : `${root}/${filled}`;
|
|
27
|
-
}
|
|
28
|
-
/** The files and directories the instance holding `p` must contain (directories end with /); {path} entries are repo-relative. */
|
|
29
|
-
export function requiredFilesIn(scope, input) {
|
|
30
|
-
const c = classifyIn(scope, input);
|
|
31
|
-
if (!c.slot)
|
|
32
|
-
return [];
|
|
33
|
-
const slot = scope.byId.get(c.slot);
|
|
34
|
-
return (slot.requires ?? []).map((entry) => requiredEntry(entry, c.bindings, c.root));
|
|
35
|
-
}
|
|
36
|
-
function growBindings(combos, name, values) {
|
|
37
|
-
const next = [];
|
|
38
|
-
for (const combo of combos) {
|
|
39
|
-
for (const value of values)
|
|
40
|
-
next.push({ ...combo, [name]: value });
|
|
41
|
-
}
|
|
42
|
-
combos.splice(0, combos.length, ...next);
|
|
43
|
-
}
|
|
44
|
-
const expandApps = (repo, slot) => repo.apps.filter((a) => slot.appKind === undefined || a.kind === slot.appKind);
|
|
45
|
-
function appendRequiredVariantPaths(repo, slot, variant, paths) {
|
|
46
|
-
const names = [...new Set(varsOf(variant))];
|
|
47
|
-
const fixed = { ...slot.requiredInstances };
|
|
48
|
-
const open = names.filter((name) => name !== 'app' && !(name in fixed));
|
|
49
|
-
if (open.length)
|
|
50
|
-
return;
|
|
51
|
-
const combos = [{}];
|
|
52
|
-
if (names.includes('app'))
|
|
53
|
-
growBindings(combos, 'app', expandApps(repo, slot).map((app) => app.name));
|
|
54
|
-
for (const [name, values] of Object.entries(fixed))
|
|
55
|
-
growBindings(combos, name, values);
|
|
56
|
-
const isInstance = names.length > 0;
|
|
57
|
-
for (const bindings of combos) {
|
|
58
|
-
const target = fillVars(variant, bindings);
|
|
59
|
-
paths.push({ slot: slot.id, path: target, via: isInstance ? 'instance' : 'slot' });
|
|
60
|
-
const root = target.endsWith('/') ? target.slice(0, -1) : path.posix.dirname(target);
|
|
61
|
-
for (const entry of slot.requires ?? [])
|
|
62
|
-
paths.push({ slot: slot.id, path: requiredEntry(entry, bindings, root), via: 'requires' });
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function appendRequiredSlotPaths(scope, slot, paths, minimums) {
|
|
66
|
-
if (slot.presence !== 'required' || !slotEnabled(scope, slot))
|
|
67
|
-
return;
|
|
68
|
-
if (slot.requiredWhen === 'connections' && !scope.repo.connections.length)
|
|
69
|
-
return;
|
|
70
|
-
if (slot.minInstances)
|
|
71
|
-
minimums.push({ slot: slot.id, min: slot.minInstances, ...(slot.appKind ? { appKind: slot.appKind } : {}) });
|
|
72
|
-
for (const variant of braceVariants(slot.path))
|
|
73
|
-
appendRequiredVariantPaths(scope.repo, slot, variant, paths);
|
|
74
|
-
}
|
|
75
|
-
function uniqueRequiredPaths(paths) {
|
|
76
|
-
const seen = new Set();
|
|
77
|
-
return paths.filter((entry) => {
|
|
78
|
-
const key = `${entry.slot}|${entry.path}`;
|
|
79
|
-
if (seen.has(key))
|
|
80
|
-
return false;
|
|
81
|
-
seen.add(key);
|
|
82
|
-
return true;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* What the repository must contain, without walking it: {paths: [{slot, path, via}], minimums: [{slot, min}]}.
|
|
87
|
-
* via is slot (a fixed path), instance (a requiredInstances or app-kind root) or requires (a file an instance needs).
|
|
88
|
-
*/
|
|
89
|
-
export function requiredPathsIn(scope) {
|
|
90
|
-
const paths = [];
|
|
91
|
-
const minimums = [];
|
|
92
|
-
for (const slot of scope.slots)
|
|
93
|
-
appendRequiredSlotPaths(scope, slot, paths, minimums);
|
|
94
|
-
return { paths: uniqueRequiredPaths(paths), minimums };
|
|
95
|
-
}
|