@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,9 +0,0 @@
|
|
|
1
|
-
// config-get.mjs — `git config [--local] --get <key>`: one configuration value of a checkout (empty when unset).
|
|
2
|
-
import { gitRunner } from './lib.mjs';
|
|
3
|
-
/**
|
|
4
|
-
* {ok, stdout, stderr}; `local` reads the repository's own config only; `env` replaces the process env (a caller drops
|
|
5
|
-
* git's repository-local variables). git: the caller's runner or null.
|
|
6
|
-
*/
|
|
7
|
-
export function configGet(cwd, key, { local = false, env = undefined, git = null } = {}) {
|
|
8
|
-
return gitRunner(git)(['config', ...(local ? ['--local'] : []), '--get', key], env ? { cwd, env } : { cwd });
|
|
9
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
// diff.mjs — `git diff <args>`: the changes between commits, the index and the working tree.
|
|
2
|
-
import { runGit } from './lib.mjs';
|
|
3
|
-
/** The spawn result {status, stdout, stderr, error} of `git diff ...args`; options are runGit's (cwd or dir, config, timeout, maxBuffer, input, encoding, env, git). */
|
|
4
|
-
export const diff = (args = [], options = {}) => runGit(['diff', ...args], options);
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// scripts/api/git/lib.mjs — the one place the runtime spawns git (RT_EXTERNAL_OWNER of scripts/hfs/runtime-rules/external-owner.mjs enforces it).
|
|
2
|
-
//
|
|
3
|
-
// Every caller spelt the same options by hand - encoding:'utf8', windowsHide:true, sometimes a timeout - with two shapes:
|
|
4
|
-
// `git args` in a cwd and `git -C dir args`. gitSpawn keeps the spawnSync(file, args, options) signature so an injected
|
|
5
|
-
// runner or a spec's fake takes the same three arguments; runGit is the `-C` / `-c` convenience; gitRunner folds any
|
|
6
|
-
// caller's runner into {ok, stdout, stderr}. Only the call files beside this one import it: each names one git verb
|
|
7
|
-
// (diff.mjs, ls-files.mjs, worktree-*.mjs, ...), and a caller folds the spawn result it gets back with the pure
|
|
8
|
-
// helpers of scripts/lib/git.mjs (gitResultOf, gitOutputOf).
|
|
9
|
-
import { assertMutationFence } from '../../lib/mutation-fence.mjs';
|
|
10
|
-
import fs from 'node:fs';
|
|
11
|
-
import os from 'node:os';
|
|
12
|
-
import path from 'node:path';
|
|
13
|
-
import { spawnSync } from 'node:child_process';
|
|
14
|
-
import { withoutGitLocalEnv } from '../../lib/git.mjs';
|
|
15
|
-
import { withTempEnv } from '../../../engine/temp-root.mjs';
|
|
16
|
-
/**
|
|
17
|
-
* Spawn `file` (the git binary) once with `args`: utf8 text, a hidden window, never a shell.
|
|
18
|
-
* Options pass through last, so cwd, timeout, input, env or maxBuffer land as given. encoding:'buffer'
|
|
19
|
-
* is a request for raw bytes, not an encoding: spawnSync encodes a string `input` with it and throws
|
|
20
|
-
* ERR_UNKNOWN_ENCODING, so it reaches spawnSync as encoding:null (Buffer output either way).
|
|
21
|
-
*/
|
|
22
|
-
const gitSpawn = (file, args, options = {}) => {
|
|
23
|
-
assertMutationFence({ kind: 'git-effect', args });
|
|
24
|
-
const spawn = { encoding: 'utf8', windowsHide: true, ...options };
|
|
25
|
-
if (spawn.encoding === 'buffer')
|
|
26
|
-
spawn.encoding = null;
|
|
27
|
-
// tempChildEnv copies the env (node adds NODE_V8_COVERAGE to the env object it is given: a frozen caller env must not throw under coverage) and points TEMP/TMP/TMPDIR at the temp root
|
|
28
|
-
// reason: encoding:null (the former 'buffer') returns Buffers; callers of that mode read the result as raw bytes
|
|
29
|
-
const spawnOptions = withTempEnv(spawn);
|
|
30
|
-
return spawnSync(file, args, spawnOptions);
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* `git args` in `cwd`, or `git -C dir args` when `dir` is given. `git` overrides the binary; `config` ({key: value})
|
|
34
|
-
* prefixes one `-c key=value` per entry (core.quotepath=off, a committer identity). Scoped calls discard ambient
|
|
35
|
-
* hook repository variables; an explicit env remains authoritative, including an intentional temporary index.
|
|
36
|
-
*/
|
|
37
|
-
export const runGit = (args, { cwd = null, dir = null, git = 'git', config = null, ...options } = {}) => gitSpawn(git, [...(dir ? ['-C', dir] : []), ...Object.entries(config ?? {}).flatMap(([key, value]) => ['-c', `${key}=${value}`]), ...args], {
|
|
38
|
-
...(cwd ? { cwd } : {}), ...options,
|
|
39
|
-
...((cwd || dir) && options.env === undefined ? { env: withoutGitLocalEnv(process.env) } : {}),
|
|
40
|
-
});
|
|
41
|
-
/**
|
|
42
|
-
* A caller's git runner folded to (args, opts) -> {ok, stdout, stderr}. `git`: the caller's runner (args, {cwd}) ->
|
|
43
|
-
* {ok|status, stdout|out, stderr|err} (a spec's fake); null: runGit with a 5-minute timeout and a 64 MB buffer.
|
|
44
|
-
*/
|
|
45
|
-
export const gitRunner = (git = null) => (args, opts = {}) => {
|
|
46
|
-
const r = git ? git(args, opts) : runGit(args, { timeout: 300_000, maxBuffer: 64 * 1024 * 1024, ...opts });
|
|
47
|
-
return { ok: r?.ok ?? (!r?.error && r?.status === 0), stdout: String(r?.stdout ?? r?.out ?? '').trim(), stderr: String(r?.stderr ?? r?.err ?? (typeof r?.error === 'object' ? r.error?.message : undefined) ?? r?.error ?? '').trim() };
|
|
48
|
-
};
|
|
49
|
-
let cachedGit;
|
|
50
|
-
const gitPathOf = ({ env, platform, home, exists }) => {
|
|
51
|
-
const p = platform === 'win32' ? path.win32 : path.posix;
|
|
52
|
-
const pathKey = Object.keys(env).find((name) => name.toLowerCase() === 'path');
|
|
53
|
-
const shim = p.join(home, '.starci', 'bin');
|
|
54
|
-
const same = (a, b) => (platform === 'win32' ? p.resolve(a).toLowerCase() === p.resolve(b).toLowerCase() : p.resolve(a) === p.resolve(b));
|
|
55
|
-
const binary = platform === 'win32' ? 'git.exe' : 'git';
|
|
56
|
-
for (const raw of String(pathKey ? env[pathKey] : '').split(platform === 'win32' ? ';' : ':')) {
|
|
57
|
-
const dir = raw.replace(/^"(.*)"$/, '$1');
|
|
58
|
-
const file = dir && p.isAbsolute(dir) && !same(dir, shim) ? p.join(dir, binary) : null;
|
|
59
|
-
if (file && exists(file))
|
|
60
|
-
return file;
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* The absolute path of the real git binary, or null: the first PATH directory holding git (git.exe on Windows) that is not
|
|
66
|
-
* the StarCi shim directory <home>/.starci/bin (a seat's guard shim is never the git the runtime itself runs). A bare name is never
|
|
67
|
-
* spawned, so a writable directory cannot be reached by name lookup at spawn time. Resolved once per process; options (env,
|
|
68
|
-
* platform, home, exists) are for a spec and bypass the cache.
|
|
69
|
-
*/
|
|
70
|
-
export const gitExecutable = (options = null) => {
|
|
71
|
-
if (!options && cachedGit !== undefined)
|
|
72
|
-
return cachedGit;
|
|
73
|
-
const { env = process.env, platform = process.platform, home = os.homedir(), exists = (file) => fs.statSync(file, { throwIfNoEntry: false })?.isFile() === true } = options ?? {};
|
|
74
|
-
const found = gitPathOf({ env, platform, home, exists });
|
|
75
|
-
if (!options)
|
|
76
|
-
cachedGit = found;
|
|
77
|
-
return found;
|
|
78
|
-
};
|
|
79
|
-
/** The output ceiling of the whole-diff and `cat-file --batch` calls batch (a release diff is tens of megabytes). */
|
|
80
|
-
export const BATCH_MAX_BUFFER = 1024 * 1024 * 1024;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// ls-files.mjs — `git ls-files <args>`: the paths the index tracks (--cached), or the untracked / deleted / ignored ones
|
|
2
|
-
// the flags ask for (-z keeps any file name intact).
|
|
3
|
-
import { runGit } from './lib.mjs';
|
|
4
|
-
/** The spawn result {status, stdout, stderr, error} of `git ls-files ...args`; options are runGit's (cwd or dir, config, timeout, maxBuffer, input, encoding, env, git). */
|
|
5
|
-
export const lsFiles = (args = [], options = {}) => runGit(['ls-files', ...args], options);
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
// ls-tree.mjs — `git ls-tree <args>`: the entries of a tree object.
|
|
2
|
-
import { runGit } from './lib.mjs';
|
|
3
|
-
/** The spawn result {status, stdout, stderr, error} of `git ls-tree ...args`; options are runGit's (cwd or dir, config, timeout, maxBuffer, input, encoding, env, git). */
|
|
4
|
-
export const lsTree = (args = [], options = {}) => runGit(['ls-tree', ...args], options);
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// merge-base.mjs — `git merge-base <a> <b>`: the best common ancestor of two commits. Whether one commit is in another
|
|
2
|
-
// is is-ancestor.mjs.
|
|
3
|
-
import { gitRunner } from './lib.mjs';
|
|
4
|
-
/** The best common ancestor of commits `a` and `b` (a sha), or null when they share none or a ref does not resolve. */
|
|
5
|
-
export const mergeBase = (cwd, a, b, { git = null } = {}) => {
|
|
6
|
-
const r = gitRunner(git)(['merge-base', a, b], { cwd });
|
|
7
|
-
return r.ok && r.stdout ? r.stdout : null;
|
|
8
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
// remote.mjs — `git remote <args>`: the configured remotes (get-url <name>).
|
|
2
|
-
import { runGit } from './lib.mjs';
|
|
3
|
-
/** The spawn result {status, stdout, stderr, error} of `git remote ...args`; options are runGit's (cwd or dir, config, timeout, maxBuffer, input, encoding, env, git). */
|
|
4
|
-
export const remote = (args = [], options = {}) => runGit(['remote', ...args], options);
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
// rev-parse-query.mjs — `git rev-parse <args>`: one rev-parse query (--show-toplevel, --git-common-dir, --git-path, a ref): the text it prints.
|
|
2
|
-
import { runGit } from './lib.mjs';
|
|
3
|
-
/** The spawn result {status, stdout, stderr, error} of `git rev-parse ...args`; options are runGit's (cwd or dir, config, timeout, maxBuffer, input, encoding, env, git). */
|
|
4
|
-
export const revParseQuery = (args = [], options = {}) => runGit(['rev-parse', ...args], options);
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// show.mjs — `git show <args>`: an object of a repository - a file at a revision (`<rev>:<path>`), or a commit's
|
|
2
|
-
// header and message (-s --format=...).
|
|
3
|
-
import { runGit } from './lib.mjs';
|
|
4
|
-
/** The spawn result {status, stdout, stderr, error} of `git show ...args`; options are runGit's (cwd or dir, config, timeout, maxBuffer, input, encoding, env, git). */
|
|
5
|
-
export const show = (args = [], options = {}) => runGit(['show', ...args], options);
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
// tag.mjs — `git tag <args>`: list or create tags (--points-at <rev>, -l <pattern>, -a <name> -m <message>).
|
|
2
|
-
import { runGit } from './lib.mjs';
|
|
3
|
-
/** The spawn result {status, stdout, stderr, error} of `git tag ...args`; options are runGit's (cwd or dir, config, timeout, maxBuffer, input, encoding, env, git). */
|
|
4
|
-
export const tag = (args = [], options = {}) => runGit(['tag', ...args], options);
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { braceVariants, globExpression } from '../lib/glob.mjs';
|
|
3
|
-
import { declaredLogicOf } from './manifest-shape.mjs';
|
|
4
|
-
/**
|
|
5
|
-
* What a slot's `requires`, `allows` and `forbids` entries (knowledge/hfs/slots.yaml) say about a file, read through the
|
|
6
|
-
* resolver of scripts/hfs/slots.mjs. The machine checks that judge "this folder holds only what its slot allows"
|
|
7
|
-
* (feature-shape, fe-slot-allows) and the front-end lint rules (through `hfs.allows(file)` of scripts/hfs/view.mjs) read it here so no check keeps a path list.
|
|
8
|
-
*
|
|
9
|
-
* An entry is a name relative to the slot instance root: `<var>` is the instance's bound variable when the slot binds it
|
|
10
|
-
* (`<feature>`, `<capability>`) and one path segment of any text otherwise (`<action>`), `*` and `?` stay inside a segment,
|
|
11
|
-
* `{a,b}` alternates, a trailing `/` names a directory and everything below it. A slot also admits, unlisted, the unit spec beside each
|
|
12
|
-
* measured file it names (isMeasuredSpec): a file it declares in `logic`, or a named file of a logic role.
|
|
13
|
-
*/
|
|
14
|
-
const VAR = /<([A-Za-z][A-Za-z0-9-]*)>/g;
|
|
15
|
-
const SPEC = /\.spec\.ts$/;
|
|
16
|
-
/**
|
|
17
|
-
* Whether `relative` is the unit spec `<stem>.spec.ts` of a measured file beside it that the slot names: a file the slot declares in
|
|
18
|
-
* `logic`, or a `requires`/`allows` file of a logic role (ruleParams.be.logicRoles), in a slot whose coverage is required and whose tests
|
|
19
|
-
* are unit-beside. The slot admits that spec without listing it, as unit-test-colocated (R47) accepts it.
|
|
20
|
-
*/
|
|
21
|
-
function isMeasuredSpec(resolver, classified, slot, relative, named) {
|
|
22
|
-
if (!SPEC.test(relative) || slot.coverage !== 'required' || slot.tests !== 'unit-beside')
|
|
23
|
-
return false;
|
|
24
|
-
const subject = relative.replace(SPEC, '.ts');
|
|
25
|
-
if (declaredLogicOf(slot).includes(subject))
|
|
26
|
-
return true;
|
|
27
|
-
const role = /\.([a-z0-9-]+)\.ts$/.exec(subject)?.[1];
|
|
28
|
-
// An app resolver keeps no rule parameters of its own: a path on a side reads that side's.
|
|
29
|
-
const params = classified.side ? resolver.sides?.[classified.side]?.ruleParams() : resolver.ruleParams?.();
|
|
30
|
-
return (params?.logicRoles ?? []).includes(role) && named.some((matcher) => matcher.expression.test(subject));
|
|
31
|
-
}
|
|
32
|
-
function matchersOf(entries, bindings) {
|
|
33
|
-
return (entries ?? []).flatMap((entry) => {
|
|
34
|
-
const directory = entry.endsWith('/');
|
|
35
|
-
const body = directory ? entry.slice(0, -1) : entry;
|
|
36
|
-
const filled = body.replace(VAR, (_whole, name) => bindings[name] ?? '*');
|
|
37
|
-
return braceVariants(filled).map((variant) => ({ entry, directory, expression: globExpression(directory ? `${variant}/**` : variant) }));
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/** The path of `file` below the instance root of the slot that owns it. */
|
|
41
|
-
export function relativeToRoot(file, root) {
|
|
42
|
-
return root && file.startsWith(`${root}/`) ? file.slice(root.length + 1) : path.posix.basename(file);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Whether the slot that owns `file` names it in `requires` or `allows` (and does not forbid it); null when no enabled slot
|
|
46
|
-
* owns it. Unlike allowsFile it judges a slot that lists only `requires` too, so a folder closed by its slot (an app's
|
|
47
|
-
* src/) is read from the slot and never from a check's own list.
|
|
48
|
-
*/
|
|
49
|
-
export function slotAdmitsFile(resolver, file) {
|
|
50
|
-
const classified = resolver.classifyPath(file);
|
|
51
|
-
if (classified.status === 'no-slot' || classified.status === 'ambiguous' || !classified.slot)
|
|
52
|
-
return null;
|
|
53
|
-
const slot = resolver.slot(classified.slot);
|
|
54
|
-
const relative = relativeToRoot(classified.path, classified.root);
|
|
55
|
-
const named = matchersOf([...(slot.requires ?? []), ...(slot.allows ?? [])], classified.bindings);
|
|
56
|
-
const hit = named.some(matcher => matcher.expression.test(relative)) || isMeasuredSpec(resolver, classified, slot, relative, named);
|
|
57
|
-
const forbidden = matchersOf(slot.forbids, classified.bindings).some(matcher => matcher.expression.test(relative) || matcher.expression.test(`${relative}/`));
|
|
58
|
-
return hit && !forbidden;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* {slot, root, relative, allowed, entry?, forbiddenBy?} for a repository-relative file, or null when no enabled slot owns
|
|
62
|
-
* it or the slot names no `allows`. `allowed` is true when the relative path matches a `requires` or `allows` entry.
|
|
63
|
-
*/
|
|
64
|
-
export function allowsFile(resolver, file) {
|
|
65
|
-
const classified = resolver.classifyPath(file);
|
|
66
|
-
if (classified.status === 'no-slot' || classified.status === 'ambiguous' || !classified.slot)
|
|
67
|
-
return null;
|
|
68
|
-
const slot = resolver.slot(classified.slot);
|
|
69
|
-
if (!slot?.allows?.length)
|
|
70
|
-
return null;
|
|
71
|
-
const relative = relativeToRoot(classified.path, classified.root);
|
|
72
|
-
const named = matchersOf([...(slot.requires ?? []), ...slot.allows], classified.bindings);
|
|
73
|
-
const hit = named.find(matcher => matcher.expression.test(relative));
|
|
74
|
-
const spec = !hit && isMeasuredSpec(resolver, classified, slot, relative, named);
|
|
75
|
-
const forbidden = matchersOf(slot.forbids, classified.bindings).find(matcher => matcher.expression.test(relative) || matcher.expression.test(`${relative}/`));
|
|
76
|
-
return { slot: slot.id, root: classified.root, relative, allowed: (Boolean(hit) || spec) && !forbidden, entry: hit?.entry, forbiddenBy: forbidden?.entry, allows: slot.allows };
|
|
77
|
-
}
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import { canonical, isInside } from './config.mjs';
|
|
2
|
-
import { hasAnyFlag, isConstVariable, sourceLocation } from '../../lib/ts-ast.mjs';
|
|
3
|
-
import { UNPROVEN_FRAMEWORK, isUnshadowedCommonJsRequire, relativePath, unwrapExpression } from './typescript.mjs';
|
|
4
|
-
/** `expression` unwrapped by the caller's own predicate set (a predicate absent on an older ts reads as never). */
|
|
5
|
-
export function unwrapEach(_ts, expression, predicates) {
|
|
6
|
-
let current = expression;
|
|
7
|
-
// The predicates the caller passes select wrapper nodes, which all carry an `expression` child.
|
|
8
|
-
while (current && predicates.some((predicate) => predicate?.(current)))
|
|
9
|
-
current = current.expression;
|
|
10
|
-
return current;
|
|
11
|
-
}
|
|
12
|
-
/** `value` with every TS alias hop resolved (a re-exported import reads as its target symbol). */
|
|
13
|
-
export function normalizedSymbolValue(ts, checker, value = null) {
|
|
14
|
-
let symbol = value;
|
|
15
|
-
const seen = new Set();
|
|
16
|
-
while (symbol && hasAnyFlag(symbol.flags, ts.SymbolFlags.Alias) && !seen.has(symbol)) {
|
|
17
|
-
seen.add(symbol);
|
|
18
|
-
const target = checker.getAliasedSymbol(symbol);
|
|
19
|
-
if (!target || target === symbol)
|
|
20
|
-
break;
|
|
21
|
-
symbol = target;
|
|
22
|
-
}
|
|
23
|
-
return symbol;
|
|
24
|
-
}
|
|
25
|
-
/** The symbol `node` names, aliases resolved. */
|
|
26
|
-
export function normalizedSymbol(ts, checker, node) {
|
|
27
|
-
return normalizedSymbolValue(ts, checker, checker?.getSymbolAtLocation(node) ?? null);
|
|
28
|
-
}
|
|
29
|
-
/** The identifier or member-name node an expression selects through unwrapExpression, or null. */
|
|
30
|
-
export function selectedNode(ts, expression) {
|
|
31
|
-
const unwrapped = unwrapExpression(ts, expression);
|
|
32
|
-
if (ts.isIdentifier(unwrapped))
|
|
33
|
-
return unwrapped;
|
|
34
|
-
if (ts.isPropertyAccessExpression(unwrapped))
|
|
35
|
-
return unwrapped.name;
|
|
36
|
-
if (ts.isElementAccessExpression(unwrapped) && ts.isStringLiteralLike(unwrapped.argumentExpression))
|
|
37
|
-
return unwrapped.argumentExpression;
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The symbol `node` ultimately evaluates to: its own symbol, followed through a single `const` variable
|
|
42
|
-
* initializer (and so on). `unselected: 'null'` answers null when `node` selects no name at all.
|
|
43
|
-
*/
|
|
44
|
-
export function valueSymbol(ts, checker, node, seen = new Set(), { unselected = 'node' } = {}) {
|
|
45
|
-
const selected = selectedNode(ts, node);
|
|
46
|
-
if (!selected && unselected === 'null')
|
|
47
|
-
return null;
|
|
48
|
-
const symbol = normalizedSymbol(ts, checker, selected ?? node);
|
|
49
|
-
if (!symbol || seen.has(symbol))
|
|
50
|
-
return symbol;
|
|
51
|
-
seen.add(symbol);
|
|
52
|
-
const declarations = symbol.getDeclarations?.() ?? [];
|
|
53
|
-
const [only] = declarations;
|
|
54
|
-
if (declarations.length === 1 && only && ts.isVariableDeclaration(only) && only.initializer
|
|
55
|
-
&& isConstVariable(ts, only)) {
|
|
56
|
-
return valueSymbol(ts, checker, only.initializer, seen, { unselected });
|
|
57
|
-
}
|
|
58
|
-
return symbol;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* The expressions `declaration` returns: its body when it is an expression-bodied arrow/function, else every
|
|
62
|
-
* `return`'s argument without descending into nested functions. `functionLike` overrides which node kinds bound
|
|
63
|
-
* that descent (default the four callable declaration kinds; pass `ts.isFunctionLike` for the wider set).
|
|
64
|
-
*/
|
|
65
|
-
export function returnedExpressions(ts, declaration, { functionLike = null } = {}) {
|
|
66
|
-
const boundary = functionLike ?? ((node) => ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)
|
|
67
|
-
|| ts.isArrowFunction(node) || ts.isFunctionExpression(node));
|
|
68
|
-
if ((ts.isArrowFunction(declaration) || ts.isFunctionExpression(declaration)) && !ts.isBlock(declaration.body))
|
|
69
|
-
return [declaration.body];
|
|
70
|
-
// A node the boundary predicate accepts is a function-like, which carries a `body`.
|
|
71
|
-
const body = boundary(declaration) ? declaration.body : null;
|
|
72
|
-
if (!body || !ts.isBlock(body))
|
|
73
|
-
return [];
|
|
74
|
-
const returned = [];
|
|
75
|
-
const visit = (node) => {
|
|
76
|
-
if (node !== body && boundary(node))
|
|
77
|
-
return;
|
|
78
|
-
if (ts.isReturnStatement(node) && node.expression)
|
|
79
|
-
returned.push(node.expression);
|
|
80
|
-
else
|
|
81
|
-
ts.forEachChild(node, visit);
|
|
82
|
-
};
|
|
83
|
-
visit(body);
|
|
84
|
-
return returned;
|
|
85
|
-
}
|
|
86
|
-
/** A node's decorators across TS versions (ts.getDecorators, else the legacy `decorators` property). */
|
|
87
|
-
export function nodeDecorators(ts, node) {
|
|
88
|
-
return ts.canHaveDecorators(node) ? ts.getDecorators(node) ?? [] : node.decorators ?? [];
|
|
89
|
-
}
|
|
90
|
-
/** One finding row: rule id, root-relative path, node position and message, plus rule extras. */
|
|
91
|
-
export function violation(config, sourceFile, node, ruleId, message, extra = {}) {
|
|
92
|
-
return { ruleId, path: relativePath(config.root, sourceFile.fileName), ...sourceLocation(sourceFile, node), message, ...extra };
|
|
93
|
-
}
|
|
94
|
-
/** Whether `match` holds for `node` or a descendant (the walk stops at the first match). */
|
|
95
|
-
export function anyDescendant(ts, node, match) {
|
|
96
|
-
let found = false;
|
|
97
|
-
const visit = (current) => {
|
|
98
|
-
if (found)
|
|
99
|
-
return;
|
|
100
|
-
if (match(current)) {
|
|
101
|
-
found = true;
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
ts.forEachChild(current, visit);
|
|
105
|
-
};
|
|
106
|
-
visit(node);
|
|
107
|
-
return found;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* The framework kinds `expression` can produce: `directOf(ts, checker, {symbol, selected, targets})` maps a
|
|
111
|
-
* selected node's symbols to a kind (default `targets.get(symbol)`); `shorthandOf` (when set) also resolves
|
|
112
|
-
* shorthand-property declarations and descends property assignments; `newExpression` descends `new X()` callees.
|
|
113
|
-
*/
|
|
114
|
-
const addKinds = (target, source) => { for (const kind of source)
|
|
115
|
-
target.add(kind); };
|
|
116
|
-
const kindsFromReturns = (ts, checker, declaration, targets, options) => {
|
|
117
|
-
const kinds = new Set();
|
|
118
|
-
for (const returned of returnedExpressions(ts, declaration))
|
|
119
|
-
addKinds(kinds, tracedFrameworkKinds(ts, checker, returned, targets, options));
|
|
120
|
-
return kinds;
|
|
121
|
-
};
|
|
122
|
-
const kindsFromDeclaration = (ts, checker, declaration, targets, options, shorthandOf) => {
|
|
123
|
-
const kinds = new Set();
|
|
124
|
-
if (ts.isVariableDeclaration(declaration) && declaration.initializer)
|
|
125
|
-
addKinds(kinds, tracedFrameworkKinds(ts, checker, declaration.initializer, targets, options));
|
|
126
|
-
if (shorthandOf && ts.isShorthandPropertyAssignment(declaration)) {
|
|
127
|
-
const target = normalizedSymbolValue(ts, checker, checker.getShorthandAssignmentValueSymbol?.(declaration));
|
|
128
|
-
const kind = shorthandOf(ts, checker, target, targets);
|
|
129
|
-
if (kind)
|
|
130
|
-
kinds.add(kind);
|
|
131
|
-
}
|
|
132
|
-
if (shorthandOf && ts.isPropertyAssignment(declaration))
|
|
133
|
-
addKinds(kinds, tracedFrameworkKinds(ts, checker, declaration.initializer, targets, options));
|
|
134
|
-
addKinds(kinds, kindsFromReturns(ts, checker, declaration, targets, options));
|
|
135
|
-
return kinds;
|
|
136
|
-
};
|
|
137
|
-
const kindsFromSymbol = (ts, checker, symbol, targets, seen, options) => {
|
|
138
|
-
const nextSeen = new Set(seen).add(symbol);
|
|
139
|
-
const declarationOptions = { ...options, seen: nextSeen };
|
|
140
|
-
const kinds = new Set();
|
|
141
|
-
for (const declaration of symbol.getDeclarations?.() ?? [])
|
|
142
|
-
addKinds(kinds, kindsFromDeclaration(ts, checker, declaration, targets, declarationOptions, options.shorthandOf));
|
|
143
|
-
return kinds;
|
|
144
|
-
};
|
|
145
|
-
const defaultDirectOf = (_ts, _checker, { symbol, targets }) => targets.get(symbol) ?? null;
|
|
146
|
-
export function tracedFrameworkKinds(ts, checker, expression, targets, { seen = new Set(), depth = 0, directOf = null, shorthandOf = null, newExpression = false } = {}) {
|
|
147
|
-
if (!expression)
|
|
148
|
-
return new Set();
|
|
149
|
-
if (depth > 10)
|
|
150
|
-
return new Set([UNPROVEN_FRAMEWORK]);
|
|
151
|
-
const unwrapped = unwrapExpression(ts, expression);
|
|
152
|
-
const selected = selectedNode(ts, unwrapped);
|
|
153
|
-
const symbol = selected ? normalizedSymbol(ts, checker, selected) : null;
|
|
154
|
-
const direct = symbol && selected ? (directOf ?? defaultDirectOf)(ts, checker, { symbol, selected, targets }) : null;
|
|
155
|
-
if (direct)
|
|
156
|
-
return new Set([direct]);
|
|
157
|
-
const options = { depth: depth + 1, directOf, shorthandOf, newExpression };
|
|
158
|
-
if (ts.isArrowFunction(unwrapped) || ts.isFunctionExpression(unwrapped))
|
|
159
|
-
return kindsFromReturns(ts, checker, unwrapped, targets, { ...options, seen });
|
|
160
|
-
if (ts.isCallExpression(unwrapped)) {
|
|
161
|
-
const kinds = tracedFrameworkKinds(ts, checker, unwrapped.expression, targets, { ...options, seen });
|
|
162
|
-
if (kinds.size)
|
|
163
|
-
return kinds;
|
|
164
|
-
}
|
|
165
|
-
if (newExpression && ts.isNewExpression(unwrapped))
|
|
166
|
-
return tracedFrameworkKinds(ts, checker, unwrapped.expression, targets, { ...options, seen });
|
|
167
|
-
if (!symbol || seen.has(symbol))
|
|
168
|
-
return new Set();
|
|
169
|
-
return kindsFromSymbol(ts, checker, symbol, targets, seen, options);
|
|
170
|
-
}
|
|
171
|
-
/** 'unproven framework' | 'multiple framework' | the one kind | null, for a decorator whose expression constructs. */
|
|
172
|
-
export function constructedDecoratorKind(ts, checker, decorator, targets, traceOpts = {}) {
|
|
173
|
-
const callee = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
174
|
-
const kinds = tracedFrameworkKinds(ts, checker, callee, targets, traceOpts);
|
|
175
|
-
if (kinds.has(UNPROVEN_FRAMEWORK))
|
|
176
|
-
return 'unproven framework';
|
|
177
|
-
if (kinds.size === 1)
|
|
178
|
-
return [...kinds][0] ?? null;
|
|
179
|
-
return kinds.size ? 'multiple framework' : null;
|
|
180
|
-
}
|
|
181
|
-
/** The target a decorator resolves to through a `let`/`var` alias's single initializer, or null. */
|
|
182
|
-
export function mutableDecoratorKind(ts, checker, decorator, targets) {
|
|
183
|
-
const callee = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
184
|
-
const selected = selectedNode(ts, callee);
|
|
185
|
-
const symbol = selected ? normalizedSymbol(ts, checker, selected) : null;
|
|
186
|
-
const declarations = symbol?.getDeclarations?.() ?? [];
|
|
187
|
-
const [only] = declarations;
|
|
188
|
-
if (declarations.length !== 1 || !only || !ts.isVariableDeclaration(only) || !only.initializer
|
|
189
|
-
|| isConstVariable(ts, only))
|
|
190
|
-
return null;
|
|
191
|
-
const resolved = valueSymbol(ts, checker, only.initializer);
|
|
192
|
-
return (resolved ? targets.get(resolved) : undefined) ?? null;
|
|
193
|
-
}
|
|
194
|
-
/** The callee expression of a decorator (the called expression of `@x(...)`, else the expression itself). */
|
|
195
|
-
export function decoratorCallee(ts, decorator) {
|
|
196
|
-
return ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* The module `statement` (import, export-from or import-equals) statically binds: its specifier text, the
|
|
200
|
-
* module's symbol and its exported symbols by name (aliases resolved); `symbol` is null when the module does
|
|
201
|
-
* not resolve. Null when the statement names no static specifier.
|
|
202
|
-
*/
|
|
203
|
-
export function moduleExportsOf(ts, checker, statement) {
|
|
204
|
-
let moduleSpecifier = null;
|
|
205
|
-
if ((ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement))
|
|
206
|
-
&& statement.moduleSpecifier && ts.isStringLiteralLike(statement.moduleSpecifier))
|
|
207
|
-
moduleSpecifier = statement.moduleSpecifier;
|
|
208
|
-
let importEquals = null;
|
|
209
|
-
if (ts.isImportEqualsDeclaration(statement) && ts.isExternalModuleReference(statement.moduleReference)
|
|
210
|
-
&& statement.moduleReference.expression && ts.isStringLiteralLike(statement.moduleReference.expression))
|
|
211
|
-
importEquals = statement.moduleReference.expression;
|
|
212
|
-
const specifierNode = moduleSpecifier ?? importEquals;
|
|
213
|
-
if (!specifierNode)
|
|
214
|
-
return null;
|
|
215
|
-
const specifier = specifierNode.text;
|
|
216
|
-
const symbol = checker.getSymbolAtLocation(specifierNode) ?? null;
|
|
217
|
-
const exports = new Map((symbol ? checker.getExportsOfModule(symbol) : [])
|
|
218
|
-
.map((item) => [item.getName(), normalizedSymbolValue(ts, checker, item) ?? null]));
|
|
219
|
-
return { specifierNode, specifier, symbol, exports };
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* The program source files a framework-target scan of `checker` judges: every file in `localFiles`, plus (when
|
|
223
|
-
* `root` is given) declaration files inside the root but outside node_modules. Null when no program of the
|
|
224
|
-
* context owns the checker.
|
|
225
|
-
*/
|
|
226
|
-
export function programSourcesOf(context, checker, localFiles, { root = null } = {}) {
|
|
227
|
-
const program = context.programs.find(candidate => candidate.getTypeChecker() === checker) ?? null;
|
|
228
|
-
if (!program)
|
|
229
|
-
return null;
|
|
230
|
-
return program.getSourceFiles().filter(sourceFile => localFiles.has(canonical(sourceFile.fileName))
|
|
231
|
-
|| (root && sourceFile.isDeclarationFile && isInside(root, sourceFile.fileName)
|
|
232
|
-
&& !sourceFile.fileName.replaceAll('\\', '/').includes('/node_modules/')));
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* The CommonJS require() caveat every framework scan reports: each `require('<specifier>')` `accepted` pushes
|
|
236
|
-
* `${filePath} uses a CommonJS <label ?? specifier> <detail>` (the import-shape reasoning cannot prove that binding).
|
|
237
|
-
*/
|
|
238
|
-
export function commonJsRequireReasons(ts, checker, sourceFile, accepted, reasons, filePath, detail, labelArgument) {
|
|
239
|
-
const label = labelArgument ?? null;
|
|
240
|
-
const visit = (node) => {
|
|
241
|
-
if (ts.isCallExpression(node) && isUnshadowedCommonJsRequire(ts, checker, node.expression) && node.arguments.length === 1) {
|
|
242
|
-
const [argument] = node.arguments;
|
|
243
|
-
if (argument && ts.isStringLiteralLike(argument) && accepted(argument.text)) {
|
|
244
|
-
reasons.push(`${filePath} uses a CommonJS ${label ?? argument.text} ${detail}`);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
ts.forEachChild(node, visit);
|
|
248
|
-
};
|
|
249
|
-
visit(sourceFile);
|
|
250
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { readTextFile } from '../../lib/read-text.mjs';
|
|
2
|
-
// Owner ruling 2026-09-29 (layout 2026-09-30): integration, e2e and contract run MANUALLY only. No hook, default typecheck,
|
|
3
|
-
// coverage run or automatic CI trigger may include those trees or run those projects. Linting the e2e files is not running them: ESLint reads them
|
|
4
|
-
// as syntax in the one repository-wide lint run (the factory's e2e block), so no `lint:e2e` command exists to judge.
|
|
5
|
-
const E2E_COMMAND = new RegExp([
|
|
6
|
-
String.raw `\btest:(?:e2e|integration|contract)\b|`,
|
|
7
|
-
String.raw `\btypecheck:tests\b|`,
|
|
8
|
-
String.raw `--selectProjects\s+(?:e2e|integration|contract)\b|`,
|
|
9
|
-
String.raw `src\/tests\/(?:world|integration|e2e|contract)\b|`,
|
|
10
|
-
String.raw `jest[^\n|&;]*(?:e2e|integration|contract)`,
|
|
11
|
-
].join(''), 'u');
|
|
12
|
-
const UNIT_RUN_SCRIPTS = ['test', 'test:unit', 'test:ci', 'test:coverage', 'test:cov'];
|
|
13
|
-
const runsE2e = (text) => E2E_COMMAND.test(String(text).replace(/--ignore-pattern[= ]+(?:"[^"]*"|'[^']*'|\S+)/gu, ''));
|
|
14
|
-
const withoutComments = (text) => text.split('\n').filter(line => !/^\s*#/u.test(line)).join('\n');
|
|
15
|
-
function inspectHooks(state) {
|
|
16
|
-
for (const hook of ['.husky/pre-commit', '.husky/pre-push']) {
|
|
17
|
-
const text = readTextFile(state.root, hook);
|
|
18
|
-
if (text === null)
|
|
19
|
-
continue;
|
|
20
|
-
const body = withoutComments(text);
|
|
21
|
-
if (runsE2e(body))
|
|
22
|
-
state.finding(state.rule, hook, `${hook} runs integration, e2e or contract. They are manual only; hooks run unit, lint and typecheck.`);
|
|
23
|
-
for (const match of body.matchAll(/npm\s+run\s+([\w:.-]+)/gu))
|
|
24
|
-
state.pending.push(match[1]);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function inspectLintStaged(state) {
|
|
28
|
-
const lintStaged = state.pkg?.['lint-staged'];
|
|
29
|
-
if (lintStaged && runsE2e(Object.values(lintStaged).flat().join('\n')))
|
|
30
|
-
state.finding(state.rule, 'package.json', 'lint-staged runs an integration, e2e or contract command. They are manual only.');
|
|
31
|
-
}
|
|
32
|
-
function inspectHookScripts(state) {
|
|
33
|
-
for (const name of state.pending) {
|
|
34
|
-
if (state.called.has(name))
|
|
35
|
-
continue;
|
|
36
|
-
state.called.add(name);
|
|
37
|
-
const command = state.scripts[name];
|
|
38
|
-
if (typeof command !== 'string')
|
|
39
|
-
continue;
|
|
40
|
-
if (runsE2e(command))
|
|
41
|
-
state.finding(state.rule, 'package.json', `Script ${name} is run by a husky hook and touches integration, e2e or contract. They are manual only.`);
|
|
42
|
-
for (const match of command.matchAll(/npm\s+run\s+([\w:.-]+)/gu))
|
|
43
|
-
state.pending.push(match[1]);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function inspectUnitGates(state) {
|
|
47
|
-
if (state.jestConfig === null || !state.tree.hasFile(state.jestConfig))
|
|
48
|
-
return;
|
|
49
|
-
for (const name of UNIT_RUN_SCRIPTS) {
|
|
50
|
-
const command = state.scripts[name];
|
|
51
|
-
if (typeof command === 'string' && /\bjest\b/u.test(command) && !/--selectProjects\s+unit\b/u.test(command))
|
|
52
|
-
state.finding(state.rule, 'package.json', `Script ${name} runs jest without --selectProjects unit and would run the integration, e2e or contract project.`);
|
|
53
|
-
}
|
|
54
|
-
const jestText = readTextFile(state.root, state.jestConfig) ?? '';
|
|
55
|
-
if (/collectCoverageFrom/u.test(jestText) && !/!src\/tests\/(?:\*\*|e2e)/u.test(jestText))
|
|
56
|
-
state.finding(state.rule, state.jestConfig, 'collectCoverageFrom must exclude src/tests/** so no integration, e2e or contract file counts toward coverage.');
|
|
57
|
-
}
|
|
58
|
-
function inspectWorkflows(state) {
|
|
59
|
-
for (const file of state.tree.files().filter((entry) => /^\.github\/workflows\/[^/]+\.ya?ml$/u.test(entry))) {
|
|
60
|
-
const text = readTextFile(state.root, file);
|
|
61
|
-
if (text === null)
|
|
62
|
-
continue;
|
|
63
|
-
const trigger = /^on:.*(?:\n(?:[ \t].*)?$)*/mu.exec(text)?.[0] ?? '';
|
|
64
|
-
if (!/\b(?:push|pull_request)\b/u.test(trigger))
|
|
65
|
-
continue;
|
|
66
|
-
if (runsE2e(withoutComments(text)))
|
|
67
|
-
state.finding(state.rule, file, `${file} runs e2e on push or pull_request. Move the e2e job to its own workflow with on: workflow_dispatch only.`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/** Check hooks, transitive hook scripts, unit scripts, coverage and automatic workflows. */
|
|
71
|
-
export function e2eInAutomaticGate({ root, tree, jestConfig, finding }) {
|
|
72
|
-
const rule = 'HFS_E2E_IN_AUTOMATIC_GATE';
|
|
73
|
-
let pkg = null;
|
|
74
|
-
try {
|
|
75
|
-
pkg = JSON.parse(readTextFile(root, 'package.json') ?? '');
|
|
76
|
-
}
|
|
77
|
-
catch { /* the package checks own invalid JSON */ }
|
|
78
|
-
const state = { root, tree, jestConfig, finding, rule, pkg, scripts: pkg?.scripts ?? {}, pending: [], called: new Set() };
|
|
79
|
-
inspectHooks(state);
|
|
80
|
-
inspectLintStaged(state);
|
|
81
|
-
inspectHookScripts(state);
|
|
82
|
-
inspectUnitGates(state);
|
|
83
|
-
inspectWorkflows(state);
|
|
84
|
-
}
|
|
85
|
-
/** The be side's default tsconfig excludes the world, integration, e2e and contract trees (they are checked by src/tests/tsconfig.json). */
|
|
86
|
-
export function testTreesOutOfDefaultProgram({ root, tree, finding }) {
|
|
87
|
-
const rule = 'HFS_E2E_IN_AUTOMATIC_GATE';
|
|
88
|
-
const tsconfigText = readTextFile(root, 'tsconfig.json');
|
|
89
|
-
let tsconfig = null;
|
|
90
|
-
try {
|
|
91
|
-
tsconfig = tsconfigText === null ? null : JSON.parse(tsconfigText);
|
|
92
|
-
}
|
|
93
|
-
catch { /* the typecheck itself owns parsing */ }
|
|
94
|
-
if (tsconfig) {
|
|
95
|
-
const excludedText = JSON.stringify(tsconfig.exclude ?? []);
|
|
96
|
-
const excludesTestTrees = ['world', 'integration', 'e2e', 'contract'].every(tree => excludedText.includes(`src/tests/${tree}`));
|
|
97
|
-
const defaultAll = tsconfig.include === undefined && tsconfig.files === undefined;
|
|
98
|
-
const files = tree.files();
|
|
99
|
-
if (files.some((file) => /^src\/tests\/(?:world|integration|e2e|contract)\/.+\.[cm]?tsx?$/u.test(file)) && !excludesTestTrees &&
|
|
100
|
-
(defaultAll || JSON.stringify(tsconfig.include ?? []).includes('src')))
|
|
101
|
-
finding(rule, 'tsconfig.json', 'The default tsconfig includes src/tests/{world,integration,e2e,contract}/**. Exclude those trees and check them with src/tests/tsconfig.json (typecheck:tests).');
|
|
102
|
-
}
|
|
103
|
-
}
|