@starci/eslint-canon-be 3.8.20 → 3.9.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 +8 -0
- package/package.json +1 -1
- package/runtime/bundle.json +192 -0
- package/runtime/engine/by-code-unit.mjs +6 -6
- package/runtime/engine/model-config.mjs +98 -76
- package/runtime/engine/orca-config.mjs +22 -17
- package/runtime/engine/release-config.mjs +22 -18
- package/runtime/engine/removed-vocabulary.mjs +21 -20
- package/runtime/engine/resources-config.mjs +42 -35
- package/runtime/engine/runtime-root.mjs +11 -13
- package/runtime/engine/secrets.mjs +170 -102
- package/runtime/engine/sonar-config.mjs +16 -13
- package/runtime/engine/temp-root.mjs +3 -9
- package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
- package/runtime/knowledge/hfs/rules.yaml +6 -6
- package/runtime/knowledge/hfs/slots.yaml +2 -2
- package/runtime/knowledge/sonar-gate.yaml +1 -1
- package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
- package/runtime/scripts/api/git/cat-file.mjs +0 -1
- package/runtime/scripts/api/git/config-get.mjs +1 -2
- package/runtime/scripts/api/git/diff.mjs +0 -1
- package/runtime/scripts/api/git/lib.mjs +32 -32
- package/runtime/scripts/api/git/ls-files.mjs +0 -1
- package/runtime/scripts/api/git/ls-tree.mjs +0 -1
- package/runtime/scripts/api/git/merge-base.mjs +2 -3
- package/runtime/scripts/api/git/remote.mjs +0 -1
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
- package/runtime/scripts/api/git/show.mjs +0 -1
- package/runtime/scripts/hfs/allows.mjs +37 -38
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
- package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
- package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
- package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
- package/runtime/scripts/hfs/architecture/config.mjs +302 -268
- package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
- package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
- package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
- package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
- package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
- package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
- package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
- package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
- package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
- package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
- package/runtime/scripts/hfs/architecture/index.mjs +272 -272
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
- package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
- package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
- package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
- package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
- package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
- package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
- package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
- package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
- package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
- package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
- package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
- package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
- package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
- package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
- package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
- package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
- package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
- package/runtime/scripts/hfs/edition-slots.mjs +43 -40
- package/runtime/scripts/hfs/linear-text.mjs +20 -20
- package/runtime/scripts/hfs/param-names.mjs +6 -11
- package/runtime/scripts/hfs/path-findings.mjs +120 -100
- package/runtime/scripts/hfs/repo-identity.mjs +55 -42
- package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
- package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
- package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
- package/runtime/scripts/hfs/rules/read.mjs +19 -15
- package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
- package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
- package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
- package/runtime/scripts/hfs/slot-classify.mjs +42 -38
- package/runtime/scripts/hfs/slot-errors.mjs +8 -7
- package/runtime/scripts/hfs/slot-imports.mjs +70 -63
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
- package/runtime/scripts/hfs/slot-match.mjs +122 -111
- package/runtime/scripts/hfs/slot-path.mjs +0 -2
- package/runtime/scripts/hfs/slot-required.mjs +65 -59
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
- package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
- package/runtime/scripts/hfs/slots.mjs +175 -152
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
- package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
- package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
- package/runtime/scripts/hfs/view.mjs +38 -40
- package/runtime/scripts/lib/dockerfile.mjs +131 -114
- package/runtime/scripts/lib/env.mjs +3 -6
- package/runtime/scripts/lib/event-contract.mjs +73 -78
- package/runtime/scripts/lib/git.mjs +15 -16
- package/runtime/scripts/lib/glob.mjs +23 -14
- package/runtime/scripts/lib/grammar-lint.mjs +33 -37
- package/runtime/scripts/lib/i18n.mjs +32 -35
- package/runtime/scripts/lib/in-order.mjs +57 -38
- package/runtime/scripts/lib/json-clone.mjs +45 -36
- package/runtime/scripts/lib/json.mjs +26 -14
- package/runtime/scripts/lib/language.mjs +133 -129
- package/runtime/scripts/lib/list.mjs +9 -14
- package/runtime/scripts/lib/mutation-fence.mjs +10 -5
- package/runtime/scripts/lib/path-key.mjs +53 -38
- package/runtime/scripts/lib/read-text.mjs +30 -17
- package/runtime/scripts/lib/regex.mjs +1 -2
- package/runtime/scripts/lib/same-text.mjs +0 -1
- package/runtime/scripts/lib/sops-envelope.mjs +148 -120
- package/runtime/scripts/lib/stack-services.mjs +128 -129
- package/runtime/scripts/lib/ts-analysis.mjs +28 -26
- package/runtime/scripts/lib/ts-ast.mjs +36 -42
- package/runtime/scripts/lib/walk.mjs +33 -27
- package/runtime/scripts/lib/yaml-cached.mjs +4 -4
|
@@ -2,177 +2,187 @@ import path from 'node:path';
|
|
|
2
2
|
import { canonical } from './config.mjs';
|
|
3
3
|
import { hasAnyFlag, sourceLocation } from '../../lib/ts-ast.mjs';
|
|
4
4
|
import { byCodeUnit } from '../../lib/list.mjs';
|
|
5
|
-
|
|
6
5
|
const HELPER_DEPTH = 4;
|
|
7
|
-
|
|
8
6
|
const checkerOf = (env, sourceFile) => env.context.checkerFor(sourceFile.fileName);
|
|
9
|
-
|
|
10
7
|
function aliased(env, checker, symbol) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
8
|
+
const { ts } = env;
|
|
9
|
+
const seen = new Set();
|
|
10
|
+
let current = symbol;
|
|
11
|
+
while (current && hasAnyFlag(current.flags, ts.SymbolFlags.Alias) && !seen.has(current)) {
|
|
12
|
+
seen.add(current);
|
|
13
|
+
let target;
|
|
14
|
+
try {
|
|
15
|
+
target = checker.getAliasedSymbol(current);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
if (!target || target === current || !(target.declarations?.length))
|
|
21
|
+
break;
|
|
22
|
+
current = target;
|
|
23
|
+
}
|
|
24
|
+
return current;
|
|
25
|
+
}
|
|
24
26
|
function symbolAt(env, checker, node) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const { ts } = env;
|
|
28
|
+
if (!node)
|
|
29
|
+
return null;
|
|
30
|
+
const parent = node.parent;
|
|
31
|
+
if (parent && ts.isShorthandPropertyAssignment(parent) && parent.name === node)
|
|
32
|
+
return checker.getShorthandAssignmentValueSymbol(parent) ?? null;
|
|
33
|
+
return checker.getSymbolAtLocation(node) ?? null;
|
|
29
34
|
}
|
|
30
|
-
|
|
31
35
|
/** {name, module} when `target` is bound directly by an import specifier, default import or namespace import, else null. */
|
|
32
36
|
function ownImportBinding(env, checker, target) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
const { ts } = env;
|
|
38
|
+
const declaration = symbolAt(env, checker, target)?.declarations?.[0];
|
|
39
|
+
if (!declaration)
|
|
40
|
+
return null;
|
|
41
|
+
// The module specifier of an import declaration is always a string literal in a program that parses.
|
|
42
|
+
if (ts.isImportSpecifier(declaration))
|
|
43
|
+
return { name: (declaration.propertyName ?? declaration.name).text, module: declaration.parent.parent.parent.moduleSpecifier.text };
|
|
44
|
+
if (ts.isImportClause(declaration))
|
|
45
|
+
return { name: 'default', module: declaration.parent.moduleSpecifier.text };
|
|
46
|
+
if (ts.isNamespaceImport(declaration))
|
|
47
|
+
return { name: '*', module: declaration.parent.parent.moduleSpecifier.text };
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
42
50
|
/** {name, module} when `node` (identifier, or namespace.member) is bound by an import from a module specifier, else null. */
|
|
43
51
|
function importBinding(env, checker, node) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
const { ts } = env;
|
|
53
|
+
if (ts.isIdentifier(node))
|
|
54
|
+
return ownImportBinding(env, checker, node);
|
|
55
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression)) {
|
|
56
|
+
const namespace = ownImportBinding(env, checker, node.expression);
|
|
57
|
+
return namespace?.name === '*' ? { name: node.name.text, module: namespace.module } : null;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
53
61
|
function isImportOf(env, checker, node, name, moduleName) {
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
const binding = importBinding(env, checker, node);
|
|
63
|
+
return binding !== null && binding.name === name && binding.module === moduleName;
|
|
56
64
|
}
|
|
57
|
-
|
|
58
65
|
/** The declarations `node` resolves to through aliases. */
|
|
59
66
|
const declarationsOf = (env, checker, node) => aliased(env, checker, symbolAt(env, checker, node))?.declarations ?? [];
|
|
60
|
-
|
|
61
67
|
/** The repository-relative graph path of the file declaring `declaration`, or null when it is outside the program. */
|
|
62
68
|
const graphPath = (env, declaration) => env.graph.abs(canonical(declaration.getSourceFile().fileName));
|
|
63
|
-
|
|
64
69
|
const graphFile = (env, rel) => env.graph.files.get(rel) ?? null;
|
|
65
|
-
|
|
66
70
|
/** The capability (owner) root, slot and tier of a declaration, or null. */
|
|
67
71
|
function ownerOfDeclaration(env, declaration) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
const rel = graphPath(env, declaration);
|
|
73
|
+
const file = rel ? graphFile(env, rel) : null;
|
|
74
|
+
return rel && file?.owner ? { rel, root: file.owner.root, slot: file.owner.slot, tier: file.tier, name: path.posix.basename(file.owner.root) } : null;
|
|
71
75
|
}
|
|
72
|
-
|
|
73
76
|
/** The string a node evaluates to: a literal, or a const whose type is a string literal. */
|
|
74
77
|
function stringValue(env, checker, node) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
const { ts } = env;
|
|
79
|
+
if (!node)
|
|
80
|
+
return null;
|
|
81
|
+
if (ts.isStringLiteralLike(node))
|
|
82
|
+
return node.text;
|
|
83
|
+
let type;
|
|
84
|
+
try {
|
|
85
|
+
type = checker.getTypeAtLocation(node);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (type?.isStringLiteral?.())
|
|
91
|
+
return type.value;
|
|
92
|
+
const declaration = declarationsOf(env, checker, ts.isPropertyAccessExpression(node) ? node.name : node)[0];
|
|
93
|
+
if (declaration && ts.isVariableDeclaration(declaration) && declaration.initializer)
|
|
94
|
+
return stringValue(env, checker, declaration.initializer);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
86
97
|
function walk(env, node, visit) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
98
|
+
const step = (child) => {
|
|
99
|
+
if (visit(child) === false)
|
|
100
|
+
return;
|
|
101
|
+
env.ts.forEachChild(child, step);
|
|
102
|
+
};
|
|
103
|
+
step(node);
|
|
92
104
|
}
|
|
93
|
-
|
|
94
105
|
const decorators = (env, node) => (env.ts.canHaveDecorators?.(node) ? env.ts.getDecorators(node) ?? [] : []);
|
|
106
|
+
// reason: getCombinedModifierFlags reads only the modifiers, which a VariableStatement carries as well as a Declaration.
|
|
95
107
|
const isExported = (env, node) => hasAnyFlag(env.ts.getCombinedModifierFlags?.(node), env.ts.ModifierFlags.Export);
|
|
96
|
-
|
|
97
108
|
function propertyNameText(env, name) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
109
|
+
if (!name)
|
|
110
|
+
return null;
|
|
111
|
+
if (env.ts.isIdentifier(name) || env.ts.isStringLiteralLike(name))
|
|
112
|
+
return name.text;
|
|
113
|
+
return null;
|
|
101
114
|
}
|
|
102
|
-
|
|
103
115
|
/** The object literal properties of `literal` by static name. */
|
|
104
116
|
const propertyOf = (env, literal, key) => literal.properties
|
|
105
|
-
|
|
106
|
-
|
|
117
|
+
.find((property) => (env.ts.isPropertyAssignment(property) || env.ts.isShorthandPropertyAssignment(property)) && propertyNameText(env, property.name) === key);
|
|
107
118
|
const valueOfProperty = (env, property) => (env.ts.isPropertyAssignment(property) ? property.initializer : property.name);
|
|
108
|
-
|
|
109
|
-
const at = (env, rel, sourceFile, node, extra = {}) => ({ path: rel, ...sourceLocation(sourceFile, node), ...extra });
|
|
110
|
-
|
|
119
|
+
const at = (_env, rel, sourceFile, node, extra = {}) => ({ path: rel, ...sourceLocation(sourceFile, node), ...extra });
|
|
111
120
|
/** The app root file of an app (apps/<name>/src/app.module.ts), or null when the program does not hold it. */
|
|
112
121
|
const appRoot = (env, name) => graphFile(env, `apps/${name}/src/app.module.ts`);
|
|
113
|
-
|
|
114
122
|
/**
|
|
115
123
|
* Whether a repository-relative file is a composition group of an app: `apps/<app>/src/compose/<area>.ts`, the module list of
|
|
116
124
|
* one area that the app root spreads into its imports (slot allows `compose/<area>.ts` of every be.app.* slot).
|
|
117
125
|
*/
|
|
118
|
-
export const isComposeGroup = rel => /^apps\/[^/]+\/src\/compose\/[^/]+\.ts$/.test(rel) && !/\.(?:spec|d)\.ts$/.test(rel);
|
|
119
|
-
|
|
126
|
+
export const isComposeGroup = (rel) => /^apps\/[^/]+\/src\/compose\/[^/]+\.ts$/.test(rel) && !/\.(?:spec|d)\.ts$/.test(rel);
|
|
120
127
|
/** The app root and the composition groups of an app, in path order (the root first); [] when the program holds no root. */
|
|
121
128
|
const appCompositionFiles = (env, name) => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
129
|
+
const root = appRoot(env, name);
|
|
130
|
+
if (!root)
|
|
131
|
+
return [];
|
|
132
|
+
const prefix = `apps/${name}/src/compose/`;
|
|
133
|
+
const groups = [...env.graph.files.values()].filter(file => file.rel.startsWith(prefix) && isComposeGroup(file.rel));
|
|
134
|
+
return [root, ...groups.sort((a, b) => byCodeUnit(a.rel, b.rel))];
|
|
127
135
|
};
|
|
128
|
-
|
|
129
136
|
/** The body a call or a spread identifier resolves to when it is a function or a const declared in a file of the program (not a package), else null. */
|
|
130
137
|
function helperBodyOf(env, checker, node) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
138
|
+
const { ts } = env;
|
|
139
|
+
const target = ts.isCallExpression(node) ? node.expression : node;
|
|
140
|
+
for (const declaration of declarationsOf(env, checker, ts.isPropertyAccessExpression(target) ? target.name : target)) {
|
|
141
|
+
if (!graphPath(env, declaration))
|
|
142
|
+
continue;
|
|
143
|
+
if (ts.isFunctionDeclaration(declaration) && declaration.body)
|
|
144
|
+
return { declaration, body: declaration.body };
|
|
145
|
+
if (ts.isVariableDeclaration(declaration) && declaration.initializer)
|
|
146
|
+
return { declaration, body: declaration.initializer };
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
141
150
|
/** The provider entry of an object literal that provides `name` imported from `moduleName`, or null. */
|
|
142
151
|
function providerEntry(env, search, checker, literal, anchor) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
const provide = propertyOf(env, literal, 'provide');
|
|
153
|
+
if (!provide || !isImportOf(env, checker, valueOfProperty(env, provide), search.name, search.moduleName))
|
|
154
|
+
return null;
|
|
155
|
+
const use = propertyOf(env, literal, 'useClass');
|
|
156
|
+
return { node: anchor ?? literal, useClass: use ? valueOfProperty(env, use) : null, checker };
|
|
147
157
|
}
|
|
148
|
-
|
|
149
158
|
/** The expression that may reference a helper: the argument of a spread, or the call itself. */
|
|
150
159
|
function helperReferenceOf(ts, node) {
|
|
151
|
-
|
|
152
|
-
|
|
160
|
+
if (ts.isSpreadElement(node))
|
|
161
|
+
return node.expression;
|
|
162
|
+
return ts.isCallExpression(node) ? node : null;
|
|
153
163
|
}
|
|
154
|
-
|
|
155
164
|
function followHelper(env, search, checker, node, anchor, depth) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
165
|
+
const reference = helperReferenceOf(env.ts, node);
|
|
166
|
+
if (!reference || depth >= HELPER_DEPTH)
|
|
167
|
+
return;
|
|
168
|
+
const helper = helperBodyOf(env, checker, reference);
|
|
169
|
+
if (!helper || search.seen.has(helper.declaration))
|
|
170
|
+
return;
|
|
171
|
+
search.seen.add(helper.declaration);
|
|
172
|
+
scanProviders(env, search, helper.body, anchor ?? node, depth + 1);
|
|
173
|
+
}
|
|
164
174
|
function scanProviders(env, search, root, anchor, depth) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
175
|
+
const checker = checkerOf(env, root.getSourceFile());
|
|
176
|
+
walk(env, root, node => {
|
|
177
|
+
if (!env.ts.isObjectLiteralExpression(node)) {
|
|
178
|
+
followHelper(env, search, checker, node, anchor, depth);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const entry = providerEntry(env, search, checker, node, anchor);
|
|
182
|
+
if (entry)
|
|
183
|
+
search.found.push(entry);
|
|
184
|
+
});
|
|
174
185
|
}
|
|
175
|
-
|
|
176
186
|
/**
|
|
177
187
|
* The `{ provide: <token>, ... }` provider literals of `file` whose token is `name` imported from `moduleName`, in source order.
|
|
178
188
|
* A call or a spread of a function or a const declared in another file of the program is followed (to a depth of four), so a
|
|
@@ -180,11 +190,10 @@ function scanProviders(env, search, root, anchor, depth) {
|
|
|
180
190
|
* call or spread inside the app root (where the entry is provided), its `useClass` and `checker` those of the helper's file.
|
|
181
191
|
*/
|
|
182
192
|
function providersOf(env, file, name, moduleName) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
193
|
+
const search = { name, moduleName, found: [], seen: new Set() };
|
|
194
|
+
scanProviders(env, search, file.sourceFile, null, 0);
|
|
195
|
+
return search.found.sort((a, b) => a.node.getStart() - b.node.getStart());
|
|
186
196
|
}
|
|
187
|
-
|
|
188
197
|
/**
|
|
189
198
|
* The small TypeScript reading kit the R33/R38/R39/R41/R45/R84/R86 machine checks share (connection-map, sql-owner,
|
|
190
199
|
* register-once, error-masked, default-deny-app-guard, entrypoint-only-in-apps, error-home). Everything is decided by
|
|
@@ -192,33 +201,32 @@ function providersOf(env, file, name, moduleName) {
|
|
|
192
201
|
* recognised by the package it is imported from, a capability class by the file that declares it.
|
|
193
202
|
*/
|
|
194
203
|
export function machineKit({ context, graph }) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export const
|
|
224
|
-
export const pascal = name => name.split('-').filter(Boolean).map(part => part[0].toUpperCase() + part.slice(1)).join('');
|
|
204
|
+
const env = { ts: context.ts, context, graph };
|
|
205
|
+
const bound = (operation) => (...args) => operation(env, ...args);
|
|
206
|
+
return {
|
|
207
|
+
ts: env.ts,
|
|
208
|
+
resolver: graph.resolver,
|
|
209
|
+
providersOf: bound(providersOf),
|
|
210
|
+
checkerOf: bound(checkerOf),
|
|
211
|
+
aliased: bound(aliased),
|
|
212
|
+
symbolAt: bound(symbolAt),
|
|
213
|
+
importBinding: bound(importBinding),
|
|
214
|
+
isImportOf: bound(isImportOf),
|
|
215
|
+
declarationsOf: bound(declarationsOf),
|
|
216
|
+
graphPath: bound(graphPath),
|
|
217
|
+
graphFile: bound(graphFile),
|
|
218
|
+
ownerOfDeclaration: bound(ownerOfDeclaration),
|
|
219
|
+
stringValue: bound(stringValue),
|
|
220
|
+
walk: bound(walk),
|
|
221
|
+
decorators: bound(decorators),
|
|
222
|
+
isExported: bound(isExported),
|
|
223
|
+
propertyNameText: bound(propertyNameText),
|
|
224
|
+
propertyOf: bound(propertyOf),
|
|
225
|
+
valueOfProperty: bound(valueOfProperty),
|
|
226
|
+
at: bound(at),
|
|
227
|
+
appRoot: bound(appRoot),
|
|
228
|
+
appCompositionFiles: bound(appCompositionFiles),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
export const upperSnake = (name) => name.replaceAll('-', '_').toUpperCase();
|
|
232
|
+
export const pascal = (name) => name.split('-').filter(Boolean).map(part => part.charAt(0).toUpperCase() + part.slice(1)).join('');
|
|
@@ -4,30 +4,29 @@ import fs from 'node:fs';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { managedGroupOf } from '../edition-slots.mjs';
|
|
6
6
|
import { loadSlotManifest } from '../slots.mjs';
|
|
7
|
-
|
|
8
7
|
const TEMPLATE_ROOTS = [
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
path.resolve(import.meta.dirname, '..', '..', '..', 'packages', 'hfs', 'templates'),
|
|
9
|
+
path.resolve(import.meta.dirname, '..', '..', '..', '..', 'templates'),
|
|
11
10
|
];
|
|
12
11
|
const managedScriptCache = new Map();
|
|
13
|
-
const SCRIPT_ENTRY_START = String.raw`^\s*"`;
|
|
14
|
-
const SCRIPT_ENTRY_NAME = String.raw`([^"\n]+)`;
|
|
15
|
-
const SCRIPT_ENTRY_END = String.raw`":\s*"`;
|
|
12
|
+
const SCRIPT_ENTRY_START = String.raw `^\s*"`;
|
|
13
|
+
const SCRIPT_ENTRY_NAME = String.raw `([^"\n]+)`;
|
|
14
|
+
const SCRIPT_ENTRY_END = String.raw `":\s*"`;
|
|
16
15
|
const SCRIPT_ENTRY = new RegExp([SCRIPT_ENTRY_START, SCRIPT_ENTRY_NAME, SCRIPT_ENTRY_END].join(''), 'gmu');
|
|
17
|
-
|
|
18
16
|
/** The script names of a profile/edition template after its partials are expanded. */
|
|
19
17
|
export function managedScriptNames(profile, edition = 'full') {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
const key = `${profile}:${edition}`;
|
|
19
|
+
if (!managedScriptCache.has(key)) {
|
|
20
|
+
const slot = loadSlotManifest().slots.find((entry) => entry.id === `${profile}.package-manifest`);
|
|
21
|
+
const group = slot && managedGroupOf(slot, edition);
|
|
22
|
+
const templates = group && TEMPLATE_ROOTS.find((dir) => fs.existsSync(path.join(dir, profile, group, 'package.json')));
|
|
23
|
+
if (!templates)
|
|
24
|
+
throw new Error(`The managed package-scripts template of profile ${profile} cannot be found next to the runtime.`);
|
|
25
|
+
const text = fs.readFileSync(path.join(templates, profile, group, 'package.json'), 'utf8')
|
|
26
|
+
.replace(/^\{\{> ([\w./-]+)\}\}\r?\n/gmu, (_, partial) => fs.readFileSync(path.join(templates, partial), 'utf8'));
|
|
27
|
+
// The key is bounded by quotes, never the colon, so `[^"]` cannot backtrack; the strict script-name class filters after.
|
|
28
|
+
const names = [...text.matchAll(SCRIPT_ENTRY)].map((match) => match[1]);
|
|
29
|
+
managedScriptCache.set(key, new Set(names.filter((name) => /^[A-Za-z0-9:_.-]+$/.test(name))));
|
|
30
|
+
}
|
|
31
|
+
return managedScriptCache.get(key);
|
|
33
32
|
}
|