@gql.tada/cli-utils 1.7.4 → 1.8.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.
@@ -2,264 +2,613 @@ import e from "typescript";
2
2
 
3
3
  import r from "node:v8";
4
4
 
5
- import a from "node:vm";
5
+ import t from "node:vm";
6
6
 
7
- import * as t from "node:path";
7
+ import * as a from "node:fs";
8
8
 
9
- import { getSchemaNamesFromConfig as i } from "@gql.tada/internal";
9
+ import * as i from "node:path";
10
10
 
11
- import { findAllCallExpressions as o } from "@0no-co/graphqlsp/api";
11
+ import * as n from "node:crypto";
12
12
 
13
- import { e as n } from "./index-chunk2.mjs";
13
+ import { getSchemaNamesFromConfig as o, getSchemaConfigForName as s } from "@gql.tada/internal";
14
14
 
15
- import { p as s } from "./index-chunk.mjs";
15
+ import { findAllCallExpressions as u } from "@0no-co/graphqlsp/api";
16
16
 
17
- var l = 262144e4;
17
+ import { e as l } from "./index-chunk2.mjs";
18
18
 
19
- function findImportDeclaration(r) {
20
- var a = r;
21
- while (a) {
22
- if (e.isImportDeclaration(a)) {
19
+ import { p as c } from "./index-chunk.mjs";
20
+
21
+ var f = /@gql\.tada\/hash\s+([^\s*]+)/;
22
+
23
+ function getHashComment(r, t) {
24
+ var a = e.getLeadingCommentRanges(r, t.pos) || [];
25
+ for (var i = a.length - 1; i >= 0; i--) {
26
+ var n = r.slice(a[i].pos, a[i].end);
27
+ var o = f.exec(n);
28
+ if (o) {
29
+ return o[1];
30
+ }
31
+ }
32
+ return;
33
+ }
34
+
35
+ var p = "turbo-document-hash-v1";
36
+
37
+ function createDocumentHasher(r) {
38
+ var t = new WeakMap;
39
+ var a = new Map;
40
+ var i = new WeakSet;
41
+ var hashCallExpression = (e, r) => {
42
+ var a = r || "";
43
+ var n = t.get(e)?.get(a);
44
+ if (n) {
45
+ return n;
46
+ } else if (i.has(e)) {
47
+ return {
48
+ hashable: !1
49
+ };
50
+ }
51
+ i.add(e);
52
+ var o = computeCallExpressionHash(e, r);
53
+ i.delete(e);
54
+ var s = t.get(e);
55
+ if (!s) {
56
+ s = new Map;
57
+ t.set(e, s);
58
+ }
59
+ s.set(a, o);
60
+ return o;
61
+ };
62
+ var computeCallExpressionHash = (t, a) => {
63
+ var i = function getStaticStringValue(r) {
64
+ if (!r) {
65
+ return;
66
+ }
67
+ r = unwrapExpression(r);
68
+ if (e.isStringLiteral(r) || e.isNoSubstitutionTemplateLiteral(r)) {
69
+ return r.text;
70
+ }
71
+ return;
72
+ }(t.arguments[0]);
73
+ if (null == i) {
74
+ return {
75
+ hashable: !1
76
+ };
77
+ }
78
+ var o = getFragmentHashes(t.arguments[1], a);
79
+ if (!o) {
80
+ return {
81
+ hashable: !1
82
+ };
83
+ }
84
+ var s = n.createHash("sha256");
85
+ addHashPart(s, p);
86
+ addHashPart(s, a || "");
87
+ addHashPart(s, r.schemaFingerprints.get(a) || "");
88
+ addHashPart(s, i);
89
+ for (var u of o) {
90
+ addHashPart(s, u);
91
+ }
92
+ return {
93
+ hashable: !0,
94
+ documentHash: `sha256:${s.digest("hex").slice(0, 32)}`
95
+ };
96
+ };
97
+ var getFragmentHashes = (r, t) => {
98
+ if (!r) {
99
+ return [];
100
+ }
101
+ r = unwrapExpression(r);
102
+ if (e.isArrayLiteralExpression(r)) {
103
+ var a = [];
104
+ for (var i of r.elements) {
105
+ if (e.isSpreadElement(i)) {
106
+ var n = getFragmentHashes(i.expression, t);
107
+ if (!n) {
108
+ return null;
109
+ }
110
+ a.push(...n);
111
+ continue;
112
+ }
113
+ var o = resolveDocumentCallExpression(i);
114
+ if (!o) {
115
+ return null;
116
+ }
117
+ var s = hashCallExpression(o, t);
118
+ if (!s.hashable || !s.documentHash) {
119
+ return null;
120
+ }
121
+ a.push(s.documentHash);
122
+ }
23
123
  return a;
24
124
  }
25
- a = a.parent;
125
+ var u = resolveDeclarationInitializer(r);
126
+ if (u && u !== r) {
127
+ return getFragmentHashes(u, t);
128
+ }
129
+ return null;
130
+ };
131
+ var resolveDocumentCallExpression = r => {
132
+ r = unwrapExpression(r);
133
+ if (e.isCallExpression(r)) {
134
+ return r;
135
+ }
136
+ var t = getSymbol(r);
137
+ if (!t) {
138
+ return null;
139
+ }
140
+ var i = a.get(t);
141
+ if (void 0 !== i) {
142
+ return i;
143
+ }
144
+ var n = resolveSymbolCallExpression(t);
145
+ a.set(t, n);
146
+ return n;
147
+ };
148
+ var resolveDeclarationInitializer = r => {
149
+ var t = getSymbol(r);
150
+ if (!t) {
151
+ return null;
152
+ }
153
+ for (var a of t.declarations || []) {
154
+ if (e.isVariableDeclaration(a) && a.initializer) {
155
+ return a.initializer;
156
+ }
157
+ }
158
+ return null;
159
+ };
160
+ var resolveSymbolCallExpression = r => {
161
+ for (var t of r.declarations || []) {
162
+ if (e.isVariableDeclaration(t) && t.initializer) {
163
+ var a = unwrapExpression(t.initializer);
164
+ if (e.isCallExpression(a)) {
165
+ return a;
166
+ }
167
+ }
168
+ }
169
+ return null;
170
+ };
171
+ var getSymbol = t => {
172
+ var a = r.checker.getSymbolAtLocation(t);
173
+ if (a && a.flags & e.SymbolFlags.Alias) {
174
+ a = r.checker.getAliasedSymbol(a);
175
+ }
176
+ return a;
177
+ };
178
+ return {
179
+ hashCallExpression
180
+ };
181
+ }
182
+
183
+ function unwrapExpression(r) {
184
+ while (e.isParenthesizedExpression(r) || e.isAsExpression(r) || e.isTypeAssertionExpression(r) || e.isSatisfiesExpression(r) || e.isNonNullExpression(r)) {
185
+ r = r.expression;
186
+ }
187
+ return r;
188
+ }
189
+
190
+ function addHashPart(e, r) {
191
+ e.update(`${r.length}:`);
192
+ e.update(r);
193
+ e.update("\0");
194
+ }
195
+
196
+ var d = /(?:^|[^\w])(query|mutation|subscription|fragment)\b/;
197
+
198
+ function hasGraphQLDocumentCandidate(r) {
199
+ if (!r.text.includes("{")) {
200
+ return !1;
201
+ }
202
+ var t = !1;
203
+ var visit = r => {
204
+ if (t) {
205
+ return;
206
+ }
207
+ if (e.isCallExpression(r)) {
208
+ var a = r.arguments[0];
209
+ if (a && e.isStringLiteralLike(a)) {
210
+ var i = a.text;
211
+ if (i.includes("{") && function isGraphQLDocumentCandidateText(e) {
212
+ if (d.test(e)) {
213
+ return !0;
214
+ }
215
+ for (var r of e.split("\n")) {
216
+ var t = r.trimStart();
217
+ if (!t || t.startsWith("#")) {
218
+ continue;
219
+ }
220
+ return t.startsWith("{");
221
+ }
222
+ return !1;
223
+ }(i)) {
224
+ t = !0;
225
+ return;
226
+ }
227
+ }
228
+ }
229
+ e.forEachChild(r, visit);
230
+ };
231
+ visit(r);
232
+ return t;
233
+ }
234
+
235
+ var m = 262144e4;
236
+
237
+ function traceCallToImportSource(r, t, a, i) {
238
+ var n = r.expression;
239
+ var o;
240
+ if (e.isIdentifier(n)) {
241
+ o = n;
242
+ } else if (e.isPropertyAccessExpression(n) && e.isIdentifier(n.expression)) {
243
+ o = n.expression;
244
+ }
245
+ if (!o) {
246
+ return;
247
+ }
248
+ var s = `${t.fileName}\0${o.text}`;
249
+ if (i.traces.has(s)) {
250
+ return i.traces.get(s);
251
+ }
252
+ var u;
253
+ var l = a.getTypeChecker().getSymbolAtLocation(o);
254
+ if (l && l.declarations) {
255
+ for (var c of l.declarations) {
256
+ var f = findImportDeclaration(c);
257
+ if (f && e.isStringLiteral(f.moduleSpecifier)) {
258
+ u = resolveModulePath(f.moduleSpecifier.text, t, a, i);
259
+ break;
260
+ }
261
+ }
262
+ }
263
+ i.traces.set(s, u);
264
+ return u;
265
+ }
266
+
267
+ function findImportDeclaration(r) {
268
+ var t = r;
269
+ while (t) {
270
+ if (e.isImportDeclaration(t)) {
271
+ return t;
272
+ }
273
+ t = t.parent;
26
274
  }
27
275
  return;
28
276
  }
29
277
 
30
- function resolveModulePath(r, a, t) {
31
- var i = t.getCompilerOptions();
32
- var o = e.createCompilerHost(i);
33
- var n = e.resolveModuleName(r, a.fileName, i, o);
34
- if (n.resolvedModule) {
35
- return n.resolvedModule.resolvedFileName;
278
+ function resolveModulePath(r, t, a, i) {
279
+ var n = a.getCompilerOptions();
280
+ var o = i.host || (i.host = e.createCompilerHost(n));
281
+ var s = i.resolutionCache || (i.resolutionCache = e.createModuleResolutionCache(o.getCurrentDirectory(), o.getCanonicalFileName.bind(o), n));
282
+ var u = e.resolveModuleName(r, t.fileName, n, o, s);
283
+ if (u.resolvedModule) {
284
+ return u.resolvedModule.resolvedFileName;
36
285
  }
37
286
  return;
38
287
  }
39
288
 
40
- function collectImportsFromSourceFile(r, a, i, o, n) {
41
- var s = [];
42
- var l = function getTadaOutputPaths(e) {
43
- var r = [];
289
+ function collectImportsFromSourceFile(r, t, a, n, o, s, u) {
290
+ var l = [];
291
+ var c = function getTadaOutputPaths(e, r) {
292
+ var t = [];
44
293
  if ("schema" in e && e.tadaOutputLocation) {
45
- r.push(e.tadaOutputLocation);
46
- }
47
- return r;
48
- }(a);
49
- !function visit(a) {
50
- if (e.isImportDeclaration(a) && e.isStringLiteral(a.moduleSpecifier)) {
51
- var u = a.moduleSpecifier.text;
52
- if (!function isTadaImport(e, r, a) {
53
- if (e.startsWith(".")) {
54
- var i = t.dirname(r);
55
- var o = t.resolve(i, e);
56
- return a.some((e => {
57
- var r = t.resolve(e);
58
- return o === r || o.startsWith(r + t.sep);
59
- }));
294
+ t.push(i.resolve(r, e.tadaOutputLocation));
295
+ } else if ("schemas" in e) {
296
+ for (var a of e.schemas) {
297
+ if (a.tadaOutputLocation) {
298
+ t.push(i.resolve(r, a.tadaOutputLocation));
60
299
  }
61
- return a.some((r => e === r || e.startsWith(r + "/")));
62
- }(u, r.fileName, l)) {
63
- var c = a.getFullText().trim();
64
- if (o) {
65
- var p = i(u, r.fileName, o);
66
- if (n) {
67
- if (p.endsWith(".ts") || p.endsWith(".tsx")) {
68
- p = p.replace(/\.ts$/, ".js").replace(/\.tsx$/, ".js");
300
+ }
301
+ }
302
+ return t;
303
+ }(t, o);
304
+ for (var f of r.statements) {
305
+ if (e.isImportDeclaration(f) && e.isStringLiteral(f.moduleSpecifier)) {
306
+ var p = f.moduleSpecifier.text;
307
+ if (!isTadaImport(p, r.fileName, c, n)) {
308
+ var d = f.getFullText().trim();
309
+ if (s) {
310
+ var m = a(p, r.fileName, s);
311
+ if (u) {
312
+ if (m.endsWith(".ts") || m.endsWith(".tsx")) {
313
+ m = m.replace(/\.ts$/, ".js").replace(/\.tsx$/, ".js");
69
314
  }
70
315
  } else {
71
- p = p.replace(/\.ts$/, "").replace(/\.tsx$/, "");
316
+ m = m.replace(/\.ts$/, "").replace(/\.tsx$/, "");
72
317
  }
73
- if (p && !p.includes("gql.tada")) {
74
- s.push({
75
- specifier: p,
76
- importClause: c.replace(u, p)
318
+ if (m && !m.includes("gql.tada")) {
319
+ l.push({
320
+ specifier: m,
321
+ importClause: d.replace(p, m)
77
322
  });
78
323
  }
79
324
  } else {
80
- s.push({
81
- specifier: u,
82
- importClause: c
325
+ l.push({
326
+ specifier: p,
327
+ importClause: d
83
328
  });
84
329
  }
85
330
  }
86
331
  }
87
- e.forEachChild(a, visit);
88
- }(r);
89
- return s;
332
+ }
333
+ return l;
90
334
  }
91
335
 
92
- var u;
93
-
94
- function forceGc() {
95
- if (void 0 === u) {
96
- var e = globalThis.gc;
97
- if ("function" == typeof e) {
98
- u = e;
99
- } else {
100
- try {
101
- r.setFlagsFromString("--expose-gc");
102
- u = a.runInNewContext("gc");
103
- r.setFlagsFromString("--no-expose-gc");
104
- } catch {
105
- u = null;
106
- }
107
- }
336
+ function isTadaImport(e, r, t, a) {
337
+ var n = a(e, r);
338
+ if (n) {
339
+ return t.some((e => n === e));
108
340
  }
109
- if (u) {
110
- u();
341
+ if (e.startsWith(".")) {
342
+ var o = i.dirname(r);
343
+ var s = i.resolve(o, e);
344
+ return t.some((e => s === e));
111
345
  }
346
+ return t.some((r => e === r || e.startsWith(r + "/")));
112
347
  }
113
348
 
114
- var c = n((async function* _runTurbo(r) {
115
- var a = i(r.pluginConfig);
116
- var t = s(r);
117
- t.addSourceFile({
349
+ async function* _runTurbo(r) {
350
+ var t = o(r.pluginConfig);
351
+ var n = c(r);
352
+ var s = new Map;
353
+ var getCachedDocuments = t => {
354
+ var i = getTurboOutputPath(r.turboOutputPath, t);
355
+ if (!i) {
356
+ return new Map;
357
+ }
358
+ var n = s.get(i);
359
+ if (!n) {
360
+ n = function readCachedTurboDocuments(r) {
361
+ var t = new Map;
362
+ if (!r || !a.existsSync(r)) {
363
+ return t;
364
+ }
365
+ var i;
366
+ try {
367
+ i = a.readFileSync(r, "utf8");
368
+ } catch {
369
+ return t;
370
+ }
371
+ var n = e.createSourceFile(r, i, e.ScriptTarget.Latest, !0, e.ScriptKind.TS);
372
+ var visit = r => {
373
+ if (e.isInterfaceDeclaration(r) && "setupCache" === r.name.text) {
374
+ for (var a of r.members) {
375
+ if (!e.isPropertySignature(a) || !a.type) {
376
+ continue;
377
+ }
378
+ if (!e.isStringLiteral(a.name) && !e.isNumericLiteral(a.name)) {
379
+ continue;
380
+ }
381
+ var o = getHashComment(i, a);
382
+ if (!o) {
383
+ continue;
384
+ }
385
+ t.set(JSON.stringify(a.name.text), {
386
+ documentHash: o,
387
+ documentType: a.type.getText(n)
388
+ });
389
+ }
390
+ }
391
+ e.forEachChild(r, visit);
392
+ };
393
+ visit(n);
394
+ return t;
395
+ }(i);
396
+ s.set(i, n);
397
+ }
398
+ return n;
399
+ };
400
+ n.addSourceFile({
118
401
  fileId: "__gql-tada-override__.d.ts",
119
- sourceText: m,
402
+ sourceText: y,
120
403
  scriptKind: e.ScriptKind.TS
121
404
  });
122
- var n = t.createExternalFiles();
123
- if (n.length) {
405
+ var l = n.createExternalFiles();
406
+ if (l.length) {
124
407
  yield {
125
408
  kind: "EXTERNAL_WARNING"
126
409
  };
127
- await t.addVirtualFiles(n);
410
+ await n.addVirtualFiles(l);
128
411
  }
129
- var u = t.build();
130
- var c = u.buildPluginInfo(r.pluginConfig);
131
- var f = u.getSourceFiles().map((e => e.fileName));
412
+ var f = n.build();
413
+ var p = f.buildPluginInfo(r.pluginConfig);
414
+ var d = new Set(function getTurboOutputPaths(e) {
415
+ return "string" == typeof e ? [ e ] : e.map((e => e.path));
416
+ }(r.turboOutputPath).map((e => i.resolve(e))));
417
+ var h = n.rootFileNames.filter((e => function shouldScanTurboFile(e, r) {
418
+ if (r.has(i.resolve(e))) {
419
+ return !1;
420
+ }
421
+ if (e.endsWith(".d.ts") || e.endsWith(".d.mts") || e.endsWith(".d.cts")) {
422
+ return !1;
423
+ }
424
+ return !/(^|[/\\])node_modules([/\\]|$)/.test(e);
425
+ }(e, d)));
132
426
  yield {
133
427
  kind: "FILE_COUNT",
134
- fileCount: f.length
428
+ fileCount: h.length
429
+ };
430
+ var v = new Map;
431
+ var S = {
432
+ traces: new Map,
433
+ host: void 0,
434
+ resolutionCache: void 0
135
435
  };
136
- var d = new Map;
137
- var processSourceFile = (i, n, s, l) => {
138
- var u = i.fileName;
436
+ var processSourceFile = (a, i, o, s) => {
437
+ var l = a.fileName;
139
438
  var c = [];
140
- var m = [];
141
- var f = o(i, s, !1).nodes;
142
- var _loop = function(o) {
143
- var s = o.node.parent;
144
- if (!e.isCallExpression(s)) {
145
- return 0;
439
+ var f = [];
440
+ if (!hasGraphQLDocumentCandidate(a)) {
441
+ return {
442
+ filePath: l,
443
+ documents: c,
444
+ warnings: f
445
+ };
446
+ }
447
+ var p = u(a, o, {
448
+ searchExternal: !1,
449
+ collectFragments: !1
450
+ }).nodes;
451
+ for (var d of p) {
452
+ var m = d.node.parent;
453
+ if (!e.isCallExpression(m)) {
454
+ continue;
146
455
  }
147
- var f = n.getSourcePosition(i, s.getStart());
148
- u = f.fileName;
149
- if (!a.has(o.schema)) {
150
- m.push({
151
- message: o.schema ? `The '${o.schema}' schema is not in the configuration but was referenced by document.` : a.size > 1 ? "The document is not for a known schema. Have you re-generated the output file?" : "Multiple schemas are configured, but the document is not for a specific schema.",
152
- file: f.fileName,
153
- line: f.line,
154
- col: f.col
456
+ var h = i.getSourcePosition(a, m.getStart());
457
+ l = h.fileName;
458
+ if (!t.has(d.schema)) {
459
+ f.push({
460
+ message: d.schema ? `The '${d.schema}' schema is not in the configuration but was referenced by document.` : t.size > 1 ? "The document is not for a known schema. Have you re-generated the output file?" : "Multiple schemas are configured, but the document is not for a specific schema.",
461
+ file: h.fileName,
462
+ line: h.line,
463
+ col: h.col
155
464
  });
156
- return 0;
465
+ continue;
157
466
  }
158
- var g = function traceCallToImportSource(r, a, t) {
159
- var i = t.getTypeChecker();
160
- var o = r.expression;
161
- var n;
162
- if (e.isIdentifier(o)) {
163
- n = o;
164
- } else if (e.isPropertyAccessExpression(o) && e.isIdentifier(o.expression)) {
165
- n = o.expression;
166
- }
167
- if (!n) {
168
- return;
169
- }
170
- var s = i.getSymbolAtLocation(n);
171
- if (!s || !s.declarations) {
172
- return;
173
- }
174
- for (var l of s.declarations) {
175
- var u = findImportDeclaration(l);
176
- if (u && e.isStringLiteral(u.moduleSpecifier)) {
177
- return resolveModulePath(u.moduleSpecifier.text, a, t);
178
- }
179
- }
180
- return;
181
- }(s, i, n.program);
182
- if (g && !d.has(g)) {
183
- var v = n.program.getSourceFile(g);
184
- if (v) {
185
- var h = Array.isArray(r.turboOutputPath) ? r.turboOutputPath.find((e => e.schemaName === o.schema))?.path : r.turboOutputPath;
186
- var y = collectImportsFromSourceFile(v, r.pluginConfig, t.resolveModuleName.bind(t), h, !!t.wasOriginallyNodeNext);
187
- d.set(g, {
188
- absolutePath: g,
189
- imports: y
467
+ var y = traceCallToImportSource(m, a, i.program, S);
468
+ if (y && !v.has(y)) {
469
+ var T = i.program.getSourceFile(y);
470
+ if (T) {
471
+ var F = getTurboOutputPath(r.turboOutputPath, d.schema);
472
+ var b = collectImportsFromSourceFile(T, r.pluginConfig, n.resolveModuleName.bind(n), n.resolveModulePath.bind(n), r.rootPath, F, !!n.wasOriginallyNodeNext);
473
+ v.set(y, {
474
+ absolutePath: y,
475
+ imports: b
190
476
  });
191
477
  }
192
478
  }
193
- var T = l.getTypeAtLocation(s);
194
- var F = l.getTypeAtLocation(o.node);
195
- if (!T.symbol || "TadaDocumentNode" !== T.symbol.getEscapedName()) {
196
- m.push({
197
- message: 'The discovered document is not of type "TadaDocumentNode".\nIf this is unexpected, please file an issue describing your case.',
198
- file: f.fileName,
199
- line: f.line,
200
- col: f.col
201
- });
202
- return 0;
479
+ var C = JSON.stringify(d.node.text);
480
+ var N = x.hashCallExpression(m, d.schema);
481
+ var P = N.hashable && N.documentHash ? getCachedDocuments(d.schema).get(C) : void 0;
482
+ var w = void 0;
483
+ var E = !1;
484
+ if (P && P.documentHash === N.documentHash) {
485
+ w = P.documentType;
486
+ E = !0;
487
+ } else {
488
+ var L = s.getTypeAtLocation(m);
489
+ if (!L.symbol || "TadaDocumentNode" !== L.symbol.getEscapedName()) {
490
+ f.push({
491
+ message: 'The discovered document is not of type "TadaDocumentNode".\nIf this is unexpected, please file an issue describing your case.',
492
+ file: h.fileName,
493
+ line: h.line,
494
+ col: h.col
495
+ });
496
+ continue;
497
+ }
498
+ w = s.typeToString(L, m, g);
203
499
  }
204
- var S = "value" in F && "string" == typeof F.value && !(F.flags & e.TypeFlags.StringLiteral) ? JSON.stringify(F.value) : l.typeToString(F, s, p);
205
- var N = l.typeToString(T, s, p);
206
500
  c.push({
207
- schemaName: o.schema,
208
- argumentKey: S,
209
- documentType: N
501
+ schemaName: d.schema,
502
+ argumentKey: C,
503
+ documentType: w,
504
+ documentHash: N.documentHash,
505
+ isCached: E
210
506
  });
211
- };
212
- for (var g of f) {
213
- if (0 === _loop(g)) {
214
- continue;
215
- }
216
507
  }
217
508
  return {
218
- filePath: u,
509
+ filePath: l,
219
510
  documents: c,
220
- warnings: m
511
+ warnings: f
221
512
  };
222
513
  };
223
514
  var isHeapOverSoftLimit = () => {
224
- if (process.memoryUsage().heapUsed < l) {
515
+ if (process.memoryUsage().heapUsed < m) {
225
516
  return !1;
226
517
  }
227
518
  forceGc();
228
- return process.memoryUsage().heapUsed >= l;
519
+ return process.memoryUsage().heapUsed >= m;
229
520
  };
230
- var g = u.program.getTypeChecker();
231
- var v = 0;
232
- for (var h of f) {
233
- if (v > 0 && (v >= 1e3 || isHeapOverSoftLimit())) {
234
- c = (u = t.build()).buildPluginInfo(r.pluginConfig);
521
+ var T = f.program.getTypeChecker();
522
+ var x = createDocumentHasher({
523
+ get checker() {
524
+ return T;
525
+ },
526
+ schemaFingerprints: computeSchemaFingerprints(r)
527
+ });
528
+ var F = 0;
529
+ for (var b of h) {
530
+ if (F > 0 && (F >= 1e3 || isHeapOverSoftLimit())) {
531
+ p = (f = n.build()).buildPluginInfo(r.pluginConfig);
235
532
  forceGc();
236
- g = u.program.getTypeChecker();
237
- v = 0;
533
+ T = f.program.getTypeChecker();
534
+ F = 0;
238
535
  }
239
- var y = u.getSourceFile(h);
240
- if (!y) {
536
+ var C = f.getSourceFile(b);
537
+ if (!C) {
241
538
  continue;
242
539
  }
243
- var {filePath: T, documents: F, warnings: S} = processSourceFile(y, u, c, g);
244
- v++;
540
+ var {filePath: N, documents: P, warnings: w} = processSourceFile(C, f, p, T);
541
+ F++;
245
542
  yield {
246
543
  kind: "FILE_TURBO",
247
- filePath: T,
248
- documents: F,
249
- warnings: S
544
+ filePath: N,
545
+ documents: P,
546
+ warnings: w
250
547
  };
251
548
  }
252
- if (d.size > 0) {
549
+ if (v.size > 0) {
253
550
  yield {
254
551
  kind: "GRAPHQL_SOURCES",
255
- sources: Array.from(d.values())
552
+ sources: Array.from(v.values())
256
553
  };
257
554
  }
258
- }));
555
+ }
556
+
557
+ function computeSchemaFingerprints(e) {
558
+ var r = new Map;
559
+ var t = i.dirname(e.configPath);
560
+ for (var u of o(e.pluginConfig)) {
561
+ var l = s(e.pluginConfig, u || void 0);
562
+ var c = l && l.tadaOutputLocation;
563
+ if (!c) {
564
+ continue;
565
+ }
566
+ var f = void 0;
567
+ try {
568
+ f = a.readFileSync(i.resolve(t, c), "utf8");
569
+ } catch {
570
+ continue;
571
+ }
572
+ var p = n.createHash("sha256").update(f).digest("hex");
573
+ r.set(u, `sha256:${p.slice(0, 32)}`);
574
+ }
575
+ return r;
576
+ }
577
+
578
+ function getTurboOutputPath(e, r) {
579
+ if ("string" == typeof e) {
580
+ return e;
581
+ }
582
+ return e.find((e => e.schemaName === r))?.path;
583
+ }
584
+
585
+ var h;
586
+
587
+ function forceGc() {
588
+ if (void 0 === h) {
589
+ var e = globalThis.gc;
590
+ if ("function" == typeof e) {
591
+ h = e;
592
+ } else {
593
+ try {
594
+ r.setFlagsFromString("--expose-gc");
595
+ h = t.runInNewContext("gc");
596
+ r.setFlagsFromString("--no-expose-gc");
597
+ } catch {
598
+ h = null;
599
+ }
600
+ }
601
+ }
602
+ if (h) {
603
+ h();
604
+ }
605
+ }
606
+
607
+ var v = l(_runTurbo);
259
608
 
260
- var p = e.TypeFormatFlags.NoTruncation | e.TypeFormatFlags.NoTypeReduction | e.TypeFormatFlags.InTypeAlias | e.TypeFormatFlags.UseFullyQualifiedType | e.TypeFormatFlags.GenerateNamesForShadowedTypeParams | e.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | e.TypeFormatFlags.AllowUniqueESSymbolType | e.TypeFormatFlags.WriteTypeArgumentsOfSignature;
609
+ var g = e.TypeFormatFlags.NoTruncation | e.TypeFormatFlags.NoTypeReduction | e.TypeFormatFlags.InTypeAlias | e.TypeFormatFlags.UseFullyQualifiedType | e.TypeFormatFlags.GenerateNamesForShadowedTypeParams | e.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | e.TypeFormatFlags.AllowUniqueESSymbolType | e.TypeFormatFlags.WriteTypeArgumentsOfSignature;
261
610
 
262
- var m = "\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n interface setupCache {\n readonly __cacheDisabled: true;\n }\n}\n".trim();
611
+ var y = "\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n interface setupCache {\n readonly __cacheDisabled: true;\n }\n}\n".trim();
263
612
 
264
- export { c as runTurbo };
613
+ export { _runTurbo, collectImportsFromSourceFile, v as runTurbo };
265
614
  //# sourceMappingURL=thread-chunk2.mjs.map