@gql.tada/cli-utils 1.7.3 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/chunks/index-chunk.js +3476 -6166
- package/dist/chunks/index-chunk.js.map +1 -1
- package/dist/chunks/index-chunk.mjs +3418 -6114
- package/dist/chunks/index-chunk.mjs.map +1 -1
- package/dist/chunks/index-chunk2.js +79 -49
- package/dist/chunks/index-chunk2.js.map +1 -1
- package/dist/chunks/index-chunk2.mjs +128 -98
- package/dist/chunks/index-chunk2.mjs.map +1 -1
- package/dist/chunks/runner-chunk.js +2790 -0
- package/dist/chunks/runner-chunk.js.map +1 -0
- package/dist/chunks/runner-chunk.mjs +2773 -0
- package/dist/chunks/runner-chunk.mjs.map +1 -0
- package/dist/chunks/thread-chunk2.js +149 -96
- package/dist/chunks/thread-chunk2.js.map +1 -1
- package/dist/chunks/thread-chunk2.mjs +166 -113
- package/dist/chunks/thread-chunk2.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
var e = require("typescript");
|
|
2
2
|
|
|
3
|
-
var r = require("node:
|
|
3
|
+
var r = require("node:v8");
|
|
4
4
|
|
|
5
|
-
var a = require("
|
|
5
|
+
var a = require("node:vm");
|
|
6
6
|
|
|
7
|
-
var t = require("
|
|
7
|
+
var t = require("node:path");
|
|
8
8
|
|
|
9
|
-
var i = require("
|
|
9
|
+
var i = require("@gql.tada/internal");
|
|
10
10
|
|
|
11
|
-
var o = require("
|
|
11
|
+
var o = require("@0no-co/graphqlsp/api");
|
|
12
|
+
|
|
13
|
+
var n = require("./index-chunk2.js");
|
|
14
|
+
|
|
15
|
+
var s = require("./index-chunk.js");
|
|
12
16
|
|
|
13
17
|
function _interopNamespaceDefault(e) {
|
|
14
18
|
var r = Object.create(null);
|
|
@@ -29,32 +33,9 @@ function _interopNamespaceDefault(e) {
|
|
|
29
33
|
return r;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
var
|
|
36
|
+
var l = _interopNamespaceDefault(t);
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
var i = t.getTypeChecker();
|
|
36
|
-
var o = r.expression;
|
|
37
|
-
var n;
|
|
38
|
-
if (e.isIdentifier(o)) {
|
|
39
|
-
n = o;
|
|
40
|
-
} else if (e.isPropertyAccessExpression(o) && e.isIdentifier(o.expression)) {
|
|
41
|
-
n = o.expression;
|
|
42
|
-
}
|
|
43
|
-
if (!n) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
var s = i.getSymbolAtLocation(n);
|
|
47
|
-
if (!s || !s.declarations) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
for (var l of s.declarations) {
|
|
51
|
-
var u = findImportDeclaration(l);
|
|
52
|
-
if (u && e.isStringLiteral(u.moduleSpecifier)) {
|
|
53
|
-
return resolveModulePath(u.moduleSpecifier.text, a, t);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
38
|
+
var u = 262144e4;
|
|
58
39
|
|
|
59
40
|
function findImportDeclaration(r) {
|
|
60
41
|
var a = r;
|
|
@@ -78,8 +59,8 @@ function resolveModulePath(r, a, t) {
|
|
|
78
59
|
}
|
|
79
60
|
|
|
80
61
|
function collectImportsFromSourceFile(r, a, t, i, o) {
|
|
81
|
-
var
|
|
82
|
-
var
|
|
62
|
+
var n = [];
|
|
63
|
+
var s = function getTadaOutputPaths(e) {
|
|
83
64
|
var r = [];
|
|
84
65
|
if ("schema" in e && e.tadaOutputLocation) {
|
|
85
66
|
r.push(e.tadaOutputLocation);
|
|
@@ -91,15 +72,15 @@ function collectImportsFromSourceFile(r, a, t, i, o) {
|
|
|
91
72
|
var u = a.moduleSpecifier.text;
|
|
92
73
|
if (!function isTadaImport(e, r, a) {
|
|
93
74
|
if (e.startsWith(".")) {
|
|
94
|
-
var t =
|
|
95
|
-
var i =
|
|
75
|
+
var t = l.dirname(r);
|
|
76
|
+
var i = l.resolve(t, e);
|
|
96
77
|
return a.some((e => {
|
|
97
|
-
var r =
|
|
98
|
-
return i === r || i.startsWith(r +
|
|
78
|
+
var r = l.resolve(e);
|
|
79
|
+
return i === r || i.startsWith(r + l.sep);
|
|
99
80
|
}));
|
|
100
81
|
}
|
|
101
82
|
return a.some((r => e === r || e.startsWith(r + "/")));
|
|
102
|
-
}(u, r.fileName,
|
|
83
|
+
}(u, r.fileName, s)) {
|
|
103
84
|
var c = a.getFullText().trim();
|
|
104
85
|
if (i) {
|
|
105
86
|
var p = t(u, r.fileName, i);
|
|
@@ -111,13 +92,13 @@ function collectImportsFromSourceFile(r, a, t, i, o) {
|
|
|
111
92
|
p = p.replace(/\.ts$/, "").replace(/\.tsx$/, "");
|
|
112
93
|
}
|
|
113
94
|
if (p && !p.includes("gql.tada")) {
|
|
114
|
-
|
|
95
|
+
n.push({
|
|
115
96
|
specifier: p,
|
|
116
97
|
importClause: c.replace(u, p)
|
|
117
98
|
});
|
|
118
99
|
}
|
|
119
100
|
} else {
|
|
120
|
-
|
|
101
|
+
n.push({
|
|
121
102
|
specifier: u,
|
|
122
103
|
importClause: c
|
|
123
104
|
});
|
|
@@ -126,95 +107,167 @@ function collectImportsFromSourceFile(r, a, t, i, o) {
|
|
|
126
107
|
}
|
|
127
108
|
e.forEachChild(a, visit);
|
|
128
109
|
}(r);
|
|
129
|
-
return
|
|
110
|
+
return n;
|
|
130
111
|
}
|
|
131
112
|
|
|
132
|
-
var
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (c) {
|
|
131
|
+
c();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var p = n.expose((async function* _runTurbo(r) {
|
|
136
|
+
var a = i.getSchemaNamesFromConfig(r.pluginConfig);
|
|
137
|
+
var t = s.programFactory(r);
|
|
138
|
+
t.addSourceFile({
|
|
136
139
|
fileId: "__gql-tada-override__.d.ts",
|
|
137
|
-
sourceText:
|
|
140
|
+
sourceText: d,
|
|
138
141
|
scriptKind: e.ScriptKind.TS
|
|
139
142
|
});
|
|
140
|
-
var
|
|
141
|
-
if (
|
|
143
|
+
var n = t.createExternalFiles();
|
|
144
|
+
if (n.length) {
|
|
142
145
|
yield {
|
|
143
146
|
kind: "EXTERNAL_WARNING"
|
|
144
147
|
};
|
|
145
|
-
await
|
|
148
|
+
await t.addVirtualFiles(n);
|
|
146
149
|
}
|
|
147
|
-
var
|
|
148
|
-
var
|
|
149
|
-
var
|
|
150
|
+
var l = t.build();
|
|
151
|
+
var c = l.buildPluginInfo(r.pluginConfig);
|
|
152
|
+
var p = l.getSourceFiles().map((e => e.fileName));
|
|
150
153
|
yield {
|
|
151
154
|
kind: "FILE_COUNT",
|
|
152
|
-
fileCount:
|
|
155
|
+
fileCount: p.length
|
|
153
156
|
};
|
|
154
|
-
var d = c.program.getTypeChecker();
|
|
155
157
|
var m = new Map;
|
|
156
|
-
|
|
157
|
-
var
|
|
158
|
-
var
|
|
159
|
-
var
|
|
160
|
-
var
|
|
161
|
-
var _loop =
|
|
162
|
-
var
|
|
163
|
-
if (!e.isCallExpression(
|
|
158
|
+
var processSourceFile = (i, n, s, l) => {
|
|
159
|
+
var u = i.fileName;
|
|
160
|
+
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)) {
|
|
164
166
|
return 0;
|
|
165
167
|
}
|
|
166
|
-
var
|
|
167
|
-
|
|
168
|
-
if (!
|
|
169
|
-
|
|
170
|
-
message:
|
|
171
|
-
file:
|
|
172
|
-
line:
|
|
173
|
-
col:
|
|
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
|
|
174
176
|
});
|
|
175
177
|
return 0;
|
|
176
178
|
}
|
|
177
|
-
var
|
|
178
|
-
|
|
179
|
-
var
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
|
186
211
|
});
|
|
187
212
|
}
|
|
188
213
|
}
|
|
189
|
-
var T =
|
|
190
|
-
var F =
|
|
214
|
+
var T = l.getTypeAtLocation(s);
|
|
215
|
+
var F = l.getTypeAtLocation(o.node);
|
|
191
216
|
if (!T.symbol || "TadaDocumentNode" !== T.symbol.getEscapedName()) {
|
|
192
|
-
|
|
217
|
+
p.push({
|
|
193
218
|
message: 'The discovered document is not of type "TadaDocumentNode".\nIf this is unexpected, please file an issue describing your case.',
|
|
194
|
-
file:
|
|
195
|
-
line:
|
|
196
|
-
col:
|
|
219
|
+
file: d.fileName,
|
|
220
|
+
line: d.line,
|
|
221
|
+
col: d.col
|
|
197
222
|
});
|
|
198
223
|
return 0;
|
|
199
224
|
}
|
|
200
|
-
var S = "value" in F && "string" == typeof F.value && !(F.flags & e.TypeFlags.StringLiteral) ? JSON.stringify(F.value) :
|
|
201
|
-
var N =
|
|
202
|
-
|
|
203
|
-
schemaName:
|
|
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
|
+
c.push({
|
|
228
|
+
schemaName: o.schema,
|
|
204
229
|
argumentKey: S,
|
|
205
230
|
documentType: N
|
|
206
231
|
});
|
|
207
232
|
};
|
|
208
|
-
for (var
|
|
209
|
-
if (0 ===
|
|
233
|
+
for (var v of d) {
|
|
234
|
+
if (0 === _loop(v)) {
|
|
210
235
|
continue;
|
|
211
236
|
}
|
|
212
237
|
}
|
|
238
|
+
return {
|
|
239
|
+
filePath: u,
|
|
240
|
+
documents: c,
|
|
241
|
+
warnings: p
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
var isHeapOverSoftLimit = () => {
|
|
245
|
+
if (process.memoryUsage().heapUsed < u) {
|
|
246
|
+
return !1;
|
|
247
|
+
}
|
|
248
|
+
forceGc();
|
|
249
|
+
return process.memoryUsage().heapUsed >= u;
|
|
250
|
+
};
|
|
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);
|
|
256
|
+
forceGc();
|
|
257
|
+
v = l.program.getTypeChecker();
|
|
258
|
+
g = 0;
|
|
259
|
+
}
|
|
260
|
+
var y = l.getSourceFile(h);
|
|
261
|
+
if (!y) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
var {filePath: T, documents: F, warnings: S} = processSourceFile(y, l, c, v);
|
|
265
|
+
g++;
|
|
213
266
|
yield {
|
|
214
267
|
kind: "FILE_TURBO",
|
|
215
|
-
filePath:
|
|
216
|
-
documents:
|
|
217
|
-
warnings:
|
|
268
|
+
filePath: T,
|
|
269
|
+
documents: F,
|
|
270
|
+
warnings: S
|
|
218
271
|
};
|
|
219
272
|
}
|
|
220
273
|
if (m.size > 0) {
|
|
@@ -225,9 +278,9 @@ var s = i.expose((async function* _runTurbo(r) {
|
|
|
225
278
|
}
|
|
226
279
|
}));
|
|
227
280
|
|
|
228
|
-
var
|
|
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;
|
|
229
282
|
|
|
230
|
-
var
|
|
283
|
+
var d = "\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n interface setupCache {\n readonly __cacheDisabled: true;\n }\n}\n".trim();
|
|
231
284
|
|
|
232
|
-
exports.runTurbo =
|
|
285
|
+
exports.runTurbo = p;
|
|
233
286
|
//# sourceMappingURL=thread-chunk2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-chunk2.js","sources":["../../src/commands/turbo/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport * as path from 'node:path';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport { getSchemaNamesFromConfig } from '@gql.tada/internal';\nimport { findAllCallExpressions } from '@0no-co/graphqlsp/api';\n\nimport { programFactory } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type {\n TurboSignal,\n TurboWarning,\n TurboDocument,\n GraphQLSourceFile,\n GraphQLSourceImport,\n TurboPath,\n} from './types';\n\nexport interface TurboParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n turboOutputPath: string | TurboPath[];\n}\n\nfunction traceCallToImportSource(\n callExpression: ts.CallExpression,\n sourceFile: ts.SourceFile,\n program: ts.Program\n): string | undefined {\n const typeChecker = program.getTypeChecker();\n const expression = callExpression.expression;\n\n let identifier: ts.Identifier | undefined;\n if (ts.isIdentifier(expression)) {\n identifier = expression;\n } else if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression)) {\n identifier = expression.expression;\n }\n\n if (!identifier) return undefined;\n\n const symbol = typeChecker.getSymbolAtLocation(identifier);\n if (!symbol || !symbol.declarations) return undefined;\n\n for (const declaration of symbol.declarations) {\n const importDeclaration = findImportDeclaration(declaration);\n if (importDeclaration && ts.isStringLiteral(importDeclaration.moduleSpecifier)) {\n const moduleName = importDeclaration.moduleSpecifier.text;\n return resolveModulePath(moduleName, sourceFile, program);\n }\n }\n\n return undefined;\n}\n\nfunction findImportDeclaration(node: ts.Node): ts.ImportDeclaration | undefined {\n let current: ts.Node | undefined = node;\n\n while (current) {\n if (ts.isImportDeclaration(current)) {\n return current;\n }\n current = current.parent;\n }\n\n return undefined;\n}\n\nfunction resolveModulePath(\n moduleName: string,\n containingFile: ts.SourceFile,\n program: ts.Program\n): string | undefined {\n const compilerOptions = program.getCompilerOptions();\n const host = ts.createCompilerHost(compilerOptions);\n\n const resolved = ts.resolveModuleName(moduleName, containingFile.fileName, compilerOptions, host);\n\n if (resolved.resolvedModule) {\n return resolved.resolvedModule.resolvedFileName;\n }\n\n return undefined;\n}\n\nfunction collectImportsFromSourceFile(\n sourceFile: ts.SourceFile,\n pluginConfig: GraphQLSPConfig,\n resolveModuleName: (importSpecifier: string, fromPath: string, toPath: string) => string,\n turboOutputPath?: string,\n shouldTreatImportsAsNodeNext?: boolean\n): GraphQLSourceImport[] {\n const imports: GraphQLSourceImport[] = [];\n\n const tadaImportPaths = getTadaOutputPaths(pluginConfig);\n\n function visit(node: ts.Node) {\n if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {\n const specifier = node.moduleSpecifier.text;\n\n if (!isTadaImport(specifier, sourceFile.fileName, tadaImportPaths)) {\n const importClause = node.getFullText().trim();\n if (turboOutputPath) {\n // Adjust the import specifier to point to the turbo output path\n let adjustedSpecifier = resolveModuleName(\n specifier,\n sourceFile.fileName,\n turboOutputPath\n );\n\n if (shouldTreatImportsAsNodeNext) {\n if (adjustedSpecifier.endsWith('.ts') || adjustedSpecifier.endsWith('.tsx')) {\n adjustedSpecifier = adjustedSpecifier\n .replace(/\\.ts$/, '.js')\n .replace(/\\.tsx$/, '.js');\n }\n } else {\n adjustedSpecifier = adjustedSpecifier.replace(/\\.ts$/, '').replace(/\\.tsx$/, '');\n }\n\n if (adjustedSpecifier && !adjustedSpecifier.includes('gql.tada')) {\n imports.push({\n specifier: adjustedSpecifier,\n importClause: importClause.replace(specifier, adjustedSpecifier),\n });\n }\n } else {\n imports.push({ specifier, importClause });\n }\n }\n }\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return imports;\n}\n\nfunction getTadaOutputPaths(pluginConfig: GraphQLSPConfig): string[] {\n const paths: string[] = [];\n\n if ('schema' in pluginConfig && pluginConfig.tadaOutputLocation) {\n paths.push(pluginConfig.tadaOutputLocation);\n } else {\n // Multiple schemas aren't supported in this context\n }\n\n return paths;\n}\n\nfunction isTadaImport(\n importSpecifier: string,\n sourceFilePath: string,\n tadaOutputLocationPaths: string[]\n): boolean {\n if (importSpecifier.startsWith('.')) {\n const sourceDir = path.dirname(sourceFilePath);\n const absoluteImportPath = path.resolve(sourceDir, importSpecifier);\n\n return tadaOutputLocationPaths.some((tadaOutputLocationPath) => {\n const absoluteTadaPath = path.resolve(tadaOutputLocationPath);\n return (\n absoluteImportPath === absoluteTadaPath ||\n absoluteImportPath.startsWith(absoluteTadaPath + path.sep)\n );\n });\n }\n\n return tadaOutputLocationPaths.some(\n (tadaPath) => importSpecifier === tadaPath || importSpecifier.startsWith(tadaPath + '/')\n );\n}\n\nasync function* _runTurbo(params: TurboParams): AsyncIterableIterator<TurboSignal> {\n const schemaNames = getSchemaNamesFromConfig(params.pluginConfig);\n const factory = programFactory(params);\n\n // NOTE: We add our override declaration here before loading all files\n // This sets `__cacheDisabled` on the turbo cache, which disables the cache temporarily\n // If we don't disable the cache then we couldn't regenerate it from inferred types\n factory.addSourceFile({\n fileId: '__gql-tada-override__.d.ts',\n sourceText: DECLARATION_OVERRIDE,\n scriptKind: ts.ScriptKind.TS,\n });\n\n const externalFiles = factory.createExternalFiles();\n if (externalFiles.length) {\n yield { kind: 'EXTERNAL_WARNING' };\n await factory.addVirtualFiles(externalFiles);\n }\n\n const container = factory.build();\n const pluginInfo = container.buildPluginInfo(params.pluginConfig);\n const sourceFiles = container.getSourceFiles();\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: sourceFiles.length,\n };\n\n const checker = container.program.getTypeChecker();\n const uniqueGraphQLSources = new Map<string, GraphQLSourceFile>();\n\n for (const sourceFile of sourceFiles) {\n let filePath = sourceFile.fileName;\n const documents: TurboDocument[] = [];\n const warnings: TurboWarning[] = [];\n\n const calls = findAllCallExpressions(sourceFile, pluginInfo, false).nodes;\n for (const call of calls) {\n const callExpression = call.node.parent;\n if (!ts.isCallExpression(callExpression)) {\n continue;\n }\n\n const position = container.getSourcePosition(sourceFile, callExpression.getStart());\n filePath = position.fileName;\n if (!schemaNames.has(call.schema)) {\n warnings.push({\n message: call.schema\n ? `The '${call.schema}' schema is not in the configuration but was referenced by document.`\n : schemaNames.size > 1\n ? 'The document is not for a known schema. Have you re-generated the output file?'\n : 'Multiple schemas are configured, but the document is not for a specific schema.',\n file: position.fileName,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const graphqlSourcePath = traceCallToImportSource(\n callExpression,\n sourceFile,\n container.program\n );\n\n if (graphqlSourcePath && !uniqueGraphQLSources.has(graphqlSourcePath)) {\n const graphqlSourceFile = container.program.getSourceFile(graphqlSourcePath);\n if (graphqlSourceFile) {\n const turboPath = Array.isArray(params.turboOutputPath)\n ? params.turboOutputPath.find((cfg) => cfg.schemaName === call.schema)?.path\n : params.turboOutputPath;\n const imports = collectImportsFromSourceFile(\n graphqlSourceFile,\n params.pluginConfig,\n factory.resolveModuleName.bind(factory),\n turboPath,\n !!factory.wasOriginallyNodeNext\n );\n uniqueGraphQLSources.set(graphqlSourcePath, {\n absolutePath: graphqlSourcePath,\n imports,\n });\n }\n }\n\n const returnType = checker.getTypeAtLocation(callExpression);\n const argumentType = checker.getTypeAtLocation(call.node);\n // NOTE: `returnType.symbol` is incorrectly typed and is in fact\n // optional and not always present\n if (!returnType.symbol || returnType.symbol.getEscapedName() !== 'TadaDocumentNode') {\n warnings.push({\n message:\n `The discovered document is not of type \"TadaDocumentNode\".\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: position.fileName,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const argumentKey: string =\n 'value' in argumentType &&\n typeof argumentType.value === 'string' &&\n (argumentType.flags & ts.TypeFlags.StringLiteral) === 0\n ? JSON.stringify(argumentType.value)\n : checker.typeToString(argumentType, callExpression, BUILDER_FLAGS);\n const documentType = checker.typeToString(returnType, callExpression, BUILDER_FLAGS);\n\n documents.push({\n schemaName: call.schema,\n argumentKey,\n documentType,\n });\n }\n\n yield {\n kind: 'FILE_TURBO',\n filePath,\n documents,\n warnings,\n };\n }\n\n if (uniqueGraphQLSources.size > 0) {\n yield {\n kind: 'GRAPHQL_SOURCES',\n sources: Array.from(uniqueGraphQLSources.values()),\n };\n }\n}\n\nexport const runTurbo = expose(_runTurbo);\n\nconst BUILDER_FLAGS: ts.TypeFormatFlags =\n ts.TypeFormatFlags.NoTruncation |\n ts.TypeFormatFlags.NoTypeReduction |\n ts.TypeFormatFlags.InTypeAlias |\n ts.TypeFormatFlags.UseFullyQualifiedType |\n ts.TypeFormatFlags.GenerateNamesForShadowedTypeParams |\n ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope |\n ts.TypeFormatFlags.AllowUniqueESSymbolType |\n ts.TypeFormatFlags.WriteTypeArgumentsOfSignature;\n\nconst DECLARATION_OVERRIDE = `\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n interface setupCache {\n readonly __cacheDisabled: true;\n }\n}\n`.trim();\n"],"names":["traceCallToImportSource","callExpression","sourceFile","program","typeChecker","getTypeChecker","expression","identifier","ts","isIdentifier","isPropertyAccessExpression","symbol","getSymbolAtLocation","declarations","declaration","importDeclaration","findImportDeclaration","isStringLiteral","moduleSpecifier","resolveModulePath","text","node","current","isImportDeclaration","parent","moduleName","containingFile","compilerOptions","getCompilerOptions","host","createCompilerHost","resolved","resolveModuleName","fileName","resolvedModule","resolvedFileName","collectImportsFromSourceFile","pluginConfig","turboOutputPath","shouldTreatImportsAsNodeNext","imports","tadaImportPaths","getTadaOutputPaths","paths","tadaOutputLocation","push","visit","specifier","isTadaImport","importSpecifier","sourceFilePath","tadaOutputLocationPaths","startsWith","sourceDir","path","dirname","absoluteImportPath","resolve","some","tadaOutputLocationPath","absoluteTadaPath","sep","tadaPath","importClause","getFullText","trim","adjustedSpecifier","endsWith","replace","includes","forEachChild","runTurbo","expose","async","_runTurbo","params","schemaNames","getSchemaNamesFromConfig","factory","programFactory","addSourceFile","fileId","sourceText","DECLARATION_OVERRIDE","scriptKind","ScriptKind","TS","externalFiles","createExternalFiles","length","kind","addVirtualFiles","container","build","pluginInfo","buildPluginInfo","sourceFiles","getSourceFiles","fileCount","checker","uniqueGraphQLSources","Map","filePath","documents","warnings","calls","findAllCallExpressions","nodes","_loop","call","isCallExpression","position","getSourcePosition","getStart","has","schema","message","size","file","line","col","graphqlSourcePath","graphqlSourceFile","getSourceFile","turboPath","Array","isArray","find","cfg","schemaName","bind","wasOriginallyNodeNext","set","absolutePath","returnType","getTypeAtLocation","argumentType","getEscapedName","argumentKey","value","flags","TypeFlags","StringLiteral","JSON","stringify","typeToString","BUILDER_FLAGS","documentType","sources","from","values","TypeFormatFlags","NoTruncation","NoTypeReduction","InTypeAlias","UseFullyQualifiedType","GenerateNamesForShadowedTypeParams","UseAliasDefinedOutsideCurrentScope","AllowUniqueESSymbolType","WriteTypeArgumentsOfSignature"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAASA,wBACPC,GACAC,GACAC;EAEA,IAAMC,IAAcD,EAAQE;EAC5B,IAAMC,IAAaL,EAAeK;EAElC,IAAIC;EACJ,IAAIC,EAAGC,aAAaH;IAClBC,IAAaD;SACR,IAAIE,EAAGE,2BAA2BJ,MAAeE,EAAGC,aAAaH,EAAWA;IACjFC,IAAaD,EAAWA;;EAG1B,KAAKC;IAAY;;EAEjB,IAAMI,IAAS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EAAW3H,OAAO8H,kBAAyC;QACnFjC,EAAS3D,KAAK;UACZuE,SACE;UAEFE,MAAMP,EAAS9E;UACfsF,MAAMR,EAASQ;UACfC,KAAKT,EAASS;;QACb,OAAA;AAEL;MAEA,IAAMkB,IACJ,WAAWF,KACmB,mBAAvBA,EAAaG,WACnBH,EAAaI,QAAQpI,EAAGqI,UAAUC,iBAC/BC,KAAKC,UAAUR,EAAaG,SAC5BxC,EAAQ8C,aAAaT,GAAcvI,GAAgBiJ;MACzD,IAAMC,IAAehD,EAAQ8C,aAAaX,GAAYrI,GAAgBiJ;MAEtE3C,EAAU1D,KAAK;QACboF,YAAYpB,EAAKM;QACjBuB;QACAS;;AAEH;IA7ED,KAAK,IAAMtC,KAAQJ;MAAK,IAGpB,cAHoBG,MAAAC;QAGpB;;;UA4EE;MACJnB,MAAM;MACNY;MACAC;MACAC;;AAEJ;EAEA,IAAIJ,EAAqBiB,OAAO;UACxB;MACJ3B,MAAM;MACN0D,SAASvB,MAAMwB,KAAKjD,EAAqBkD;;;AAG/C;;AAIA,IAAMJ,IACJ1I,EAAG+I,gBAAgBC,eACnBhJ,EAAG+I,gBAAgBE,kBACnBjJ,EAAG+I,gBAAgBG,cACnBlJ,EAAG+I,gBAAgBI,wBACnBnJ,EAAG+I,gBAAgBK,qCACnBpJ,EAAG+I,gBAAgBM,qCACnBrJ,EAAG+I,gBAAgBO,0BACnBtJ,EAAG+I,gBAAgBQ;;AAErB,IAAM5E,IAAuB,gJAO3BlB;;"}
|
|
1
|
+
{"version":3,"file":"thread-chunk2.js","sources":["../../src/commands/turbo/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport v8 from 'node:v8';\nimport vm from 'node:vm';\nimport * as path from 'node:path';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport { getSchemaNamesFromConfig } from '@gql.tada/internal';\nimport { findAllCallExpressions } from '@0no-co/graphqlsp/api';\n\nimport type { ProgramContainer, PluginCreateInfo } from '../../ts';\nimport { programFactory } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type {\n TurboSignal,\n TurboWarning,\n TurboDocument,\n GraphQLSourceFile,\n GraphQLSourceImport,\n TurboPath,\n} from './types';\n\nexport interface TurboParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n turboOutputPath: string | TurboPath[];\n}\n\nconst HEAP_SOFT_LIMIT_BYTES = 2_500 * 1_024 * 1_024;\nconst TURBO_MAX_BATCH = 1_000;\n\nfunction traceCallToImportSource(\n callExpression: ts.CallExpression,\n sourceFile: ts.SourceFile,\n program: ts.Program\n): string | undefined {\n const typeChecker = program.getTypeChecker();\n const expression = callExpression.expression;\n\n let identifier: ts.Identifier | undefined;\n if (ts.isIdentifier(expression)) {\n identifier = expression;\n } else if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression)) {\n identifier = expression.expression;\n }\n\n if (!identifier) return undefined;\n\n const symbol = typeChecker.getSymbolAtLocation(identifier);\n if (!symbol || !symbol.declarations) return undefined;\n\n for (const declaration of symbol.declarations) {\n const importDeclaration = findImportDeclaration(declaration);\n if (importDeclaration && ts.isStringLiteral(importDeclaration.moduleSpecifier)) {\n const moduleName = importDeclaration.moduleSpecifier.text;\n return resolveModulePath(moduleName, sourceFile, program);\n }\n }\n\n return undefined;\n}\n\nfunction findImportDeclaration(node: ts.Node): ts.ImportDeclaration | undefined {\n let current: ts.Node | undefined = node;\n\n while (current) {\n if (ts.isImportDeclaration(current)) {\n return current;\n }\n current = current.parent;\n }\n\n return undefined;\n}\n\nfunction resolveModulePath(\n moduleName: string,\n containingFile: ts.SourceFile,\n program: ts.Program\n): string | undefined {\n const compilerOptions = program.getCompilerOptions();\n const host = ts.createCompilerHost(compilerOptions);\n\n const resolved = ts.resolveModuleName(moduleName, containingFile.fileName, compilerOptions, host);\n\n if (resolved.resolvedModule) {\n return resolved.resolvedModule.resolvedFileName;\n }\n\n return undefined;\n}\n\nfunction collectImportsFromSourceFile(\n sourceFile: ts.SourceFile,\n pluginConfig: GraphQLSPConfig,\n resolveModuleName: (importSpecifier: string, fromPath: string, toPath: string) => string,\n turboOutputPath?: string,\n shouldTreatImportsAsNodeNext?: boolean\n): GraphQLSourceImport[] {\n const imports: GraphQLSourceImport[] = [];\n\n const tadaImportPaths = getTadaOutputPaths(pluginConfig);\n\n function visit(node: ts.Node) {\n if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {\n const specifier = node.moduleSpecifier.text;\n\n if (!isTadaImport(specifier, sourceFile.fileName, tadaImportPaths)) {\n const importClause = node.getFullText().trim();\n if (turboOutputPath) {\n // Adjust the import specifier to point to the turbo output path\n let adjustedSpecifier = resolveModuleName(\n specifier,\n sourceFile.fileName,\n turboOutputPath\n );\n\n if (shouldTreatImportsAsNodeNext) {\n if (adjustedSpecifier.endsWith('.ts') || adjustedSpecifier.endsWith('.tsx')) {\n adjustedSpecifier = adjustedSpecifier\n .replace(/\\.ts$/, '.js')\n .replace(/\\.tsx$/, '.js');\n }\n } else {\n adjustedSpecifier = adjustedSpecifier.replace(/\\.ts$/, '').replace(/\\.tsx$/, '');\n }\n\n if (adjustedSpecifier && !adjustedSpecifier.includes('gql.tada')) {\n imports.push({\n specifier: adjustedSpecifier,\n importClause: importClause.replace(specifier, adjustedSpecifier),\n });\n }\n } else {\n imports.push({ specifier, importClause });\n }\n }\n }\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return imports;\n}\n\nfunction getTadaOutputPaths(pluginConfig: GraphQLSPConfig): string[] {\n const paths: string[] = [];\n\n if ('schema' in pluginConfig && pluginConfig.tadaOutputLocation) {\n paths.push(pluginConfig.tadaOutputLocation);\n } else {\n // Multiple schemas aren't supported in this context\n }\n\n return paths;\n}\n\nfunction isTadaImport(\n importSpecifier: string,\n sourceFilePath: string,\n tadaOutputLocationPaths: string[]\n): boolean {\n if (importSpecifier.startsWith('.')) {\n const sourceDir = path.dirname(sourceFilePath);\n const absoluteImportPath = path.resolve(sourceDir, importSpecifier);\n\n return tadaOutputLocationPaths.some((tadaOutputLocationPath) => {\n const absoluteTadaPath = path.resolve(tadaOutputLocationPath);\n return (\n absoluteImportPath === absoluteTadaPath ||\n absoluteImportPath.startsWith(absoluteTadaPath + path.sep)\n );\n });\n }\n\n return tadaOutputLocationPaths.some(\n (tadaPath) => importSpecifier === tadaPath || importSpecifier.startsWith(tadaPath + '/')\n );\n}\n\nasync function* _runTurbo(params: TurboParams): AsyncIterableIterator<TurboSignal> {\n const schemaNames = getSchemaNamesFromConfig(params.pluginConfig);\n const factory = programFactory(params);\n\n // NOTE: We add our override declaration here before loading all files\n // This sets `__cacheDisabled` on the turbo cache, which disables the cache temporarily\n // If we don't disable the cache then we couldn't regenerate it from inferred types\n factory.addSourceFile({\n fileId: '__gql-tada-override__.d.ts',\n sourceText: DECLARATION_OVERRIDE,\n scriptKind: ts.ScriptKind.TS,\n });\n\n const externalFiles = factory.createExternalFiles();\n if (externalFiles.length) {\n yield { kind: 'EXTERNAL_WARNING' };\n await factory.addVirtualFiles(externalFiles);\n }\n\n // Initially, we only build the program to count files\n // Later, we may reinstantiate to free up memory between batches\n let container = factory.build();\n let pluginInfo = container.buildPluginInfo(params.pluginConfig);\n const fileNames = container.getSourceFiles().map((sourceFile) => sourceFile.fileName);\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: fileNames.length,\n };\n\n const uniqueGraphQLSources = new Map<string, GraphQLSourceFile>();\n\n const processSourceFile = (\n sourceFile: ts.SourceFile,\n container: ProgramContainer,\n pluginInfo: PluginCreateInfo,\n checker: ts.TypeChecker\n ): { filePath: string; documents: TurboDocument[]; warnings: TurboWarning[] } => {\n let filePath = sourceFile.fileName;\n const documents: TurboDocument[] = [];\n const warnings: TurboWarning[] = [];\n\n const calls = findAllCallExpressions(sourceFile, pluginInfo, false).nodes;\n for (const call of calls) {\n const callExpression = call.node.parent;\n if (!ts.isCallExpression(callExpression)) {\n continue;\n }\n\n const position = container.getSourcePosition(sourceFile, callExpression.getStart());\n filePath = position.fileName;\n if (!schemaNames.has(call.schema)) {\n warnings.push({\n message: call.schema\n ? `The '${call.schema}' schema is not in the configuration but was referenced by document.`\n : schemaNames.size > 1\n ? 'The document is not for a known schema. Have you re-generated the output file?'\n : 'Multiple schemas are configured, but the document is not for a specific schema.',\n file: position.fileName,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const graphqlSourcePath = traceCallToImportSource(\n callExpression,\n sourceFile,\n container.program\n );\n\n if (graphqlSourcePath && !uniqueGraphQLSources.has(graphqlSourcePath)) {\n const graphqlSourceFile = container.program.getSourceFile(graphqlSourcePath);\n if (graphqlSourceFile) {\n const turboPath = Array.isArray(params.turboOutputPath)\n ? params.turboOutputPath.find((cfg) => cfg.schemaName === call.schema)?.path\n : params.turboOutputPath;\n const imports = collectImportsFromSourceFile(\n graphqlSourceFile,\n params.pluginConfig,\n factory.resolveModuleName.bind(factory),\n turboPath,\n !!factory.wasOriginallyNodeNext\n );\n uniqueGraphQLSources.set(graphqlSourcePath, {\n absolutePath: graphqlSourcePath,\n imports,\n });\n }\n }\n\n const returnType = checker.getTypeAtLocation(callExpression);\n const argumentType = checker.getTypeAtLocation(call.node);\n // NOTE: `returnType.symbol` is incorrectly typed and is in fact\n // optional and not always present\n if (!returnType.symbol || returnType.symbol.getEscapedName() !== 'TadaDocumentNode') {\n warnings.push({\n message:\n `The discovered document is not of type \"TadaDocumentNode\".\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: position.fileName,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const argumentKey: string =\n 'value' in argumentType &&\n typeof argumentType.value === 'string' &&\n (argumentType.flags & ts.TypeFlags.StringLiteral) === 0\n ? JSON.stringify(argumentType.value)\n : checker.typeToString(argumentType, callExpression, BUILDER_FLAGS);\n const documentType = checker.typeToString(returnType, callExpression, BUILDER_FLAGS);\n\n documents.push({\n schemaName: call.schema,\n argumentKey,\n documentType,\n });\n }\n\n return { filePath, documents, warnings };\n };\n\n const isHeapOverSoftLimit = (): boolean => {\n if (process.memoryUsage().heapUsed < HEAP_SOFT_LIMIT_BYTES) return false;\n forceGc();\n return process.memoryUsage().heapUsed >= HEAP_SOFT_LIMIT_BYTES;\n };\n\n let checker = container.program.getTypeChecker();\n let filesInBatch = 0;\n\n for (const fileName of fileNames) {\n // When heap or batch limit is reached, rotate out the type checker\n if (filesInBatch > 0 && (filesInBatch >= TURBO_MAX_BATCH || isHeapOverSoftLimit())) {\n container = factory.build();\n pluginInfo = container.buildPluginInfo(params.pluginConfig);\n forceGc();\n checker = container.program.getTypeChecker();\n filesInBatch = 0;\n }\n\n const sourceFile = container.getSourceFile(fileName);\n if (!sourceFile) continue;\n\n const { filePath, documents, warnings } = processSourceFile(\n sourceFile,\n container,\n pluginInfo,\n checker\n );\n filesInBatch++;\n\n yield {\n kind: 'FILE_TURBO',\n filePath,\n documents,\n warnings,\n };\n }\n\n if (uniqueGraphQLSources.size > 0) {\n yield {\n kind: 'GRAPHQL_SOURCES',\n sources: Array.from(uniqueGraphQLSources.values()),\n };\n }\n}\n\nlet cachedGc: (() => void) | null | undefined;\n\nfunction forceGc(): void {\n if (cachedGc === undefined) {\n const existing = (globalThis as { gc?: () => void }).gc;\n if (typeof existing === 'function') {\n cachedGc = existing;\n } else {\n // NOTE: If gc isn't available, try to retrieve it via `node:vm`\n try {\n v8.setFlagsFromString('--expose-gc');\n cachedGc = vm.runInNewContext('gc') as () => void;\n v8.setFlagsFromString('--no-expose-gc');\n } catch {\n cachedGc = null;\n }\n }\n }\n if (cachedGc) cachedGc();\n}\n\nexport const runTurbo = expose(_runTurbo);\n\nconst BUILDER_FLAGS: ts.TypeFormatFlags =\n ts.TypeFormatFlags.NoTruncation |\n ts.TypeFormatFlags.NoTypeReduction |\n ts.TypeFormatFlags.InTypeAlias |\n ts.TypeFormatFlags.UseFullyQualifiedType |\n ts.TypeFormatFlags.GenerateNamesForShadowedTypeParams |\n ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope |\n ts.TypeFormatFlags.AllowUniqueESSymbolType |\n ts.TypeFormatFlags.WriteTypeArgumentsOfSignature;\n\nconst DECLARATION_OVERRIDE = `\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n interface setupCache {\n readonly __cacheDisabled: true;\n }\n}\n`.trim();\n"],"names":["HEAP_SOFT_LIMIT_BYTES","findImportDeclaration","node","current","ts","isImportDeclaration","parent","resolveModulePath","moduleName","containingFile","program","compilerOptions","getCompilerOptions","host","createCompilerHost","resolved","resolveModuleName","fileName","resolvedModule","resolvedFileName","collectImportsFromSourceFile","sourceFile","pluginConfig","turboOutputPath","shouldTreatImportsAsNodeNext","imports","tadaImportPaths","getTadaOutputPaths","paths","tadaOutputLocation","push","visit","isStringLiteral","moduleSpecifier","specifier","text","isTadaImport","importSpecifier","sourceFilePath","tadaOutputLocationPaths","startsWith","sourceDir","path","dirname","absoluteImportPath","resolve","some","tadaOutputLocationPath","absoluteTadaPath","sep","tadaPath","importClause","getFullText","trim","adjustedSpecifier","endsWith","replace","includes","forEachChild","cachedGc","forceGc","undefined","existing","globalThis","gc","v8","setFlagsFromString","vm","runInNewContext","runTurbo","expose","async","_runTurbo","params","schemaNames","getSchemaNamesFromConfig","factory","programFactory","addSourceFile","fileId","sourceText","DECLARATION_OVERRIDE","scriptKind","ScriptKind","TS","externalFiles","createExternalFiles","length","kind","addVirtualFiles","container","build","pluginInfo","buildPluginInfo","fileNames","getSourceFiles","map","fileCount","uniqueGraphQLSources","Map","processSourceFile","checker","filePath","documents","warnings","calls","findAllCallExpressions","nodes","_loop","call","callExpression","isCallExpression","position","getSourcePosition","getStart","has","schema","message","size","file","line","col","graphqlSourcePath","traceCallToImportSource","typeChecker","getTypeChecker","expression","identifier","isIdentifier","isPropertyAccessExpression","symbol","getSymbolAtLocation","declarations","declaration","importDeclaration","graphqlSourceFile","getSourceFile","turboPath","Array","isArray","find","cfg","schemaName","bind","wasOriginallyNodeNext","set","absolutePath","returnType","getTypeAtLocation","argumentType","getEscapedName","argumentKey","value","flags","TypeFlags","StringLiteral","JSON","stringify","typeToString","BUILDER_FLAGS","documentType","isHeapOverSoftLimit","process","memoryUsage","heapUsed","filesInBatch","sources","from","values","TypeFormatFlags","NoTruncation","NoTypeReduction","InTypeAlias","UseFullyQualifiedType","GenerateNamesForShadowedTypeParams","UseAliasDefinedOutsideCurrentScope","AllowUniqueESSymbolType","WriteTypeArgumentsOfSignature"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAMA,IAAwB;;AAkC9B,SAASC,sBAAsBC;EAC7B,IAAIC,IAA+BD;EAEnC,OAAOC,GAAS;IACd,IAAIC,EAAGC,oBAAoBF;MACzB,OAAOA;;IAETA,IAAUA,EAAQG;AACpB;EAEA;AACF;;AAEA,SAASC,kBACPC,GACAC,GACAC;EAEA,IAAMC,IAAkBD,EAAQE;EAChC,IAAMC,IAAOT,EAAGU,mBAAmBH;EAEnC,IAAMI,IAAWX,EAAGY,kBAAkBR,GAAYC,EAAeQ,UAAUN,GAAiBE;EAE5F,IAAIE,EAASG;IACX,OAAOH,EAASG,eAAeC;;EAGjC;AACF;;AAEA,SAASC,6BACPC,GACAC,GACAN,GACAO,GACAC;EAEA,IAAMC,IAAiC;EAEvC,IAAMC,IA4CR,SAASC,mBAAmBL;IAC1B,IAAMM,IAAkB;IAExB,IAAI,YAAYN,KAAgBA,EAAaO;MAC3CD,EAAME,KAAKR,EAAaO;;IAK1B,OAAOD;AACT,GAtD0BD,CAAmBL;GAE3C,SAASS,MAAM7B;IACb,IAAIE,EAAGC,oBAAoBH,MAASE,EAAG4B,gBAAgB9B,EAAK+B,kBAAkB;MAC5E,IAAMC,IAAYhC,EAAK+B,gBAAgBE;MAEvC,KAkDN,SAASC,aACPC,GACAC,GACAC;QAEA,IAAIF,EAAgBG,WAAW,MAAM;UACnC,IAAMC,IAAYC,EAAKC,QAAQL;UAC/B,IAAMM,IAAqBF,EAAKG,QAAQJ,GAAWJ;UAEnD,OAAOE,EAAwBO,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