@starci/eslint-canon-be 3.4.52 → 3.4.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/runtime/knowledge/hfs/canon-pins.yaml +12 -5
- package/runtime/knowledge/hfs/fe-stack.yaml +12 -1
- package/runtime/knowledge/hfs/rules.yaml +6 -2
- package/runtime/knowledge/hfs/slots.yaml +5 -5
- package/runtime/scripts/hfs/architecture/index.mjs +2 -1
- package/runtime/scripts/hfs/architecture/type-context.mjs +38 -23
- package/runtime/scripts/hfs/typescript-programs.mjs +30 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.4.54 - 2026-10-26
|
|
4
|
+
|
|
5
|
+
- Changed: the bundled canon pins follow the final package versions (Grammar 0.12.12 with the lint families, the event-stream package). No rule changes.
|
|
6
|
+
|
|
7
|
+
## 3.4.53 - 2026-10-26
|
|
8
|
+
|
|
9
|
+
- Changed: the bundled canon pins follow the final package versions (Grammar 0.12.11 with the lint families). No rule changes.
|
|
10
|
+
|
|
3
11
|
## 3.4.52 - 2026-10-26
|
|
4
12
|
|
|
5
13
|
- Changed: the alpha.31.1 round folded into alpha.31; the bundled canon pins and runtime copies follow the final package versions. No rule changes.
|
package/package.json
CHANGED
|
@@ -22,36 +22,43 @@ pins:
|
|
|
22
22
|
side: fe
|
|
23
23
|
source: packages/heroicons/package.json
|
|
24
24
|
why: 'StarCi custom Heroicons-compatible cuts; eslint-grammar-starci (icon.mjs) admits @starci/heroicons/24/outline and /16/solid as icon sources, so an app that uses them gets this exact version.'
|
|
25
|
+
'@starci/event-stream':
|
|
26
|
+
version: 0.1.0
|
|
27
|
+
group: starci
|
|
28
|
+
install: registry
|
|
29
|
+
side: fe
|
|
30
|
+
source: packages/event-stream/package.json
|
|
31
|
+
why: 'the one server-sent-events client of every front end (fe-stack event-stream, owner:event-stream-package): the transport client layer (modules/api/sse/clients) creates one instance for the app with the bearer token source and the stream operations follow on it; it carries Last-Event-ID resume, the capped doubling backoff, the heartbeat timeout, the single 401 renewal and the useSWRSubscription adapter, so no app keeps a hand-written reader.'
|
|
25
32
|
'@starci/grammar':
|
|
26
|
-
version: 0.12.
|
|
33
|
+
version: 0.12.12
|
|
27
34
|
group: starci
|
|
28
35
|
install: registry
|
|
29
36
|
side: fe
|
|
30
37
|
source: packages/grammar/package.json
|
|
31
38
|
why: 'the grammar front ends read: the brand layer sets `--font-sans` and `--font-mono` and the grammar reads them; it carries the Input tel kind, the copyable and read-only Input, the IconButton disclosure props and count badge, ChatBubble, FillViewport, Textarea mentions and Enter-to-send, the leading PrimaryRailLayout rail, the plate-less Image, ListRow, the soft Alert, Progress steps, the floating primary IconButton, FlowGraph, the STATE-8 loading views and the bordered selectable TagGroup chips. The runtime source version wins for a @starci package.'
|
|
32
39
|
'@starci/eslint-canon-be':
|
|
33
|
-
version: 3.4.
|
|
40
|
+
version: 3.4.54
|
|
34
41
|
group: starci
|
|
35
42
|
install: registry
|
|
36
43
|
side: be
|
|
37
44
|
source: packages/eslint/be/package.json
|
|
38
45
|
why: 'the back-end ESLint canon: `loadHfs(import.meta.url)` of be/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the be side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; `starciBeConfig({ hfs: loadHfs(import.meta.url) })` is the typed factory and the BE-CONVENTION laws are its rules.'
|
|
39
46
|
'@starci/eslint-canon-fe':
|
|
40
|
-
version: 9.1.
|
|
47
|
+
version: 9.1.8
|
|
41
48
|
group: starci
|
|
42
49
|
install: registry
|
|
43
50
|
side: fe
|
|
44
51
|
source: packages/eslint/fe/package.json
|
|
45
52
|
why: 'the front-end ESLint canon: `loadHfs(import.meta.url)` of fe/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the fe side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; the front end has no tests (FE_NO_TESTS R97 in hfs) and no-vietnamese-in-source (R91) applies.'
|
|
46
53
|
'@starci/eslint-grammar-starci':
|
|
47
|
-
version: 0.12.
|
|
54
|
+
version: 0.12.12
|
|
48
55
|
group: starci
|
|
49
56
|
install: registry
|
|
50
57
|
side: fe
|
|
51
58
|
source: packages/eslint/grammar-starci/package.json
|
|
52
59
|
why: 'the StarCi Grammar component API lint, versioned with @starci/grammar; front ends compose this family package with the universal FE canon.'
|
|
53
60
|
'@starci/eslint-grammar-offset-pop':
|
|
54
|
-
version: 0.12.
|
|
61
|
+
version: 0.12.12
|
|
55
62
|
group: starci
|
|
56
63
|
install: registry
|
|
57
64
|
side: fe
|
|
@@ -82,7 +82,18 @@ concerns:
|
|
|
82
82
|
home: [fe.hooks.socketio]
|
|
83
83
|
pattern: FE-REALTIME
|
|
84
84
|
forbids: [subscriptions-transport-ws, '@supabase/realtime-js', pusher-js, ably]
|
|
85
|
-
why: one socket.io-client singleton per namespace and one side-effect component that dispatches to redux and SWR; both editions run the gateway in the be api process. A one-way channel served as server-sent events
|
|
85
|
+
why: one socket.io-client singleton per namespace and one side-effect component that dispatches to redux and SWR; both editions run the gateway in the be api process. A one-way channel served as server-sent events is the event-stream concern below (FE-REALTIME).
|
|
86
|
+
- id: event-stream
|
|
87
|
+
tier: opt
|
|
88
|
+
packages: ['@starci/event-stream']
|
|
89
|
+
home: [fe.transport.stream]
|
|
90
|
+
pattern: FE-REALTIME
|
|
91
|
+
forbids: ['@microsoft/fetch-event-source', eventsource, event-source-polyfill, eventsource-parser, reconnecting-eventsource, 'sse.js', 'fetch-sse', 'sse-ts']
|
|
92
|
+
why: >-
|
|
93
|
+
the one server-sent-events client (owner:event-stream-package): the app creates one instance in modules/api/sse/clients/event-stream.ts
|
|
94
|
+
with createEventStream (the bearer token source, one renewal on a 401, backoff, heartbeat timeout), each stream operation
|
|
95
|
+
(sse/<area>/stream-<channel>.ts) follows on it, and the useSubscribe<Channel>Swr hook reads that operation. No app keeps a
|
|
96
|
+
hand-written reader (read-event-stream.ts) and no second SSE library is installed.
|
|
86
97
|
- id: auth
|
|
87
98
|
tier: core
|
|
88
99
|
packages: []
|
|
@@ -5576,22 +5576,26 @@ rules:
|
|
|
5576
5576
|
templateNa: "The app composes its shell from product destinations and identity; full and lite example shells provide the reference."
|
|
5577
5577
|
- id: R318
|
|
5578
5578
|
code: "FE_NESTED_VARIANT"
|
|
5579
|
-
law: "Apps compose Grammar with layout-only CSS; paint utilities, arbitrary paint properties and inline style paint belong to Grammar. Grammar context owns all layer-aware field variants, nested Tabs defaults and the content edge of panel lists; apps omit static field variants, do not force primary Tabs inside a painted surface, do not paint raw surfaces, and add no horizontal list-wrapper padding within the nearest painted Grammar surface."
|
|
5579
|
+
law: "Apps compose Grammar with layout-only CSS; paint utilities, arbitrary paint properties and inline style paint belong to Grammar. Grammar context owns all layer-aware field variants, nested Tabs defaults and the content edge of panel lists; apps omit static field variants, do not force primary Tabs inside a painted surface, do not paint raw surfaces, and add no horizontal list-wrapper padding within the nearest painted Grammar surface. BOUNDARY-1 case-5 owns Divider full-bleed composition."
|
|
5580
5580
|
kinds: [lint, design]
|
|
5581
5581
|
gates: [pre-commit, settle, land, ci]
|
|
5582
|
-
failureCodes: ["FE_NESTED_VARIANT", "FE_LIST_PANEL_PADDING", "FE_GRAMMAR_LAYOUT_ONLY"]
|
|
5582
|
+
failureCodes: ["FE_NESTED_VARIANT", "FE_LIST_PANEL_PADDING", "FE_GRAMMAR_LAYOUT_ONLY", "FE_DIVIDER_FULL_BLEED"]
|
|
5583
5583
|
enforcers:
|
|
5584
5584
|
- {kind: eslint-fe, id: nested-control-variant}
|
|
5585
5585
|
- {kind: eslint-fe, id: no-list-panel-padding}
|
|
5586
5586
|
- {kind: eslint-fe, id: no-app-surface-paint}
|
|
5587
|
+
- {kind: eslint-fe, id: divider-full-bleed}
|
|
5587
5588
|
editions: [lite, full]
|
|
5588
5589
|
docs: ["docs/code-pattern-enforcement.md#r318-app-grammar-composition"]
|
|
5589
5590
|
templateNa: "Product composition is proved by the FE canon's Grammar import and surface fixtures; a template cannot choose product slots or lists."
|
|
5590
5591
|
proves:
|
|
5592
|
+
- {path: packages/eslint/fe/divider-full-bleed.spec.mjs, editions: [lite, full], codes: [FE_DIVIDER_FULL_BLEED]}
|
|
5591
5593
|
- {path: packages/eslint/fe/surface-rules.spec.mjs, editions: [lite, full], codes: [FE_NESTED_VARIANT, FE_LIST_PANEL_PADDING, FE_GRAMMAR_LAYOUT_ONLY]}
|
|
5592
5594
|
exemplifiedBy:
|
|
5595
|
+
- {path: packages/eslint/fe/divider-full-bleed.spec.mjs, editions: [lite, full], codes: [FE_DIVIDER_FULL_BLEED]}
|
|
5593
5596
|
- {path: packages/eslint/fe/surface-rules.spec.mjs, editions: [lite, full], codes: [FE_NESTED_VARIANT, FE_LIST_PANEL_PADDING, FE_GRAMMAR_LAYOUT_ONLY]}
|
|
5594
5597
|
witness:
|
|
5598
|
+
- {path: packages/eslint/fe/divider-full-bleed.spec.mjs, editions: [lite, full], codes: [FE_DIVIDER_FULL_BLEED]}
|
|
5595
5599
|
- {path: packages/eslint/fe/surface-rules.spec.mjs, editions: [lite, full], codes: [FE_NESTED_VARIANT, FE_LIST_PANEL_PADDING, FE_GRAMMAR_LAYOUT_ONLY]}
|
|
5596
5600
|
cases:
|
|
5597
5601
|
- id: case-1
|
|
@@ -305,7 +305,7 @@ ruleParams:
|
|
|
305
305
|
- {typeSuffix: Options, names: [options], nameSuffix: Options}
|
|
306
306
|
# R89 BE_SOURCE_FORM: the closed role-suffix vocabulary of a source file name (<kebab-name>.<suffix>.ts; BE-CONVENTION 1.15)
|
|
307
307
|
# and the suffixes that are never a role. index.ts, main.ts, app.module.ts and the migrations of be.persistence are the
|
|
308
|
-
# only names outside it.
|
|
308
|
+
# only names outside it. Typed realtime topic builders use the existing policy role (BE-REALTIME-3 of knowledge/patterns/be/realtime.yaml).
|
|
309
309
|
suffixes: [module, module-definition, decorators, options, config, connection, service, schema, command, query, handler, templates, compensation, saga-state, saga-step, saga, contracts, port, resolver, controller, gateway, webhook, subscription, consumer, cli, event, queue, projection, projection-entity, processor, step, input, type, args, request, response, mapper, policy, entity, sql, rows, error, messages, log-events, cache-keys, guard, interceptor, filter, client, adapter, spec, integration-spec, e2e-spec, contract-spec, global-setup, builder]
|
|
310
310
|
# R47 BE_CONTRACT_UNGUARDED: the world's shape vocabulary. `helper` names the function a contract spec imports to erase the values of a JSON
|
|
311
311
|
# payload (`shapeOf`); a contract spec proves a fake's fixtures by asserting helper(real) equals helper(fixture).
|
|
@@ -1617,7 +1617,7 @@ slots:
|
|
|
1617
1617
|
requires: [index.ts]
|
|
1618
1618
|
# <name>.templates.ts holds the capability's static templates, copy and presets as TS constants (owner ruling 2026-10-13);
|
|
1619
1619
|
# user-editable ones are seed rows, large or user media live in object storage.
|
|
1620
|
-
allows: ["<capability>.module.ts", "<capability>.module-definition.ts", "<capability>.config.ts", "<capability>.options.ts", errors/, messages/, persistence/, policies/, "*.service.ts", "*.service.spec.ts", "*.contracts.ts", "*.templates.ts", "*.schema.ts", "*.schema.spec.ts"]
|
|
1620
|
+
allows: ["<capability>.module.ts", "<capability>.module-definition.ts", "<capability>.config.ts", "<capability>.options.ts", errors/, messages/, persistence/, policies/, "*.service.ts", "*.service.spec.ts", "*.contracts.ts", "*.templates.ts", "*.schema.ts", "*.schema.spec.ts", "*.policy.ts", "*.policy.spec.ts"]
|
|
1621
1621
|
forbids: [testing/, exceptions/, utils/, helpers/, shared/]
|
|
1622
1622
|
tests: unit-beside # <name>.service.spec.ts beside each <name>.service.ts, nothing else
|
|
1623
1623
|
coverage: required
|
|
@@ -2336,8 +2336,8 @@ slots:
|
|
|
2336
2336
|
# The browser's calls to the back end (owner ruling 2026-10-13, fe-stack graphql/rest/codegen, FE-API-GRAPHQL): the auth and
|
|
2337
2337
|
# no-auth Apollo clients with their link chain (graphql/clients), one file per operation (graphql/queries/query-<x>.ts,
|
|
2338
2338
|
# graphql/mutations/mutation-<x>.ts and graphql/subscriptions/subscription-<x>.ts, each with its gql document map and typed request/response in types/), the generated wire types
|
|
2339
|
-
# (graphql/__generated__), the axios calls (rest/<area>/*.ts) for uploads, presigned URLs and auth endpoints and the
|
|
2340
|
-
# server-sent-events streams (sse/<area>/stream-<channel>.ts, one operation per stream, run on the stream
|
|
2339
|
+
# (graphql/__generated__), the axios calls (rest/<area>/*.ts) for uploads, presigned URLs and auth endpoints and the
|
|
2340
|
+
# server-sent-events streams (sse/<area>/stream-<channel>.ts, one operation per stream, run on the app's @starci/event-stream instance in sse/clients). A repository has
|
|
2341
2341
|
# exactly ONE client folder and ONE GraphQLResponse union: the app's (fe.transport.client/outcome) when one app calls the back end,
|
|
2342
2342
|
# or the api package's (fe.package.api.client/outcome) when several do (FE_TRANSPORT_OWNER, machine).
|
|
2343
2343
|
requires: [index.ts]
|
|
@@ -2381,7 +2381,7 @@ slots:
|
|
|
2381
2381
|
tier: transport
|
|
2382
2382
|
allows: ["*.ts"]
|
|
2383
2383
|
tests: none
|
|
2384
|
-
why: "the
|
|
2384
|
+
why: "the event-stream client of the one app that calls the back end, the stream half of the transport client layer (FE-REALTIME): event-stream.ts creates the app's one @starci/event-stream instance (createEventStream with the bearer access token source, which opens the stream with fetch, parses the events and reopens it with Last-Event-ID after a capped, doubling wait); a stream operation (sse/<area>/stream-<channel>.ts) follows on it and a useSubscribe hook of hooks/swr reads that operation; no hand-written reader lives here (owner:event-stream-package) and only a stream operation imports this folder (FE_TRANSPORT_OWNER); a repository where several apps stream keeps one instance in each of them"
|
|
2385
2385
|
rules: [FE_TRANSPORT_OWNER]
|
|
2386
2386
|
exemplifiedBy:
|
|
2387
2387
|
- {path: packages/eslint/fe/r50-transport-owner-coverage.spec.mjs, editions: [lite, full]}
|
|
@@ -2,6 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import { canonical, loadArchitectureConfig } from './config.mjs';
|
|
3
3
|
import { sameOrUnder } from '../../lib/path-key.mjs';
|
|
4
4
|
import { buildTypeScriptContext, relativePath } from './typescript.mjs';
|
|
5
|
+
import { withTypeScriptProgramRun } from '../typescript-programs.mjs';
|
|
5
6
|
import { checkBackend } from './backend.mjs';
|
|
6
7
|
import { checkBackendContracts, PUBLIC_CONTRACT_RULE_ID, READONLY_BOUNDARY_RULE_ID } from './contracts.mjs';
|
|
7
8
|
import { checkFrontend } from './frontend.mjs';
|
|
@@ -324,7 +325,7 @@ function scopeFindings({ config, context, violations, paths, surface }) {
|
|
|
324
325
|
* that read the whole repository to answer (clones, dead exports, repository-wide symbols); the pre-push check of the changed owners uses it.
|
|
325
326
|
*/
|
|
326
327
|
export function checkArchitecture(options = {}) {
|
|
327
|
-
return withTreeCache(() => checkArchitectureOnce(options));
|
|
328
|
+
return withTypeScriptProgramRun(() => withTreeCache(() => checkArchitectureOnce(options)));
|
|
328
329
|
}
|
|
329
330
|
|
|
330
331
|
function checkArchitectureOnce({ repositoryRoot, injectedTypeScript, paths = [], base, fast = false, hfs: openedHfs, surface = 'all' }) {
|
|
@@ -103,36 +103,35 @@ function createProjects(config, paths, state, selection, ts, helpers) {
|
|
|
103
103
|
return projects;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
function ownershipRank(config, project, file, helpers) {
|
|
107
|
+
return helpers.isInside(path.dirname(path.join(config.root, ...project.relative.split('/'))), file)
|
|
108
|
+
? project.relative.split('/').length : -1;
|
|
109
|
+
}
|
|
110
|
+
|
|
106
111
|
function collectProjectFiles(config, projects, helpers) {
|
|
107
|
-
const
|
|
108
|
-
const
|
|
112
|
+
const fileMap = new Map();
|
|
113
|
+
const ownerByFile = new Map();
|
|
114
|
+
// Retain only the winning source occurrence while visiting each project. Equal ranks keep the first project,
|
|
115
|
+
// as does a file outside every project directory; the deepest enclosing tsconfig otherwise owns its checker.
|
|
116
|
+
// Within that project the last realpath alias supplies the source, matching the compiler's occurrence order.
|
|
109
117
|
for (const project of projects) {
|
|
110
|
-
for (const sourceFile of project.program.getSourceFiles()
|
|
118
|
+
for (const sourceFile of project.program.getSourceFiles()) {
|
|
119
|
+
if (!helpers.isProductionSource(config.root, sourceFile)) continue;
|
|
111
120
|
const name = helpers.canonical(sourceFile.fileName);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
const owner = ownerByFile.get(name);
|
|
122
|
+
if (owner === project) { fileMap.set(name, sourceFile); continue; }
|
|
123
|
+
if (owner && ownershipRank(config, owner, name, helpers) >= ownershipRank(config, project, name, helpers)) continue;
|
|
124
|
+
ownerByFile.set(name, project);
|
|
125
|
+
fileMap.set(name, sourceFile);
|
|
115
126
|
}
|
|
116
127
|
}
|
|
117
|
-
return {
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function owningProject(config, candidates, file, helpers) {
|
|
121
|
-
return candidates.filter(item => helpers.isInside(path.dirname(path.join(config.root, ...item.relative.split('/'))), file))
|
|
122
|
-
.sort((x, y) => y.relative.split('/').length - x.relative.split('/').length)[0] ?? candidates[0];
|
|
128
|
+
return { fileMap, ownerByFile };
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
function makeFileGraph(config, projects, helpers) {
|
|
126
|
-
const {
|
|
127
|
-
const fileMap = new Map();
|
|
132
|
+
const { fileMap, ownerByFile } = collectProjectFiles(config, projects, helpers);
|
|
128
133
|
const checkerByFile = new Map();
|
|
129
|
-
const
|
|
130
|
-
for (const [name, candidates] of occurrences) {
|
|
131
|
-
const owner = owningProject(config, candidates, name, helpers);
|
|
132
|
-
ownerByFile.set(name, owner);
|
|
133
|
-
fileMap.set(name, sourceIn.get(`${owner.relative}|${name}`));
|
|
134
|
-
checkerByFile.set(name, owner.program.getTypeChecker());
|
|
135
|
-
}
|
|
134
|
+
for (const [name, owner] of ownerByFile) checkerByFile.set(name, owner.program.getTypeChecker());
|
|
136
135
|
const files = [...fileMap.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([, file]) => file);
|
|
137
136
|
const edges = new Map([...fileMap.keys()].map(file => [file, []]));
|
|
138
137
|
for (const [file, sourceFile] of fileMap) {
|
|
@@ -142,6 +141,21 @@ function makeFileGraph(config, projects, helpers) {
|
|
|
142
141
|
return { fileMap, checkerByFile, ownerByFile, files, edges };
|
|
143
142
|
}
|
|
144
143
|
|
|
144
|
+
// Resolution entries contain failed lookup paths as well as hits. Keep only one bounded batch for the current project;
|
|
145
|
+
// graph edges retain the resolved targets, so rotating this scratch cache changes neither coverage nor findings.
|
|
146
|
+
const RESOLUTION_BATCH_SIZE = 1024;
|
|
147
|
+
|
|
148
|
+
function resolutionCache(state, project) {
|
|
149
|
+
if (state.resolutionProject !== project || state.resolutionCount === RESOLUTION_BATCH_SIZE) {
|
|
150
|
+
state.resolutionProject = project;
|
|
151
|
+
state.resolutionCount = 0;
|
|
152
|
+
state.resolutionCache = state.ts.createModuleResolutionCache(state.config.root,
|
|
153
|
+
file => state.ts.sys.useCaseSensitiveFileNames ? file : file.toLowerCase(), project.options);
|
|
154
|
+
}
|
|
155
|
+
state.resolutionCount += 1;
|
|
156
|
+
return state.resolutionCache;
|
|
157
|
+
}
|
|
158
|
+
|
|
145
159
|
function addUnprovenFindings(sourceFile, project, references, errors, config, helpers) {
|
|
146
160
|
for (const item of references.unproven) errors.push({
|
|
147
161
|
ruleId: 'ARCH_DYNAMIC_DEPENDENCY_UNPROVEN',
|
|
@@ -229,7 +243,7 @@ function processReference(from, sourceFile, project, owningWorkspace, reference,
|
|
|
229
243
|
const { config, ts, workspaceNames, workspaces, host, errors, helpers } = state;
|
|
230
244
|
// A workspace package is read at its source, never at its build: the same import resolves whether or not dist exists.
|
|
231
245
|
const workspaceTarget = workspaces.filter(item => item.root !== helpers.canonical(config.root)).map(item => helpers.workspaceSourceEntry(ts, item, reference.specifier)).find(Boolean);
|
|
232
|
-
const resolvedName = workspaceTarget ?? helpers.resolveTypeScriptModule(ts, reference.specifier, sourceFile.fileName, project.options, host);
|
|
246
|
+
const resolvedName = workspaceTarget ?? helpers.resolveTypeScriptModule(ts, reference.specifier, sourceFile.fileName, project.options, host, resolutionCache(state, project));
|
|
233
247
|
if (!resolvedName) {
|
|
234
248
|
unresolvedReferenceFinding(reference, sourceFile, project, config, workspaceNames, errors, helpers);
|
|
235
249
|
return;
|
|
@@ -279,7 +293,8 @@ export function contextFromProjects(config, loaded, paths, helpers) {
|
|
|
279
293
|
const fileGraph = makeFileGraph(config, projects, helpers);
|
|
280
294
|
const { edges, workspaces } = dependencyGraph(config, loaded, fileGraph, fileGraph.ownerByFile, errors, helpers);
|
|
281
295
|
if (projects.length && fileGraph.files.length === 0) errors.push({ ruleId: 'ARCH_NO_SOURCE', message: 'The configured TypeScript projects contain no production TypeScript or JavaScript source.' });
|
|
296
|
+
const { checkerByFile } = fileGraph;
|
|
282
297
|
return { loaded, errors, files: fileGraph.files, edges, programs: projects.map(item => item.program), program: projects[0]?.program ?? null, projects, ts, workspaces,
|
|
283
|
-
checkerFor: file =>
|
|
298
|
+
checkerFor: file => checkerByFile.get(helpers.canonical(file)) ?? null,
|
|
284
299
|
workspaceOf: file => helpers.workspaceOf(workspaces, helpers.canonical(file)) };
|
|
285
300
|
}
|
|
@@ -9,6 +9,11 @@ import { byCodeUnit } from '../lib/list.mjs';
|
|
|
9
9
|
// builds afresh.
|
|
10
10
|
const runs = new AsyncLocalStorage();
|
|
11
11
|
|
|
12
|
+
/** Share compiler inputs only until this check finishes; nested callers join the same run. */
|
|
13
|
+
export function withTypeScriptProgramRun(run) {
|
|
14
|
+
return runs.getStore() ? run() : runs.run(new Map(), run);
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
|
|
13
18
|
function keyOf(value) {
|
|
14
19
|
if (value === undefined) return 'u';
|
|
@@ -48,7 +53,28 @@ export function sharedInProgramRun(kind, ts, input, build) {
|
|
|
48
53
|
/** ts.createProgram, shared inside a program run. */
|
|
49
54
|
export function createTypeScriptProgram(ts, { rootNames, options, projectReferences }) {
|
|
50
55
|
return sharedInProgramRun('program', ts, { rootNames, options, projectReferences },
|
|
51
|
-
() => ts.createProgram({ rootNames, options, projectReferences }));
|
|
56
|
+
() => ts.createProgram({ rootNames, options, projectReferences, host: sharedSourceHost(ts, options) }));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function sharedSourceHost(ts, options) {
|
|
60
|
+
if (!runs.getStore()) return undefined;
|
|
61
|
+
const registry = sharedInProgramRun('documents', ts, null,
|
|
62
|
+
() => ts.createDocumentRegistry(ts.sys.useCaseSensitiveFileNames, ts.sys.getCurrentDirectory()));
|
|
63
|
+
const host = ts.createCompilerHost(options);
|
|
64
|
+
const readSource = host.getSourceFile;
|
|
65
|
+
// TypeScript's registry separates parse-affecting settings and Node module formats. Sharing syntax trees leaves
|
|
66
|
+
// module resolution and symbol/type caches with each program, including projects with different path aliases.
|
|
67
|
+
host.getSourceFile = (file, sourceOptions, onError, fresh) => {
|
|
68
|
+
if (fresh) return readSource(file, sourceOptions, onError, fresh);
|
|
69
|
+
let text;
|
|
70
|
+
try { text = host.readFile(file); } catch (error) {
|
|
71
|
+
onError?.(String(error.message ?? error));
|
|
72
|
+
text = '';
|
|
73
|
+
}
|
|
74
|
+
if (text === undefined) return undefined;
|
|
75
|
+
return registry.acquireDocument(file, options, ts.ScriptSnapshot.fromString(text), '0', undefined, sourceOptions);
|
|
76
|
+
};
|
|
77
|
+
return host;
|
|
52
78
|
}
|
|
53
79
|
|
|
54
80
|
/** Read and expand a tsconfig with the caller's TypeScript compiler and optional tracked file reader. */
|
|
@@ -66,6 +92,7 @@ export function typeScriptProjectReferencePath(ts, reference) {
|
|
|
66
92
|
}
|
|
67
93
|
|
|
68
94
|
/** Resolve an import using the selected project's compiler options. */
|
|
69
|
-
export function resolveTypeScriptModule(ts, specifier, from, options, host
|
|
70
|
-
|
|
95
|
+
export function resolveTypeScriptModule(ts, specifier, from, options, host, cache) {
|
|
96
|
+
const resolverHost = host === undefined ? ts.sys : host;
|
|
97
|
+
return ts.resolveModuleName(specifier, from, options, resolverHost, cache).resolvedModule?.resolvedFileName;
|
|
71
98
|
}
|