@tipolink/mcp 1.0.1 → 1.0.2
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/dist/cli.js +607 -199
- package/dist/extractor.d.ts +10 -1
- package/dist/extractor.js +584 -185
- package/dist/index.d.ts +1 -1
- package/dist/index.js +617 -207
- package/dist/mcp-stdio.d.ts +1 -1
- package/dist/mcp-stdio.js +605 -197
- package/package.json +1 -1
package/dist/extractor.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
// src/extractor.ts
|
|
2
2
|
import { createHash as createHash4 } from "node:crypto";
|
|
3
|
-
import { readdirSync as readdirSync2, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2 } from "node:fs";
|
|
3
|
+
import { existsSync as existsSync3, readdirSync as readdirSync2, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
4
4
|
import path6 from "node:path";
|
|
5
5
|
|
|
6
6
|
// ../engine/src/ast-extractor.ts
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
|
-
import
|
|
8
|
+
import path3 from "node:path";
|
|
9
9
|
import ts from "typescript";
|
|
10
10
|
|
|
11
|
+
// ../engine/src/cache.ts
|
|
12
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
13
|
+
import path2 from "node:path";
|
|
14
|
+
|
|
11
15
|
// ../engine/src/paths.ts
|
|
12
16
|
import path from "node:path";
|
|
13
17
|
function compareText(a, b) {
|
|
@@ -46,9 +50,143 @@ function computeRelativeImportSpec(fromRelPath, toRelPath) {
|
|
|
46
50
|
return rel;
|
|
47
51
|
}
|
|
48
52
|
|
|
53
|
+
// ../engine/src/cache.ts
|
|
54
|
+
var CACHE_SCHEMA_VERSION = "1.0.2";
|
|
55
|
+
function cacheEntryMatches(entry, contentSha256, mtimeMs, size) {
|
|
56
|
+
if (contentSha256 !== void 0) {
|
|
57
|
+
return entry.contentSha256 === contentSha256;
|
|
58
|
+
}
|
|
59
|
+
if (mtimeMs !== void 0 || size !== void 0) {
|
|
60
|
+
if (mtimeMs !== void 0 && entry.mtimeMs !== mtimeMs) return false;
|
|
61
|
+
if (size !== void 0 && entry.size !== size) return false;
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
var JsonFileAstCache = class {
|
|
67
|
+
filePath;
|
|
68
|
+
schemaInvalidated = false;
|
|
69
|
+
autoSave;
|
|
70
|
+
workspaces = /* @__PURE__ */ new Map();
|
|
71
|
+
dirty = false;
|
|
72
|
+
constructor(filePathOrOptions) {
|
|
73
|
+
if (typeof filePathOrOptions === "string") {
|
|
74
|
+
this.filePath = filePathOrOptions;
|
|
75
|
+
this.autoSave = true;
|
|
76
|
+
} else {
|
|
77
|
+
this.filePath = filePathOrOptions.filePath;
|
|
78
|
+
this.autoSave = filePathOrOptions.autoSave ?? true;
|
|
79
|
+
}
|
|
80
|
+
this.loadFromDisk();
|
|
81
|
+
}
|
|
82
|
+
loadFromDisk() {
|
|
83
|
+
if (!existsSync(this.filePath)) return;
|
|
84
|
+
try {
|
|
85
|
+
const raw = readFileSync(this.filePath, "utf8");
|
|
86
|
+
if (!raw.trim()) return;
|
|
87
|
+
const parsed = JSON.parse(raw);
|
|
88
|
+
if (!parsed || typeof parsed !== "object" || !parsed.workspaces || typeof parsed.workspaces !== "object") {
|
|
89
|
+
this.schemaInvalidated = true;
|
|
90
|
+
this.dirty = true;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (parsed.manifestSchemaVersion !== CACHE_SCHEMA_VERSION) {
|
|
94
|
+
this.workspaces.clear();
|
|
95
|
+
this.schemaInvalidated = true;
|
|
96
|
+
this.dirty = true;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
for (const [workspaceId, files] of Object.entries(parsed.workspaces)) {
|
|
100
|
+
if (!files || typeof files !== "object") continue;
|
|
101
|
+
const map = /* @__PURE__ */ new Map();
|
|
102
|
+
for (const [relPath, manifest] of Object.entries(files)) {
|
|
103
|
+
if (manifest && typeof manifest === "object" && typeof manifest.contentSha256 === "string") {
|
|
104
|
+
const norm = toPosix(relPath);
|
|
105
|
+
map.set(norm, { ...manifest, relativePath: norm });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
this.workspaces.set(workspaceId, map);
|
|
109
|
+
}
|
|
110
|
+
} catch {
|
|
111
|
+
this.workspaces.clear();
|
|
112
|
+
this.schemaInvalidated = true;
|
|
113
|
+
this.dirty = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
get(workspaceId, relativePath, contentSha256, mtimeMs, size) {
|
|
117
|
+
const wsMap = this.workspaces.get(workspaceId);
|
|
118
|
+
if (!wsMap) return void 0;
|
|
119
|
+
const hit = wsMap.get(toPosix(relativePath));
|
|
120
|
+
if (!hit) return void 0;
|
|
121
|
+
return cacheEntryMatches(hit, contentSha256, mtimeMs, size) ? hit : void 0;
|
|
122
|
+
}
|
|
123
|
+
set(workspaceId, manifest) {
|
|
124
|
+
const norm = toPosix(manifest.relativePath);
|
|
125
|
+
const normalized = {
|
|
126
|
+
...manifest,
|
|
127
|
+
relativePath: norm
|
|
128
|
+
};
|
|
129
|
+
let wsMap = this.workspaces.get(workspaceId);
|
|
130
|
+
if (!wsMap) {
|
|
131
|
+
wsMap = /* @__PURE__ */ new Map();
|
|
132
|
+
this.workspaces.set(workspaceId, wsMap);
|
|
133
|
+
}
|
|
134
|
+
wsMap.set(norm, normalized);
|
|
135
|
+
this.dirty = true;
|
|
136
|
+
if (this.autoSave) {
|
|
137
|
+
this.save();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
getAllWorkspaceManifests(workspaceId) {
|
|
141
|
+
const wsMap = this.workspaces.get(workspaceId);
|
|
142
|
+
if (!wsMap) return [];
|
|
143
|
+
return [...wsMap.values()];
|
|
144
|
+
}
|
|
145
|
+
clear(workspaceId) {
|
|
146
|
+
if (workspaceId === void 0) {
|
|
147
|
+
this.workspaces.clear();
|
|
148
|
+
} else {
|
|
149
|
+
this.workspaces.delete(workspaceId);
|
|
150
|
+
}
|
|
151
|
+
this.dirty = true;
|
|
152
|
+
if (this.autoSave) {
|
|
153
|
+
this.save();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
save() {
|
|
157
|
+
if (!this.dirty && existsSync(this.filePath)) return;
|
|
158
|
+
const payload = {
|
|
159
|
+
version: 1,
|
|
160
|
+
manifestSchemaVersion: CACHE_SCHEMA_VERSION,
|
|
161
|
+
workspaces: {}
|
|
162
|
+
};
|
|
163
|
+
for (const [workspaceId, wsMap] of this.workspaces.entries()) {
|
|
164
|
+
const obj = {};
|
|
165
|
+
for (const [relPath, manifest] of wsMap.entries()) {
|
|
166
|
+
obj[relPath] = manifest;
|
|
167
|
+
}
|
|
168
|
+
payload.workspaces[workspaceId] = obj;
|
|
169
|
+
}
|
|
170
|
+
const dir = path2.dirname(this.filePath);
|
|
171
|
+
mkdirSync(dir, { recursive: true });
|
|
172
|
+
const serialized = JSON.stringify(payload, null, 2);
|
|
173
|
+
const tmpPath = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
174
|
+
try {
|
|
175
|
+
writeFileSync(tmpPath, serialized, "utf8");
|
|
176
|
+
renameSync(tmpPath, this.filePath);
|
|
177
|
+
} catch {
|
|
178
|
+
writeFileSync(this.filePath, serialized, "utf8");
|
|
179
|
+
}
|
|
180
|
+
this.dirty = false;
|
|
181
|
+
}
|
|
182
|
+
flush() {
|
|
183
|
+
this.save();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
49
187
|
// ../engine/src/ast-extractor.ts
|
|
50
188
|
function scriptKindFor(filePath) {
|
|
51
|
-
switch (
|
|
189
|
+
switch (path3.extname(filePath).toLowerCase()) {
|
|
52
190
|
case ".tsx":
|
|
53
191
|
return ts.ScriptKind.TSX;
|
|
54
192
|
case ".jsx":
|
|
@@ -62,7 +200,7 @@ function scriptKindFor(filePath) {
|
|
|
62
200
|
}
|
|
63
201
|
}
|
|
64
202
|
function jsTsLanguageFor(filePath) {
|
|
65
|
-
switch (
|
|
203
|
+
switch (path3.extname(filePath).toLowerCase()) {
|
|
66
204
|
case ".js":
|
|
67
205
|
case ".jsx":
|
|
68
206
|
case ".mjs":
|
|
@@ -87,19 +225,123 @@ function hasModifier(node, kind) {
|
|
|
87
225
|
function isFunctionLikeNode(node) {
|
|
88
226
|
return ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node) || ts.isMethodDeclaration(node);
|
|
89
227
|
}
|
|
90
|
-
function
|
|
228
|
+
function collectBindingNames(binding, out) {
|
|
229
|
+
if (ts.isIdentifier(binding)) {
|
|
230
|
+
out.add(binding.text);
|
|
231
|
+
} else if (ts.isObjectBindingPattern(binding) || ts.isArrayBindingPattern(binding)) {
|
|
232
|
+
for (const elem of binding.elements) {
|
|
233
|
+
if (ts.isBindingElement(elem)) {
|
|
234
|
+
collectBindingNames(elem.name, out);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function collectFunctionScopeBindings(fn, out) {
|
|
240
|
+
if (fn.name && ts.isIdentifier(fn.name)) {
|
|
241
|
+
out.add(fn.name.text);
|
|
242
|
+
}
|
|
243
|
+
if (fn.typeParameters) {
|
|
244
|
+
for (const tp of fn.typeParameters) {
|
|
245
|
+
out.add(tp.name.text);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
for (const param of fn.parameters) {
|
|
249
|
+
collectBindingNames(param.name, out);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function collectHoistedVarDeclarations(node, out) {
|
|
253
|
+
const walk = (curr) => {
|
|
254
|
+
if (isFunctionLikeNode(curr)) return;
|
|
255
|
+
if (ts.isVariableDeclarationList(curr)) {
|
|
256
|
+
const isBlockScoped = (curr.flags & (ts.NodeFlags.Const | ts.NodeFlags.Let)) !== 0;
|
|
257
|
+
if (!isBlockScoped) {
|
|
258
|
+
for (const decl of curr.declarations) {
|
|
259
|
+
collectBindingNames(decl.name, out);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
ts.forEachChild(curr, walk);
|
|
264
|
+
};
|
|
265
|
+
ts.forEachChild(node, walk);
|
|
266
|
+
}
|
|
267
|
+
function collectDirectStatementLocals(statements, out) {
|
|
268
|
+
for (const stmt of statements) {
|
|
269
|
+
if (ts.isVariableStatement(stmt)) {
|
|
270
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
271
|
+
collectBindingNames(decl.name, out);
|
|
272
|
+
}
|
|
273
|
+
} else if (ts.isFunctionDeclaration(stmt) && stmt.name) {
|
|
274
|
+
out.add(stmt.name.text);
|
|
275
|
+
} else if (ts.isClassDeclaration(stmt) && stmt.name) {
|
|
276
|
+
out.add(stmt.name.text);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function classifyIdentifierRole(curr, parent) {
|
|
281
|
+
if (!parent) return "variable";
|
|
282
|
+
if (ts.isPropertyAccessExpression(parent) && parent.name === curr) return "property";
|
|
283
|
+
if (ts.isQualifiedName(parent) && parent.right === curr) return "property";
|
|
284
|
+
if (ts.isBindingElement(parent) && parent.propertyName === curr) return "object_key";
|
|
285
|
+
if (ts.isPropertyAssignment(parent) && parent.name === curr) return "object_key";
|
|
286
|
+
if (ts.isPropertySignature(parent) && parent.name === curr) return "object_key";
|
|
287
|
+
if (ts.isMethodDeclaration(parent) && parent.name === curr) return "object_key";
|
|
288
|
+
if (ts.isMethodSignature(parent) && parent.name === curr) return "object_key";
|
|
289
|
+
if (ts.isGetAccessorDeclaration(parent) && parent.name === curr) return "object_key";
|
|
290
|
+
if (ts.isSetAccessorDeclaration(parent) && parent.name === curr) return "object_key";
|
|
291
|
+
if (ts.isPropertyDeclaration(parent) && parent.name === curr) return "object_key";
|
|
292
|
+
if (ts.isJsxAttribute(parent) && parent.name === curr) return "object_key";
|
|
293
|
+
if ((ts.isLabeledStatement(parent) || ts.isBreakStatement(parent) || ts.isContinueStatement(parent)) && parent.label === curr) {
|
|
294
|
+
return "property";
|
|
295
|
+
}
|
|
296
|
+
if (ts.isParameter(parent) && parent.name === curr || ts.isVariableDeclaration(parent) && parent.name === curr || ts.isBindingElement(parent) && parent.name === curr || ts.isFunctionDeclaration(parent) && parent.name === curr || ts.isFunctionExpression(parent) && parent.name === curr || ts.isClassDeclaration(parent) && parent.name === curr || ts.isClassExpression(parent) && parent.name === curr || ts.isTypeParameterDeclaration(parent) && parent.name === curr) {
|
|
297
|
+
return "declaration";
|
|
298
|
+
}
|
|
299
|
+
return "variable";
|
|
300
|
+
}
|
|
301
|
+
function collectModuleLocalDeclarations(sourceFile) {
|
|
302
|
+
const decls = /* @__PURE__ */ new Set();
|
|
303
|
+
for (const stmt of sourceFile.statements) {
|
|
304
|
+
if (ts.isVariableStatement(stmt)) {
|
|
305
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
306
|
+
collectBindingNames(decl.name, decls);
|
|
307
|
+
}
|
|
308
|
+
} else if (ts.isFunctionDeclaration(stmt) && stmt.name) {
|
|
309
|
+
decls.add(stmt.name.text);
|
|
310
|
+
} else if (ts.isClassDeclaration(stmt) && stmt.name) {
|
|
311
|
+
decls.add(stmt.name.text);
|
|
312
|
+
} else if (ts.isEnumDeclaration(stmt)) {
|
|
313
|
+
decls.add(stmt.name.text);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return decls;
|
|
317
|
+
}
|
|
318
|
+
function computeStructuralHashWithCount(node, sourceFile, options) {
|
|
91
319
|
const target = ts.isVariableDeclaration(node) && node.initializer && (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer)) ? node.initializer : node;
|
|
320
|
+
const normalizedFilePath = normalizeRelPath(options?.filePath ?? sourceFile.fileName);
|
|
321
|
+
const moduleLocalDecls = options?.moduleLocalDecls ?? collectModuleLocalDeclarations(sourceFile);
|
|
92
322
|
const tokens = [];
|
|
93
323
|
let nodeCount = 0;
|
|
94
324
|
let astNodeCount = 0;
|
|
95
|
-
const visit = (curr, countAsBody) => {
|
|
325
|
+
const visit = (curr, countAsBody, scope, parent) => {
|
|
96
326
|
nodeCount += 1;
|
|
97
327
|
if (countAsBody) {
|
|
98
328
|
astNodeCount += 1;
|
|
99
329
|
}
|
|
100
330
|
tokens.push(`K:${curr.kind}`);
|
|
331
|
+
let childScope = scope;
|
|
101
332
|
if (ts.isPropertyAccessExpression(curr)) {
|
|
102
|
-
tokens.push(`PROP
|
|
333
|
+
tokens.push(`PROP:${curr.name.text}`);
|
|
334
|
+
} else if (ts.isStringLiteral(curr) || ts.isNoSubstitutionTemplateLiteral(curr)) {
|
|
335
|
+
tokens.push(`STR:${curr.text}`);
|
|
336
|
+
} else if (ts.isTemplateExpression(curr)) {
|
|
337
|
+
tokens.push(`TPL_H:${curr.head.text}`);
|
|
338
|
+
for (const span of curr.templateSpans) {
|
|
339
|
+
tokens.push(`TPL_M:${span.literal.text}`);
|
|
340
|
+
}
|
|
341
|
+
} else if (ts.isNumericLiteral(curr)) {
|
|
342
|
+
tokens.push(`NUM:${curr.text}`);
|
|
343
|
+
} else if (ts.isRegularExpressionLiteral(curr)) {
|
|
344
|
+
tokens.push(`REGEX:${curr.text}`);
|
|
103
345
|
} else if (ts.isBinaryExpression(curr)) {
|
|
104
346
|
tokens.push(`OP:${curr.operatorToken.kind}`);
|
|
105
347
|
} else if (ts.isPrefixUnaryExpression(curr)) {
|
|
@@ -109,10 +351,61 @@ function computeStructuralHashWithCount(node, sourceFile) {
|
|
|
109
351
|
} else if (ts.isVariableDeclarationList(curr)) {
|
|
110
352
|
const declFlag = curr.flags & (ts.NodeFlags.Const | ts.NodeFlags.Let);
|
|
111
353
|
tokens.push(`VF:${declFlag}`);
|
|
354
|
+
} else if (ts.isIdentifier(curr)) {
|
|
355
|
+
const role = classifyIdentifierRole(curr, parent);
|
|
356
|
+
if (role === "declaration") {
|
|
357
|
+
tokens.push("ID:$L");
|
|
358
|
+
} else if (role === "object_key") {
|
|
359
|
+
tokens.push(`KEY:${curr.text}`);
|
|
360
|
+
} else if (role === "variable") {
|
|
361
|
+
if (scope.has(curr.text)) {
|
|
362
|
+
tokens.push("ID:$L");
|
|
363
|
+
} else if (moduleLocalDecls.has(curr.text)) {
|
|
364
|
+
tokens.push(`STATE:${normalizedFilePath}:${curr.text}`);
|
|
365
|
+
} else {
|
|
366
|
+
tokens.push(`EXT:${curr.text}`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (curr !== target && isFunctionLikeNode(curr)) {
|
|
371
|
+
const next = new Set(scope);
|
|
372
|
+
collectFunctionScopeBindings(curr, next);
|
|
373
|
+
if (curr.body) {
|
|
374
|
+
collectHoistedVarDeclarations(curr.body, next);
|
|
375
|
+
}
|
|
376
|
+
childScope = next;
|
|
377
|
+
} else if (ts.isBlock(curr)) {
|
|
378
|
+
const next = new Set(scope);
|
|
379
|
+
collectDirectStatementLocals(curr.statements, next);
|
|
380
|
+
childScope = next;
|
|
381
|
+
} else if (ts.isCaseClause(curr) || ts.isDefaultClause(curr)) {
|
|
382
|
+
const next = new Set(scope);
|
|
383
|
+
collectDirectStatementLocals(curr.statements, next);
|
|
384
|
+
childScope = next;
|
|
385
|
+
} else if (ts.isForStatement(curr) || ts.isForInStatement(curr) || ts.isForOfStatement(curr)) {
|
|
386
|
+
if (curr.initializer && ts.isVariableDeclarationList(curr.initializer)) {
|
|
387
|
+
const next = new Set(scope);
|
|
388
|
+
for (const decl of curr.initializer.declarations) {
|
|
389
|
+
collectBindingNames(decl.name, next);
|
|
390
|
+
}
|
|
391
|
+
childScope = next;
|
|
392
|
+
}
|
|
393
|
+
} else if (ts.isCatchClause(curr) && curr.variableDeclaration) {
|
|
394
|
+
const next = new Set(scope);
|
|
395
|
+
collectBindingNames(curr.variableDeclaration.name, next);
|
|
396
|
+
childScope = next;
|
|
112
397
|
}
|
|
113
|
-
ts.forEachChild(curr, (child) => visit(child, countAsBody));
|
|
398
|
+
ts.forEachChild(curr, (child) => visit(child, countAsBody, childScope, curr));
|
|
114
399
|
};
|
|
115
400
|
if (isFunctionLikeNode(target)) {
|
|
401
|
+
const rootScope = /* @__PURE__ */ new Set();
|
|
402
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
403
|
+
rootScope.add(node.name.text);
|
|
404
|
+
}
|
|
405
|
+
collectFunctionScopeBindings(target, rootScope);
|
|
406
|
+
if (target.body) {
|
|
407
|
+
collectHoistedVarDeclarations(target.body, rootScope);
|
|
408
|
+
}
|
|
116
409
|
tokens.push("FN");
|
|
117
410
|
if (hasModifier(target, ts.SyntaxKind.AsyncKeyword)) {
|
|
118
411
|
tokens.push("MOD:ASYNC");
|
|
@@ -121,14 +414,13 @@ function computeStructuralHashWithCount(node, sourceFile) {
|
|
|
121
414
|
tokens.push("MOD:GEN");
|
|
122
415
|
}
|
|
123
416
|
for (const param of target.parameters) {
|
|
124
|
-
visit(param, false);
|
|
417
|
+
visit(param, false, rootScope, target);
|
|
125
418
|
}
|
|
126
419
|
if (target.body) {
|
|
127
|
-
visit(target.body, true);
|
|
420
|
+
visit(target.body, true, rootScope, target);
|
|
128
421
|
}
|
|
129
422
|
} else {
|
|
130
|
-
void
|
|
131
|
-
visit(target, true);
|
|
423
|
+
visit(target, true, /* @__PURE__ */ new Set(), void 0);
|
|
132
424
|
}
|
|
133
425
|
const structuralHash = createHash("sha256").update(tokens.join("|"), "utf8").digest("hex").slice(0, 16);
|
|
134
426
|
return { structuralHash, nodeCount, astNodeCount };
|
|
@@ -162,7 +454,7 @@ function formatConstSummary(decl, sourceFile) {
|
|
|
162
454
|
}
|
|
163
455
|
if (ts.isObjectLiteralExpression(init)) {
|
|
164
456
|
const keys = init.properties.slice(0, 5).map((prop) => {
|
|
165
|
-
if (ts.isPropertyAssignment(prop) || ts.isShorthandPropertyAssignment(prop)) {
|
|
457
|
+
if (ts.isPropertyAssignment(prop) || ts.isShorthandPropertyAssignment(prop) || ts.isMethodDeclaration(prop)) {
|
|
166
458
|
return prop.name.getText(sourceFile);
|
|
167
459
|
}
|
|
168
460
|
return "...";
|
|
@@ -203,10 +495,10 @@ function formatEnumSignature(node, sourceFile) {
|
|
|
203
495
|
function lineNumberOf(node, sourceFile) {
|
|
204
496
|
return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
|
|
205
497
|
}
|
|
206
|
-
function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, isTypeOnly) {
|
|
498
|
+
function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, isTypeOnly, isDynamic = false) {
|
|
207
499
|
const trimmed = rawSpecifier.trim();
|
|
208
500
|
if (!trimmed) return;
|
|
209
|
-
const dedupKey = `${trimmed}\0${isReExport ? "1" : "0"}\0${isTypeOnly ? "1" : "0"}`;
|
|
501
|
+
const dedupKey = `${trimmed}\0${isReExport ? "1" : "0"}\0${isTypeOnly ? "1" : "0"}\0${isDynamic ? "1" : "0"}`;
|
|
210
502
|
const existing = keyMap.get(dedupKey);
|
|
211
503
|
if (existing) {
|
|
212
504
|
for (const name of importedNames) {
|
|
@@ -220,7 +512,8 @@ function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, is
|
|
|
220
512
|
rawSpecifier: trimmed,
|
|
221
513
|
importedNames: [...new Set(importedNames)],
|
|
222
514
|
isReExport,
|
|
223
|
-
isTypeOnly
|
|
515
|
+
isTypeOnly,
|
|
516
|
+
...isDynamic ? { isDynamic: true } : {}
|
|
224
517
|
};
|
|
225
518
|
keyMap.set(dedupKey, entry);
|
|
226
519
|
refs.push(entry);
|
|
@@ -233,7 +526,10 @@ function extractImports(sourceFile) {
|
|
|
233
526
|
if (ts.isStringLiteral(node.moduleSpecifier)) {
|
|
234
527
|
const names = [];
|
|
235
528
|
const clause = node.importClause;
|
|
236
|
-
const
|
|
529
|
+
const allNamedTypeOnly = Boolean(
|
|
530
|
+
clause && !clause.name && clause.namedBindings && ts.isNamedImports(clause.namedBindings) && clause.namedBindings.elements.length > 0 && clause.namedBindings.elements.every((elem) => elem.isTypeOnly)
|
|
531
|
+
);
|
|
532
|
+
const isTypeOnly = Boolean(clause?.isTypeOnly) || allNamedTypeOnly;
|
|
237
533
|
if (clause) {
|
|
238
534
|
if (clause.name) names.push("default");
|
|
239
535
|
if (clause.namedBindings) {
|
|
@@ -246,13 +542,19 @@ function extractImports(sourceFile) {
|
|
|
246
542
|
}
|
|
247
543
|
}
|
|
248
544
|
}
|
|
249
|
-
pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, false, isTypeOnly);
|
|
545
|
+
pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, false, isTypeOnly, false);
|
|
250
546
|
}
|
|
251
547
|
} else if (ts.isExportDeclaration(node)) {
|
|
252
548
|
if (node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
253
549
|
const names = [];
|
|
550
|
+
const allNamedTypeOnly = Boolean(
|
|
551
|
+
node.exportClause && ts.isNamedExports(node.exportClause) && node.exportClause.elements.length > 0 && node.exportClause.elements.every((elem) => elem.isTypeOnly)
|
|
552
|
+
);
|
|
553
|
+
const isTypeOnly = Boolean(node.isTypeOnly) || allNamedTypeOnly;
|
|
254
554
|
if (!node.exportClause) {
|
|
255
|
-
|
|
555
|
+
if (!isTypeOnly) {
|
|
556
|
+
names.push("*");
|
|
557
|
+
}
|
|
256
558
|
} else if (ts.isNamespaceExport(node.exportClause)) {
|
|
257
559
|
names.push("*");
|
|
258
560
|
} else if (ts.isNamedExports(node.exportClause)) {
|
|
@@ -260,27 +562,27 @@ function extractImports(sourceFile) {
|
|
|
260
562
|
names.push((elem.propertyName ?? elem.name).text);
|
|
261
563
|
}
|
|
262
564
|
}
|
|
263
|
-
pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, true,
|
|
565
|
+
pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, true, isTypeOnly, false);
|
|
264
566
|
}
|
|
265
567
|
} else if (ts.isImportEqualsDeclaration(node)) {
|
|
266
568
|
if (ts.isExternalModuleReference(node.moduleReference) && ts.isStringLiteral(node.moduleReference.expression)) {
|
|
267
|
-
pushImportRef(refs, keyMap, node.moduleReference.expression.text, [node.name.text], false, false);
|
|
569
|
+
pushImportRef(refs, keyMap, node.moduleReference.expression.text, [node.name.text], false, false, false);
|
|
268
570
|
}
|
|
269
571
|
} else if (ts.isCallExpression(node)) {
|
|
270
572
|
const first = node.arguments[0];
|
|
271
573
|
if (first && ts.isStringLiteralLike(first)) {
|
|
272
574
|
const callee = node.expression;
|
|
273
575
|
if (callee.kind === ts.SyntaxKind.ImportKeyword) {
|
|
274
|
-
pushImportRef(refs, keyMap, first.text, [], false, false);
|
|
576
|
+
pushImportRef(refs, keyMap, first.text, [], false, false, true);
|
|
275
577
|
} else if (ts.isIdentifier(callee) && callee.text === "require") {
|
|
276
|
-
pushImportRef(refs, keyMap, first.text, [], false, false);
|
|
578
|
+
pushImportRef(refs, keyMap, first.text, [], false, false, false);
|
|
277
579
|
}
|
|
278
580
|
}
|
|
279
581
|
} else if (ts.isImportTypeNode(node)) {
|
|
280
582
|
const argument = node.argument;
|
|
281
583
|
if (ts.isLiteralTypeNode(argument) && ts.isStringLiteral(argument.literal)) {
|
|
282
584
|
const names = node.qualifier ? [collapseWhitespace(node.qualifier.getText(sourceFile))] : [];
|
|
283
|
-
pushImportRef(refs, keyMap, argument.literal.text, names, false, true);
|
|
585
|
+
pushImportRef(refs, keyMap, argument.literal.text, names, false, true, false);
|
|
284
586
|
}
|
|
285
587
|
}
|
|
286
588
|
ts.forEachChild(node, visit);
|
|
@@ -299,6 +601,8 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
299
601
|
scriptKindFor(absolutePath)
|
|
300
602
|
);
|
|
301
603
|
const imports = extractImports(sourceFile);
|
|
604
|
+
const moduleLocalDecls = collectModuleLocalDeclarations(sourceFile);
|
|
605
|
+
const hashOptions = { filePath: rel, moduleLocalDecls };
|
|
302
606
|
const localDecls = /* @__PURE__ */ new Map();
|
|
303
607
|
const exportedSymbols = [];
|
|
304
608
|
const internalFunctions = [];
|
|
@@ -316,7 +620,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
316
620
|
if (ts.isFunctionDeclaration(stmt)) {
|
|
317
621
|
if (!stmt.body) continue;
|
|
318
622
|
const declName = stmt.name?.text;
|
|
319
|
-
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
623
|
+
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
624
|
+
stmt,
|
|
625
|
+
sourceFile,
|
|
626
|
+
hashOptions
|
|
627
|
+
);
|
|
320
628
|
const signature = formatFunctionSignature(stmt, sourceFile);
|
|
321
629
|
const line = lineNumberOf(stmt, sourceFile);
|
|
322
630
|
if (declName) {
|
|
@@ -358,7 +666,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
358
666
|
const line = lineNumberOf(decl, sourceFile);
|
|
359
667
|
const init = decl.initializer;
|
|
360
668
|
if (init && (ts.isArrowFunction(init) || ts.isFunctionExpression(init))) {
|
|
361
|
-
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
669
|
+
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
670
|
+
decl,
|
|
671
|
+
sourceFile,
|
|
672
|
+
hashOptions
|
|
673
|
+
);
|
|
362
674
|
const signature = formatFunctionSignature(init, sourceFile);
|
|
363
675
|
localDecls.set(declName, {
|
|
364
676
|
name: declName,
|
|
@@ -596,7 +908,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
596
908
|
});
|
|
597
909
|
}
|
|
598
910
|
} else if (ts.isArrowFunction(stmt.expression) || ts.isFunctionExpression(stmt.expression)) {
|
|
599
|
-
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
911
|
+
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
912
|
+
stmt.expression,
|
|
913
|
+
sourceFile,
|
|
914
|
+
hashOptions
|
|
915
|
+
);
|
|
600
916
|
addExported({
|
|
601
917
|
name: "default",
|
|
602
918
|
kind: "function",
|
|
@@ -639,6 +955,7 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
639
955
|
return {
|
|
640
956
|
relativePath: rel,
|
|
641
957
|
contentSha256,
|
|
958
|
+
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
642
959
|
language: jsTsLanguageFor(absolutePath),
|
|
643
960
|
...mtimeMs !== void 0 ? { mtimeMs } : {},
|
|
644
961
|
...size !== void 0 ? { size } : {},
|
|
@@ -648,129 +965,6 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
648
965
|
};
|
|
649
966
|
}
|
|
650
967
|
|
|
651
|
-
// ../engine/src/cache.ts
|
|
652
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
653
|
-
import path3 from "node:path";
|
|
654
|
-
function cacheEntryMatches(entry, contentSha256, mtimeMs, size) {
|
|
655
|
-
if (contentSha256 !== void 0) {
|
|
656
|
-
return entry.contentSha256 === contentSha256;
|
|
657
|
-
}
|
|
658
|
-
if (mtimeMs !== void 0 || size !== void 0) {
|
|
659
|
-
if (mtimeMs !== void 0 && entry.mtimeMs !== mtimeMs) return false;
|
|
660
|
-
if (size !== void 0 && entry.size !== size) return false;
|
|
661
|
-
return true;
|
|
662
|
-
}
|
|
663
|
-
return true;
|
|
664
|
-
}
|
|
665
|
-
var JsonFileAstCache = class {
|
|
666
|
-
filePath;
|
|
667
|
-
autoSave;
|
|
668
|
-
workspaces = /* @__PURE__ */ new Map();
|
|
669
|
-
dirty = false;
|
|
670
|
-
constructor(filePathOrOptions) {
|
|
671
|
-
if (typeof filePathOrOptions === "string") {
|
|
672
|
-
this.filePath = filePathOrOptions;
|
|
673
|
-
this.autoSave = true;
|
|
674
|
-
} else {
|
|
675
|
-
this.filePath = filePathOrOptions.filePath;
|
|
676
|
-
this.autoSave = filePathOrOptions.autoSave ?? true;
|
|
677
|
-
}
|
|
678
|
-
this.loadFromDisk();
|
|
679
|
-
}
|
|
680
|
-
loadFromDisk() {
|
|
681
|
-
if (!existsSync(this.filePath)) return;
|
|
682
|
-
try {
|
|
683
|
-
const raw = readFileSync(this.filePath, "utf8");
|
|
684
|
-
if (!raw.trim()) return;
|
|
685
|
-
const parsed = JSON.parse(raw);
|
|
686
|
-
if (!parsed || typeof parsed !== "object" || !parsed.workspaces || typeof parsed.workspaces !== "object") {
|
|
687
|
-
return;
|
|
688
|
-
}
|
|
689
|
-
for (const [workspaceId, files] of Object.entries(parsed.workspaces)) {
|
|
690
|
-
if (!files || typeof files !== "object") continue;
|
|
691
|
-
const map = /* @__PURE__ */ new Map();
|
|
692
|
-
for (const [relPath, manifest] of Object.entries(files)) {
|
|
693
|
-
if (manifest && typeof manifest === "object" && typeof manifest.contentSha256 === "string") {
|
|
694
|
-
const norm = toPosix(relPath);
|
|
695
|
-
map.set(norm, { ...manifest, relativePath: norm });
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
this.workspaces.set(workspaceId, map);
|
|
699
|
-
}
|
|
700
|
-
} catch {
|
|
701
|
-
this.workspaces.clear();
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
get(workspaceId, relativePath, contentSha256, mtimeMs, size) {
|
|
705
|
-
const wsMap = this.workspaces.get(workspaceId);
|
|
706
|
-
if (!wsMap) return void 0;
|
|
707
|
-
const hit = wsMap.get(toPosix(relativePath));
|
|
708
|
-
if (!hit) return void 0;
|
|
709
|
-
return cacheEntryMatches(hit, contentSha256, mtimeMs, size) ? hit : void 0;
|
|
710
|
-
}
|
|
711
|
-
set(workspaceId, manifest) {
|
|
712
|
-
const norm = toPosix(manifest.relativePath);
|
|
713
|
-
const normalized = {
|
|
714
|
-
...manifest,
|
|
715
|
-
relativePath: norm
|
|
716
|
-
};
|
|
717
|
-
let wsMap = this.workspaces.get(workspaceId);
|
|
718
|
-
if (!wsMap) {
|
|
719
|
-
wsMap = /* @__PURE__ */ new Map();
|
|
720
|
-
this.workspaces.set(workspaceId, wsMap);
|
|
721
|
-
}
|
|
722
|
-
wsMap.set(norm, normalized);
|
|
723
|
-
this.dirty = true;
|
|
724
|
-
if (this.autoSave) {
|
|
725
|
-
this.save();
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
getAllWorkspaceManifests(workspaceId) {
|
|
729
|
-
const wsMap = this.workspaces.get(workspaceId);
|
|
730
|
-
if (!wsMap) return [];
|
|
731
|
-
return [...wsMap.values()];
|
|
732
|
-
}
|
|
733
|
-
clear(workspaceId) {
|
|
734
|
-
if (workspaceId === void 0) {
|
|
735
|
-
this.workspaces.clear();
|
|
736
|
-
} else {
|
|
737
|
-
this.workspaces.delete(workspaceId);
|
|
738
|
-
}
|
|
739
|
-
this.dirty = true;
|
|
740
|
-
if (this.autoSave) {
|
|
741
|
-
this.save();
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
save() {
|
|
745
|
-
if (!this.dirty && existsSync(this.filePath)) return;
|
|
746
|
-
const payload = {
|
|
747
|
-
version: 1,
|
|
748
|
-
workspaces: {}
|
|
749
|
-
};
|
|
750
|
-
for (const [workspaceId, wsMap] of this.workspaces.entries()) {
|
|
751
|
-
const obj = {};
|
|
752
|
-
for (const [relPath, manifest] of wsMap.entries()) {
|
|
753
|
-
obj[relPath] = manifest;
|
|
754
|
-
}
|
|
755
|
-
payload.workspaces[workspaceId] = obj;
|
|
756
|
-
}
|
|
757
|
-
const dir = path3.dirname(this.filePath);
|
|
758
|
-
mkdirSync(dir, { recursive: true });
|
|
759
|
-
const serialized = JSON.stringify(payload, null, 2);
|
|
760
|
-
const tmpPath = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
761
|
-
try {
|
|
762
|
-
writeFileSync(tmpPath, serialized, "utf8");
|
|
763
|
-
renameSync(tmpPath, this.filePath);
|
|
764
|
-
} catch {
|
|
765
|
-
writeFileSync(this.filePath, serialized, "utf8");
|
|
766
|
-
}
|
|
767
|
-
this.dirty = false;
|
|
768
|
-
}
|
|
769
|
-
flush() {
|
|
770
|
-
this.save();
|
|
771
|
-
}
|
|
772
|
-
};
|
|
773
|
-
|
|
774
968
|
// ../engine/src/indexer.ts
|
|
775
969
|
import { createHash as createHash3 } from "node:crypto";
|
|
776
970
|
import { readFileSync as readFileSync3, readdirSync, realpathSync, statSync } from "node:fs";
|
|
@@ -2910,6 +3104,45 @@ function buildWorkspaceResolutionContext(root, rootReal, allRelativePaths, confi
|
|
|
2910
3104
|
|
|
2911
3105
|
// ../engine/src/indexer.ts
|
|
2912
3106
|
var SOURCE_EXTENSIONS = new Set(defaultPolyglotRegistry.supportedExtensions);
|
|
3107
|
+
var NON_CODE_ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
3108
|
+
".css",
|
|
3109
|
+
".scss",
|
|
3110
|
+
".less",
|
|
3111
|
+
".svg",
|
|
3112
|
+
".png",
|
|
3113
|
+
".jpg",
|
|
3114
|
+
".jpeg",
|
|
3115
|
+
".webp",
|
|
3116
|
+
".gif",
|
|
3117
|
+
".ico",
|
|
3118
|
+
".woff",
|
|
3119
|
+
".woff2",
|
|
3120
|
+
".ttf",
|
|
3121
|
+
".wasm",
|
|
3122
|
+
".json",
|
|
3123
|
+
".glsl",
|
|
3124
|
+
".sql",
|
|
3125
|
+
".txt",
|
|
3126
|
+
".md"
|
|
3127
|
+
]);
|
|
3128
|
+
function stripImportQueryAndHash(specifier) {
|
|
3129
|
+
const trimmed = specifier.trim();
|
|
3130
|
+
const qIdx = trimmed.indexOf("?");
|
|
3131
|
+
const hIdx = trimmed.indexOf("#");
|
|
3132
|
+
let cut = trimmed.length;
|
|
3133
|
+
if (qIdx !== -1 && qIdx < cut) cut = qIdx;
|
|
3134
|
+
if (hIdx !== -1 && hIdx < cut) cut = hIdx;
|
|
3135
|
+
return trimmed.slice(0, cut);
|
|
3136
|
+
}
|
|
3137
|
+
function isRelativeImportSpecifier(specifier) {
|
|
3138
|
+
const clean = stripImportQueryAndHash(specifier);
|
|
3139
|
+
return clean === "." || clean === ".." || clean.startsWith("./") || clean.startsWith("../");
|
|
3140
|
+
}
|
|
3141
|
+
function isNonCodeAssetSpecifier(specifier) {
|
|
3142
|
+
const clean = stripImportQueryAndHash(specifier);
|
|
3143
|
+
const ext = path5.posix.extname(clean).toLowerCase();
|
|
3144
|
+
return ext.length > 0 && NON_CODE_ASSET_EXTENSIONS.has(ext) && !SOURCE_EXTENSIONS.has(ext);
|
|
3145
|
+
}
|
|
2913
3146
|
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
2914
3147
|
"node_modules",
|
|
2915
3148
|
".git",
|
|
@@ -3119,7 +3352,18 @@ function resolveAlias(spec, fromFile, index) {
|
|
|
3119
3352
|
}
|
|
3120
3353
|
return null;
|
|
3121
3354
|
}
|
|
3122
|
-
function
|
|
3355
|
+
function buildEdgeFlags(importedNames, meta) {
|
|
3356
|
+
const isTypeOnly = meta?.isTypeOnly === true;
|
|
3357
|
+
const isDynamic = meta?.isDynamic === true;
|
|
3358
|
+
const hasStaticValueImport = !isTypeOnly && !isDynamic && meta?.verifiedAssetOnDisk !== true && importedNames.length > 0;
|
|
3359
|
+
return {
|
|
3360
|
+
...isTypeOnly ? { isTypeOnly: true } : {},
|
|
3361
|
+
...isDynamic ? { isDynamic: true } : {},
|
|
3362
|
+
hasStaticValueImport,
|
|
3363
|
+
...meta?.verifiedAssetOnDisk !== void 0 ? { verifiedAssetOnDisk: meta.verifiedAssetOnDisk } : {}
|
|
3364
|
+
};
|
|
3365
|
+
}
|
|
3366
|
+
function localRef(found, index, importedNames, isReExport, meta) {
|
|
3123
3367
|
let real;
|
|
3124
3368
|
try {
|
|
3125
3369
|
real = realpathSync.native(found);
|
|
@@ -3132,55 +3376,72 @@ function localRef(found, index, importedNames, isReExport) {
|
|
|
3132
3376
|
kind: "local",
|
|
3133
3377
|
label,
|
|
3134
3378
|
importedNames: [...importedNames],
|
|
3135
|
-
isReExport
|
|
3379
|
+
isReExport,
|
|
3380
|
+
...buildEdgeFlags(importedNames, meta)
|
|
3136
3381
|
};
|
|
3137
3382
|
}
|
|
3138
|
-
function unresolvedRef(base, index, importedNames, isReExport) {
|
|
3383
|
+
function unresolvedRef(base, index, importedNames, isReExport, meta) {
|
|
3139
3384
|
const label = displayPath(index.root, path5.resolve(base));
|
|
3140
3385
|
return {
|
|
3141
3386
|
key: `unresolved:${label}`,
|
|
3142
3387
|
kind: "unresolved",
|
|
3143
3388
|
label: `${label} (unresolved)`,
|
|
3144
3389
|
importedNames: [...importedNames],
|
|
3145
|
-
isReExport
|
|
3390
|
+
isReExport,
|
|
3391
|
+
...buildEdgeFlags(importedNames, meta)
|
|
3146
3392
|
};
|
|
3147
3393
|
}
|
|
3148
|
-
function externalRef(spec, importedNames, isReExport) {
|
|
3394
|
+
function externalRef(spec, importedNames, isReExport, meta) {
|
|
3149
3395
|
return {
|
|
3150
3396
|
key: `pkg:${spec}`,
|
|
3151
3397
|
kind: "external",
|
|
3152
3398
|
label: spec,
|
|
3153
3399
|
importedNames: [...importedNames],
|
|
3154
|
-
isReExport
|
|
3400
|
+
isReExport,
|
|
3401
|
+
...buildEdgeFlags(importedNames, meta)
|
|
3155
3402
|
};
|
|
3156
3403
|
}
|
|
3157
|
-
function resolveModule(rawSpec, fromFile, index, importedNames = [], isReExport = false) {
|
|
3158
|
-
const spec = rawSpec
|
|
3404
|
+
function resolveModule(rawSpec, fromFile, index, importedNames = [], isReExport = false, meta) {
|
|
3405
|
+
const spec = stripImportQueryAndHash(rawSpec);
|
|
3159
3406
|
if (spec === "." || spec === ".." || spec.startsWith("./") || spec.startsWith("../")) {
|
|
3160
3407
|
const base = path5.resolve(path5.dirname(fromFile), spec);
|
|
3161
3408
|
const found = resolveCandidate(base);
|
|
3162
|
-
|
|
3409
|
+
const isAsset = isNonCodeAssetSpecifier(spec);
|
|
3410
|
+
const verifiedAssetOnDisk = isAsset ? Boolean(found) : meta?.verifiedAssetOnDisk;
|
|
3411
|
+
const effectiveMeta = {
|
|
3412
|
+
...meta,
|
|
3413
|
+
...verifiedAssetOnDisk !== void 0 ? { verifiedAssetOnDisk } : {}
|
|
3414
|
+
};
|
|
3415
|
+
return found ? localRef(found, index, importedNames, isReExport, effectiveMeta) : unresolvedRef(base, index, importedNames, isReExport, effectiveMeta);
|
|
3163
3416
|
}
|
|
3164
3417
|
if (spec.startsWith("node:")) {
|
|
3165
|
-
return externalRef(spec, importedNames, isReExport);
|
|
3418
|
+
return externalRef(spec, importedNames, isReExport, meta);
|
|
3166
3419
|
}
|
|
3167
3420
|
if (NODE_BUILTINS.has(spec)) {
|
|
3168
|
-
return externalRef(`node:${spec}`, importedNames, isReExport);
|
|
3421
|
+
return externalRef(`node:${spec}`, importedNames, isReExport, meta);
|
|
3169
3422
|
}
|
|
3170
3423
|
if (path5.isAbsolute(spec)) {
|
|
3171
3424
|
const found = resolveCandidate(spec);
|
|
3172
|
-
if (found) return localRef(found, index, importedNames, isReExport);
|
|
3425
|
+
if (found) return localRef(found, index, importedNames, isReExport, meta);
|
|
3173
3426
|
}
|
|
3174
3427
|
const aliased = resolveAlias(spec, fromFile, index);
|
|
3175
|
-
if (aliased)
|
|
3176
|
-
|
|
3428
|
+
if (aliased) {
|
|
3429
|
+
const isAsset = isNonCodeAssetSpecifier(aliased);
|
|
3430
|
+
return localRef(aliased, index, importedNames, isReExport, {
|
|
3431
|
+
...meta,
|
|
3432
|
+
...isAsset ? { verifiedAssetOnDisk: true } : {}
|
|
3433
|
+
});
|
|
3434
|
+
}
|
|
3435
|
+
return externalRef(spec, importedNames, isReExport, meta);
|
|
3177
3436
|
}
|
|
3178
3437
|
function mergeModuleRef(modules, ref) {
|
|
3438
|
+
const incomingHasStatic = ref.hasStaticValueImport ?? (ref.isTypeOnly !== true && ref.isDynamic !== true && ref.verifiedAssetOnDisk !== true && ref.importedNames.length > 0);
|
|
3179
3439
|
const existing = modules.get(ref.key);
|
|
3180
3440
|
if (!existing) {
|
|
3181
3441
|
modules.set(ref.key, {
|
|
3182
3442
|
...ref,
|
|
3183
|
-
importedNames: [...ref.importedNames]
|
|
3443
|
+
importedNames: [...ref.importedNames],
|
|
3444
|
+
hasStaticValueImport: incomingHasStatic
|
|
3184
3445
|
});
|
|
3185
3446
|
return;
|
|
3186
3447
|
}
|
|
@@ -3192,6 +3453,15 @@ function mergeModuleRef(modules, ref) {
|
|
|
3192
3453
|
if (ref.isReExport) {
|
|
3193
3454
|
existing.isReExport = true;
|
|
3194
3455
|
}
|
|
3456
|
+
const existingHasStatic = existing.hasStaticValueImport ?? (existing.isTypeOnly !== true && existing.isDynamic !== true && existing.verifiedAssetOnDisk !== true && existing.importedNames.length > 0);
|
|
3457
|
+
existing.hasStaticValueImport = existingHasStatic || incomingHasStatic;
|
|
3458
|
+
existing.isTypeOnly = Boolean(existing.isTypeOnly) && Boolean(ref.isTypeOnly);
|
|
3459
|
+
existing.isDynamic = Boolean(existing.isDynamic) && Boolean(ref.isDynamic);
|
|
3460
|
+
if (ref.verifiedAssetOnDisk === true) {
|
|
3461
|
+
existing.verifiedAssetOnDisk = true;
|
|
3462
|
+
} else if (ref.verifiedAssetOnDisk === false && existing.verifiedAssetOnDisk === void 0) {
|
|
3463
|
+
existing.verifiedAssetOnDisk = false;
|
|
3464
|
+
}
|
|
3195
3465
|
}
|
|
3196
3466
|
function addInboundEdge(index, callerRel, targetRel) {
|
|
3197
3467
|
let inboundSet = index.inbound.get(targetRel);
|
|
@@ -3224,8 +3494,13 @@ function registerIndexedFile(index, file, extraId) {
|
|
|
3224
3494
|
function resolveNonJsTsImport(imp, relative, language, index, modules) {
|
|
3225
3495
|
const adapter = defaultPolyglotRegistry.getAdapterById(language);
|
|
3226
3496
|
const ctx = index.resolutionContext;
|
|
3497
|
+
const edgeMeta = {
|
|
3498
|
+
isTypeOnly: imp.isTypeOnly,
|
|
3499
|
+
isDynamic: imp.isDynamic,
|
|
3500
|
+
verifiedAssetOnDisk: imp.verifiedAssetOnDisk
|
|
3501
|
+
};
|
|
3227
3502
|
if (!adapter || !ctx) {
|
|
3228
|
-
const ext = externalRef(imp.rawSpecifier, imp.importedNames, imp.isReExport);
|
|
3503
|
+
const ext = externalRef(imp.rawSpecifier, imp.importedNames, imp.isReExport, edgeMeta);
|
|
3229
3504
|
mergeModuleRef(modules, { ...ext, rawSpecifier: imp.rawSpecifier });
|
|
3230
3505
|
return { ...imp, resolvedKind: "external", resolvedPaths: [] };
|
|
3231
3506
|
}
|
|
@@ -3238,6 +3513,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
|
|
|
3238
3513
|
label: targetRel,
|
|
3239
3514
|
importedNames: [...imp.importedNames],
|
|
3240
3515
|
isReExport: imp.isReExport,
|
|
3516
|
+
...buildEdgeFlags(imp.importedNames, edgeMeta),
|
|
3241
3517
|
rawSpecifier: imp.rawSpecifier
|
|
3242
3518
|
});
|
|
3243
3519
|
}
|
|
@@ -3255,6 +3531,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
|
|
|
3255
3531
|
label: `${attempt} (unresolved)`,
|
|
3256
3532
|
importedNames: [...imp.importedNames],
|
|
3257
3533
|
isReExport: imp.isReExport,
|
|
3534
|
+
...buildEdgeFlags(imp.importedNames, edgeMeta),
|
|
3258
3535
|
rawSpecifier: imp.rawSpecifier
|
|
3259
3536
|
});
|
|
3260
3537
|
return {
|
|
@@ -3265,7 +3542,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
|
|
|
3265
3542
|
}
|
|
3266
3543
|
const extLabel = res.externalLabel ?? imp.rawSpecifier;
|
|
3267
3544
|
mergeModuleRef(modules, {
|
|
3268
|
-
...externalRef(extLabel, imp.importedNames, imp.isReExport),
|
|
3545
|
+
...externalRef(extLabel, imp.importedNames, imp.isReExport, edgeMeta),
|
|
3269
3546
|
rawSpecifier: imp.rawSpecifier
|
|
3270
3547
|
});
|
|
3271
3548
|
return {
|
|
@@ -3326,11 +3603,29 @@ function indexFileOnDisk(absolute, index, options) {
|
|
|
3326
3603
|
const resolvedImports = [];
|
|
3327
3604
|
for (const imp of manifest.imports) {
|
|
3328
3605
|
if (isJsTs) {
|
|
3329
|
-
const
|
|
3606
|
+
const cleanSpec = stripImportQueryAndHash(imp.rawSpecifier);
|
|
3607
|
+
let verifiedAssetOnDisk = imp.verifiedAssetOnDisk;
|
|
3608
|
+
if (isRelativeImportSpecifier(cleanSpec) && isNonCodeAssetSpecifier(cleanSpec)) {
|
|
3609
|
+
verifiedAssetOnDisk = isFile(path5.resolve(path5.dirname(realAbs), cleanSpec));
|
|
3610
|
+
}
|
|
3611
|
+
const ref = resolveModule(
|
|
3612
|
+
imp.rawSpecifier,
|
|
3613
|
+
realAbs,
|
|
3614
|
+
index,
|
|
3615
|
+
imp.importedNames,
|
|
3616
|
+
imp.isReExport,
|
|
3617
|
+
{
|
|
3618
|
+
isTypeOnly: imp.isTypeOnly,
|
|
3619
|
+
isDynamic: imp.isDynamic,
|
|
3620
|
+
verifiedAssetOnDisk
|
|
3621
|
+
}
|
|
3622
|
+
);
|
|
3330
3623
|
mergeModuleRef(modules, { ...ref, rawSpecifier: imp.rawSpecifier });
|
|
3331
3624
|
const resolvedPaths = ref.kind === "local" ? [ref.label] : ref.kind === "unresolved" ? [ref.label.replace(/ \(unresolved\)$/, "")] : [];
|
|
3625
|
+
const effectiveVerifiedAsset = ref.verifiedAssetOnDisk !== void 0 ? ref.verifiedAssetOnDisk : verifiedAssetOnDisk;
|
|
3332
3626
|
resolvedImports.push({
|
|
3333
3627
|
...imp,
|
|
3628
|
+
...effectiveVerifiedAsset !== void 0 ? { verifiedAssetOnDisk: effectiveVerifiedAsset } : {},
|
|
3334
3629
|
resolvedKind: ref.kind,
|
|
3335
3630
|
resolvedPaths
|
|
3336
3631
|
});
|
|
@@ -3421,6 +3716,84 @@ function buildIndex(root, options) {
|
|
|
3421
3716
|
function sha256Text(text) {
|
|
3422
3717
|
return createHash4("sha256").update(text, "utf8").digest("hex");
|
|
3423
3718
|
}
|
|
3719
|
+
function computeManifestSyncHash(manifest) {
|
|
3720
|
+
const assetSig = manifest.imports.map((imp) => {
|
|
3721
|
+
const assetFlag = imp.verifiedAssetOnDisk === true ? "1" : imp.verifiedAssetOnDisk === false ? "0" : "-";
|
|
3722
|
+
const dynFlag = imp.isDynamic === true ? "D" : "S";
|
|
3723
|
+
const typeFlag = imp.isTypeOnly ? "T" : "V";
|
|
3724
|
+
return `${imp.rawSpecifier}:${typeFlag}${dynFlag}${assetFlag}:${imp.importedNames.length}`;
|
|
3725
|
+
}).join("|");
|
|
3726
|
+
const symSig = manifest.exportedSymbols.map((s) => `${s.name}:${s.structuralHash ?? ""}`).join(",");
|
|
3727
|
+
const internalSig = manifest.internalFunctions.map((f) => `${f.name}:${f.structuralHash}`).join(",");
|
|
3728
|
+
const schema = manifest.schemaVersion ?? CACHE_SCHEMA_VERSION;
|
|
3729
|
+
return sha256Text(`${schema}\0${manifest.contentSha256}\0${assetSig}\0${symSig}\0${internalSig}`);
|
|
3730
|
+
}
|
|
3731
|
+
function verifyRelativeAssetsOnDisk(manifest, sourceAbsPath) {
|
|
3732
|
+
const sourceDir = path6.dirname(sourceAbsPath);
|
|
3733
|
+
let changed = false;
|
|
3734
|
+
const updatedImports = manifest.imports.map((imp) => {
|
|
3735
|
+
const cleanSpec = stripImportQueryAndHash(imp.rawSpecifier);
|
|
3736
|
+
if (!isRelativeImportSpecifier(cleanSpec) || !isNonCodeAssetSpecifier(cleanSpec)) {
|
|
3737
|
+
return imp;
|
|
3738
|
+
}
|
|
3739
|
+
const resolvedDiskPath = path6.resolve(sourceDir, cleanSpec);
|
|
3740
|
+
const verified = existsSync3(resolvedDiskPath);
|
|
3741
|
+
if (imp.verifiedAssetOnDisk !== verified) {
|
|
3742
|
+
changed = true;
|
|
3743
|
+
}
|
|
3744
|
+
return {
|
|
3745
|
+
...imp,
|
|
3746
|
+
verifiedAssetOnDisk: verified
|
|
3747
|
+
};
|
|
3748
|
+
});
|
|
3749
|
+
if (!changed) {
|
|
3750
|
+
return { manifest, changed: false };
|
|
3751
|
+
}
|
|
3752
|
+
return {
|
|
3753
|
+
manifest: {
|
|
3754
|
+
...manifest,
|
|
3755
|
+
imports: updatedImports
|
|
3756
|
+
},
|
|
3757
|
+
changed: true
|
|
3758
|
+
};
|
|
3759
|
+
}
|
|
3760
|
+
function invalidateStaleCloudSyncFile(cachePath, workspaceId) {
|
|
3761
|
+
const syncPath = path6.join(path6.dirname(cachePath), "cloud-sync.json");
|
|
3762
|
+
if (!existsSync3(syncPath)) return;
|
|
3763
|
+
try {
|
|
3764
|
+
const parsed = JSON.parse(readFileSync4(syncPath, "utf8"));
|
|
3765
|
+
if (!parsed || typeof parsed !== "object") return;
|
|
3766
|
+
if (parsed.manifestSchemaVersion !== CACHE_SCHEMA_VERSION) {
|
|
3767
|
+
writeFileSync2(
|
|
3768
|
+
syncPath,
|
|
3769
|
+
JSON.stringify(
|
|
3770
|
+
{
|
|
3771
|
+
version: 1,
|
|
3772
|
+
manifestSchemaVersion: CACHE_SCHEMA_VERSION,
|
|
3773
|
+
workspaces: {}
|
|
3774
|
+
},
|
|
3775
|
+
null,
|
|
3776
|
+
2
|
|
3777
|
+
),
|
|
3778
|
+
"utf8"
|
|
3779
|
+
);
|
|
3780
|
+
return;
|
|
3781
|
+
}
|
|
3782
|
+
if (parsed.workspaces && typeof parsed.workspaces === "object") {
|
|
3783
|
+
let modified = false;
|
|
3784
|
+
for (const key of Object.keys(parsed.workspaces)) {
|
|
3785
|
+
if (key === workspaceId || key.endsWith(`::${workspaceId}`)) {
|
|
3786
|
+
delete parsed.workspaces[key];
|
|
3787
|
+
modified = true;
|
|
3788
|
+
}
|
|
3789
|
+
}
|
|
3790
|
+
if (modified) {
|
|
3791
|
+
writeFileSync2(syncPath, JSON.stringify(parsed, null, 2), "utf8");
|
|
3792
|
+
}
|
|
3793
|
+
}
|
|
3794
|
+
} catch {
|
|
3795
|
+
}
|
|
3796
|
+
}
|
|
3424
3797
|
function hasSkippedPathSegment(relPath) {
|
|
3425
3798
|
const segments = toPosix(relPath).replace(/^\.\//, "").split("/");
|
|
3426
3799
|
return segments.some((seg) => seg.length > 0 && SKIP_DIRS.has(seg));
|
|
@@ -3433,6 +3806,7 @@ function sanitizeManifest(manifest) {
|
|
|
3433
3806
|
return {
|
|
3434
3807
|
relativePath: toPosix(manifest.relativePath),
|
|
3435
3808
|
contentSha256: manifest.contentSha256,
|
|
3809
|
+
schemaVersion: manifest.schemaVersion ?? CACHE_SCHEMA_VERSION,
|
|
3436
3810
|
...manifest.language !== void 0 ? { language: manifest.language } : {},
|
|
3437
3811
|
...manifest.mtimeMs !== void 0 ? { mtimeMs: manifest.mtimeMs } : {},
|
|
3438
3812
|
...manifest.size !== void 0 ? { size: manifest.size } : {},
|
|
@@ -3441,6 +3815,8 @@ function sanitizeManifest(manifest) {
|
|
|
3441
3815
|
importedNames: [...imp.importedNames],
|
|
3442
3816
|
isReExport: imp.isReExport,
|
|
3443
3817
|
isTypeOnly: imp.isTypeOnly,
|
|
3818
|
+
...imp.isDynamic === true ? { isDynamic: true } : {},
|
|
3819
|
+
...typeof imp.verifiedAssetOnDisk === "boolean" ? { verifiedAssetOnDisk: imp.verifiedAssetOnDisk } : {},
|
|
3444
3820
|
...Array.isArray(imp.resolvedPaths) ? { resolvedPaths: imp.resolvedPaths.map((p) => toPosix(p)) } : {},
|
|
3445
3821
|
...imp.resolvedKind !== void 0 ? { resolvedKind: imp.resolvedKind } : {}
|
|
3446
3822
|
})),
|
|
@@ -3513,6 +3889,7 @@ function scanWorkspaceManifests(rootDir, options = {}) {
|
|
|
3513
3889
|
const cachePath = options.cachePath ?? path6.join(resolvedRoot, ".tipolink", "cache.json");
|
|
3514
3890
|
const writeCache = options.writeCache ?? true;
|
|
3515
3891
|
const cache = new JsonFileAstCache({ filePath: cachePath, autoSave: false });
|
|
3892
|
+
const schemaInvalidated = cache.schemaInvalidated;
|
|
3516
3893
|
const priorManifests = cache.getAllWorkspaceManifests(workspaceId);
|
|
3517
3894
|
const priorPaths = /* @__PURE__ */ new Set();
|
|
3518
3895
|
let prunedSkippedEntries = false;
|
|
@@ -3529,7 +3906,7 @@ function scanWorkspaceManifests(rootDir, options = {}) {
|
|
|
3529
3906
|
const deltaRelPaths = /* @__PURE__ */ new Set();
|
|
3530
3907
|
let cacheHits = 0;
|
|
3531
3908
|
let parsedCount = 0;
|
|
3532
|
-
let cacheMutated =
|
|
3909
|
+
let cacheMutated = schemaInvalidated;
|
|
3533
3910
|
for (const absPath of sourceFiles) {
|
|
3534
3911
|
let realAbs;
|
|
3535
3912
|
try {
|
|
@@ -3548,29 +3925,44 @@ function scanWorkspaceManifests(rootDir, options = {}) {
|
|
|
3548
3925
|
}
|
|
3549
3926
|
if (!stats.isFile()) continue;
|
|
3550
3927
|
const statHit = cache.get(workspaceId, relPath, void 0, stats.mtimeMs, stats.size);
|
|
3551
|
-
if (statHit) {
|
|
3928
|
+
if (statHit && statHit.schemaVersion === CACHE_SCHEMA_VERSION) {
|
|
3552
3929
|
cacheHits += 1;
|
|
3553
|
-
|
|
3930
|
+
const verified = verifyRelativeAssetsOnDisk(sanitizeManifest(statHit), realAbs);
|
|
3931
|
+
if (verified.changed) {
|
|
3932
|
+
cache.set(workspaceId, verified.manifest);
|
|
3933
|
+
cacheMutated = true;
|
|
3934
|
+
deltaRelPaths.add(relPath);
|
|
3935
|
+
}
|
|
3936
|
+
rawAllManifests.push(verified.manifest);
|
|
3554
3937
|
continue;
|
|
3555
3938
|
}
|
|
3556
3939
|
const source = readFileSync4(realAbs, "utf8");
|
|
3557
3940
|
const contentSha256 = sha256Text(source);
|
|
3558
3941
|
const hashHit = cache.get(workspaceId, relPath, contentSha256);
|
|
3559
|
-
if (hashHit) {
|
|
3942
|
+
if (hashHit && hashHit.schemaVersion === CACHE_SCHEMA_VERSION) {
|
|
3560
3943
|
cacheHits += 1;
|
|
3561
|
-
const
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3944
|
+
const verified = verifyRelativeAssetsOnDisk(
|
|
3945
|
+
sanitizeManifest({
|
|
3946
|
+
...hashHit,
|
|
3947
|
+
mtimeMs: stats.mtimeMs,
|
|
3948
|
+
size: stats.size
|
|
3949
|
+
}),
|
|
3950
|
+
realAbs
|
|
3951
|
+
);
|
|
3952
|
+
cache.set(workspaceId, verified.manifest);
|
|
3567
3953
|
cacheMutated = true;
|
|
3568
|
-
|
|
3954
|
+
if (verified.changed) {
|
|
3955
|
+
deltaRelPaths.add(relPath);
|
|
3956
|
+
}
|
|
3957
|
+
rawAllManifests.push(verified.manifest);
|
|
3569
3958
|
continue;
|
|
3570
3959
|
}
|
|
3571
|
-
const extracted =
|
|
3572
|
-
|
|
3573
|
-
|
|
3960
|
+
const extracted = verifyRelativeAssetsOnDisk(
|
|
3961
|
+
sanitizeManifest(
|
|
3962
|
+
defaultPolyglotRegistry.extractManifest(source, realAbs, relPath, stats.mtimeMs, stats.size)
|
|
3963
|
+
),
|
|
3964
|
+
realAbs
|
|
3965
|
+
).manifest;
|
|
3574
3966
|
parsedCount += 1;
|
|
3575
3967
|
cache.set(workspaceId, extracted);
|
|
3576
3968
|
cacheMutated = true;
|
|
@@ -3592,22 +3984,27 @@ function scanWorkspaceManifests(rootDir, options = {}) {
|
|
|
3592
3984
|
}
|
|
3593
3985
|
if (writeCache && cacheMutated) {
|
|
3594
3986
|
cache.flush();
|
|
3987
|
+
if (schemaInvalidated) {
|
|
3988
|
+
invalidateStaleCloudSyncFile(cachePath, workspaceId);
|
|
3989
|
+
}
|
|
3595
3990
|
}
|
|
3596
3991
|
const index = buildIndex(resolvedRoot, { workspaceId, cache });
|
|
3597
3992
|
const allManifests = [];
|
|
3598
3993
|
const manifestDelta = [];
|
|
3599
3994
|
for (const file of index.files) {
|
|
3600
3995
|
if (hasSkippedPathSegment(file.relative)) continue;
|
|
3601
|
-
const
|
|
3602
|
-
allManifests.push(
|
|
3996
|
+
const verified = verifyRelativeAssetsOnDisk(sanitizeManifest(file.manifest), file.absolute).manifest;
|
|
3997
|
+
allManifests.push(verified);
|
|
3603
3998
|
if (deltaRelPaths.has(file.relative)) {
|
|
3604
|
-
manifestDelta.push(
|
|
3999
|
+
manifestDelta.push(verified);
|
|
3605
4000
|
}
|
|
3606
4001
|
}
|
|
3607
4002
|
return {
|
|
3608
4003
|
workspaceId,
|
|
3609
4004
|
rootDir: resolvedRoot,
|
|
3610
4005
|
cachePath,
|
|
4006
|
+
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
4007
|
+
schemaInvalidated,
|
|
3611
4008
|
allManifests,
|
|
3612
4009
|
manifestDelta,
|
|
3613
4010
|
removedPaths,
|
|
@@ -3617,6 +4014,8 @@ function scanWorkspaceManifests(rootDir, options = {}) {
|
|
|
3617
4014
|
};
|
|
3618
4015
|
}
|
|
3619
4016
|
export {
|
|
4017
|
+
CACHE_SCHEMA_VERSION,
|
|
4018
|
+
computeManifestSyncHash,
|
|
3620
4019
|
deriveWorkspaceId,
|
|
3621
4020
|
sanitizeManifest,
|
|
3622
4021
|
scanWorkspaceManifests
|