@starci/eslint-grammar-core 0.22.0 → 0.23.1
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/lib/app-shell-create.js +2 -2
- package/package.json +4 -2
- package/runtime/bundle.json +2 -68
- 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/yaml.mjs +0 -161
- package/runtime/knowledge/grammars/core/playbook.yaml +0 -1198
- package/runtime/knowledge/grammars/index.yaml +0 -114
- package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
- package/runtime/knowledge/hfs/rules.yaml +0 -6760
- package/runtime/knowledge/hfs/slots.yaml +0 -2783
- package/runtime/knowledge/ui/presentation/font.yaml +0 -101
- package/runtime/knowledge/ui/presentation/padding.yaml +0 -217
- 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/hfs/allows.mjs +0 -77
- package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
- package/runtime/scripts/hfs/architecture/config.mjs +0 -407
- package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
- package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
- package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
- 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/manifest-shape.mjs +0 -474
- package/runtime/scripts/hfs/param-names.mjs +0 -13
- package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
- package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
- 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/typescript-programs.mjs +0 -95
- package/runtime/scripts/hfs/view.mjs +0 -180
- 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/json-clone.mjs +0 -70
- package/runtime/scripts/lib/json.mjs +0 -44
- package/runtime/scripts/lib/list.mjs +0 -26
- 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/source-phrases.mjs +0 -34
- 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,78 +0,0 @@
|
|
|
1
|
-
// root-packages.mjs - the workspace packages of an app ROOT (packages/<name>: the agent SDK, a block library, a module package, the managed packages/modules).
|
|
2
|
-
// They lie outside both side folders and belong to no side; both sides import them by package name, through their package entry points
|
|
3
|
-
// (the `exports` of the manifest), so the import graph reads them as first-party packages and the back-end canon never reads them as
|
|
4
|
-
// a third-party library. The app root's one package.json lists them in `workspaces`; the patterns that start with a side folder
|
|
5
|
-
// (`fe/apps/*`) are that side's own workspaces and are not read here.
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import { readJsonFile as readJson } from '../../lib/json.mjs';
|
|
9
|
-
import { byCodeUnit } from '../../lib/list.mjs';
|
|
10
|
-
import { isInside } from '../../lib/walk.mjs';
|
|
11
|
-
import { slash } from '../../lib/path-key.mjs';
|
|
12
|
-
/** The slots whose directories at the app root are first-party packages of the app (agent SDK, module packages, the managed registry). */
|
|
13
|
-
export const ROOT_PACKAGE_SLOTS = new Set(['app.packages', 'app.module-registry']);
|
|
14
|
-
const SIDE_PREFIX = /^(?:be|fe)\//;
|
|
15
|
-
/** A workspace pattern this reader expands (a literal path, or `*` as a whole segment); the others are judged by the workspace rules. */
|
|
16
|
-
const expandablePattern = (written) => !path.isAbsolute(written) && written.split('/').every(segment => segment !== '..' && (!segment.includes('*') || segment === '*'));
|
|
17
|
-
function expandSegment(base, segment) {
|
|
18
|
-
if (segment !== '*')
|
|
19
|
-
return [path.join(base, segment)];
|
|
20
|
-
if (!fs.existsSync(base) || !fs.lstatSync(base).isDirectory())
|
|
21
|
-
return [];
|
|
22
|
-
return fs.readdirSync(base, { withFileTypes: true }).filter(item => item.isDirectory()).sort((a, b) => byCodeUnit(a.name, b.name)).map(item => path.join(base, item.name));
|
|
23
|
-
}
|
|
24
|
-
/** A package folder with a regular package.json (a link is not one). */
|
|
25
|
-
export function packageDirectory(absolute) {
|
|
26
|
-
try {
|
|
27
|
-
if (!fs.lstatSync(absolute).isDirectory())
|
|
28
|
-
return false;
|
|
29
|
-
const manifest = fs.lstatSync(path.join(absolute, 'package.json'));
|
|
30
|
-
return manifest.isFile() && !manifest.isSymbolicLink();
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/** The folders the `workspaces` of the app root's package.json name that no side owns, as absolute paths in code-unit order. */
|
|
37
|
-
export function rootWorkspaceDirectories(packageRoot) {
|
|
38
|
-
const manifest = readJson(path.join(packageRoot, 'package.json'));
|
|
39
|
-
const declared = manifest?.workspaces;
|
|
40
|
-
const patterns = Array.isArray(declared) ? declared : declared?.packages;
|
|
41
|
-
const found = new Set();
|
|
42
|
-
for (const pattern of Array.isArray(patterns) ? patterns : []) {
|
|
43
|
-
if (typeof pattern !== 'string' || !pattern.trim())
|
|
44
|
-
continue;
|
|
45
|
-
const written = slash(pattern.trim()).replace(/^\.\//, '');
|
|
46
|
-
if (SIDE_PREFIX.test(written) || !expandablePattern(written))
|
|
47
|
-
continue;
|
|
48
|
-
let bases = [packageRoot];
|
|
49
|
-
for (const segment of written.split('/'))
|
|
50
|
-
bases = bases.flatMap(base => expandSegment(base, segment));
|
|
51
|
-
for (const base of bases)
|
|
52
|
-
found.add(path.resolve(base));
|
|
53
|
-
}
|
|
54
|
-
return [...found].sort(byCodeUnit);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* The record of one package folder of the app root, or null when it is no named package inside the app root.
|
|
58
|
-
* `canonical` is the file-identity function of the caller (the real path), so a record agrees with the files the graph reads.
|
|
59
|
-
*/
|
|
60
|
-
export function rootPackageRecord(packageRoot, directory, canonical) {
|
|
61
|
-
if (!packageDirectory(directory) || !isInside(packageRoot, directory))
|
|
62
|
-
return null;
|
|
63
|
-
const manifest = readJson(path.join(directory, 'package.json'));
|
|
64
|
-
const name = manifest?.['name'];
|
|
65
|
-
if (manifest === null || typeof name !== 'string' || !name)
|
|
66
|
-
return null;
|
|
67
|
-
return { root: canonical(directory), relative: slash(path.relative(packageRoot, directory)), name, exports: manifest['exports'], manifest, workspace: true, app: false };
|
|
68
|
-
}
|
|
69
|
-
/** The names of the workspace packages of the app root: what the back-end canon must not read as third-party libraries. */
|
|
70
|
-
export function rootPackageNames(packageRoot) {
|
|
71
|
-
const names = new Set();
|
|
72
|
-
for (const directory of rootWorkspaceDirectories(packageRoot)) {
|
|
73
|
-
const record = rootPackageRecord(packageRoot, directory, (file) => file);
|
|
74
|
-
if (record !== null)
|
|
75
|
-
names.add(record.name);
|
|
76
|
-
}
|
|
77
|
-
return names;
|
|
78
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// side-boundary.mjs - what counts as an import that leaves a side of an app (ARCH_INTERNAL_IMPORT_OUTSIDE).
|
|
2
|
-
// A side (be/ or fe/) imports nothing of the app outside itself: the root holds no source and the other side is another program; a
|
|
3
|
-
// declared read of the OTHER side (be/contracts/) is codegen input, never an import. A declared read of a tree the APP ROOT owns
|
|
4
|
-
// (db/types/, sides.<side>.reads of the slot manifest) is the one thing both sides do import: the generated database types.
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { isInside, slash } from './config.mjs';
|
|
7
|
-
const OTHER_SIDE = /^(be|fe)\//;
|
|
8
|
-
/** True when `target` (an absolute path) lies in a tree of the app root that the side declares it reads (`reads` of the side declaration). */
|
|
9
|
-
const readsAppTree = (config, target) => (config.hfs?.repo?.reads ?? [])
|
|
10
|
-
.some((read) => !OTHER_SIDE.test(read) && isInside(path.join(config.packageRoot, read), target));
|
|
11
|
-
/** Whether an import of `target` leaves the side the machine judges (config.root) for the app (config.packageRoot), declared app-root reads excepted. */
|
|
12
|
-
export const crossesSide = (config, target) => config.packageRoot !== undefined && config.packageRoot !== config.root
|
|
13
|
-
&& isInside(config.packageRoot, target) && !isInside(config.root, target) && !slash(target).includes('/node_modules/') && !readsAppTree(config, target);
|
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
function appendProjectReferences(relative, parsed, config, ts, helpers, queue, errors) {
|
|
4
|
-
for (const reference of parsed.projectReferences ?? []) {
|
|
5
|
-
const referencedFile = helpers.typeScriptProjectReferencePath(ts, reference);
|
|
6
|
-
const absoluteReference = path.resolve(referencedFile);
|
|
7
|
-
if (!helpers.isInside(config.root, absoluteReference)) {
|
|
8
|
-
errors.push({ ruleId: 'ARCH_TSCONFIG_REFERENCE_OUTSIDE', project: relative, message: `Project reference leaves the repository: ${helpers.slash(path.relative(config.root, absoluteReference))}.` });
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
queue.push(helpers.slash(path.relative(config.root, absoluteReference)));
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function readProject(relative, config, ts, helpers, state) {
|
|
16
|
-
const configFile = path.join(config.root, ...relative.split('/'));
|
|
17
|
-
if (!fs.existsSync(configFile)) {
|
|
18
|
-
state.errors.push({ ruleId: 'ARCH_TSCONFIG_MISSING', project: relative, message: `${relative} does not exist.` });
|
|
19
|
-
state.invalidProjects.add(relative);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const { read, parsed } = helpers.readTypeScriptProject(ts, configFile);
|
|
23
|
-
if (parsed === null) {
|
|
24
|
-
state.errors.push(helpers.compilerError(ts, config.root, read.error, relative));
|
|
25
|
-
state.invalidProjects.add(relative);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (parsed.errors.length) {
|
|
29
|
-
state.errors.push(...parsed.errors.map(item => helpers.compilerError(ts, config.root, item, relative)));
|
|
30
|
-
state.invalidProjects.add(relative);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
appendProjectReferences(relative, parsed, config, ts, helpers, state.queue, state.errors);
|
|
34
|
-
state.parsedProjects.set(relative, parsed);
|
|
35
|
-
}
|
|
36
|
-
function loadProjectConfigurations(config, ts, helpers, errors) {
|
|
37
|
-
const state = { errors, parsedProjects: new Map(), invalidProjects: new Set(), queue: [...config.projects] };
|
|
38
|
-
const seenProjects = new Set();
|
|
39
|
-
while (state.queue.length) {
|
|
40
|
-
const relative = state.queue.shift(); // length checked by the loop condition
|
|
41
|
-
if (seenProjects.has(relative))
|
|
42
|
-
continue;
|
|
43
|
-
seenProjects.add(relative);
|
|
44
|
-
readProject(relative, config, ts, helpers, state);
|
|
45
|
-
}
|
|
46
|
-
return state;
|
|
47
|
-
}
|
|
48
|
-
function pathMatches(config, paths, file, helpers) {
|
|
49
|
-
const relative = helpers.slash(path.relative(config.root, file));
|
|
50
|
-
const normalized = helpers.slash(paths).replace(/\/$/, '');
|
|
51
|
-
return helpers.sameOrUnder(relative, normalized);
|
|
52
|
-
}
|
|
53
|
-
function visitProjectReferences(relative, selected, parsedProjects, config, ts, helpers) {
|
|
54
|
-
if (selected.has(relative))
|
|
55
|
-
return;
|
|
56
|
-
selected.add(relative);
|
|
57
|
-
for (const reference of parsedProjects.get(relative)?.projectReferences ?? []) {
|
|
58
|
-
const referencedFile = helpers.typeScriptProjectReferencePath(ts, reference);
|
|
59
|
-
const referenced = helpers.slash(path.relative(config.root, path.resolve(referencedFile)));
|
|
60
|
-
if (parsedProjects.has(referenced))
|
|
61
|
-
visitProjectReferences(referenced, selected, parsedProjects, config, ts, helpers);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function invalidProjectMatches(config, paths, relative, helpers) {
|
|
65
|
-
const directory = path.dirname(path.join(config.root, ...relative.split('/')));
|
|
66
|
-
return paths.some(prefix => {
|
|
67
|
-
const absolute = path.join(config.root, ...helpers.slash(prefix).split('/'));
|
|
68
|
-
return helpers.isInside(directory, absolute);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
function selectProjects(config, paths, ts, state, helpers) {
|
|
72
|
-
const selected = new Set();
|
|
73
|
-
const direct = new Set();
|
|
74
|
-
if (!paths.length)
|
|
75
|
-
return { selected, direct };
|
|
76
|
-
for (const [relative, parsed] of state.parsedProjects) {
|
|
77
|
-
if (parsed.fileNames.some(file => paths.some(prefix => pathMatches(config, prefix, file, helpers)))) {
|
|
78
|
-
direct.add(relative);
|
|
79
|
-
visitProjectReferences(relative, selected, state.parsedProjects, config, ts, helpers);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
for (const relative of state.invalidProjects) {
|
|
83
|
-
if (invalidProjectMatches(config, paths, relative, helpers))
|
|
84
|
-
selected.add(relative);
|
|
85
|
-
}
|
|
86
|
-
state.errors.splice(0, state.errors.length, ...state.errors.filter(error => !error.project || selected.has(error.project)));
|
|
87
|
-
return { selected, direct };
|
|
88
|
-
}
|
|
89
|
-
function createProjects(config, paths, state, selection, ts, helpers) {
|
|
90
|
-
const projects = [];
|
|
91
|
-
for (const [relative, parsed] of state.parsedProjects) {
|
|
92
|
-
if (paths.length && !selection.selected.has(relative))
|
|
93
|
-
continue;
|
|
94
|
-
const rootNames = paths.length && selection.direct.has(relative)
|
|
95
|
-
? parsed.fileNames.filter(file => paths.some(prefix => pathMatches(config, prefix, file, helpers)))
|
|
96
|
-
: parsed.fileNames;
|
|
97
|
-
const program = helpers.createTypeScriptProgram(ts, { rootNames, options: parsed.options, projectReferences: parsed.projectReferences });
|
|
98
|
-
state.errors.push(...program.getSyntacticDiagnostics().filter(item => !item.file || helpers.isInside(config.root, item.file.fileName))
|
|
99
|
-
.map(item => helpers.compilerError(ts, config.root, item, relative, 'ARCH_SYNTAX_INVALID')));
|
|
100
|
-
projects.push({ relative, program, options: parsed.options });
|
|
101
|
-
}
|
|
102
|
-
return projects;
|
|
103
|
-
}
|
|
104
|
-
function ownershipRank(config, project, file, helpers) {
|
|
105
|
-
return helpers.isInside(path.dirname(path.join(config.root, ...project.relative.split('/'))), file)
|
|
106
|
-
? project.relative.split('/').length : -1;
|
|
107
|
-
}
|
|
108
|
-
function collectProjectFiles(config, projects, helpers) {
|
|
109
|
-
const fileMap = new Map();
|
|
110
|
-
const ownerByFile = new Map();
|
|
111
|
-
// Retain only the winning source occurrence while visiting each project. Equal ranks keep the first project,
|
|
112
|
-
// as does a file outside every project directory; the deepest enclosing tsconfig otherwise owns its checker.
|
|
113
|
-
// Within that project the last realpath alias supplies the source, matching the compiler's occurrence order.
|
|
114
|
-
for (const project of projects) {
|
|
115
|
-
for (const sourceFile of project.program.getSourceFiles()) {
|
|
116
|
-
if (!helpers.isProductionSource(config.root, sourceFile))
|
|
117
|
-
continue;
|
|
118
|
-
const name = helpers.canonical(sourceFile.fileName);
|
|
119
|
-
const owner = ownerByFile.get(name);
|
|
120
|
-
if (owner === project) {
|
|
121
|
-
fileMap.set(name, sourceFile);
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
if (owner && ownershipRank(config, owner, name, helpers) >= ownershipRank(config, project, name, helpers))
|
|
125
|
-
continue;
|
|
126
|
-
ownerByFile.set(name, project);
|
|
127
|
-
fileMap.set(name, sourceFile);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return { fileMap, ownerByFile };
|
|
131
|
-
}
|
|
132
|
-
function makeFileGraph(config, projects, helpers) {
|
|
133
|
-
const { fileMap, ownerByFile } = collectProjectFiles(config, projects, helpers);
|
|
134
|
-
const checkerByFile = new Map();
|
|
135
|
-
for (const [name, owner] of ownerByFile)
|
|
136
|
-
checkerByFile.set(name, owner.program.getTypeChecker());
|
|
137
|
-
const files = [...fileMap.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([, file]) => file);
|
|
138
|
-
const edges = new Map([...fileMap.keys()].map((file) => [file, []]));
|
|
139
|
-
for (const [file, sourceFile] of fileMap) {
|
|
140
|
-
const sourceName = path.resolve(sourceFile.fileName);
|
|
141
|
-
if (sourceName !== file)
|
|
142
|
-
edges.set(sourceName, edges.get(file) ?? []);
|
|
143
|
-
}
|
|
144
|
-
return { fileMap, checkerByFile, ownerByFile, files, edges };
|
|
145
|
-
}
|
|
146
|
-
// Resolution entries contain failed lookup paths as well as hits. Keep only one bounded batch for the current project;
|
|
147
|
-
// graph edges retain the resolved targets, so rotating this scratch cache changes neither coverage nor findings.
|
|
148
|
-
const RESOLUTION_BATCH_SIZE = 1024;
|
|
149
|
-
function resolutionCache(state, project) {
|
|
150
|
-
if (state.resolutionProject !== project || state.resolutionCount === RESOLUTION_BATCH_SIZE) {
|
|
151
|
-
state.resolutionProject = project;
|
|
152
|
-
state.resolutionCount = 0;
|
|
153
|
-
state.resolutionCache = state.ts.createModuleResolutionCache(state.config.root, file => state.ts.sys.useCaseSensitiveFileNames ? file : file.toLowerCase(), project.options);
|
|
154
|
-
}
|
|
155
|
-
state.resolutionCount += 1;
|
|
156
|
-
return state.resolutionCache;
|
|
157
|
-
}
|
|
158
|
-
function addUnprovenFindings(sourceFile, project, references, errors, config, helpers) {
|
|
159
|
-
for (const item of references.unproven)
|
|
160
|
-
errors.push({
|
|
161
|
-
ruleId: 'ARCH_DYNAMIC_DEPENDENCY_UNPROVEN',
|
|
162
|
-
project: project.relative,
|
|
163
|
-
path: helpers.relativePath(config.root, sourceFile.fileName),
|
|
164
|
-
...helpers.sourceLocation(sourceFile, item.node),
|
|
165
|
-
message: `${item.kind} must use a string-literal module name so architecture coverage can resolve its dependency.`,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
function unresolvedReferenceFinding(reference, sourceFile, project, config, workspaceNames, errors, helpers) {
|
|
169
|
-
const codeLike = !helpers.assetExtension.test(reference.specifier);
|
|
170
|
-
const workspaceImport = [...workspaceNames].some(name => helpers.sameOrUnder(reference.specifier, name));
|
|
171
|
-
const internal = reference.specifier.startsWith('.') || helpers.pathAliasMatches(reference.specifier, project.options.paths) || workspaceImport;
|
|
172
|
-
// A __generated__/ folder is the gitignored output of the app's codegen step (the GraphQL wire types, fe-stack codegen): it
|
|
173
|
-
// exists after `npm run codegen`, which lint, typecheck and build run first, and the compiler proves those imports there.
|
|
174
|
-
const generated = /(?:^|\/)__generated__(?:\/|$)/.test(reference.specifier);
|
|
175
|
-
if (codeLike && internal && !generated)
|
|
176
|
-
errors.push({
|
|
177
|
-
ruleId: 'ARCH_INTERNAL_IMPORT_UNRESOLVED',
|
|
178
|
-
project: project.relative,
|
|
179
|
-
path: helpers.relativePath(config.root, sourceFile.fileName),
|
|
180
|
-
...helpers.sourceLocation(sourceFile, reference.node),
|
|
181
|
-
specifier: reference.specifier,
|
|
182
|
-
message: `Internal import ${reference.specifier} is not resolvable with ${project.relative}.`,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
function internalReference(reference, project, workspaceNames, helpers) {
|
|
186
|
-
const workspaceImport = [...workspaceNames].some(name => reference.specifier === name || reference.specifier.startsWith(`${name}/`));
|
|
187
|
-
return reference.specifier.startsWith('.') || helpers.pathAliasMatches(reference.specifier, project.options.paths) || workspaceImport;
|
|
188
|
-
}
|
|
189
|
-
function appendBoundaryFinding(state, reference, sourceFile, project, actualTarget, { internal, reviewable }) {
|
|
190
|
-
const { config, errors, helpers } = state;
|
|
191
|
-
if (internal && helpers.crossesSide(config, actualTarget)) {
|
|
192
|
-
errors.push({
|
|
193
|
-
ruleId: 'ARCH_INTERNAL_IMPORT_OUTSIDE',
|
|
194
|
-
project: project.relative,
|
|
195
|
-
path: helpers.relativePath(config.root, sourceFile.fileName),
|
|
196
|
-
...helpers.sourceLocation(sourceFile, reference.node),
|
|
197
|
-
specifier: reference.specifier,
|
|
198
|
-
message: `Internal import ${reference.specifier} leaves the ${path.basename(config.root)} side for ${helpers.slash(path.relative(config.packageRoot, actualTarget))}; nothing crosses the sides of an app.`,
|
|
199
|
-
});
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
if (internal && !reviewable) {
|
|
203
|
-
errors.push({
|
|
204
|
-
ruleId: 'ARCH_INTERNAL_IMPORT_OUTSIDE',
|
|
205
|
-
project: project.relative,
|
|
206
|
-
path: helpers.relativePath(config.root, sourceFile.fileName),
|
|
207
|
-
...helpers.sourceLocation(sourceFile, reference.node),
|
|
208
|
-
specifier: reference.specifier,
|
|
209
|
-
message: `Internal import ${reference.specifier} resolves outside the checked repository.`,
|
|
210
|
-
});
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
function appendEdge(from, sourceFile, project, owningWorkspace, reference, actualTarget, state) {
|
|
216
|
-
if (!state.fileMap.has(actualTarget))
|
|
217
|
-
return;
|
|
218
|
-
const { config, ts, edges, edgeKeys, errors, helpers, workspaces } = state;
|
|
219
|
-
const edge = {
|
|
220
|
-
from,
|
|
221
|
-
to: actualTarget,
|
|
222
|
-
runtime: reference.runtime,
|
|
223
|
-
specifier: reference.specifier,
|
|
224
|
-
node: reference.node,
|
|
225
|
-
declaration: reference.declaration,
|
|
226
|
-
reexport: ts.isExportDeclaration(reference.declaration),
|
|
227
|
-
sourceFile,
|
|
228
|
-
project: project.relative,
|
|
229
|
-
...helpers.sourceLocation(sourceFile, reference.node),
|
|
230
|
-
};
|
|
231
|
-
const key = `${from}\0${actualTarget}\0${reference.node.getStart(sourceFile)}\0${reference.specifier}`;
|
|
232
|
-
if (!edgeKeys.has(key)) {
|
|
233
|
-
edges.get(from)?.push(edge);
|
|
234
|
-
edgeKeys.add(key);
|
|
235
|
-
}
|
|
236
|
-
const targetWorkspace = helpers.workspaceOf(workspaces, actualTarget);
|
|
237
|
-
if (owningWorkspace && targetWorkspace && owningWorkspace !== targetWorkspace) {
|
|
238
|
-
if (!owningWorkspace.app && targetWorkspace.app)
|
|
239
|
-
errors.push(helpers.boundaryViolation(config.root, edge, owningWorkspace, targetWorkspace, 'ARCH_PACKAGE_IMPORTS_APP', 'A reusable workspace package cannot depend on an application workspace.'));
|
|
240
|
-
if (!helpers.packageExported(ts, targetWorkspace, reference.specifier, actualTarget))
|
|
241
|
-
errors.push(helpers.boundaryViolation(config.root, edge, owningWorkspace, targetWorkspace, 'ARCH_PACKAGE_EXPORT_BYPASS', 'Cross-package imports must use the target package name and a declared package export.'));
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* An import of one of the app's root workspace packages (`@scope/agent-sdk`, `@scope/agent-sdk/workbench`). The package lies outside the side
|
|
246
|
-
* folder, yet it is first-party source both sides may import: through its package entry points (the `exports` of its manifest) and never past
|
|
247
|
-
* them. An entry point is no import that leaves the side and adds no edge (the package is not part of this side's graph; the package's own
|
|
248
|
-
* lint judges its files); a path into the package's source is refused. Returns true when the reference was settled here.
|
|
249
|
-
*/
|
|
250
|
-
function rootPackageReference(sourceFile, project, reference, state) {
|
|
251
|
-
const { config, errors, helpers, host, ts } = state;
|
|
252
|
-
if (!config.rootPackages?.length)
|
|
253
|
-
return false;
|
|
254
|
-
const item = helpers.rootPackageOf(config, reference.specifier);
|
|
255
|
-
if (item === null)
|
|
256
|
-
return false;
|
|
257
|
-
if (!helpers.rootPackageEntryDeclared(item, reference.specifier)) {
|
|
258
|
-
errors.push({
|
|
259
|
-
ruleId: 'ARCH_INTERNAL_IMPORT_OUTSIDE',
|
|
260
|
-
project: project.relative,
|
|
261
|
-
path: helpers.relativePath(config.root, sourceFile.fileName),
|
|
262
|
-
...helpers.sourceLocation(sourceFile, reference.node),
|
|
263
|
-
specifier: reference.specifier,
|
|
264
|
-
message: `Internal import ${reference.specifier} reaches into the package ${item.name} past its package entry points; import ${helpers.rootPackageEntries(item).join(', ')} instead.`,
|
|
265
|
-
});
|
|
266
|
-
return true;
|
|
267
|
-
}
|
|
268
|
-
// An entry point that a path alias sends outside the package is no entry point: the ordinary boundary judges it.
|
|
269
|
-
const resolved = helpers.resolveTypeScriptModule(ts, reference.specifier, sourceFile.fileName, project.options, host, resolutionCache(state, project));
|
|
270
|
-
return resolved === undefined || helpers.isInside(item.root, helpers.canonical(resolved));
|
|
271
|
-
}
|
|
272
|
-
function processReference(from, sourceFile, project, owningWorkspace, reference, state) {
|
|
273
|
-
const { config, ts, workspaceNames, workspaces, host, errors, helpers } = state;
|
|
274
|
-
if (rootPackageReference(sourceFile, project, reference, state))
|
|
275
|
-
return;
|
|
276
|
-
// A workspace package is read at its source, never at its build: the same import resolves whether or not dist exists.
|
|
277
|
-
const workspaceTarget = workspaces.filter(item => item.root !== helpers.canonical(config.root)).map(item => helpers.workspaceSourceEntry(ts, item, reference.specifier)).find(Boolean);
|
|
278
|
-
const resolvedName = workspaceTarget ?? helpers.resolveTypeScriptModule(ts, reference.specifier, sourceFile.fileName, project.options, host, resolutionCache(state, project));
|
|
279
|
-
if (!resolvedName) {
|
|
280
|
-
unresolvedReferenceFinding(reference, sourceFile, project, config, workspaceNames, errors, helpers);
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
const actualTarget = helpers.canonical(resolvedName);
|
|
284
|
-
const internal = internalReference(reference, project, workspaceNames, helpers);
|
|
285
|
-
// The boundary is the checkout, not the checked project: a path alias that lands in a sibling
|
|
286
|
-
// package of the same repository (`@fe-kit/*` -> packages/fe-kit) is still source a reviewer can
|
|
287
|
-
// open, while anything past the repository, or anything inside an installed dependency tree, is
|
|
288
|
-
// not. `config.repository` is null when there is no git checkout around the project, and the
|
|
289
|
-
// project is then the boundary it always was.
|
|
290
|
-
const reviewable = helpers.isInside(config.root, actualTarget)
|
|
291
|
-
|| Boolean(config.repository && helpers.isInside(config.repository, actualTarget) && !helpers.slash(actualTarget).includes('/node_modules/'));
|
|
292
|
-
// A side of an app (config.root is be/ or fe/) imports nothing of the app outside itself: the root holds no source, the other
|
|
293
|
-
// side is another program, and a declared read (sides.fe.reads, be/contracts/) is codegen input, never an import.
|
|
294
|
-
if (appendBoundaryFinding(state, reference, sourceFile, project, actualTarget, { internal, reviewable }))
|
|
295
|
-
return;
|
|
296
|
-
appendEdge(from, sourceFile, project, owningWorkspace, reference, actualTarget, state);
|
|
297
|
-
}
|
|
298
|
-
function processSourceFile(from, sourceFile, state) {
|
|
299
|
-
const { config, ts, workspaces, ownerByFile, helpers } = state;
|
|
300
|
-
const owningWorkspace = helpers.workspaceOf(workspaces, from);
|
|
301
|
-
const project = ownerByFile.get(from);
|
|
302
|
-
if (!project)
|
|
303
|
-
return;
|
|
304
|
-
const references = helpers.moduleReferences(ts, sourceFile, project.program.getTypeChecker());
|
|
305
|
-
addUnprovenFindings(sourceFile, project, references, state.errors, config, helpers);
|
|
306
|
-
for (const reference of references.found)
|
|
307
|
-
processReference(from, sourceFile, project, owningWorkspace, reference, state);
|
|
308
|
-
}
|
|
309
|
-
function dependencyGraph(config, loaded, fileGraph, ownerByFile, errors, helpers) {
|
|
310
|
-
const { ts } = loaded;
|
|
311
|
-
const edgeKeys = new Set();
|
|
312
|
-
const host = { ...ts.sys, fileExists: ts.sys.fileExists, readFile: ts.sys.readFile, realpath: ts.sys.realpath };
|
|
313
|
-
const workspaces = helpers.workspaceMetadata(config);
|
|
314
|
-
const workspaceNames = new Set(workspaces.map(item => item.name).filter((name) => Boolean(name)));
|
|
315
|
-
const state = { config, ts, fileMap: fileGraph.fileMap, edges: fileGraph.edges, edgeKeys, errors, workspaces, workspaceNames, host, ownerByFile, helpers, resolutionCount: 0 };
|
|
316
|
-
for (const [from, sourceFile] of fileGraph.fileMap)
|
|
317
|
-
processSourceFile(from, sourceFile, state);
|
|
318
|
-
return { edges: fileGraph.edges, workspaces };
|
|
319
|
-
}
|
|
320
|
-
export function contextFromProjects(config, loaded, paths, helpers) {
|
|
321
|
-
const { ts } = loaded;
|
|
322
|
-
const errors = [];
|
|
323
|
-
const projectState = loadProjectConfigurations(config, ts, helpers, errors);
|
|
324
|
-
const selection = selectProjects(config, paths, ts, projectState, helpers);
|
|
325
|
-
const projects = createProjects(config, paths, projectState, selection, ts, helpers);
|
|
326
|
-
const fileGraph = makeFileGraph(config, projects, helpers);
|
|
327
|
-
const { edges, workspaces } = dependencyGraph(config, loaded, fileGraph, fileGraph.ownerByFile, errors, helpers);
|
|
328
|
-
if (projects.length && fileGraph.files.length === 0)
|
|
329
|
-
errors.push({ ruleId: 'ARCH_NO_SOURCE', message: 'The configured TypeScript projects contain no production TypeScript or JavaScript source.' });
|
|
330
|
-
const { checkerByFile } = fileGraph;
|
|
331
|
-
return { loaded, errors, files: fileGraph.files, edges, programs: projects.map(item => item.program), program: projects[0]?.program ?? null, projects, ts, workspaces,
|
|
332
|
-
// reason: every file the checkers walk belongs to a program; an unknown file still answers null, as before.
|
|
333
|
-
checkerFor: (file) => (checkerByFile.get(helpers.canonical(file)) ?? null),
|
|
334
|
-
workspaceOf: (file) => helpers.workspaceOf(workspaces, helpers.canonical(file)) };
|
|
335
|
-
}
|