@starci/eslint-canon-be 3.18.3 → 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 +8 -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 -716
- 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,166 +0,0 @@
|
|
|
1
|
-
/** A script file (`.js`, `.mjs`, `.cjs`, `.jsx`): it has no declaration emit and stands for its content. */
|
|
2
|
-
export const SCRIPT = /\.(?:[cm]?jsx?)$/;
|
|
3
|
-
/** A declaration file: it is its own surface. */
|
|
4
|
-
export const DECLARATION = /\.d\.[cm]?ts$/;
|
|
5
|
-
/** A TypeScript source file whose surface the declaration emit writes. */
|
|
6
|
-
export const TYPESCRIPT = /\.(?:[cm]?tsx?)$/;
|
|
7
|
-
/** Whether `file` is a TypeScript source (not a declaration file) the declaration emit reads. */
|
|
8
|
-
export const isEmittableSource = (file) => TYPESCRIPT.test(file) && !DECLARATION.test(file);
|
|
9
|
-
/** Whether `expression` is a JSX element, fragment, `null` or `undefined`, or a conditional of those: its type does not depend on any other file. */
|
|
10
|
-
function isJsxValue(ts, expression) {
|
|
11
|
-
if (expression === undefined)
|
|
12
|
-
return false;
|
|
13
|
-
let node = expression;
|
|
14
|
-
while (ts.isParenthesizedExpression(node))
|
|
15
|
-
node = node.expression;
|
|
16
|
-
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node) || node.kind === ts.SyntaxKind.NullKeyword)
|
|
17
|
-
return true;
|
|
18
|
-
if (ts.isIdentifier(node))
|
|
19
|
-
return node.text === 'undefined';
|
|
20
|
-
return ts.isConditionalExpression(node) && isJsxValue(ts, node.whenTrue) && isJsxValue(ts, node.whenFalse);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Whether the function (or method) the declaration diagnostic at `start` points at has the type `JSX.Element | null | undefined` whatever its body
|
|
24
|
-
* reads: not async, not a generator, and every `return` of its own (and its concise body) a JSX value. A React component written without a return
|
|
25
|
-
* type is the common case; its inferred type is one the JSX namespace of the installed packages gives, which a lockfile change dirties as a whole.
|
|
26
|
-
*/
|
|
27
|
-
function returnsOnlyJsx(ts, source, start) {
|
|
28
|
-
let found;
|
|
29
|
-
const find = (node) => {
|
|
30
|
-
if (found !== undefined || start < node.getFullStart() || start >= node.end)
|
|
31
|
-
return;
|
|
32
|
-
const named = (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)) && node.name !== undefined && node.name.getStart(source) === start;
|
|
33
|
-
if (named || ((ts.isArrowFunction(node) || ts.isFunctionExpression(node)) && node.getStart(source) === start)) {
|
|
34
|
-
found = node;
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
ts.forEachChild(node, find);
|
|
38
|
-
};
|
|
39
|
-
find(source);
|
|
40
|
-
const fn = found;
|
|
41
|
-
if (fn === undefined || fn.type !== undefined || fn.body === undefined)
|
|
42
|
-
return false;
|
|
43
|
-
if (fn.asteriskToken !== undefined || (ts.getCombinedModifierFlags(fn) & ts.ModifierFlags.Async) !== 0)
|
|
44
|
-
return false;
|
|
45
|
-
if (!ts.isBlock(fn.body))
|
|
46
|
-
return isJsxValue(ts, fn.body);
|
|
47
|
-
let only = true;
|
|
48
|
-
const visit = (node) => {
|
|
49
|
-
if (!only || ts.isFunctionLike(node) || ts.isClassLike(node))
|
|
50
|
-
return;
|
|
51
|
-
if (ts.isReturnStatement(node) && node.expression !== undefined && !isJsxValue(ts, node.expression))
|
|
52
|
-
only = false;
|
|
53
|
-
ts.forEachChild(node, visit);
|
|
54
|
-
};
|
|
55
|
-
ts.forEachChild(fn.body, visit);
|
|
56
|
-
return only;
|
|
57
|
-
}
|
|
58
|
-
/** The package whose module-definition helpers return a type they state in their own declaration (R368 accepts a destructured export of their call). */
|
|
59
|
-
export const STATED_SURFACE_PACKAGE = '@starci/nest-kit';
|
|
60
|
-
/** The helpers of that package: each is called with the options type as a type argument and returns the explicitly typed definition. */
|
|
61
|
-
export const STATED_SURFACE_HELPERS = new Set(['defineConfigurableModule', 'defineCapabilityModule']);
|
|
62
|
-
/** The local names under which `source` imports a stated-surface helper from its package (`import { defineConfigurableModule as define }` gives `define`). */
|
|
63
|
-
function statedHelperNames(ts, source) {
|
|
64
|
-
const names = new Set();
|
|
65
|
-
for (const statement of source.statements) {
|
|
66
|
-
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier) || statement.moduleSpecifier.text !== STATED_SURFACE_PACKAGE)
|
|
67
|
-
continue;
|
|
68
|
-
const bindings = statement.importClause?.namedBindings;
|
|
69
|
-
if (bindings === undefined || !ts.isNamedImports(bindings))
|
|
70
|
-
continue;
|
|
71
|
-
for (const element of bindings.elements)
|
|
72
|
-
if (STATED_SURFACE_HELPERS.has((element.propertyName ?? element.name).text))
|
|
73
|
-
names.add(element.name.text);
|
|
74
|
-
}
|
|
75
|
-
return names;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Whether the destructured export the diagnostic at `start` points at is `export const { A, B } = helper<Options>()` for a stated-surface helper:
|
|
79
|
-
* each name has the type the helper's declaration gives it, written there, so the file states its surface by naming the helper and the options
|
|
80
|
-
* type, exactly as `export const A: Host["A"] = built.A` states it through `Host`.
|
|
81
|
-
*/
|
|
82
|
-
function statesSurfaceThroughHelper(ts, source, start) {
|
|
83
|
-
const helpers = statedHelperNames(ts, source);
|
|
84
|
-
if (helpers.size === 0)
|
|
85
|
-
return null;
|
|
86
|
-
let innermost = source;
|
|
87
|
-
const descend = (node) => {
|
|
88
|
-
if (start < node.getFullStart() || start >= node.end)
|
|
89
|
-
return;
|
|
90
|
-
innermost = node;
|
|
91
|
-
ts.forEachChild(node, descend);
|
|
92
|
-
};
|
|
93
|
-
ts.forEachChild(source, descend);
|
|
94
|
-
for (let node = innermost; node !== undefined && node !== source; node = node.parent) {
|
|
95
|
-
if (!ts.isVariableDeclaration(node))
|
|
96
|
-
continue;
|
|
97
|
-
const call = node.initializer;
|
|
98
|
-
const stated = ts.isObjectBindingPattern(node.name) && call !== undefined && ts.isCallExpression(call) && ts.isIdentifier(call.expression) && helpers.has(call.expression.text)
|
|
99
|
-
&& (call.typeArguments?.length ?? 0) > 0 && node.name.elements.every((element) => ts.isIdentifier(element.name) && element.dotDotDotToken === undefined);
|
|
100
|
-
return stated && call !== undefined ? call.getText(source) : null;
|
|
101
|
-
}
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
/** What to annotate for each isolated-declaration diagnostic code; any other code asks for the exported value's type. */
|
|
105
|
-
const ANNOTATE = new Map([
|
|
106
|
-
[9007, 'return type'], [9008, 'return type'], [9009, 'accessor type'], [9010, 'variable type'], [9011, 'parameter type'], [9012, 'property type'],
|
|
107
|
-
[9019, 'destructured export'], [9025, 'parameter type'],
|
|
108
|
-
]);
|
|
109
|
-
/** The declaration kinds whose name labels the export a diagnostic sits in, innermost first. */
|
|
110
|
-
function nameOf(ts, source, start) {
|
|
111
|
-
let innermost = source;
|
|
112
|
-
const descend = (node) => {
|
|
113
|
-
if (start < node.getFullStart() || start >= node.end)
|
|
114
|
-
return;
|
|
115
|
-
innermost = node;
|
|
116
|
-
ts.forEachChild(node, descend);
|
|
117
|
-
};
|
|
118
|
-
ts.forEachChild(source, descend);
|
|
119
|
-
for (let node = innermost; node !== undefined && node !== source; node = node.parent) {
|
|
120
|
-
if (ts.isExportAssignment(node))
|
|
121
|
-
return 'default export';
|
|
122
|
-
if (ts.isBindingElement(node) && ts.isIdentifier(node.name))
|
|
123
|
-
return node.name.text;
|
|
124
|
-
if ((ts.isVariableDeclaration(node) || ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node) || ts.isMethodDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isPropertyAssignment(node) || ts.isGetAccessorDeclaration(node)) && node.name !== undefined && ts.isIdentifier(node.name))
|
|
125
|
-
return node.name.text;
|
|
126
|
-
if (ts.isFunctionDeclaration(node) && (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Default) !== 0)
|
|
127
|
-
return 'default export';
|
|
128
|
-
}
|
|
129
|
-
return 'default export';
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* The declaration emit of one TypeScript source and the exports it could not write explicitly (a type inferred from bodies and other files), or null
|
|
133
|
-
* when the compiler has no `transpileDeclaration` (before TypeScript 5.5). A declaration whose only diagnostics are components returning JSX has the
|
|
134
|
-
* surface its emit shows. `module` is the side's `module` compiler option, which the emit reads. A throw from the compiler propagates: the caller
|
|
135
|
-
* decides what an unreadable file means.
|
|
136
|
-
*/
|
|
137
|
-
export function declarationSurface(ts, file, text, module) {
|
|
138
|
-
const emit = ts.transpileDeclaration;
|
|
139
|
-
if (emit === undefined)
|
|
140
|
-
return null;
|
|
141
|
-
const declared = emit.call(ts, text, { compilerOptions: { jsx: ts.JsxEmit.Preserve, target: ts.ScriptTarget.Latest, ...(module === undefined ? {} : { module }) }, fileName: file, reportDiagnostics: true });
|
|
142
|
-
const diagnostics = (declared.diagnostics ?? []);
|
|
143
|
-
if (diagnostics.length === 0)
|
|
144
|
-
return { outputText: declared.outputText, problems: [] };
|
|
145
|
-
const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, file.endsWith('x') ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
146
|
-
const problems = [];
|
|
147
|
-
// The emit writes `any` for a destructured export; the call that states its type joins the digest, so a change of the options type reaches the importers.
|
|
148
|
-
const stated = new Set();
|
|
149
|
-
for (const diagnostic of diagnostics) {
|
|
150
|
-
const call = diagnostic.code === 9019 && diagnostic.start !== undefined ? statesSurfaceThroughHelper(ts, source, diagnostic.start) : null;
|
|
151
|
-
if (call !== null) {
|
|
152
|
-
stated.add(call);
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
const exempt = (diagnostic.code === 9007 || diagnostic.code === 9008) && diagnostic.start !== undefined && returnsOnlyJsx(ts, source, diagnostic.start);
|
|
156
|
-
if (exempt)
|
|
157
|
-
continue;
|
|
158
|
-
const start = diagnostic.start ?? 0;
|
|
159
|
-
problems.push({
|
|
160
|
-
code: diagnostic.code, start, length: diagnostic.length ?? 0, name: nameOf(ts, source, start), annotate: ANNOTATE.get(diagnostic.code) ?? 'exported value',
|
|
161
|
-
reason: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n').split('\n')[0] ?? '',
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
const outputText = stated.size === 0 ? declared.outputText : `${declared.outputText}${[...stated].sort().map((call) => `// stated by ${call}\n`).join('')}`;
|
|
165
|
-
return { outputText, problems };
|
|
166
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
// dockerfile.mjs - a Dockerfile read by its own grammar (no regular-expression matching of instruction names inside the text):
|
|
2
|
-
// one statement per logical line (a trailing backslash continues it, comment lines inside a continuation are dropped), the
|
|
3
|
-
// instruction keyword is the first word, the stages open at each FROM. Parser directives (`# syntax=`, `# escape=`) and
|
|
4
|
-
// comments are kept apart from the instructions. Here-documents are not part of the subset the canon uses and are read as text.
|
|
5
|
-
/** Split a shell-form or exec-form argument string into its words (quotes group a word and are removed). */
|
|
6
|
-
export function words(text) {
|
|
7
|
-
const out = [];
|
|
8
|
-
let current = '';
|
|
9
|
-
let quote = null;
|
|
10
|
-
let started = false;
|
|
11
|
-
for (const char of text) {
|
|
12
|
-
if (quote) {
|
|
13
|
-
if (char === quote)
|
|
14
|
-
quote = null;
|
|
15
|
-
else
|
|
16
|
-
current += char;
|
|
17
|
-
}
|
|
18
|
-
else if (char === '"' || char === "'") {
|
|
19
|
-
quote = char;
|
|
20
|
-
started = true;
|
|
21
|
-
}
|
|
22
|
-
else if (char === ' ' || char === '\t' || char === '\n') {
|
|
23
|
-
if (started || current)
|
|
24
|
-
out.push(current);
|
|
25
|
-
current = '';
|
|
26
|
-
started = false;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
current += char;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (started || current)
|
|
33
|
-
out.push(current);
|
|
34
|
-
return out;
|
|
35
|
-
}
|
|
36
|
-
/** The exec-form array of an instruction's argument text (`["node", "x.js"]`), or null when it is not a JSON array of strings. */
|
|
37
|
-
export function execForm(text) {
|
|
38
|
-
const trimmed = text.trim();
|
|
39
|
-
if (!trimmed.startsWith('['))
|
|
40
|
-
return null;
|
|
41
|
-
try {
|
|
42
|
-
const value = JSON.parse(trimmed);
|
|
43
|
-
return Array.isArray(value) && value.every((item) => typeof item === 'string') ? value : null;
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/** The commands of a shell-form RUN body: the text split at `&&`, `||`, `;` and `|` outside quotes, each as its words. */
|
|
50
|
-
export function shellCommands(body) {
|
|
51
|
-
const commands = [];
|
|
52
|
-
let current = '';
|
|
53
|
-
let quote = null;
|
|
54
|
-
const flush = () => {
|
|
55
|
-
const parts = words(current);
|
|
56
|
-
if (parts.length)
|
|
57
|
-
commands.push(parts);
|
|
58
|
-
current = '';
|
|
59
|
-
};
|
|
60
|
-
for (let i = 0; i < body.length; i += 1) {
|
|
61
|
-
const char = body.charAt(i);
|
|
62
|
-
if (quote) {
|
|
63
|
-
current += char;
|
|
64
|
-
if (char === quote)
|
|
65
|
-
quote = null;
|
|
66
|
-
}
|
|
67
|
-
else if (char === '"' || char === "'") {
|
|
68
|
-
quote = char;
|
|
69
|
-
current += char;
|
|
70
|
-
}
|
|
71
|
-
else if (isCommandSeparator(body, i, char)) {
|
|
72
|
-
i += commandSeparatorAdvance(body, i, char);
|
|
73
|
-
flush();
|
|
74
|
-
}
|
|
75
|
-
else if (char === '\\' && body[i + 1] === '\n') {
|
|
76
|
-
i += 1;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
current += char;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
flush();
|
|
83
|
-
return commands;
|
|
84
|
-
}
|
|
85
|
-
const isCommandSeparator = (body, index, char) => char === ';' || char === '|' || (char === '&' && body[index + 1] === '&');
|
|
86
|
-
const commandSeparatorAdvance = (body, index, char) => char !== ';' && body[index + 1] === char ? 1 : 0;
|
|
87
|
-
/**
|
|
88
|
-
* Parse a Dockerfile: { instructions: [{ keyword, text, line, stage }], stages: [{ index, name, image, line, instructions }],
|
|
89
|
-
* comments: [{ text, line }], preamble: [instruction before the first FROM (ARG)] }. `keyword` is upper-case; `text` is the
|
|
90
|
-
* argument text of the logical line; `stage` is the index of the stage the instruction belongs to (-1 before the first FROM).
|
|
91
|
-
*/
|
|
92
|
-
export function parseDockerfile(source) {
|
|
93
|
-
const lines = String(source).replaceAll('\r\n', '\n').split('\n');
|
|
94
|
-
const { instructions, comments } = parseInstructions(lines);
|
|
95
|
-
const stages = [];
|
|
96
|
-
const preamble = [];
|
|
97
|
-
for (const instruction of instructions) {
|
|
98
|
-
if (instruction.keyword === 'FROM') {
|
|
99
|
-
const parts = words(instruction.text).filter((part) => !part.startsWith('--'));
|
|
100
|
-
const asAt = parts.findIndex((part, index) => index > 0 && part.toUpperCase() === 'AS');
|
|
101
|
-
stages.push({ index: stages.length, name: asAt > 0 ? parts[asAt + 1] ?? null : null, image: parts[0] ?? '', line: instruction.line, instructions: [] });
|
|
102
|
-
}
|
|
103
|
-
instruction.stage = stages.length - 1;
|
|
104
|
-
if (stages.length)
|
|
105
|
-
stages.at(-1).instructions.push(instruction);
|
|
106
|
-
else
|
|
107
|
-
preamble.push(instruction);
|
|
108
|
-
}
|
|
109
|
-
return { instructions, stages, comments, preamble };
|
|
110
|
-
}
|
|
111
|
-
function parseInstructions(lines) {
|
|
112
|
-
const instructions = [];
|
|
113
|
-
const comments = [];
|
|
114
|
-
const state = { escape: '\\', directives: true };
|
|
115
|
-
let i = 0;
|
|
116
|
-
while (i < lines.length) {
|
|
117
|
-
const parsed = parseInstructionLine(lines, i, state);
|
|
118
|
-
if (parsed.comment)
|
|
119
|
-
comments.push(parsed.comment);
|
|
120
|
-
if (parsed.instruction)
|
|
121
|
-
instructions.push(parsed.instruction);
|
|
122
|
-
i = parsed.nextLine + 1;
|
|
123
|
-
}
|
|
124
|
-
return { instructions, comments };
|
|
125
|
-
}
|
|
126
|
-
function parseInstructionLine(lines, index, state) {
|
|
127
|
-
const trimmed = lines[index].trim();
|
|
128
|
-
if (trimmed === '') {
|
|
129
|
-
state.directives = false;
|
|
130
|
-
return { nextLine: index };
|
|
131
|
-
}
|
|
132
|
-
if (trimmed.startsWith('#'))
|
|
133
|
-
return parseCommentLine(trimmed, index, state);
|
|
134
|
-
state.directives = false;
|
|
135
|
-
const { logical, nextLine } = logicalInstructionOf(lines, index, state.escape);
|
|
136
|
-
const split = logical.search(/\s/);
|
|
137
|
-
const keyword = (split < 0 ? logical : logical.slice(0, split)).toUpperCase();
|
|
138
|
-
return { nextLine, instruction: { keyword, text: split < 0 ? '' : logical.slice(split).trim(), line: index + 1, stage: -1 } };
|
|
139
|
-
}
|
|
140
|
-
function parseCommentLine(trimmed, index, state) {
|
|
141
|
-
const body = trimmed.slice(1).trim();
|
|
142
|
-
const directive = state.directives ? /^(syntax|escape|check)\s*=\s*(\S+)$/i.exec(body) : null;
|
|
143
|
-
if (directive) {
|
|
144
|
-
if (directive[1].toLowerCase() === 'escape')
|
|
145
|
-
state.escape = directive[2];
|
|
146
|
-
return { nextLine: index };
|
|
147
|
-
}
|
|
148
|
-
state.directives = false;
|
|
149
|
-
return { nextLine: index, comment: { text: body, line: index + 1 } };
|
|
150
|
-
}
|
|
151
|
-
function logicalInstructionOf(lines, index, escape) {
|
|
152
|
-
let logical = lines[index].trim();
|
|
153
|
-
let nextLine = index;
|
|
154
|
-
while (logical.endsWith(escape) && nextLine + 1 < lines.length) {
|
|
155
|
-
logical = logical.slice(0, -1).trimEnd();
|
|
156
|
-
nextLine += 1;
|
|
157
|
-
while (nextLine < lines.length && lines[nextLine].trim().startsWith('#'))
|
|
158
|
-
nextLine += 1;
|
|
159
|
-
if (nextLine >= lines.length)
|
|
160
|
-
break;
|
|
161
|
-
logical = `${logical} ${lines[nextLine].trim()}`;
|
|
162
|
-
}
|
|
163
|
-
return { logical, nextLine };
|
|
164
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// env.mjs - the one place the runtime reads a named environment variable (smell S8-01/S8-02/S11-04; scripts/checks/check-env.mjs).
|
|
2
|
-
// modules/schemas/env.yaml catalogues every variable with its purpose and kind. Production code reads a variable here
|
|
3
|
-
// (readEnv) or takes an injected `env` parameter; it never reads `process.env.NAME` itself. The test runner is observed
|
|
4
|
-
// in exactly one place, isSpecRun: code that must not touch the host's real state during a spec asks it.
|
|
5
|
-
/** The value of the environment variable `name` in `env` (default: the process environment), or undefined. */
|
|
6
|
-
export const readEnv = (name, env = process.env) => env[name];
|
|
7
|
-
/** True when `env` (default: the process environment) belongs to a spec run (`node --test` marks its children with NODE_TEST_CONTEXT). */
|
|
8
|
-
export const isSpecRun = (env = process.env) => Boolean(env.NODE_TEST_CONTEXT);
|
|
9
|
-
/**
|
|
10
|
-
* The environment for a child that is itself a test runner: `env` without the mark of an enclosing spec run. A `node --test` that inherits NODE_TEST_CONTEXT believes it is a
|
|
11
|
-
* subtest of that run: it reports to its parent and exits 0 whatever its tests did, so a verb that runs specs as a child (the package clean-test, the scaffold e2e, the release cut)
|
|
12
|
-
* would pass red specs from inside a test process. The runner marks the spec files it starts itself, so isSpecRun stays true inside them.
|
|
13
|
-
*/
|
|
14
|
-
export function withoutTestRunner(env = process.env) {
|
|
15
|
-
const rest = { ...env };
|
|
16
|
-
delete rest.NODE_TEST_CONTEXT;
|
|
17
|
-
return rest;
|
|
18
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { byCodeUnit } from './list.mjs';
|
|
2
|
-
const EVENT_CONTRACT_SCHEMA = 'starci/event-contract@1';
|
|
3
|
-
const FIELD_TYPE = /^(?:string|number|boolean|string\[\]|number\[\])\??$/;
|
|
4
|
-
const hasStatic = (ts, member) => member.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword) === true;
|
|
5
|
-
/** The literal of a `static readonly <name> = <literal>` member: `{ text }` for a string, `{ number }` for an integer, or null. */
|
|
6
|
-
function staticLiteral(ts, member) {
|
|
7
|
-
if (!ts.isPropertyDeclaration(member) || !hasStatic(ts, member) || !ts.isIdentifier(member.name) || member.initializer === undefined)
|
|
8
|
-
return null;
|
|
9
|
-
let value = member.initializer;
|
|
10
|
-
while (ts.isAsExpression(value) || ts.isParenthesizedExpression(value))
|
|
11
|
-
value = value.expression;
|
|
12
|
-
if (ts.isStringLiteralLike(value))
|
|
13
|
-
return { name: member.name.text, text: value.text };
|
|
14
|
-
if (ts.isNumericLiteral(value) && Number.isInteger(Number(value.text)))
|
|
15
|
-
return { name: member.name.text, number: Number(value.text) };
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
/** The text of a type node when it is one of the wire field types (`string`, `number`, `boolean`, `string[]`, `number[]`), else null. */
|
|
19
|
-
function fieldType(ts, node) {
|
|
20
|
-
if (node.kind === ts.SyntaxKind.StringKeyword)
|
|
21
|
-
return 'string';
|
|
22
|
-
if (node.kind === ts.SyntaxKind.NumberKeyword)
|
|
23
|
-
return 'number';
|
|
24
|
-
if (node.kind === ts.SyntaxKind.BooleanKeyword)
|
|
25
|
-
return 'boolean';
|
|
26
|
-
if (ts.isArrayTypeNode(node)) {
|
|
27
|
-
const element = fieldType(ts, node.elementType);
|
|
28
|
-
return element === 'string' || element === 'number' ? `${element}[]` : null;
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
function appendPayloadMember(ts, member, typeName, problems, where, payload) {
|
|
33
|
-
if (!ts.isPropertySignature(member) || !ts.isIdentifier(member.name) || member.type === undefined) {
|
|
34
|
-
problems.push(`${where}: the payload ${typeName} holds a member that is not \`name: type\``);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const type = fieldType(ts, member.type);
|
|
38
|
-
let written = null;
|
|
39
|
-
if (type !== null)
|
|
40
|
-
written = `${type}${member.questionToken ? '?' : ''}`;
|
|
41
|
-
if (written === null || !FIELD_TYPE.test(written))
|
|
42
|
-
problems.push(`${where}: payload field ${member.name.text} must be string, number, boolean, string[] or number[]`);
|
|
43
|
-
else
|
|
44
|
-
payload[member.name.text] = written;
|
|
45
|
-
}
|
|
46
|
-
/** The payload fields of the interface or type literal named `typeName` in the file: `{ <field>: <type> }`, optional fields with a `?`. */
|
|
47
|
-
function payloadOf(ts, sourceFile, typeName, problems, where) {
|
|
48
|
-
let members = null;
|
|
49
|
-
for (const statement of sourceFile.statements) {
|
|
50
|
-
if (ts.isInterfaceDeclaration(statement) && statement.name.text === typeName)
|
|
51
|
-
members = statement.members;
|
|
52
|
-
if (ts.isTypeAliasDeclaration(statement) && statement.name.text === typeName && ts.isTypeLiteralNode(statement.type))
|
|
53
|
-
members = statement.type.members;
|
|
54
|
-
}
|
|
55
|
-
if (members === null) {
|
|
56
|
-
problems.push(`${where}: the payload type ${typeName} is not an interface or type literal of the file`);
|
|
57
|
-
return {};
|
|
58
|
-
}
|
|
59
|
-
const payload = {};
|
|
60
|
-
for (const member of members)
|
|
61
|
-
appendPayloadMember(ts, member, typeName, problems, where, payload);
|
|
62
|
-
return payload;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* The event classes of one source text: `{ events: [{ className, name, version, compensates, payload }], problems: [text] }`. A class is an event
|
|
66
|
-
* when it declares `static readonly eventName`; `version` is required, `create(payload: <Interface>)` names the payload.
|
|
67
|
-
*/
|
|
68
|
-
export function readEventClasses(ts, text, file = 'event.ts') {
|
|
69
|
-
const sourceFile = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
70
|
-
const events = [];
|
|
71
|
-
const problems = [];
|
|
72
|
-
for (const statement of sourceFile.statements) {
|
|
73
|
-
if (!ts.isClassDeclaration(statement) || statement.name === undefined)
|
|
74
|
-
continue;
|
|
75
|
-
const literals = statement.members.map((member) => staticLiteral(ts, member)).filter((literal) => literal !== null);
|
|
76
|
-
const name = literals.find((literal) => literal.name === 'eventName')?.text;
|
|
77
|
-
if (name === undefined)
|
|
78
|
-
continue;
|
|
79
|
-
const className = statement.name.text;
|
|
80
|
-
const version = literals.find((literal) => literal.name === 'version')?.number;
|
|
81
|
-
const compensates = literals.find((literal) => literal.name === 'compensates')?.text;
|
|
82
|
-
if (version === undefined || version < 1)
|
|
83
|
-
problems.push(`${className} needs \`static readonly version\` as a positive integer`);
|
|
84
|
-
const create = statement.members.find((member) => ts.isMethodDeclaration(member) && hasStatic(ts, member) && ts.isIdentifier(member.name) && member.name.text === 'create');
|
|
85
|
-
const parameter = create?.parameters[0]?.type;
|
|
86
|
-
if (parameter === undefined || !ts.isTypeReferenceNode(parameter) || !ts.isIdentifier(parameter.typeName)) {
|
|
87
|
-
problems.push(`${className} needs \`static create(payload: <Interface>)\` naming its payload interface`);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
events.push({ className, name, version: version ?? 0, ...(compensates === undefined ? {} : { compensates }), payload: payloadOf(ts, sourceFile, parameter.typeName.text, problems, className) });
|
|
91
|
-
}
|
|
92
|
-
return { events, problems };
|
|
93
|
-
}
|
|
94
|
-
/** The sorted object: keys in code-point order, recursively (what the snapshot prints). */
|
|
95
|
-
const sorted = (value) => (value !== null && typeof value === 'object' && !Array.isArray(value) ? Object.fromEntries(Object.keys(value).sort(byCodeUnit).map((key) => [key, sorted(value[key])])) : value);
|
|
96
|
-
/** The text of the snapshot of a service from its event classes: 2-space JSON, sorted keys, one final newline. */
|
|
97
|
-
export function snapshotText(service, events) {
|
|
98
|
-
const table = Object.fromEntries(events.map(({ name, version, compensates, payload }) => [name, { version, payload, ...(compensates === undefined ? {} : { compensates }) }]));
|
|
99
|
-
return `${JSON.stringify(sorted({ schema: EVENT_CONTRACT_SCHEMA, service, events: table }), null, 2)}\n`;
|
|
100
|
-
}
|
|
101
|
-
/** The snapshot's text with line endings folded, for comparing a committed file to a fresh one. */
|
|
102
|
-
export const folded = (text) => text.replaceAll('\r\n', '\n');
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// git-hooks-dir.mjs - whether a checkout's hooks folder holds installed hooks. The one judgement read by `starci npm ci` and
|
|
2
|
-
// `starci npm install` (scripts/machine/npm-hooks.mjs, which runs the app's hook installer when it fails) and by the HFS check
|
|
3
|
-
// HFS_HOOKS_NOT_INSTALLED (scripts/hfs/architecture/hfs.mjs). husky's `.husky/_` is generated per checkout: a linked worktree or
|
|
4
|
-
// an install whose lifecycle scripts were ignored has none, or only the runtime's own wrapped hooks, so git runs no pre-commit gate.
|
|
5
|
-
import fs from 'node:fs';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
|
|
8
|
-
/** husky's generated hooks folder; every hook file in it sources the dispatcher `h`, which runs the tracked `.husky/<hook>`. */
|
|
9
|
-
const HUSKY_GENERATED = /^\.husky\/_\/?$/u;
|
|
10
|
-
const HUSKY_DISPATCHER = 'h';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The state of the hooks folder `hooksPath` (a core.hooksPath value, relative to the checkout `root` or absolute):
|
|
14
|
-
* `{ state, dir }` with state `installed`, `missing` (no such folder), `empty` (no hook file; for husky's `.husky/_`, no
|
|
15
|
-
* dispatcher `h`) or `unreadable` (with `error`).
|
|
16
|
-
*/
|
|
17
|
-
export function hooksDirState(root, hooksPath) {
|
|
18
|
-
const value = String(hooksPath ?? '').trim().replaceAll('\\', '/');
|
|
19
|
-
const dir = path.resolve(root, value);
|
|
20
|
-
let entries;
|
|
21
|
-
try {
|
|
22
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
23
|
-
} catch (error) {
|
|
24
|
-
if (error?.code === 'ENOENT' || error?.code === 'ENOTDIR') return { state: 'missing', dir };
|
|
25
|
-
return { state: 'unreadable', dir, error: String(error?.message ?? error) };
|
|
26
|
-
}
|
|
27
|
-
const files = entries.filter((entry) => entry.isFile() && entry.name !== '.gitignore').map((entry) => entry.name);
|
|
28
|
-
const installed = HUSKY_GENERATED.test(value) ? files.includes(HUSKY_DISPATCHER) : files.length > 0;
|
|
29
|
-
return { state: installed ? 'installed' : 'empty', dir };
|
|
30
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// git.mjs — pure helpers over git's text output, spawn results and env. The git spawn itself lives in scripts/api/git/ (lib.mjs and its call files).
|
|
2
|
-
/**
|
|
3
|
-
* git's C-quoted diff path decoded - `"b\303\251"` a `+++ ` header line prints when core.quotePath
|
|
4
|
-
* covers the name. Octal escapes become \u00XX for JSON.parse (which answers \n, \t, \" and \\);
|
|
5
|
-
* a value not wrapped in quotes passes through unchanged.
|
|
6
|
-
*/
|
|
7
|
-
export const unquoteDiffPath = (value) => /^".*"$/.test(value)
|
|
8
|
-
? JSON.parse(value.replace(/\\([0-7]{3})/g, (_, octal) => String.raw `\u00${Number.parseInt(octal, 8).toString(16).padStart(2, '0')}`))
|
|
9
|
-
: value;
|
|
10
|
-
// git's repository-local variables (git rev-parse --local-env-vars). A hook or alias run in a linked worktree exports
|
|
11
|
-
// GIT_DIR=<main>/.git/worktrees/<wt>; a spec inheriting it pointed every fixture git at the LIVE .claude repo and re-inited
|
|
12
|
-
// it core.bare=true (2026-09-29, a6f60352c). e2e/setup/isolated-registry.mjs drops the same list.
|
|
13
|
-
export const GIT_LOCAL_ENV_VARS = ['GIT_DIR', 'GIT_COMMON_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_OBJECT_DIRECTORY', 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_IMPLICIT_WORK_TREE', 'GIT_PREFIX', 'GIT_CONFIG', 'GIT_CONFIG_PARAMETERS', 'GIT_CONFIG_COUNT', 'GIT_GRAFT_FILE', 'GIT_NO_REPLACE_OBJECTS', 'GIT_REPLACE_REF_BASE', 'GIT_SHALLOW_FILE', 'GIT_INTERNAL_SUPER_PREFIX'];
|
|
14
|
-
/** `parent` (the caller's env) without git's repository-local variables (GIT_CONFIG_KEY_n/VALUE_n go with GIT_CONFIG_COUNT). Pure. */
|
|
15
|
-
export function withoutGitLocalEnv(parent) {
|
|
16
|
-
const env = { ...parent };
|
|
17
|
-
for (const key of Object.keys(env))
|
|
18
|
-
if (GIT_LOCAL_ENV_VARS.includes(key) || /^GIT_CONFIG_(KEY|VALUE)_\d+$/.test(key))
|
|
19
|
-
delete env[key];
|
|
20
|
-
return env;
|
|
21
|
-
}
|
|
22
|
-
/** A git spawn result (a scripts/api/git call file's) as {ok, stdout, error}: ok only on a clean exit, error from stderr or the spawn. Pure. */
|
|
23
|
-
export const gitResultOf = (r) => ({
|
|
24
|
-
ok: !r.error && r.status === 0,
|
|
25
|
-
stdout: r.stdout ?? '',
|
|
26
|
-
error: (r.stderr ?? '').trim() || String(r.error?.message ?? (r.status == null ? 'timed out' : `exit ${r.status}`)),
|
|
27
|
-
});
|
|
28
|
-
/** A git spawn result's stdout text; throws the spawn error, or an Error naming `what` with git's stderr and exit status, unless git exited 0. Pure. */
|
|
29
|
-
export function gitOutputOf(r, what = 'git') {
|
|
30
|
-
if (r.error)
|
|
31
|
-
throw r.error;
|
|
32
|
-
if (r.status !== 0)
|
|
33
|
-
throw Object.assign(new Error(`${what} exited ${r.status}: ${(r.stderr ?? '').trim()}`), { status: r.status, stderr: r.stderr });
|
|
34
|
-
return r.stdout;
|
|
35
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// glob.mjs — the path-glob subset ESLint, SonarQube and the scoped-lint config share: `**` spans directories,
|
|
2
|
-
// `*` and `?` stay inside one segment, `{a,b}` alternates.
|
|
3
|
-
import { posixPath } from './path-key.mjs';
|
|
4
|
-
/** Every alternative a `{a,b}` pattern spells, braces expanded left to right. */
|
|
5
|
-
export function braceVariants(value) {
|
|
6
|
-
const match = /\{([^{}]+)\}/.exec(value);
|
|
7
|
-
return match ? match[1].split(',').flatMap((part) => braceVariants(`${value.slice(0, match.index)}${part}${value.slice(match.index + match[0].length)}`)) : [value];
|
|
8
|
-
}
|
|
9
|
-
/** The anchored RegExp of one brace-free glob, read as a posix path (backslashes and a leading './' folded). */
|
|
10
|
-
export function globExpression(value) {
|
|
11
|
-
const input = posixPath(value);
|
|
12
|
-
let source = '';
|
|
13
|
-
for (let i = 0; i < input.length; i += 1) {
|
|
14
|
-
const c = input.charAt(i);
|
|
15
|
-
if (c === '*' && input[i + 1] === '*') {
|
|
16
|
-
i += 1;
|
|
17
|
-
if (input[i + 1] === '/') {
|
|
18
|
-
i += 1;
|
|
19
|
-
source += '(?:.*/)?';
|
|
20
|
-
}
|
|
21
|
-
else
|
|
22
|
-
source += '.*';
|
|
23
|
-
}
|
|
24
|
-
else if (c === '*')
|
|
25
|
-
source += '[^/]*';
|
|
26
|
-
else if (c === '?')
|
|
27
|
-
source += '[^/]';
|
|
28
|
-
else
|
|
29
|
-
source += /[.+^${}()|[\]\\]/.test(c) ? `\\${c}` : c;
|
|
30
|
-
}
|
|
31
|
-
return new RegExp(`^${source}$`);
|
|
32
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// Grammar-family lint selection reads the family catalog; an absent selection never chooses a family.
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { parseYamlCached } from './yaml-cached.mjs';
|
|
4
|
-
const CATALOG_FILE = new URL('../../knowledge/grammars/index.yaml', import.meta.url);
|
|
5
|
-
function readCatalog() {
|
|
6
|
-
return parseYamlCached(fs.readFileSync(CATALOG_FILE, 'utf8'));
|
|
7
|
-
}
|
|
8
|
-
function selectedFamily(family) {
|
|
9
|
-
if (typeof family !== 'string' || !family.trim())
|
|
10
|
-
throw new Error('sides.fe.grammar must explicitly name the selected Grammar family');
|
|
11
|
-
const catalog = readCatalog();
|
|
12
|
-
const matches = (catalog.families ?? []).filter(entry => entry.id === family);
|
|
13
|
-
if (matches.length !== 1)
|
|
14
|
-
throw new Error(`Grammar family ${family} has no declared lint contract in knowledge/grammars/index.yaml`);
|
|
15
|
-
return { catalog, selected: matches[0] };
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Resolve a selection to its declared family id; only a catalog family id resolves, there are no aliases.
|
|
19
|
-
* @param {string} family - The id an app or caller names (sides.fe.grammar).
|
|
20
|
-
* @returns {{ id: string }} The declared family id.
|
|
21
|
-
*/
|
|
22
|
-
export function resolveGrammarFamily(family) {
|
|
23
|
-
return Object.freeze({ id: selectedFamily(family).selected.id });
|
|
24
|
-
}
|
|
25
|
-
/** The explicitly selected authored family entry; callers share the catalog lookup rather than inferring a family. */
|
|
26
|
-
export function grammarFamilyFor(family) {
|
|
27
|
-
return Object.freeze(selectedFamily(family).selected);
|
|
28
|
-
}
|
|
29
|
-
/** The declared family's lint contract, including an explicit null package when that family has no rules. */
|
|
30
|
-
export function grammarLintFor(family) {
|
|
31
|
-
const { selected } = selectedFamily(family);
|
|
32
|
-
if (!selected.lint || !Object.hasOwn(selected.lint, 'package')) {
|
|
33
|
-
throw new Error(`Grammar family ${family} has no declared lint contract in knowledge/grammars/index.yaml`);
|
|
34
|
-
}
|
|
35
|
-
const lint = selected.lint;
|
|
36
|
-
if (lint.package === null)
|
|
37
|
-
return Object.freeze({ family: selected.id, package: null });
|
|
38
|
-
if (typeof lint.package !== 'string' || !lint.package.startsWith('@starci/eslint-grammar-')
|
|
39
|
-
|| typeof lint.factory !== 'string' || !/^[a-zA-Z][a-zA-Z0-9]*$/.test(lint.factory)
|
|
40
|
-
|| typeof lint.prefix !== 'string' || !/^[a-z][a-z0-9-]*$/.test(lint.prefix)) {
|
|
41
|
-
throw new Error(`Grammar family ${family} has an invalid lint contract in knowledge/grammars/index.yaml`);
|
|
42
|
-
}
|
|
43
|
-
return Object.freeze({ family: selected.id, package: lint.package, factory: lint.factory, prefix: lint.prefix });
|
|
44
|
-
}
|
|
45
|
-
/** The selected family's shared component/export contract, resolved through its catalog reference. */
|
|
46
|
-
export function grammarContractFor(family) {
|
|
47
|
-
const { catalog, selected } = selectedFamily(family);
|
|
48
|
-
const owners = (catalog.families ?? []).filter(entry => entry.id === selected.contractRef);
|
|
49
|
-
const contract = owners.length === 1 ? owners[0]?.componentContract : null;
|
|
50
|
-
if (!contract || typeof contract.package !== 'string' || !contract.package
|
|
51
|
-
|| typeof contract.entry !== 'string' || !contract.entry.startsWith(`${contract.package}/`)
|
|
52
|
-
|| typeof contract.styleEntry !== 'string' || !contract.styleEntry.startsWith(`${contract.package}/`)
|
|
53
|
-
|| !Array.isArray(contract.peers) || !contract.peers.every(peer => typeof peer === 'string' && peer.trim())) {
|
|
54
|
-
throw new Error(`Grammar family ${family} has no valid component contract in knowledge/grammars/index.yaml`);
|
|
55
|
-
}
|
|
56
|
-
return Object.freeze({ ...contract, peers: Object.freeze([...contract.peers]) });
|
|
57
|
-
}
|