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