@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,231 +0,0 @@
|
|
|
1
|
-
// jwt-ast.mjs - shared TypeScript-symbol and expression helpers of the identity checks (token verification and the principal).
|
|
2
|
-
// Recognition follows imported declarations and inferred types, never local spelling alone.
|
|
3
|
-
import { unwrapExpression } from '../../lib/ts-analysis.mjs';
|
|
4
|
-
import { accessName as memberName, hasAnyFlag } from '../../lib/ts-ast.mjs';
|
|
5
|
-
export { accessName as memberName } from '../../lib/ts-ast.mjs';
|
|
6
|
-
export const moduleNameOf = (ts, node) => {
|
|
7
|
-
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier))
|
|
8
|
-
return node.moduleSpecifier.text;
|
|
9
|
-
if (!ts.isCallExpression(node))
|
|
10
|
-
return null;
|
|
11
|
-
const dynamic = node.expression.kind === ts.SyntaxKind.ImportKeyword;
|
|
12
|
-
const required = ts.isIdentifier(node.expression) && node.expression.text === 'require';
|
|
13
|
-
const first = node.arguments[0];
|
|
14
|
-
return (dynamic || required) && node.arguments.length === 1 && first && ts.isStringLiteralLike(first) ? first.text : null;
|
|
15
|
-
};
|
|
16
|
-
export const importedFrom = (kit, checker, node, modules, names = null) => {
|
|
17
|
-
const binding = kit.importBinding(checker, node);
|
|
18
|
-
return Boolean(binding && modules.has(binding.module) && (names === null || names.has(binding.name)));
|
|
19
|
-
};
|
|
20
|
-
export function unwrap(ts, node) {
|
|
21
|
-
return unwrapExpression(ts, node, { awaitExpressions: true, satisfiesExpressions: false });
|
|
22
|
-
}
|
|
23
|
-
export const callName = (ts, call) => ts.isCallExpression(call) ? memberName(ts, call.expression) : null;
|
|
24
|
-
export const chainParts = (ts, expression) => {
|
|
25
|
-
const names = [];
|
|
26
|
-
let current = unwrap(ts, expression);
|
|
27
|
-
while (current) {
|
|
28
|
-
if (ts.isCallExpression(current)) {
|
|
29
|
-
current = unwrap(ts, current.expression);
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
if (ts.isPropertyAccessExpression(current) || ts.isElementAccessExpression(current)) {
|
|
33
|
-
const name = memberName(ts, current);
|
|
34
|
-
if (name)
|
|
35
|
-
names.unshift(name);
|
|
36
|
-
current = unwrap(ts, current.expression);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
return names;
|
|
42
|
-
};
|
|
43
|
-
export const reportAt = (violations, kit, ruleId, file, node, message, extra = {}) => {
|
|
44
|
-
violations.push({ ruleId, ...kit.at(file.rel, file.sourceFile, node), message, ...extra });
|
|
45
|
-
};
|
|
46
|
-
const declarationsOf = (ts, checker, node) => {
|
|
47
|
-
const target = ts.isPropertyAccessExpression(node) ? node.name : node;
|
|
48
|
-
const parent = target.parent;
|
|
49
|
-
// A shorthand property (`issuer,`) names the variable it reads, not the property it creates.
|
|
50
|
-
let symbol = parent && ts.isShorthandPropertyAssignment(parent) && parent.name === target
|
|
51
|
-
? checker.getShorthandAssignmentValueSymbol(parent)
|
|
52
|
-
: checker.getSymbolAtLocation(target);
|
|
53
|
-
if (symbol && hasAnyFlag(symbol.flags, ts.SymbolFlags.Alias))
|
|
54
|
-
symbol = checker.getAliasedSymbol(symbol);
|
|
55
|
-
return symbol?.declarations ?? [];
|
|
56
|
-
};
|
|
57
|
-
const configType = (checker, node) => {
|
|
58
|
-
const type = checker.getTypeAtLocation(node);
|
|
59
|
-
return [type.symbol, type.aliasSymbol].some(symbol => symbol?.declarations?.some(declaration => /(?:\.config|\.options|\.env)\.ts$|\/modules\/config\/|\/node_modules\/@nestjs\/config\//u.test(String(declaration.getSourceFile().fileName).replaceAll('\\', '/'))
|
|
60
|
-
|| /(?:Config|Options|Env)$/u.test(symbol.name)));
|
|
61
|
-
};
|
|
62
|
-
/** Trace an issuer or audience to typed configuration values through local URL/string transformations. */
|
|
63
|
-
export const fromConfig = (ts, checker, expression, seen = new Set()) => {
|
|
64
|
-
const node = unwrap(ts, expression);
|
|
65
|
-
if (!node || seen.has(node))
|
|
66
|
-
return false;
|
|
67
|
-
const next = new Set(seen).add(node);
|
|
68
|
-
if (ts.isIdentifier(node)) {
|
|
69
|
-
return declarationsOf(ts, checker, node).some(declaration => {
|
|
70
|
-
if (ts.isVariableDeclaration(declaration) && declaration.initializer)
|
|
71
|
-
return fromConfig(ts, checker, declaration.initializer, next);
|
|
72
|
-
if (ts.isParameter(declaration) || ts.isPropertyDeclaration(declaration))
|
|
73
|
-
return configType(checker, node);
|
|
74
|
-
return /(?:\.config|\.env)\.ts$|\/modules\/config\//u.test(String(declaration.getSourceFile().fileName).replaceAll('\\', '/'));
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
|
|
78
|
-
return fromConfig(ts, checker, node.expression, next) || declarationsOf(ts, checker, node).some(declaration => (ts.isParameter(declaration) || ts.isPropertyDeclaration(declaration)) && !declaration.initializer && configType(checker, node));
|
|
79
|
-
}
|
|
80
|
-
if (ts.isTemplateExpression(node))
|
|
81
|
-
return node.templateSpans.some(span => fromConfig(ts, checker, span.expression, next));
|
|
82
|
-
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
83
|
-
return fromConfig(ts, checker, node.left, next) || fromConfig(ts, checker, node.right, next);
|
|
84
|
-
}
|
|
85
|
-
if (ts.isCallExpression(node) || ts.isNewExpression(node)) {
|
|
86
|
-
return fromConfig(ts, checker, node.expression, next) || node.arguments?.some(argument => fromConfig(ts, checker, argument, next));
|
|
87
|
-
}
|
|
88
|
-
return false;
|
|
89
|
-
};
|
|
90
|
-
const objectValue = (ts, checker, expression) => {
|
|
91
|
-
const node = unwrap(ts, expression);
|
|
92
|
-
if (!node)
|
|
93
|
-
return null;
|
|
94
|
-
if (ts.isObjectLiteralExpression(node))
|
|
95
|
-
return node;
|
|
96
|
-
if (!ts.isIdentifier(node))
|
|
97
|
-
return null;
|
|
98
|
-
const declared = declarationsOf(ts, checker, node).find((declaration) => ts.isVariableDeclaration(declaration)
|
|
99
|
-
&& declaration.initializer !== undefined && ts.isObjectLiteralExpression(unwrap(ts, declaration.initializer)));
|
|
100
|
-
// The declaration is the one whose initializer unwraps to an object literal, so the unwrapped node is what is returned.
|
|
101
|
-
const initializer = unwrap(ts, declared?.initializer);
|
|
102
|
-
return initializer && ts.isObjectLiteralExpression(initializer) ? initializer : null;
|
|
103
|
-
};
|
|
104
|
-
const literalString = (ts, checker, expression) => {
|
|
105
|
-
const node = unwrap(ts, expression);
|
|
106
|
-
if (!node)
|
|
107
|
-
return null;
|
|
108
|
-
if (ts.isStringLiteralLike(node))
|
|
109
|
-
return node.text;
|
|
110
|
-
const type = checker.getTypeAtLocation(node);
|
|
111
|
-
return type.isStringLiteral?.() ? type.value : null;
|
|
112
|
-
};
|
|
113
|
-
/** A role read must belong to the payload produced by this verification, including destructuring aliases. */
|
|
114
|
-
const verifiedPayload = (ts, checker, expression, call, seen = new Set()) => {
|
|
115
|
-
const node = unwrap(ts, expression);
|
|
116
|
-
if (!node || seen.has(node))
|
|
117
|
-
return false;
|
|
118
|
-
const next = new Set(seen).add(node);
|
|
119
|
-
if ((ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) && memberName(ts, node) === 'payload') {
|
|
120
|
-
const value = unwrap(ts, node.expression);
|
|
121
|
-
if (value === call)
|
|
122
|
-
return true;
|
|
123
|
-
if (ts.isIdentifier(value))
|
|
124
|
-
return declarationsOf(ts, checker, value).some(declaration => ts.isVariableDeclaration(declaration) && unwrap(ts, declaration.initializer) === call);
|
|
125
|
-
}
|
|
126
|
-
if (!ts.isIdentifier(node))
|
|
127
|
-
return false;
|
|
128
|
-
return declarationsOf(ts, checker, node).some(declaration => {
|
|
129
|
-
if (ts.isVariableDeclaration(declaration))
|
|
130
|
-
return declaration.initializer && verifiedPayload(ts, checker, declaration.initializer, call, next);
|
|
131
|
-
if (!ts.isBindingElement(declaration) || (declaration.propertyName ?? declaration.name).getText() !== 'payload')
|
|
132
|
-
return false;
|
|
133
|
-
return unwrap(ts, declaration.parent.parent.initializer) === call;
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
const rejects = (ts, statement) => {
|
|
137
|
-
if (ts.isBlock(statement)) {
|
|
138
|
-
const exit = statement.statements.find(item => ts.isThrowStatement(item) || ts.isReturnStatement(item));
|
|
139
|
-
return Boolean(exit && rejects(ts, exit));
|
|
140
|
-
}
|
|
141
|
-
if (ts.isThrowStatement(statement))
|
|
142
|
-
return true;
|
|
143
|
-
if (!ts.isReturnStatement(statement))
|
|
144
|
-
return false;
|
|
145
|
-
const value = statement.expression && unwrap(ts, statement.expression);
|
|
146
|
-
return !value || value.kind === ts.SyntaxKind.NullKeyword || value.kind === ts.SyntaxKind.FalseKeyword
|
|
147
|
-
|| (ts.isCallExpression(value) && /^(?:refused|err|fail|failure)$/u.test(value.expression.getText()));
|
|
148
|
-
};
|
|
149
|
-
const roleCondition = (ts, checker, condition, call, equality = false) => {
|
|
150
|
-
const node = unwrap(ts, condition);
|
|
151
|
-
if (!node || !ts.isBinaryExpression(node))
|
|
152
|
-
return false;
|
|
153
|
-
const combined = equality ? ts.SyntaxKind.AmpersandAmpersandToken : ts.SyntaxKind.BarBarToken;
|
|
154
|
-
if (node.operatorToken.kind === combined)
|
|
155
|
-
return roleCondition(ts, checker, node.left, call, equality) || roleCondition(ts, checker, node.right, call, equality);
|
|
156
|
-
const operators = equality ? [ts.SyntaxKind.EqualsEqualsEqualsToken, ts.SyntaxKind.EqualsEqualsToken]
|
|
157
|
-
: [ts.SyntaxKind.ExclamationEqualsEqualsToken, ts.SyntaxKind.ExclamationEqualsToken];
|
|
158
|
-
if (!operators.includes(node.operatorToken.kind))
|
|
159
|
-
return false;
|
|
160
|
-
const role = (expression) => (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression))
|
|
161
|
-
&& memberName(ts, expression) === 'role' && verifiedPayload(ts, checker, expression.expression, call);
|
|
162
|
-
return (role(node.left) && literalString(ts, checker, node.right) === 'authenticated')
|
|
163
|
-
|| (role(node.right) && literalString(ts, checker, node.left) === 'authenticated');
|
|
164
|
-
};
|
|
165
|
-
const returnsPrincipal = (ts, statement) => {
|
|
166
|
-
let accepted = false;
|
|
167
|
-
const visit = (node) => {
|
|
168
|
-
if (ts.isFunctionLike(node))
|
|
169
|
-
return;
|
|
170
|
-
if (ts.isReturnStatement(node) && !rejects(ts, node))
|
|
171
|
-
accepted = true;
|
|
172
|
-
ts.forEachChild(node, visit);
|
|
173
|
-
};
|
|
174
|
-
visit(statement);
|
|
175
|
-
return accepted;
|
|
176
|
-
};
|
|
177
|
-
const statementsAfterVerify = (ts, call) => {
|
|
178
|
-
let statement = call;
|
|
179
|
-
while (statement.parent && !ts.isBlock(statement.parent))
|
|
180
|
-
statement = statement.parent;
|
|
181
|
-
const block = statement.parent;
|
|
182
|
-
if (!block || !ts.isBlock(block))
|
|
183
|
-
return [];
|
|
184
|
-
const siblings = block.statements;
|
|
185
|
-
return block.statements.slice(siblings.indexOf(statement) + 1);
|
|
186
|
-
};
|
|
187
|
-
const rejectsRoleGuard = (ts, checker, statement, call) => {
|
|
188
|
-
if (!ts.isIfStatement(statement))
|
|
189
|
-
return false;
|
|
190
|
-
if (roleCondition(ts, checker, statement.expression, call) && rejects(ts, statement.thenStatement))
|
|
191
|
-
return true;
|
|
192
|
-
return Boolean(statement.elseStatement && roleCondition(ts, checker, statement.expression, call, true) && rejects(ts, statement.elseStatement));
|
|
193
|
-
};
|
|
194
|
-
const rejectsOtherRoles = (ts, checker, call) => {
|
|
195
|
-
for (const item of statementsAfterVerify(ts, call)) {
|
|
196
|
-
if (ts.isReturnStatement(item) || ts.isThrowStatement(item))
|
|
197
|
-
return false;
|
|
198
|
-
if (rejectsRoleGuard(ts, checker, item, call))
|
|
199
|
-
return true;
|
|
200
|
-
if (returnsPrincipal(ts, item))
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
return false;
|
|
204
|
-
};
|
|
205
|
-
/** R260 is shared by the architecture machine and the published typed ESLint rule. */
|
|
206
|
-
export const jwtPolicyProblems = (ts, checker, call) => {
|
|
207
|
-
const problems = [];
|
|
208
|
-
const options = objectValue(ts, checker, call.arguments[2]);
|
|
209
|
-
const property = (name) => options?.properties.findLast((entry) => (ts.isPropertyAssignment(entry) || ts.isShorthandPropertyAssignment(entry))
|
|
210
|
-
&& (ts.isIdentifier(entry.name) || ts.isStringLiteralLike(entry.name)) && entry.name.text === name);
|
|
211
|
-
const value = (name) => {
|
|
212
|
-
const entry = property(name);
|
|
213
|
-
return entry && unwrap(ts, ts.isPropertyAssignment(entry) ? entry.initializer : entry.name);
|
|
214
|
-
};
|
|
215
|
-
const algorithms = value('algorithms');
|
|
216
|
-
const secure = new Set(['ES256', 'RS256', 'EdDSA']);
|
|
217
|
-
if (!algorithms || !ts.isArrayLiteralExpression(algorithms) || !algorithms.elements.length
|
|
218
|
-
|| algorithms.elements.some(item => !ts.isStringLiteralLike(item) || !secure.has(item.text))
|
|
219
|
-
|| options?.properties.some(entry => ts.isSpreadAssignment(entry))) {
|
|
220
|
-
problems.push('BE_JWT_ALG_PINNED: algorithms must be a non-empty literal subset of ES256, RS256 and EdDSA.');
|
|
221
|
-
}
|
|
222
|
-
if (!fromConfig(ts, checker, value('issuer')))
|
|
223
|
-
problems.push('BE_JWT_ALG_PINNED: issuer must derive from typed configuration.');
|
|
224
|
-
// The principal is bound either by an audience of typed configuration (an OIDC client such as Keycloak, the app's own
|
|
225
|
-
// Passport tokens) or, where the audience is shared by every token of the issuer (Supabase's literal 'authenticated'),
|
|
226
|
-
// by rejecting every role other than authenticated before the principal is returned.
|
|
227
|
-
if (!fromConfig(ts, checker, value('audience')) && !rejectsOtherRoles(ts, checker, call)) {
|
|
228
|
-
problems.push('BE_JWT_ALG_PINNED: an OIDC verifier audience must derive from typed configuration, or the verified principal must reject every role other than authenticated before returning it.');
|
|
229
|
-
}
|
|
230
|
-
return problems;
|
|
231
|
-
};
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { canonical } from './config.mjs';
|
|
3
|
-
import { hasAnyFlag, sourceLocation } from '../../lib/ts-ast.mjs';
|
|
4
|
-
import { byCodeUnit } from '../../lib/list.mjs';
|
|
5
|
-
const HELPER_DEPTH = 4;
|
|
6
|
-
const checkerOf = (env, sourceFile) => env.context.checkerFor(sourceFile.fileName);
|
|
7
|
-
function aliased(env, checker, symbol) {
|
|
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
|
-
}
|
|
26
|
-
function symbolAt(env, checker, node) {
|
|
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;
|
|
34
|
-
}
|
|
35
|
-
/** {name, module} when `target` is bound directly by an import specifier, default import or namespace import, else null. */
|
|
36
|
-
function ownImportBinding(env, checker, target) {
|
|
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
|
-
}
|
|
50
|
-
/** {name, module} when `node` (identifier, or namespace.member) is bound by an import from a module specifier, else null. */
|
|
51
|
-
function importBinding(env, checker, node) {
|
|
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
|
-
}
|
|
61
|
-
function isImportOf(env, checker, node, name, moduleName) {
|
|
62
|
-
const binding = importBinding(env, checker, node);
|
|
63
|
-
return binding !== null && binding.name === name && binding.module === moduleName;
|
|
64
|
-
}
|
|
65
|
-
/** The declarations `node` resolves to through aliases. */
|
|
66
|
-
const declarationsOf = (env, checker, node) => aliased(env, checker, symbolAt(env, checker, node))?.declarations ?? [];
|
|
67
|
-
/** The repository-relative graph path of the file declaring `declaration`, or null when it is outside the program. */
|
|
68
|
-
const graphPath = (env, declaration) => env.graph.abs(canonical(declaration.getSourceFile().fileName));
|
|
69
|
-
const graphFile = (env, rel) => env.graph.files.get(rel) ?? null;
|
|
70
|
-
/** The capability (owner) root, slot and tier of a declaration, or null. */
|
|
71
|
-
function ownerOfDeclaration(env, declaration) {
|
|
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;
|
|
75
|
-
}
|
|
76
|
-
/** The string a node evaluates to: a literal, or a const whose type is a string literal. */
|
|
77
|
-
function stringValue(env, checker, node) {
|
|
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
|
-
}
|
|
97
|
-
function walk(env, node, visit) {
|
|
98
|
-
const step = (child) => {
|
|
99
|
-
if (visit(child) === false)
|
|
100
|
-
return;
|
|
101
|
-
env.ts.forEachChild(child, step);
|
|
102
|
-
};
|
|
103
|
-
step(node);
|
|
104
|
-
}
|
|
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.
|
|
107
|
-
const isExported = (env, node) => hasAnyFlag(env.ts.getCombinedModifierFlags?.(node), env.ts.ModifierFlags.Export);
|
|
108
|
-
function propertyNameText(env, name) {
|
|
109
|
-
if (!name)
|
|
110
|
-
return null;
|
|
111
|
-
if (env.ts.isIdentifier(name) || env.ts.isStringLiteralLike(name))
|
|
112
|
-
return name.text;
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
/** The object literal properties of `literal` by static name. */
|
|
116
|
-
const propertyOf = (env, literal, key) => literal.properties
|
|
117
|
-
.find((property) => (env.ts.isPropertyAssignment(property) || env.ts.isShorthandPropertyAssignment(property)) && propertyNameText(env, property.name) === key);
|
|
118
|
-
const valueOfProperty = (env, property) => (env.ts.isPropertyAssignment(property) ? property.initializer : property.name);
|
|
119
|
-
const at = (_env, rel, sourceFile, node, extra = {}) => ({ path: rel, ...sourceLocation(sourceFile, node), ...extra });
|
|
120
|
-
/** The app root file of an app (apps/<name>/src/app.module.ts), or null when the program does not hold it. */
|
|
121
|
-
const appRoot = (env, name) => graphFile(env, `apps/${name}/src/app.module.ts`);
|
|
122
|
-
/**
|
|
123
|
-
* Whether a repository-relative file is a composition group of an app: `apps/<app>/src/compose/<area>.ts`, the module list of
|
|
124
|
-
* one area that the app root spreads into its imports (slot allows `compose/<area>.ts` of every be.app.* slot).
|
|
125
|
-
*/
|
|
126
|
-
export const isComposeGroup = (rel) => /^apps\/[^/]+\/src\/compose\/[^/]+\.ts$/.test(rel) && !/\.(?:spec|d)\.ts$/.test(rel);
|
|
127
|
-
/** The app root and the composition groups of an app, in path order (the root first); [] when the program holds no root. */
|
|
128
|
-
const appCompositionFiles = (env, name) => {
|
|
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))];
|
|
135
|
-
};
|
|
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. */
|
|
137
|
-
function helperBodyOf(env, checker, node) {
|
|
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
|
-
}
|
|
150
|
-
/** The provider entry of an object literal that provides `name` imported from `moduleName`, or null. */
|
|
151
|
-
function providerEntry(env, search, checker, literal, anchor) {
|
|
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 };
|
|
157
|
-
}
|
|
158
|
-
/** The expression that may reference a helper: the argument of a spread, or the call itself. */
|
|
159
|
-
function helperReferenceOf(ts, node) {
|
|
160
|
-
if (ts.isSpreadElement(node))
|
|
161
|
-
return node.expression;
|
|
162
|
-
return ts.isCallExpression(node) ? node : null;
|
|
163
|
-
}
|
|
164
|
-
function followHelper(env, search, checker, node, anchor, depth) {
|
|
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
|
-
}
|
|
174
|
-
function scanProviders(env, search, root, anchor, depth) {
|
|
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
|
-
});
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* The `{ provide: <token>, ... }` provider literals of `file` whose token is `name` imported from `moduleName`, in source order.
|
|
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
|
|
189
|
-
* helper that builds the `APP_GUARD` or `APP_FILTER` entries outside the app root file is read too: the entry's `node` is then the
|
|
190
|
-
* call or spread inside the app root (where the entry is provided), its `useClass` and `checker` those of the helper's file.
|
|
191
|
-
*/
|
|
192
|
-
function providersOf(env, file, name, moduleName) {
|
|
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());
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* The small TypeScript reading kit the R33/R38/R39/R41/R45/R84/R86 machine checks share (connection-map, sql-owner,
|
|
199
|
-
* register-once, error-masked, default-deny-app-guard, entrypoint-only-in-apps, error-home). Everything is decided by
|
|
200
|
-
* the checker and by where a declaration lives (the HFS graph), never by a variable name: a framework symbol is
|
|
201
|
-
* recognised by the package it is imported from, a capability class by the file that declares it.
|
|
202
|
-
*/
|
|
203
|
-
export function machineKit({ context, graph }) {
|
|
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('');
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// managed-scripts.mjs - reads the script names from the managed package-script template for one HFS profile and
|
|
2
|
-
// edition. Templates stay the source of truth; README presentation checks consume only this cached name set.
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { managedGroupOf } from '../edition-slots.mjs';
|
|
6
|
-
import { loadSlotManifest } from '../slots.mjs';
|
|
7
|
-
const TEMPLATE_ROOTS = [
|
|
8
|
-
path.resolve(import.meta.dirname, '..', '..', '..', 'packages', 'hfs', 'templates'),
|
|
9
|
-
path.resolve(import.meta.dirname, '..', '..', '..', '..', 'templates'),
|
|
10
|
-
];
|
|
11
|
-
const managedScriptCache = new Map();
|
|
12
|
-
const SCRIPT_ENTRY_START = String.raw `^\s*"`;
|
|
13
|
-
const SCRIPT_ENTRY_NAME = String.raw `([^"\n]+)`;
|
|
14
|
-
const SCRIPT_ENTRY_END = String.raw `":\s*"`;
|
|
15
|
-
const SCRIPT_ENTRY = new RegExp([SCRIPT_ENTRY_START, SCRIPT_ENTRY_NAME, SCRIPT_ENTRY_END].join(''), 'gmu');
|
|
16
|
-
/** The script names of a profile/edition template after its partials are expanded. */
|
|
17
|
-
export function managedScriptNames(profile, edition = 'full') {
|
|
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);
|
|
32
|
-
}
|