@starci/eslint-canon-be 3.18.4 → 3.19.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 +4 -0
- package/dist/comments.js +1 -1
- package/dist/explicit-surface.js +1 -1
- package/dist/index.js +1 -1
- package/dist/jwt-alg.js +1 -1
- package/dist/lib/edition.d.ts +1 -1
- package/dist/lib/edition.js +1 -1
- package/dist/lib/hfs.d.ts +0 -6
- package/dist/lib/hfs.js +7 -5
- package/dist/lib/runtime-root.d.ts +6 -1
- package/dist/lib/runtime-root.js +8 -2
- package/dist/lib/subject-values.js +1 -1
- package/dist/module-layering.js +2 -2
- package/dist/project-graph.js +1 -1
- package/dist/third-party-owner.js +1 -1
- package/package.json +3 -1
- package/runtime/bundle.json +1 -190
- package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
- package/runtime/scripts/hfs/project-graph.mjs +6 -6
- package/runtime/scripts/hfs/project-rule.mjs +3 -3
- package/runtime/config.example.yaml +0 -194
- 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/temp-root.mjs +0 -26
- package/runtime/engine/yaml.mjs +0 -161
- package/runtime/knowledge/grammars/index.yaml +0 -114
- package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
- package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
- package/runtime/knowledge/hfs/rules.yaml +0 -6760
- package/runtime/knowledge/hfs/slots.yaml +0 -2783
- package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
- package/runtime/knowledge/sonar-gate.yaml +0 -151
- 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/api/git/cat-file.mjs +0 -4
- package/runtime/scripts/api/git/config-get.mjs +0 -9
- package/runtime/scripts/api/git/diff.mjs +0 -4
- package/runtime/scripts/api/git/lib.mjs +0 -80
- package/runtime/scripts/api/git/ls-files.mjs +0 -5
- package/runtime/scripts/api/git/ls-tree.mjs +0 -4
- package/runtime/scripts/api/git/merge-base.mjs +0 -8
- package/runtime/scripts/api/git/remote.mjs +0 -4
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
- package/runtime/scripts/api/git/show.mjs +0 -5
- package/runtime/scripts/api/git/tag.mjs +0 -4
- package/runtime/scripts/hfs/allows.mjs +0 -77
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
- package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
- package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
- package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
- package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
- package/runtime/scripts/hfs/architecture/config.mjs +0 -407
- package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
- package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
- package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
- package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
- package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
- package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
- package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
- package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
- package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
- package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
- package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
- package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
- package/runtime/scripts/hfs/architecture/index.mjs +0 -402
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
- package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
- package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
- package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
- package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
- package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
- package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
- package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
- package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
- package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
- package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
- package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
- package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
- package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
- package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
- package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
- package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
- package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
- package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
- package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
- 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/explicit-surface-rule.mjs +0 -59
- package/runtime/scripts/hfs/linear-text.mjs +0 -30
- package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
- package/runtime/scripts/hfs/param-names.mjs +0 -13
- package/runtime/scripts/hfs/path-findings.mjs +0 -167
- package/runtime/scripts/hfs/repo-identity.mjs +0 -89
- package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
- package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
- package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
- package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
- package/runtime/scripts/hfs/rules/read.mjs +0 -45
- package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
- package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
- 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/test-world-slot.mjs +0 -5
- package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
- package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
- package/runtime/scripts/hfs/view.mjs +0 -180
- package/runtime/scripts/lib/declaration-surface.mjs +0 -166
- package/runtime/scripts/lib/dockerfile.mjs +0 -164
- package/runtime/scripts/lib/env.mjs +0 -18
- package/runtime/scripts/lib/event-contract.mjs +0 -102
- package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
- package/runtime/scripts/lib/git.mjs +0 -35
- package/runtime/scripts/lib/glob.mjs +0 -32
- package/runtime/scripts/lib/grammar-lint.mjs +0 -57
- package/runtime/scripts/lib/i18n.mjs +0 -82
- package/runtime/scripts/lib/in-order.mjs +0 -90
- package/runtime/scripts/lib/json-clone.mjs +0 -70
- package/runtime/scripts/lib/json.mjs +0 -44
- package/runtime/scripts/lib/language.mjs +0 -233
- package/runtime/scripts/lib/list.mjs +0 -26
- package/runtime/scripts/lib/mutation-fence.mjs +0 -20
- package/runtime/scripts/lib/package-at.mjs +0 -62
- package/runtime/scripts/lib/path-key.mjs +0 -124
- package/runtime/scripts/lib/read-text.mjs +0 -47
- package/runtime/scripts/lib/regex.mjs +0 -3
- package/runtime/scripts/lib/rule-packs.mjs +0 -243
- package/runtime/scripts/lib/same-text.mjs +0 -4
- package/runtime/scripts/lib/secret-patterns.mjs +0 -230
- package/runtime/scripts/lib/sops-envelope.mjs +0 -212
- package/runtime/scripts/lib/stack-services.mjs +0 -191
- package/runtime/scripts/lib/ts-analysis.mjs +0 -39
- package/runtime/scripts/lib/ts-ast.mjs +0 -63
- package/runtime/scripts/lib/walk.mjs +0 -45
- package/runtime/scripts/lib/yaml-cached.mjs +0 -14
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
// hfs-slots.mjs - the HFS slot manifest and app declaration, loaded once and asked four questions:
|
|
2
|
-
// which slot owns path P slotOf(P) / classifyPath(P) (an unknown path reports its nearest slot)
|
|
3
|
-
// is import A -> B allowed importAllowed(A, B) (tier matrix, cross-owner entry, cross-app, layers)
|
|
4
|
-
// which files are required requiredFiles(P) / requiredPaths()
|
|
5
|
-
// is this path tracked isTracked(P) / trackingOf(P); the rule catalog (knowledge/hfs/rules.yaml, modules/schemas/hfs-rules.schema.yaml) loads through loadRuleCatalog / rules().
|
|
6
|
-
// Every check and lint rule of HFS reads knowledge/hfs/slots.yaml through this module; none keeps its own path
|
|
7
|
-
// list. The manifest shape is modules/schemas/hfs-slots.schema.yaml and hfs.json is modules/schemas/hfs-repo.schema.yaml;
|
|
8
|
-
// the installed runtime carries no npm dependency, so this file re-states those shapes instead of loading ajv.
|
|
9
|
-
//
|
|
10
|
-
// A product is ONE app repository: hfs.json at the app root has kind `app` and declares its two sides, `be` and `fe`, each in
|
|
11
|
-
// the folder of that name. The resolver of the app answers for the whole tree: a root path with the slots of profile `app`,
|
|
12
|
-
// a path below a side folder with that side's resolver (profile be or fe, the side folder as its root: the side view), so
|
|
13
|
-
// every check and lint rule runs unchanged with a side folder as its repository root. Nothing crosses sides except the
|
|
14
|
-
// paths the declaration lists in `sides.<side>.reads` (a subset of the manifest's `sides.<side>.reads`).
|
|
15
|
-
//
|
|
16
|
-
// One loader, two manifest kinds. `kind: app` (the default; knowledge/hfs/slots.yaml) is the product standard above.
|
|
17
|
-
// `kind: runtime` (knowledge/hfs/runtime-slots.yaml, schema starci/runtime-slots@<major>) is the standard of the StarCi
|
|
18
|
-
// runtime repository itself: one profile `runtime`, no sides and no app kinds, slot ids runtime.<name>, the tracked value
|
|
19
|
-
// `generated` (a copy written only by the slot's `generatedBy`). A runtime repository declares itself with
|
|
20
|
-
// hfs.json {"hfs": <major>, "kind": "runtime", "project": <name>}.
|
|
21
|
-
import fs from 'node:fs';
|
|
22
|
-
import path from 'node:path';
|
|
23
|
-
import { skillRoot } from '../../engine/runtime-root.mjs';
|
|
24
|
-
import { parseYamlCached } from '../lib/yaml-cached.mjs';
|
|
25
|
-
import { braceVariants } from '../lib/glob.mjs';
|
|
26
|
-
import { APP_KIND, RUNTIME_KIND, manifestKind } from './manifest-shape.mjs';
|
|
27
|
-
import { APP_SCOPE, isSide, manifestShapeProblems, PROFILES } from './slot-manifest-shape.mjs';
|
|
28
|
-
import { manifestSemanticProblems } from './slot-semantic-problems.mjs';
|
|
29
|
-
import { classifyIn, ownerIn, slotEnabled, tierIn } from './slot-classify.mjs';
|
|
30
|
-
import { compileVariant, varsOf, variantsOf } from './slot-match.mjs';
|
|
31
|
-
import { importAllowedIn } from './slot-imports.mjs';
|
|
32
|
-
import { requiredFilesIn, requiredPathsIn } from './slot-required.mjs';
|
|
33
|
-
import { appResolver, isAppRepo } from './slot-app-view.mjs';
|
|
34
|
-
import { sideProblems } from './slot-side-problems.mjs';
|
|
35
|
-
import { declarationShapeProblems } from './declaration-shape.mjs';
|
|
36
|
-
import { declarationEdition, editionRuleParams, effectiveSlot, slotInEdition } from './edition-slots.mjs';
|
|
37
|
-
import { fail } from './slot-errors.mjs';
|
|
38
|
-
import { loadRuleCatalog } from './rule-catalog.mjs';
|
|
39
|
-
export { litePresenceOf, slotInEdition } from './edition-slots.mjs';
|
|
40
|
-
export { HfsSlotsError } from './slot-errors.mjs';
|
|
41
|
-
export { loadRuleCatalog };
|
|
42
|
-
export { rules } from './rule-catalog.mjs';
|
|
43
|
-
export { APP_SCOPE };
|
|
44
|
-
const HFS_MANIFEST_FILE = 'knowledge/hfs/slots.yaml';
|
|
45
|
-
/** The manifest of kind runtime: the standard tree of the StarCi runtime repository (judged by scripts/hfs/runtime-check.mjs). */
|
|
46
|
-
export const RUNTIME_MANIFEST_FILE = 'knowledge/hfs/runtime-slots.yaml';
|
|
47
|
-
export const HFS_DECLARATION_FILE = 'hfs.json';
|
|
48
|
-
export const SIDES = Object.freeze([...PROFILES]);
|
|
49
|
-
/**
|
|
50
|
-
* The rewriter of a side's finding messages: `(message) => message` with its paths made app-relative like the finding's own path.
|
|
51
|
-
* Every check and rule of a side judges the side folder as its root, so the paths it names (`apps/web/src/...`, `src/modules/...`,
|
|
52
|
-
* `tsconfig.json`) are side-relative. A path here is a token that starts at a word boundary with a top-level entry of the side folder
|
|
53
|
-
* (`sideRoot`, read once) and goes on with `/`, or is that entry when its name holds a dot (a file). An import specifier (`@/x`,
|
|
54
|
-
* `../x`) or a path already app-relative is left alone.
|
|
55
|
-
*/
|
|
56
|
-
export function appRelativeMessages(side, sideRoot) {
|
|
57
|
-
let entries = [];
|
|
58
|
-
try {
|
|
59
|
-
entries = fs.readdirSync(sideRoot).filter((name) => name !== 'node_modules' && !name.startsWith('.git'));
|
|
60
|
-
}
|
|
61
|
-
catch { /* no side folder: nothing to rewrite */ }
|
|
62
|
-
if (!entries.length)
|
|
63
|
-
return (message) => message;
|
|
64
|
-
const escaped = entries.sort((a, b) => b.length - a.length).map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`));
|
|
65
|
-
const token = new RegExp(`(^|[\\s'"\`(\\[{,;=<>])((?:${escaped.join('|')})(?=/|[\\s'"\`)\\]},;:!?<>]|\\.(?:\\s|$)|$))`, 'g');
|
|
66
|
-
return (message) => (typeof message === 'string' && message
|
|
67
|
-
? message.replace(token, (whole, before, entry, offset) => (message.startsWith('/', offset + whole.length) || entry.includes('.') ? `${before}${side}/${entry}` : whole))
|
|
68
|
-
: message);
|
|
69
|
-
}
|
|
70
|
-
// ------------------------------------------------------------------------------------------- manifest
|
|
71
|
-
/**
|
|
72
|
-
* The parsed and validated manifest. `text` (or `file`, or `root`) selects the source; the default is the runtime's own
|
|
73
|
-
* knowledge/hfs/slots.yaml. A manifest that fails its shape or a semantic rule is refused whole (HFS_MANIFEST_INVALID).
|
|
74
|
-
*/
|
|
75
|
-
export function loadSlotManifest({ root = skillRoot, file = path.join(root, HFS_MANIFEST_FILE), text } = {}) {
|
|
76
|
-
let doc;
|
|
77
|
-
try {
|
|
78
|
-
doc = parseYamlCached(text ?? fs.readFileSync(file, 'utf8'));
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
fail('HFS_MANIFEST_INVALID', `the slot manifest cannot be read (${String(error?.message ?? error).split('\n')[0]})`, { file });
|
|
82
|
-
}
|
|
83
|
-
const problems = manifestShapeProblems(doc);
|
|
84
|
-
if (!problems.length)
|
|
85
|
-
problems.push(...manifestSemanticProblems(doc, { varsOf, braceVariants, compileVariant }));
|
|
86
|
-
if (problems.length)
|
|
87
|
-
fail('HFS_MANIFEST_INVALID', `the slot manifest breaks its schema: ${problems.slice(0, 5).join('; ')}${problems.length > 5 ? '; and ' + (problems.length - 5) + ' more' : ''}`, { file, problems });
|
|
88
|
-
const [major, minor, patch] = doc.version.split('.').map(Number);
|
|
89
|
-
return Object.freeze({ ...doc, major, minor, patch });
|
|
90
|
-
}
|
|
91
|
-
// ------------------------------------------------------------------------------------- declaration
|
|
92
|
-
const declarationInvalid = (problems, file) => fail('HFS_DECLARATION_INVALID', `hfs.json is refused: ${problems.slice(0, 5).join('; ')}${problems.length > 5 ? '; and ' + (problems.length - 5) + ' more' : ''}`, { file, problems });
|
|
93
|
-
function runtimeDeclaration(manifest, declaration, file, side) {
|
|
94
|
-
if (side !== null)
|
|
95
|
-
fail('HFS_DECLARATION_INVALID', 'a runtime repository has no sides', { file, side });
|
|
96
|
-
return Object.freeze({
|
|
97
|
-
hfs: declaration.hfs,
|
|
98
|
-
kind: RUNTIME_KIND,
|
|
99
|
-
project: declaration.project,
|
|
100
|
-
side: null,
|
|
101
|
-
profile: RUNTIME_KIND,
|
|
102
|
-
apps: Object.freeze([]),
|
|
103
|
-
optionalSlots: Object.freeze([]),
|
|
104
|
-
connections: Object.freeze([]),
|
|
105
|
-
reads: Object.freeze([]),
|
|
106
|
-
manifestVersion: manifest.version,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
const connectionView = (c) => Object.freeze({ name: c.name, envPrefix: c.envPrefix, owner: c.owner, isolation: c.isolation, ...(c.provider !== undefined ? { provider: c.provider } : {}) });
|
|
110
|
-
/** The declaration of one side of an app, frozen: the view a check of that side folder runs under. */
|
|
111
|
-
function sideDeclaration(manifest, declaration, name, edition, providers) {
|
|
112
|
-
const s = declaration.sides[name];
|
|
113
|
-
return Object.freeze({
|
|
114
|
-
hfs: declaration.hfs,
|
|
115
|
-
kind: APP_KIND,
|
|
116
|
-
project: declaration.project,
|
|
117
|
-
edition,
|
|
118
|
-
side: name,
|
|
119
|
-
profile: name,
|
|
120
|
-
apps: Object.freeze(s.apps.map((a) => Object.freeze({ name: a.name, kind: a.kind }))),
|
|
121
|
-
optionalSlots: Object.freeze([...(s.optionalSlots ?? [])]),
|
|
122
|
-
patterns: Object.freeze([...(s.patterns ?? [])]), kinds: Object.freeze([...(s.kinds ?? [])]),
|
|
123
|
-
backing: Object.freeze([...(s.backing ?? [])]),
|
|
124
|
-
connections: Object.freeze((s.connections ?? []).map(connectionView)),
|
|
125
|
-
providers,
|
|
126
|
-
reads: Object.freeze([...(s.reads ?? [])]),
|
|
127
|
-
dbFunctions: Object.freeze((s.dbFunctions ?? []).map((entry) => Object.freeze({ ...entry }))),
|
|
128
|
-
sqlPassThrough: Object.freeze((s.sqlPassThrough ?? []).map((entry) => Object.freeze({ ...entry }))),
|
|
129
|
-
...(s.grammar === undefined ? {} : { grammar: s.grammar }),
|
|
130
|
-
...(s.extraPackages === undefined ? {} : { extraPackages: Object.freeze(s.extraPackages.map((entry) => Object.freeze({ ...entry }))) }),
|
|
131
|
-
manifestVersion: manifest.version,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/** R334: an app's bare database function name must be a pg built-in the canon lists bare (ruleParams.be.dbFunctions); any other is schema.name. */
|
|
135
|
-
function bareDbFunctionProblems(manifest, be) {
|
|
136
|
-
const builtins = new Set((manifest.ruleParams?.be?.dbFunctions ?? []).map((entry) => entry.name).filter((name) => !name.includes('.')));
|
|
137
|
-
return (be?.dbFunctions ?? []).filter((entry) => !entry.name.includes('.') && !builtins.has(entry.name))
|
|
138
|
-
.map((entry) => `sides.be.dbFunctions names ${entry.name} bare, but a bare name is only a pg built-in of the canon's list (ruleParams.be.dbFunctions); name a function of a migration schema-qualified (public.${entry.name})`);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* A declaration checked against the manifest: kind app, the pinned major the manifest's (HFS_MANIFEST_MAJOR_MISMATCH otherwise,
|
|
142
|
-
* and there is no compatibility window), and per side: app kinds of that profile, optionalSlots naming only opt-in slots of the
|
|
143
|
-
* side that no app kind implies, every required app kind declared, reads within the manifest's. Returns the app (profile app,
|
|
144
|
-
* its two sides under `sides`), or with `side` that side's view: the declaration a check of the side folder runs under.
|
|
145
|
-
*/
|
|
146
|
-
export function resolveRepoDeclaration(manifest, declaration, { file = HFS_DECLARATION_FILE, side = null } = {}) {
|
|
147
|
-
const problems = declarationShapeProblems(declaration, PROFILES);
|
|
148
|
-
if (problems.length)
|
|
149
|
-
declarationInvalid(problems, file);
|
|
150
|
-
if (declaration.kind !== manifestKind(manifest))
|
|
151
|
-
declarationInvalid([`hfs.json is of kind ${declaration.kind}, but the manifest it is judged by is of kind ${manifestKind(manifest)}`], file);
|
|
152
|
-
if (declaration.hfs !== manifest.major)
|
|
153
|
-
fail('HFS_MANIFEST_MAJOR_MISMATCH', `hfs.json pins manifest major ${declaration.hfs} but the manifest is ${manifest.version}`, { pinned: declaration.hfs, manifest: manifest.version, manifestMajor: manifest.major, file });
|
|
154
|
-
if (declaration.kind === RUNTIME_KIND)
|
|
155
|
-
return runtimeDeclaration(manifest, declaration, file, side);
|
|
156
|
-
const { edition, known, valid } = declarationEdition(manifest, declaration);
|
|
157
|
-
if (!valid)
|
|
158
|
-
fail('HFS_EDITION_INVALID', `hfs.json edition is ${JSON.stringify(declaration.edition)}; the editions this manifest knows are ${known.join(', ')} (absent means full)`, { file, edition: declaration.edition });
|
|
159
|
-
const bad = [...PROFILES.flatMap((name) => sideProblems(manifest, name, declaration.sides[name], edition)), ...bareDbFunctionProblems(manifest, declaration.sides.be)];
|
|
160
|
-
if (bad.length)
|
|
161
|
-
declarationInvalid(bad, file);
|
|
162
|
-
if (side !== null && !isSide(side))
|
|
163
|
-
fail('HFS_DECLARATION_INVALID', `${side} is not a side of an app (be, fe)`, { file, side });
|
|
164
|
-
// A provider declared on any connection enables the provider slots of every profile (a fe side declares none): each view carries the union.
|
|
165
|
-
const providers = Object.freeze([...new Set(PROFILES.flatMap((name) => (declaration.sides[name].connections ?? []).map((c) => c.provider).filter((p) => p !== undefined)))]);
|
|
166
|
-
const sides = Object.fromEntries(PROFILES.map((name) => [name, sideDeclaration(manifest, declaration, name, edition, providers)]));
|
|
167
|
-
if (side !== null)
|
|
168
|
-
return sides[side];
|
|
169
|
-
return Object.freeze({
|
|
170
|
-
hfs: declaration.hfs,
|
|
171
|
-
kind: APP_KIND,
|
|
172
|
-
project: declaration.project,
|
|
173
|
-
edition,
|
|
174
|
-
side: null,
|
|
175
|
-
profile: APP_SCOPE,
|
|
176
|
-
// The root declares no app or connection of its own (each side does); its opt-in slots are the browser journey and the managed
|
|
177
|
-
// tsconfig.json that type-checks it, both switched on by `browser: true`.
|
|
178
|
-
apps: Object.freeze([]),
|
|
179
|
-
optionalSlots: Object.freeze(declaration.browser === true ? ['app.browser', 'app.browser-config'] : []),
|
|
180
|
-
modules: declaration.modules === 'data' ? 'data' : 'packages',
|
|
181
|
-
connections: Object.freeze([]),
|
|
182
|
-
providers,
|
|
183
|
-
reads: Object.freeze([]),
|
|
184
|
-
sides: Object.freeze(sides),
|
|
185
|
-
manifestVersion: manifest.version,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* The view of a whole app (profile app, both sides) that resolveRepoDeclaration builds for an app declaration; a declaration that
|
|
190
|
-
* resolves to a view without sides (a runtime repository) is refused HFS_DECLARATION_INVALID.
|
|
191
|
-
*/
|
|
192
|
-
export function resolveAppDeclaration(manifest, declaration, { file = HFS_DECLARATION_FILE } = {}) {
|
|
193
|
-
const view = resolveRepoDeclaration(manifest, declaration, { file });
|
|
194
|
-
if (!isAppRepo(view))
|
|
195
|
-
declarationInvalid([`a ${view.kind} declaration has no sides`], file);
|
|
196
|
-
return view;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Where the declaration of `dir` lives: `dir` itself when it holds hfs.json (the app root), else its parent when `dir` is a side
|
|
200
|
-
* folder (be/ or fe/) of an app (the side view). `{ file, appRoot, side }`; side is null at the app root.
|
|
201
|
-
*/
|
|
202
|
-
export function locateDeclaration(dir) {
|
|
203
|
-
const own = path.join(dir, HFS_DECLARATION_FILE);
|
|
204
|
-
if (fs.existsSync(own))
|
|
205
|
-
return { file: own, appRoot: dir, side: null };
|
|
206
|
-
const parent = path.dirname(dir);
|
|
207
|
-
const side = path.basename(dir);
|
|
208
|
-
const up = path.join(parent, HFS_DECLARATION_FILE);
|
|
209
|
-
if (isSide(side) && fs.existsSync(up))
|
|
210
|
-
return { file: up, appRoot: parent, side };
|
|
211
|
-
return { file: own, appRoot: dir, side: null };
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* hfs.json of the app at `repoRoot` (the app itself), or of the app whose side folder `repoRoot` is (that side's view), parsed and
|
|
215
|
-
* resolved; a missing or unreadable file is a refusal, never "unavailable".
|
|
216
|
-
*/
|
|
217
|
-
export function readRepoDeclaration(manifest, repoRoot) {
|
|
218
|
-
const { file, side } = locateDeclaration(repoRoot);
|
|
219
|
-
let declaration;
|
|
220
|
-
try {
|
|
221
|
-
declaration = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
declarationInvalid([`hfs.json cannot be read (${String(error?.code ?? error?.message ?? error).split('\n')[0]})`], file);
|
|
225
|
-
}
|
|
226
|
-
return resolveRepoDeclaration(manifest, declaration, { file, side });
|
|
227
|
-
}
|
|
228
|
-
// ------------------------------------------------------------------------------------------- resolver
|
|
229
|
-
/**
|
|
230
|
-
* The four questions for one scope: the app root (profile app, root paths) or one side (profile be or fe, paths relative to the
|
|
231
|
-
* side folder). createSlotResolver composes them; nothing else calls this.
|
|
232
|
-
*/
|
|
233
|
-
function createScopeResolver(manifest, repo) {
|
|
234
|
-
const profile = repo.profile;
|
|
235
|
-
const edition = repo.edition ?? 'full';
|
|
236
|
-
const slots = manifest.slots.filter((s) => s.managedOnly !== true && s.profiles.includes(profile) && slotInEdition(manifest, s, edition)).map((s) => effectiveSlot(s, profile, edition));
|
|
237
|
-
const scope = { manifest, repo, profile, slots, byId: new Map(slots.map((s) => [s.id, s])), variants: slots.flatMap(variantsOf), appKind: new Map(repo.apps.map((a) => [a.name, a.kind])) };
|
|
238
|
-
const classifyPath = (input) => classifyIn(scope, input);
|
|
239
|
-
/** tracked | ignored | external for the slot owning `p`, or null when no slot owns it. */
|
|
240
|
-
const trackingOf = (p) => classifyPath(p).tracking ?? null;
|
|
241
|
-
return Object.freeze({
|
|
242
|
-
repo,
|
|
243
|
-
slot: (id) => scope.byId.get(id) ?? null,
|
|
244
|
-
slots: () => slots,
|
|
245
|
-
slotEnabled: (slot) => slotEnabled(scope, slot),
|
|
246
|
-
classifyPath,
|
|
247
|
-
slotOf: (p) => { const c = classifyPath(p); return c.slot ? scope.byId.get(c.slot) : null; },
|
|
248
|
-
ownerOf: (input) => ownerIn(scope, input),
|
|
249
|
-
tierOf: (input) => tierIn(scope, input),
|
|
250
|
-
importAllowed: (fromPath, toPath) => importAllowedIn(scope, fromPath, toPath),
|
|
251
|
-
requiredFiles: (input) => requiredFilesIn(scope, input),
|
|
252
|
-
requiredPaths: () => requiredPathsIn(scope),
|
|
253
|
-
trackingOf,
|
|
254
|
-
/** True only for a path a slot owns and requires to be committed. */
|
|
255
|
-
isTracked: (p) => trackingOf(p) === 'tracked',
|
|
256
|
-
// The app's own database functions and SQL pass-through files (hfs.json sides.be.dbFunctions, sides.be.sqlPassThrough) join the canon's lists (R334).
|
|
257
|
-
ruleParams: () => withDeclaredLists(ruleParams(manifest, profile, edition), repo),
|
|
258
|
-
allowedImports: (tier) => manifest.tiers[profile]?.[tier]?.mayImport ?? null,
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* The four questions for one app, or for one side of it. `repo` comes from resolveRepoDeclaration / readRepoDeclaration.
|
|
263
|
-
* Paths are relative to the root the declaration was resolved for (backslashes and a leading ./ are folded; a trailing / or a
|
|
264
|
-
* directory path is fine): a side view (repo.side set) answers for the side folder as its root, exactly as a check of that side
|
|
265
|
-
* runs; the app (profile app) answers a root path with the app-root slots and a path below be/ or fe/ with that side's view,
|
|
266
|
-
* the side prefixed back onto every path and root it returns (and `side` added). Only the declared `reads` cross sides.
|
|
267
|
-
*/
|
|
268
|
-
export function createSlotResolver(manifest, repo) {
|
|
269
|
-
if (repo.profile !== APP_SCOPE)
|
|
270
|
-
return createScopeResolver(manifest, repo);
|
|
271
|
-
// The root declares no connection of its own, yet a provider slot of the app profile is enabled by a
|
|
272
|
-
// side's connection with that provider: the root scope reads the union of the sides' connections.
|
|
273
|
-
// reason: the profile is app, so the declaration resolveRepoDeclaration built carries both sides
|
|
274
|
-
const app = repo;
|
|
275
|
-
const root = createScopeResolver(manifest, { ...repo, connections: SIDES.flatMap((side) => app.sides[side].connections) });
|
|
276
|
-
const sides = Object.fromEntries(PROFILES.map((side) => [side, createScopeResolver(manifest, app.sides[side])]));
|
|
277
|
-
return appResolver(app, root, sides);
|
|
278
|
-
}
|
|
279
|
-
/** The rule parameters with the app's declared database functions and SQL pass-through files appended to `dbFunctions` and `sqlPassThrough` (be only), the result frozen. */
|
|
280
|
-
const withDeclaredLists = (params, repo) => {
|
|
281
|
-
const functions = repo.dbFunctions ?? [];
|
|
282
|
-
const passThrough = repo.sqlPassThrough ?? [];
|
|
283
|
-
if ((params.dbFunctions === undefined && !functions.length) && (params.sqlPassThrough === undefined && !passThrough.length))
|
|
284
|
-
return params;
|
|
285
|
-
return Object.freeze({
|
|
286
|
-
...params,
|
|
287
|
-
...(params.dbFunctions === undefined && !functions.length ? {} : { dbFunctions: [...(params.dbFunctions ?? []), ...functions] }),
|
|
288
|
-
...(params.sqlPassThrough === undefined && !passThrough.length ? {} : { sqlPassThrough: [...(params.sqlPassThrough ?? []), ...passThrough] }),
|
|
289
|
-
});
|
|
290
|
-
};
|
|
291
|
-
/** The rule parameters of one profile (be: infraOwners, suffixes, bannedSuffixes and the rest over the shared ruleParams.common fileLines and duplicateBlock; fe: common alone or with its overrides; runtime: ruleParams.runtime of a runtime manifest), as a frozen deep copy. Under `edition` lite the `lite` overrides of ruleParams.<profile> merge over the base (the `lite` key itself is never returned). */
|
|
292
|
-
export function ruleParams(manifest, profile, edition = 'full') {
|
|
293
|
-
const profiles = manifestKind(manifest) === RUNTIME_KIND ? [RUNTIME_KIND] : PROFILES;
|
|
294
|
-
if (!profiles.includes(profile))
|
|
295
|
-
fail('HFS_MANIFEST_INVALID', `ruleParams has no profile ${profile}`, { profile });
|
|
296
|
-
return editionRuleParams({ ...manifest.ruleParams.common, ...manifest.ruleParams[profile] }, edition);
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* The manifest of this runtime plus the resolver for the app or side folder at `repoRoot` (a side folder gets that side's view), or
|
|
300
|
-
* for an already-parsed declaration (the app, or with `side` that side's view).
|
|
301
|
-
*/
|
|
302
|
-
export function openHfs({ root = skillRoot, repoRoot, declaration, side = null, manifest = loadSlotManifest({ root }) } = {}) {
|
|
303
|
-
const repo = declaration !== undefined ? resolveRepoDeclaration(manifest, declaration, { side }) : readRepoDeclaration(manifest, repoRoot);
|
|
304
|
-
const resolver = createSlotResolver(manifest, repo);
|
|
305
|
-
return { manifest, ...resolver, rules: () => loadRuleCatalog({ root, manifest }) };
|
|
306
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// test-world-slot.mjs - the one answer of the machine checks to "is this slot the test world": the slot `be.tests.world` or one of its
|
|
2
|
-
// sub-slots (`be.tests.world.kit`, the world's inlined helpers), which form one test composition root. The lint side asks the same of
|
|
3
|
-
// the slot view through `inTestWorld` of packages/eslint/be/lib/hfs.mjs.
|
|
4
|
-
/** True when `slot` (a slot id, or a file's slot) belongs to the test world family. */
|
|
5
|
-
export const isTestWorldSlot = (slot) => typeof slot === 'string' && (slot === 'be.tests.world' || slot.startsWith('be.tests.world.'));
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Trailing-slash trimming for slot paths and generated roots, linear in the length of the text.
|
|
2
|
-
/** `text` without its trailing `/` characters. */
|
|
3
|
-
export function trimTrailingSlashes(text) {
|
|
4
|
-
let end = text.length;
|
|
5
|
-
while (end > 0 && text.codePointAt(end - 1) === 47)
|
|
6
|
-
end -= 1;
|
|
7
|
-
return text.slice(0, end);
|
|
8
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { byCodeUnit } from '../lib/list.mjs';
|
|
4
|
-
const runs = new AsyncLocalStorage();
|
|
5
|
-
/** Share compiler inputs only until this check finishes; nested callers join the same run. */
|
|
6
|
-
export function withTypeScriptProgramRun(run) {
|
|
7
|
-
return runs.getStore() ? run() : runs.run(new Map(), run);
|
|
8
|
-
}
|
|
9
|
-
function keyOf(value) {
|
|
10
|
-
if (value === undefined)
|
|
11
|
-
return 'u';
|
|
12
|
-
if (value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
|
|
13
|
-
return JSON.stringify(value);
|
|
14
|
-
if (Array.isArray(value)) {
|
|
15
|
-
const items = value.map(keyOf);
|
|
16
|
-
return items.includes(null) ? null : `[${items.join(',')}]`;
|
|
17
|
-
}
|
|
18
|
-
if (typeof value !== 'object' || (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null))
|
|
19
|
-
return null;
|
|
20
|
-
const entries = [];
|
|
21
|
-
for (const name of Object.keys(value).sort(byCodeUnit)) {
|
|
22
|
-
const item = keyOf(value[name]);
|
|
23
|
-
if (item === null)
|
|
24
|
-
return null;
|
|
25
|
-
entries.push(`${JSON.stringify(name)}:${item}`);
|
|
26
|
-
}
|
|
27
|
-
return `{${entries.join(',')}}`;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* build(), shared inside a program run by every caller that asks for the same kind, compiler and input. An input that
|
|
31
|
-
* is not plain data (a function, a class instance) is never shared.
|
|
32
|
-
*/
|
|
33
|
-
export function sharedInProgramRun(kind, ts, input, build) {
|
|
34
|
-
const values = runs.getStore();
|
|
35
|
-
const key = values ? keyOf(input) : null;
|
|
36
|
-
if (key === null || !values)
|
|
37
|
-
return build();
|
|
38
|
-
let byKey = values.get(ts);
|
|
39
|
-
if (!byKey) {
|
|
40
|
-
byKey = new Map();
|
|
41
|
-
values.set(ts, byKey);
|
|
42
|
-
}
|
|
43
|
-
const id = `${kind}\0${key}`;
|
|
44
|
-
if (!byKey.has(id))
|
|
45
|
-
byKey.set(id, build());
|
|
46
|
-
return byKey.get(id);
|
|
47
|
-
}
|
|
48
|
-
/** ts.createProgram, shared inside a program run. */
|
|
49
|
-
export function createTypeScriptProgram(ts, { rootNames, options, projectReferences }) {
|
|
50
|
-
return sharedInProgramRun('program', ts, { rootNames, options, projectReferences }, () => ts.createProgram({ rootNames, options, projectReferences, host: sharedSourceHost(ts, options) })); // exactOptionalPropertyTypes: the optional host and references are passed through as undefined, as before
|
|
51
|
-
}
|
|
52
|
-
function sharedSourceHost(ts, options) {
|
|
53
|
-
if (!runs.getStore())
|
|
54
|
-
return undefined;
|
|
55
|
-
const registry = sharedInProgramRun('documents', ts, null, () => ts.createDocumentRegistry(ts.sys.useCaseSensitiveFileNames, ts.sys.getCurrentDirectory()));
|
|
56
|
-
const host = ts.createCompilerHost(options);
|
|
57
|
-
const readSource = host.getSourceFile;
|
|
58
|
-
// TypeScript's registry separates parse-affecting settings and Node module formats. Sharing syntax trees leaves
|
|
59
|
-
// module resolution and symbol/type caches with each program, including projects with different path aliases.
|
|
60
|
-
host.getSourceFile = (file, sourceOptions, onError, fresh) => {
|
|
61
|
-
if (fresh)
|
|
62
|
-
return readSource(file, sourceOptions, onError, fresh);
|
|
63
|
-
let text;
|
|
64
|
-
try {
|
|
65
|
-
text = host.readFile(file);
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
onError?.(String(error.message ?? error));
|
|
69
|
-
text = '';
|
|
70
|
-
}
|
|
71
|
-
if (text === undefined)
|
|
72
|
-
return undefined;
|
|
73
|
-
return registry.acquireDocument(file, options, ts.ScriptSnapshot.fromString(text), '0', undefined, sourceOptions);
|
|
74
|
-
};
|
|
75
|
-
return host;
|
|
76
|
-
}
|
|
77
|
-
/** Read and expand a tsconfig with the caller's TypeScript compiler and optional tracked file reader. */
|
|
78
|
-
export function readTypeScriptProject(ts, configFile, readFile = ts.sys.readFile) {
|
|
79
|
-
const read = ts.readConfigFile(configFile, readFile);
|
|
80
|
-
if (read.error)
|
|
81
|
-
return { read: read, parsed: null };
|
|
82
|
-
const host = readFile === ts.sys.readFile ? ts.sys : { ...ts.sys, readFile };
|
|
83
|
-
return { read: read, parsed: ts.parseJsonConfigFileContent(read.config, host, path.dirname(configFile), undefined, configFile) };
|
|
84
|
-
}
|
|
85
|
-
/** Resolve a project reference with the compiler's API, including older compiler fallback. */
|
|
86
|
-
export function typeScriptProjectReferencePath(ts, reference) {
|
|
87
|
-
if (typeof ts.resolveProjectReferencePath === 'function')
|
|
88
|
-
return ts.resolveProjectReferencePath(reference);
|
|
89
|
-
return path.extname(reference.path) ? reference.path : path.join(reference.path, 'tsconfig.json');
|
|
90
|
-
}
|
|
91
|
-
/** Resolve an import using the selected project's compiler options. */
|
|
92
|
-
export function resolveTypeScriptModule(ts, specifier, from, options, host, cache) {
|
|
93
|
-
const resolverHost = host === undefined ? ts.sys : host;
|
|
94
|
-
return ts.resolveModuleName(specifier, from, options, resolverHost, cache).resolvedModule?.resolvedFileName;
|
|
95
|
-
}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
// hfs-view.mjs - the frozen view of one side of an app (be/ or fe/, the side folder as its root) that the lint factories hand
|
|
2
|
-
// their rules (`settings.starci.hfs`). Both @starci/eslint-canon-be and @starci/eslint-canon-fe ship a byte copy of this file in their
|
|
3
|
-
// runtime/ bundle (scripts/hfs/sync-runtime.mjs), so a path-scoped rule in either package asks the SAME resolver the
|
|
4
|
-
// architecture machine and `starci app check` use, and never tests a path with a regular expression of its own.
|
|
5
|
-
import fs from 'node:fs';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
import { allowsFile } from './allows.mjs';
|
|
8
|
-
import { openHfs } from './slots.mjs';
|
|
9
|
-
import { ROOT_PACKAGE_SLOTS } from './architecture/root-packages.mjs';
|
|
10
|
-
const posix = (p) => String(p).replaceAll('\\', '/');
|
|
11
|
-
const isAbsoluteAny = (text) => path.isAbsolute(text) || /^[A-Za-z]:\//.test(text);
|
|
12
|
-
/**
|
|
13
|
-
* The view rules read, over an opened resolver.
|
|
14
|
-
*
|
|
15
|
-
* @param {object} opened - The result of `openHfs` (manifest, repo and resolver methods).
|
|
16
|
-
* @param {string} repoRoot - The absolute repository root.
|
|
17
|
-
* @returns {object} The frozen view: profile, apps, connections, patterns, ruleParams, relative, classify, slotOf, tierOf, ownerOf, slot.
|
|
18
|
-
*/
|
|
19
|
-
function hfsView(opened, repoRoot) {
|
|
20
|
-
const rel = (file) => {
|
|
21
|
-
const text = posix(file);
|
|
22
|
-
if (!isAbsoluteAny(text))
|
|
23
|
-
return text.replace(/^\.\//, '');
|
|
24
|
-
return posix(path.relative(repoRoot, file));
|
|
25
|
-
};
|
|
26
|
-
const slotCache = new Map();
|
|
27
|
-
const classify = (file) => {
|
|
28
|
-
const key = rel(file);
|
|
29
|
-
if (!slotCache.has(key))
|
|
30
|
-
slotCache.set(key, opened.classifyPath(key));
|
|
31
|
-
return slotCache.get(key);
|
|
32
|
-
};
|
|
33
|
-
return Object.freeze({
|
|
34
|
-
repoRoot,
|
|
35
|
-
profile: opened.repo.profile,
|
|
36
|
-
side: opened.repo.side ?? null,
|
|
37
|
-
edition: opened.repo.edition ?? 'full',
|
|
38
|
-
...(opened.repo.grammar === undefined ? {} : { grammar: opened.repo.grammar }),
|
|
39
|
-
apps: opened.repo.apps,
|
|
40
|
-
connections: opened.repo.connections,
|
|
41
|
-
patterns: Object.freeze([...(opened.repo.patterns ?? [])]),
|
|
42
|
-
ruleParams: opened.ruleParams(),
|
|
43
|
-
/** The repository-relative, forward-slash form of a linted filename. */
|
|
44
|
-
relative: rel,
|
|
45
|
-
/** The classification of a file: `{ slot, tier, owner?, bindings? ... }` or a no-slot status. */
|
|
46
|
-
classify,
|
|
47
|
-
/** The slot id that owns a file, or null when no slot does. */
|
|
48
|
-
slotOf: (file) => classify(file).slot ?? null,
|
|
49
|
-
/** The tier of a file, or null. */
|
|
50
|
-
tierOf: (file) => opened.tierOf(rel(file)) ?? null,
|
|
51
|
-
/** The owner root of a file, or null. */
|
|
52
|
-
ownerOf: (file) => opened.ownerOf(rel(file))?.root ?? null,
|
|
53
|
-
/** What the slot that owns a file says about it: `{ slot, root, relative, allowed, entry?, forbiddenBy?, allows }`, or null when the slot names no `allows`. */
|
|
54
|
-
allows: (file) => allowsFile(opened, rel(file)),
|
|
55
|
-
/** A slot definition by id. */
|
|
56
|
-
slot: (id) => opened.slot(id),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* The view of the app folder on disk at `repoRoot`, against the manifest under `runtimeRoot`: a side folder (be/, fe/) finds the
|
|
61
|
-
* app-root hfs.json one level up and gets that side's view, so every linted file below it is judged by its own side's slots.
|
|
62
|
-
*
|
|
63
|
-
* @param {{ runtimeRoot: string, repoRoot: string }} input - Where the manifest copy lives and the side folder (or app root).
|
|
64
|
-
* @returns {object} The frozen view.
|
|
65
|
-
*/
|
|
66
|
-
export const openHfsView = ({ runtimeRoot, repoRoot }) => hfsView(openHfs({ root: runtimeRoot, repoRoot }), repoRoot);
|
|
67
|
-
/**
|
|
68
|
-
* The view of one side of an in-memory app declaration (rule tests): no file is read except the manifest.
|
|
69
|
-
*
|
|
70
|
-
* @param {{ runtimeRoot: string, declaration: object, repoRoot: string, side: string }} input - Manifest root, hfs.json object, the linted side folder, its side.
|
|
71
|
-
* @returns {object} The frozen view.
|
|
72
|
-
*/
|
|
73
|
-
export const declaredHfsView = ({ runtimeRoot, declaration, repoRoot, side }) => hfsView(openHfs({ root: runtimeRoot, declaration, side }), repoRoot);
|
|
74
|
-
const CONTRACT_KEYS = ['errorBase', 'outcome'];
|
|
75
|
-
/**
|
|
76
|
-
* The contract of the package at `packageDir` (app-root relative, `packages/<pkg>`), read from the `starci` key of its manifest. A
|
|
77
|
-
* declaration that is not `{ name, file }` with an identifier name and a file inside `src/` stops the lint, because a rule must not guess.
|
|
78
|
-
*
|
|
79
|
-
* @param {string} repoRoot - The absolute app root.
|
|
80
|
-
* @param {string} packageDir - The package folder, relative to the app root.
|
|
81
|
-
* @returns {object} The declared error base and outcome union, each with its file relative to the app root.
|
|
82
|
-
*/
|
|
83
|
-
export const readPackageContract = (repoRoot, packageDir) => {
|
|
84
|
-
const manifestPath = path.join(repoRoot, packageDir, 'package.json');
|
|
85
|
-
const manifest = (fs.existsSync(manifestPath) ? JSON.parse(fs.readFileSync(manifestPath, 'utf8')) : null);
|
|
86
|
-
const declared = manifest?.starci;
|
|
87
|
-
if (declared === undefined)
|
|
88
|
-
return {};
|
|
89
|
-
if (typeof declared !== 'object' || declared === null)
|
|
90
|
-
throw new Error(`${packageDir}/package.json: "starci" is an object ({ errorBase, outcome })`);
|
|
91
|
-
const contract = {};
|
|
92
|
-
for (const key of CONTRACT_KEYS) {
|
|
93
|
-
const entry = declared[key];
|
|
94
|
-
if (entry === undefined)
|
|
95
|
-
continue;
|
|
96
|
-
const { name, file } = (typeof entry === 'object' && entry !== null ? entry : {});
|
|
97
|
-
if (typeof name !== 'string' || !/^[A-Za-z_$][\w$]*$/.test(name) || typeof file !== 'string' || !/^src\/(?:[\w.-]+\/)*[\w.-]+\.ts$/.test(file)) {
|
|
98
|
-
throw new Error(`${packageDir}/package.json: "starci.${key}" is { "name": "<Identifier>", "file": "src/<path>.ts" }`);
|
|
99
|
-
}
|
|
100
|
-
contract[key] = Object.freeze({ name, file: `${packageDir}/${file}` });
|
|
101
|
-
}
|
|
102
|
-
return Object.freeze(contract);
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* The view of the root workspace packages of an app (`packages/<pkg>/src/**`, slots app.packages and app.module-registry), as the lint of one
|
|
106
|
-
* side sees them: the rule parameters, the apps and the Grammar of `side` (a package is judged by the laws of the side whose subpath a file
|
|
107
|
-
* sits in), and the paths of the APP ROOT (`repoRoot` is the app root, not a side folder). The slots answer for the root paths; a file of a
|
|
108
|
-
* package is of the tier `package` and has no owner: the owner laws (one `index.ts` per owner root) are the module folders', a package's public
|
|
109
|
-
* surface being the `exports` of its manifest.
|
|
110
|
-
*
|
|
111
|
-
* @param {object} opened - The result of `openHfs` for the app root (profile app, both sides resolved).
|
|
112
|
-
* @param {string} repoRoot - The absolute app root.
|
|
113
|
-
* @param {string} side - `be` or `fe`: the side whose laws the file is judged by.
|
|
114
|
-
* @returns {object} The frozen view: the profile of the side over the paths of the app root.
|
|
115
|
-
*/
|
|
116
|
-
function packagesView(opened, repoRoot, side) {
|
|
117
|
-
const scope = opened.sides?.[side];
|
|
118
|
-
const sideRepo = opened.repo.sides?.[side];
|
|
119
|
-
if (scope === undefined || sideRepo === undefined)
|
|
120
|
-
throw new Error('the view of the root packages needs the declaration of an app with both sides');
|
|
121
|
-
const rel = (file) => {
|
|
122
|
-
const text = posix(file);
|
|
123
|
-
return isAbsoluteAny(text) ? posix(path.relative(repoRoot, file)) : text.replace(/^\.\//, '');
|
|
124
|
-
};
|
|
125
|
-
const cache = new Map();
|
|
126
|
-
const classify = (file) => {
|
|
127
|
-
const key = rel(file);
|
|
128
|
-
if (!cache.has(key))
|
|
129
|
-
cache.set(key, opened.classifyPath(key));
|
|
130
|
-
return cache.get(key);
|
|
131
|
-
};
|
|
132
|
-
const packageOf = (file) => {
|
|
133
|
-
const slot = classify(file).slot;
|
|
134
|
-
const relative = rel(file);
|
|
135
|
-
return slot !== undefined && ROOT_PACKAGE_SLOTS.has(slot) ? relative.split('/').slice(0, 2).join('/') : null;
|
|
136
|
-
};
|
|
137
|
-
const contracts = new Map();
|
|
138
|
-
const packageContract = (file) => {
|
|
139
|
-
const dir = packageOf(file);
|
|
140
|
-
if (dir === null)
|
|
141
|
-
return null;
|
|
142
|
-
if (!contracts.has(dir))
|
|
143
|
-
contracts.set(dir, readPackageContract(repoRoot, dir));
|
|
144
|
-
return contracts.get(dir);
|
|
145
|
-
};
|
|
146
|
-
return Object.freeze({
|
|
147
|
-
repoRoot,
|
|
148
|
-
profile: side,
|
|
149
|
-
side,
|
|
150
|
-
edition: opened.repo.edition ?? 'full',
|
|
151
|
-
...(sideRepo.grammar === undefined ? {} : { grammar: sideRepo.grammar }),
|
|
152
|
-
apps: sideRepo.apps,
|
|
153
|
-
connections: sideRepo.connections,
|
|
154
|
-
patterns: Object.freeze([...(sideRepo.patterns ?? [])]),
|
|
155
|
-
ruleParams: scope.ruleParams(),
|
|
156
|
-
relative: rel,
|
|
157
|
-
classify,
|
|
158
|
-
slotOf: (file) => classify(file).slot ?? null,
|
|
159
|
-
tierOf: (file) => (packageOf(file) === null ? null : 'package'),
|
|
160
|
-
// A package is no owner of the module laws (one index.ts at the owner root): its public surface is the `exports` of its manifest, so no file of it has an owner.
|
|
161
|
-
ownerOf: () => null,
|
|
162
|
-
allows: (file) => allowsFile(opened, rel(file)),
|
|
163
|
-
slot: (id) => opened.slot(id),
|
|
164
|
-
packageContract,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* The view of the root packages of the app at `repoRoot` (the app root, where the root `eslint.config.mjs` lives), for the laws of `side`.
|
|
169
|
-
*
|
|
170
|
-
* @param {{ runtimeRoot: string, repoRoot: string, side: string }} input - Where the manifest copy lives, the app root, and the side whose laws apply.
|
|
171
|
-
* @returns {object} The frozen view.
|
|
172
|
-
*/
|
|
173
|
-
export const openPackagesHfsView = ({ runtimeRoot, repoRoot, side }) => packagesView(openHfs({ root: runtimeRoot, repoRoot }), repoRoot, side);
|
|
174
|
-
/**
|
|
175
|
-
* The view of the root packages of an in-memory app declaration (rule tests): no file is read except the manifest.
|
|
176
|
-
*
|
|
177
|
-
* @param {{ runtimeRoot: string, declaration: object, repoRoot: string, side: string }} input - Manifest root, the app hfs.json object, the app root and the side.
|
|
178
|
-
* @returns {object} The frozen view.
|
|
179
|
-
*/
|
|
180
|
-
export const declaredPackagesHfsView = ({ runtimeRoot, declaration, repoRoot, side }) => packagesView(openHfs({ root: runtimeRoot, declaration }), repoRoot, side);
|