@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.
- package/CHANGELOG.md +35 -0
- package/dist/chunks/index-chunk.js +735 -561
- package/dist/chunks/index-chunk.js.map +1 -1
- package/dist/chunks/index-chunk.mjs +951 -777
- package/dist/chunks/index-chunk.mjs.map +1 -1
- package/dist/chunks/runner-chunk.js +912 -880
- package/dist/chunks/runner-chunk.js.map +1 -1
- package/dist/chunks/runner-chunk.mjs +45 -13
- package/dist/chunks/runner-chunk.mjs.map +1 -1
- package/dist/chunks/thread-chunk.js +472 -476
- package/dist/chunks/thread-chunk.js.map +1 -1
- package/dist/chunks/thread-chunk.mjs +494 -498
- package/dist/chunks/thread-chunk.mjs.map +1 -1
- package/dist/chunks/thread-chunk2.js +528 -171
- package/dist/chunks/thread-chunk2.js.map +1 -1
- package/dist/chunks/thread-chunk2.mjs +529 -180
- package/dist/chunks/thread-chunk2.mjs.map +1 -1
- package/dist/chunks/thread-chunk3.js +45 -33
- package/dist/chunks/thread-chunk3.js.map +1 -1
- package/dist/chunks/thread-chunk3.mjs +51 -39
- package/dist/chunks/thread-chunk3.mjs.map +1 -1
- package/dist/gql-tada-cli.d.ts +6 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-chunk2.mjs","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,MAAMC;YACnC,IAAMC,IAAmBN,EAAKG,QAAQE;YACtC,OACEH,MAAuBI,KACvBJ,EAAmBJ,WAAWQ,IAAmBN,EAAKO;AAAI;AAGhE;QA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;MAAEP;MAAUC;MAAWC;;AAAU;EAG1C,IAAMyD,sBAAsBA;IAC1B,IAAIC,QAAQC,cAAcC,WAAWpK;MAAuB,QAAO;;IACnE4D;IACA,OAAOsG,QAAQC,cAAcC,YAAYpK;AAAqB;EAGhE,IAAIqG,IAAUX,EAAUhF,QAAQmH;EAChC,IAAIwC,IAAe;EAEnB,KAAK,IAAMpJ,KAAY6E,GAAW;IAEhC,IAAIuE,IAAe,MAAMA,KA/RL,OA+RwCJ,wBAAwB;MAElFrE,KADAF,IAAYd,EAAQe,SACGE,gBAAgBpB,EAAOnD;MAC9CsC;MACAyC,IAAUX,EAAUhF,QAAQmH;MAC5BwC,IAAe;AACjB;IAEA,IAAMhJ,IAAaqE,EAAU8C,cAAcvH;IAC3C,KAAKI;MAAY;;IAEjB,KAAMiF,UAAEA,GAAQC,WAAEA,GAASC,UAAEA,KAAaJ,kBACxC/E,GACAqE,GACAE,GACAS;IAEFgE;UAEM;MACJ7E,MAAM;MACNc;MACAC;MACAC;;AAEJ;EAEA,IAAIN,EAAqBoB,OAAO;UACxB;MACJ9B,MAAM;MACN8E,SAAS5B,MAAM6B,KAAKrE,EAAqBsE;;;AAG/C;;AAyBA,IAAMT,IACJ3J,EAAGqK,gBAAgBC,eACnBtK,EAAGqK,gBAAgBE,kBACnBvK,EAAGqK,gBAAgBG,cACnBxK,EAAGqK,gBAAgBI,wBACnBzK,EAAGqK,gBAAgBK,qCACnB1K,EAAGqK,gBAAgBM,qCACnB3K,EAAGqK,gBAAgBO,0BACnB5K,EAAGqK,gBAAgBQ;;AAErB,IAAMhG,IAAuB,gJAO3B5B;;"}
|
|
1
|
+
{"version":3,"file":"thread-chunk2.mjs","sources":["../../src/commands/turbo/cache.ts","../../src/commands/turbo/hash.ts","../../src/commands/turbo/scan.ts","../../src/commands/turbo/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport * as fs from 'node:fs';\n\nconst HASH_COMMENT = /@gql\\.tada\\/hash\\s+([^\\s*]+)/;\n\nexport interface CachedTurboDocument {\n documentHash: string;\n documentType: string;\n}\n\nexport type CachedTurboDocuments = Map<string, CachedTurboDocument>;\n\nexport function readCachedTurboDocuments(cachePath: string | undefined): CachedTurboDocuments {\n const documents: CachedTurboDocuments = new Map();\n if (!cachePath || !fs.existsSync(cachePath)) {\n return documents;\n }\n\n let contents: string;\n try {\n contents = fs.readFileSync(cachePath, 'utf8');\n } catch {\n return documents;\n }\n\n const sourceFile = ts.createSourceFile(\n cachePath,\n contents,\n ts.ScriptTarget.Latest,\n /*setParentNodes*/ true,\n ts.ScriptKind.TS\n );\n\n const visit = (node: ts.Node) => {\n if (ts.isInterfaceDeclaration(node) && node.name.text === 'setupCache') {\n for (const member of node.members) {\n if (!ts.isPropertySignature(member) || !member.type) continue;\n if (!ts.isStringLiteral(member.name) && !ts.isNumericLiteral(member.name)) continue;\n\n const documentHash = getHashComment(contents, member);\n if (!documentHash) continue;\n\n documents.set(JSON.stringify(member.name.text), {\n documentHash,\n documentType: member.type.getText(sourceFile),\n });\n }\n }\n\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n return documents;\n}\n\nfunction getHashComment(contents: string, node: ts.Node): string | undefined {\n const comments = ts.getLeadingCommentRanges(contents, node.pos) || [];\n for (let i = comments.length - 1; i >= 0; i--) {\n const comment = contents.slice(comments[i].pos, comments[i].end);\n const match = HASH_COMMENT.exec(comment);\n if (match) return match[1];\n }\n return undefined;\n}\n","import ts from 'typescript';\nimport * as crypto from 'node:crypto';\n\n// NOTE(@kitten): Change if document type input or output changes\nconst CACHE_BUSTER = 'turbo-document-hash-v1';\n\nexport interface DocumentHashResult {\n hashable: boolean;\n documentHash?: string;\n}\n\nexport interface DocumentHasher {\n hashCallExpression(\n callExpression: ts.CallExpression,\n schemaName: string | null\n ): DocumentHashResult;\n}\n\ninterface HashContext {\n readonly checker: ts.TypeChecker;\n schemaFingerprints: ReadonlyMap<string | null, string>;\n}\n\nexport function createDocumentHasher(context: HashContext): DocumentHasher {\n const callExpressionCache = new WeakMap<ts.CallExpression, Map<string, DocumentHashResult>>();\n const symbolCallCache = new Map<ts.Symbol, ts.CallExpression | null>();\n const activeCalls = new WeakSet<ts.CallExpression>();\n\n const hashCallExpression = (\n callExpression: ts.CallExpression,\n schemaName: string | null\n ): DocumentHashResult => {\n const schemaKey = schemaName || '';\n const cached = callExpressionCache.get(callExpression)?.get(schemaKey);\n if (cached) {\n return cached;\n } else if (activeCalls.has(callExpression)) {\n return { hashable: false };\n }\n\n activeCalls.add(callExpression);\n const result = computeCallExpressionHash(callExpression, schemaName);\n activeCalls.delete(callExpression);\n\n let schemaCache = callExpressionCache.get(callExpression);\n if (!schemaCache) {\n schemaCache = new Map();\n callExpressionCache.set(callExpression, schemaCache);\n }\n\n schemaCache.set(schemaKey, result);\n return result;\n };\n\n const computeCallExpressionHash = (\n callExpression: ts.CallExpression,\n schemaName: string | null\n ): DocumentHashResult => {\n const documentText = getStaticStringValue(callExpression.arguments[0]);\n if (documentText == null) {\n return { hashable: false };\n }\n\n const fragmentHashes = getFragmentHashes(callExpression.arguments[1], schemaName);\n if (!fragmentHashes) {\n return { hashable: false };\n }\n\n const hash = crypto.createHash('sha256');\n\n addHashPart(hash, CACHE_BUSTER);\n addHashPart(hash, schemaName || '');\n addHashPart(hash, context.schemaFingerprints.get(schemaName) || '');\n addHashPart(hash, documentText);\n for (const fragmentHash of fragmentHashes) {\n addHashPart(hash, fragmentHash);\n }\n\n return {\n hashable: true,\n documentHash: `sha256:${hash.digest('hex').slice(0, 32)}`,\n };\n };\n\n const getFragmentHashes = (\n fragmentsExpression: ts.Expression | undefined,\n schemaName: string | null\n ): string[] | null => {\n if (!fragmentsExpression) return [];\n\n fragmentsExpression = unwrapExpression(fragmentsExpression);\n\n if (ts.isArrayLiteralExpression(fragmentsExpression)) {\n const hashes: string[] = [];\n for (const element of fragmentsExpression.elements) {\n if (ts.isSpreadElement(element)) {\n const spreadHashes = getFragmentHashes(element.expression, schemaName);\n if (!spreadHashes) return null;\n hashes.push(...spreadHashes);\n continue;\n }\n\n const documentCall = resolveDocumentCallExpression(element);\n if (!documentCall) return null;\n\n const fragmentHash = hashCallExpression(documentCall, schemaName);\n if (!fragmentHash.hashable || !fragmentHash.documentHash) return null;\n hashes.push(fragmentHash.documentHash);\n }\n return hashes;\n }\n\n const declarationExpression = resolveDeclarationInitializer(fragmentsExpression);\n if (declarationExpression && declarationExpression !== fragmentsExpression) {\n return getFragmentHashes(declarationExpression, schemaName);\n }\n\n return null;\n };\n\n const resolveDocumentCallExpression = (expression: ts.Expression): ts.CallExpression | null => {\n expression = unwrapExpression(expression);\n if (ts.isCallExpression(expression)) return expression;\n\n const symbol = getSymbol(expression);\n if (!symbol) return null;\n\n const cached = symbolCallCache.get(symbol);\n if (cached !== undefined) return cached;\n\n const callExpression = resolveSymbolCallExpression(symbol);\n symbolCallCache.set(symbol, callExpression);\n return callExpression;\n };\n\n const resolveDeclarationInitializer = (expression: ts.Expression): ts.Expression | null => {\n const symbol = getSymbol(expression);\n if (!symbol) return null;\n\n for (const declaration of symbol.declarations || []) {\n if (ts.isVariableDeclaration(declaration) && declaration.initializer) {\n return declaration.initializer;\n }\n }\n\n return null;\n };\n\n const resolveSymbolCallExpression = (symbol: ts.Symbol): ts.CallExpression | null => {\n for (const declaration of symbol.declarations || []) {\n if (ts.isVariableDeclaration(declaration) && declaration.initializer) {\n const initializer = unwrapExpression(declaration.initializer);\n if (ts.isCallExpression(initializer)) return initializer;\n }\n }\n return null;\n };\n\n const getSymbol = (expression: ts.Expression): ts.Symbol | undefined => {\n let symbol = context.checker.getSymbolAtLocation(expression);\n if (symbol && symbol.flags & ts.SymbolFlags.Alias) {\n symbol = context.checker.getAliasedSymbol(symbol);\n }\n return symbol;\n };\n\n return { hashCallExpression };\n}\n\nfunction getStaticStringValue(expression: ts.Expression | undefined): string | undefined {\n if (!expression) return undefined;\n expression = unwrapExpression(expression);\n\n if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) {\n return expression.text;\n }\n\n return undefined;\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n while (\n ts.isParenthesizedExpression(expression) ||\n ts.isAsExpression(expression) ||\n ts.isTypeAssertionExpression(expression) ||\n ts.isSatisfiesExpression(expression) ||\n ts.isNonNullExpression(expression)\n ) {\n expression = expression.expression;\n }\n return expression;\n}\n\nfunction addHashPart(hash: crypto.Hash, part: string): void {\n hash.update(`${part.length}:`);\n hash.update(part);\n hash.update('\\0');\n}\n","import * as path from 'node:path';\nimport ts from 'typescript';\n\nexport function shouldScanTurboFile(fileName: string, turboOutputPaths: Set<string>): boolean {\n if (turboOutputPaths.has(path.resolve(fileName))) return false;\n if (fileName.endsWith('.d.ts') || fileName.endsWith('.d.mts') || fileName.endsWith('.d.cts')) {\n return false;\n }\n return !/(^|[/\\\\])node_modules([/\\\\]|$)/.test(fileName);\n}\n\nconst GRAPHQL_DOCUMENT_START = /(?:^|[^\\w])(query|mutation|subscription|fragment)\\b/;\n\nexport function hasGraphQLDocumentCandidate(sourceFile: ts.SourceFile): boolean {\n if (!sourceFile.text.includes('{')) return false;\n\n let hasCandidate = false;\n\n const visit = (node: ts.Node): void => {\n if (hasCandidate) return;\n\n if (ts.isCallExpression(node)) {\n const argument = node.arguments[0];\n if (argument && ts.isStringLiteralLike(argument)) {\n const text = argument.text;\n if (text.includes('{') && isGraphQLDocumentCandidateText(text)) {\n hasCandidate = true;\n return;\n }\n }\n }\n\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n return hasCandidate;\n}\n\nfunction isGraphQLDocumentCandidateText(text: string): boolean {\n if (GRAPHQL_DOCUMENT_START.test(text)) return true;\n\n for (const line of text.split('\\n')) {\n const trimmed = line.trimStart();\n if (!trimmed || trimmed.startsWith('#')) continue;\n return trimmed.startsWith('{');\n }\n\n return false;\n}\n","import ts from 'typescript';\nimport v8 from 'node:v8';\nimport vm from 'node:vm';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as crypto from 'node:crypto';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport { getSchemaNamesFromConfig, getSchemaConfigForName } 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';\nimport { readCachedTurboDocuments, type CachedTurboDocuments } from './cache';\nimport { createDocumentHasher } from './hash';\nimport { hasGraphQLDocumentCandidate, shouldScanTurboFile } from './scan';\n\nexport interface TurboParams {\n rootPath: string;\n tsconfigPath?: 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\ninterface ImportTraceCache {\n /** Resolved import source per `fileName\\0identifier` key */\n traces: Map<string, string | undefined>;\n host: ts.CompilerHost | undefined;\n resolutionCache: ts.ModuleResolutionCache | undefined;\n}\n\nconst createImportTraceCache = (): ImportTraceCache => ({\n traces: new Map(),\n host: undefined,\n resolutionCache: undefined,\n});\n\nfunction traceCallToImportSource(\n callExpression: ts.CallExpression,\n sourceFile: ts.SourceFile,\n program: ts.Program,\n cache: ImportTraceCache\n): string | undefined {\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 // NOTE: All calls of the same identifier in a file resolve to the same import\n // source, so the resolution is cached per file and identifier name\n const traceKey = `${sourceFile.fileName}\\0${identifier.text}`;\n if (cache.traces.has(traceKey)) return cache.traces.get(traceKey);\n\n let result: string | undefined;\n const typeChecker = program.getTypeChecker();\n const symbol = typeChecker.getSymbolAtLocation(identifier);\n if (symbol && symbol.declarations) {\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 result = resolveModulePath(moduleName, sourceFile, program, cache);\n break;\n }\n }\n }\n\n cache.traces.set(traceKey, result);\n return result;\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 cache: ImportTraceCache\n): string | undefined {\n const compilerOptions = program.getCompilerOptions();\n const host = cache.host || (cache.host = ts.createCompilerHost(compilerOptions));\n const resolutionCache =\n cache.resolutionCache ||\n (cache.resolutionCache = ts.createModuleResolutionCache(\n host.getCurrentDirectory(),\n host.getCanonicalFileName.bind(host),\n compilerOptions\n ));\n\n const resolved = ts.resolveModuleName(\n moduleName,\n containingFile.fileName,\n compilerOptions,\n host,\n resolutionCache\n );\n\n if (resolved.resolvedModule) {\n return resolved.resolvedModule.resolvedFileName;\n }\n\n return undefined;\n}\n\nexport function collectImportsFromSourceFile(\n sourceFile: ts.SourceFile,\n pluginConfig: GraphQLSPConfig,\n resolveModuleName: (importSpecifier: string, fromPath: string, toPath: string) => string,\n resolveModulePath: (importSpecifier: string, fromPath: string) => string | undefined,\n rootPath: string,\n turboOutputPath?: string,\n shouldTreatImportsAsNodeNext?: boolean\n): GraphQLSourceImport[] {\n const imports: GraphQLSourceImport[] = [];\n\n const tadaImportPaths = getTadaOutputPaths(pluginConfig, rootPath);\n\n // NOTE: Import declarations may only appear as top-level statements\n for (const node of sourceFile.statements) {\n if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {\n const specifier = node.moduleSpecifier.text;\n\n if (!isTadaImport(specifier, sourceFile.fileName, tadaImportPaths, resolveModulePath)) {\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 }\n\n return imports;\n}\n\nfunction getTadaOutputPaths(pluginConfig: GraphQLSPConfig, rootPath: string): string[] {\n const paths: string[] = [];\n\n if ('schema' in pluginConfig && pluginConfig.tadaOutputLocation) {\n paths.push(path.resolve(rootPath, pluginConfig.tadaOutputLocation));\n } else if ('schemas' in pluginConfig) {\n for (const schemaConfig of pluginConfig.schemas) {\n if (schemaConfig.tadaOutputLocation) {\n paths.push(path.resolve(rootPath, schemaConfig.tadaOutputLocation));\n }\n }\n }\n\n return paths;\n}\n\nfunction isTadaImport(\n importSpecifier: string,\n sourceFilePath: string,\n tadaOutputLocationPaths: string[],\n resolveModulePath: (importSpecifier: string, fromPath: string) => string | undefined\n): boolean {\n const resolvedImportPath = resolveModulePath(importSpecifier, sourceFilePath);\n if (resolvedImportPath) {\n return tadaOutputLocationPaths.some(\n (tadaOutputLocationPath) => resolvedImportPath === tadaOutputLocationPath\n );\n }\n\n if (importSpecifier.startsWith('.')) {\n const sourceDir = path.dirname(sourceFilePath);\n const absoluteImportPath = path.resolve(sourceDir, importSpecifier);\n\n return tadaOutputLocationPaths.some((tadaOutputLocationPath) => {\n return absoluteImportPath === tadaOutputLocationPath;\n });\n }\n\n return tadaOutputLocationPaths.some(\n (tadaPath) => importSpecifier === tadaPath || importSpecifier.startsWith(tadaPath + '/')\n );\n}\n\nexport async function* _runTurbo(params: TurboParams): AsyncIterableIterator<TurboSignal> {\n const schemaNames = getSchemaNamesFromConfig(params.pluginConfig);\n const factory = programFactory(params);\n const cachedDocumentsByPath = new Map<string, CachedTurboDocuments>();\n\n const getCachedDocuments = (schemaName: string | null): CachedTurboDocuments => {\n const turboOutputPath = getTurboOutputPath(params.turboOutputPath, schemaName);\n if (!turboOutputPath) return new Map();\n\n let cachedDocuments = cachedDocumentsByPath.get(turboOutputPath);\n if (!cachedDocuments) {\n cachedDocuments = readCachedTurboDocuments(turboOutputPath);\n cachedDocumentsByPath.set(turboOutputPath, cachedDocuments);\n }\n return cachedDocuments;\n };\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 turboOutputPaths = new Set(\n getTurboOutputPaths(params.turboOutputPath).map((fileName) => path.resolve(fileName))\n );\n const fileNames = factory.rootFileNames.filter((fileName) =>\n shouldScanTurboFile(fileName, turboOutputPaths)\n );\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: fileNames.length,\n };\n\n const uniqueGraphQLSources = new Map<string, GraphQLSourceFile>();\n const importTraceCache = createImportTraceCache();\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 if (!hasGraphQLDocumentCandidate(sourceFile)) {\n return { filePath, documents, warnings };\n }\n\n // NOTE: Turbo only consumes the discovered call nodes, so fragment definitions\n // aren't collected and external fragment documents aren't searched for\n const calls = findAllCallExpressions(sourceFile, pluginInfo, {\n searchExternal: false,\n collectFragments: false,\n }).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 importTraceCache\n );\n\n if (graphqlSourcePath && !uniqueGraphQLSources.has(graphqlSourcePath)) {\n const graphqlSourceFile = container.program.getSourceFile(graphqlSourcePath);\n if (graphqlSourceFile) {\n const turboPath = getTurboOutputPath(params.turboOutputPath, call.schema);\n const imports = collectImportsFromSourceFile(\n graphqlSourceFile,\n params.pluginConfig,\n factory.resolveModuleName.bind(factory),\n factory.resolveModulePath.bind(factory),\n params.rootPath,\n turboPath,\n !!factory.wasOriginallyNodeNext\n );\n uniqueGraphQLSources.set(graphqlSourcePath, {\n absolutePath: graphqlSourcePath,\n imports,\n });\n }\n }\n\n const argumentKey = JSON.stringify(call.node.text);\n\n const documentHash = documentHasher.hashCallExpression(callExpression, call.schema);\n const cachedDocument =\n documentHash.hashable && documentHash.documentHash\n ? getCachedDocuments(call.schema).get(argumentKey)\n : undefined;\n\n let documentType: string;\n let isCached = false;\n if (cachedDocument && cachedDocument.documentHash === documentHash.documentHash) {\n documentType = cachedDocument.documentType;\n isCached = true;\n } else {\n const returnType = checker.getTypeAtLocation(callExpression);\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 documentType = checker.typeToString(returnType, callExpression, BUILDER_FLAGS);\n }\n\n documents.push({\n schemaName: call.schema,\n argumentKey,\n documentType,\n documentHash: documentHash.documentHash,\n isCached,\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 const documentHasher = createDocumentHasher({\n get checker() {\n return checker;\n },\n schemaFingerprints: computeSchemaFingerprints(params),\n });\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\nfunction computeSchemaFingerprints(params: TurboParams): Map<string | null, string> {\n const fingerprints = new Map<string | null, string>();\n const configDir = path.dirname(params.configPath);\n for (const schemaName of getSchemaNamesFromConfig(params.pluginConfig)) {\n const schemaConfig = getSchemaConfigForName(params.pluginConfig, schemaName || undefined);\n const outputLocation = schemaConfig && schemaConfig.tadaOutputLocation;\n if (!outputLocation) continue;\n\n let contents: string;\n try {\n contents = fs.readFileSync(path.resolve(configDir, outputLocation), 'utf8');\n } catch {\n continue;\n }\n\n const hash = crypto.createHash('sha256').update(contents).digest('hex');\n fingerprints.set(schemaName, `sha256:${hash.slice(0, 32)}`);\n }\n return fingerprints;\n}\n\nfunction getTurboOutputPath(\n turboOutputPath: string | TurboPath[],\n schemaName: string | null\n): string | undefined {\n if (typeof turboOutputPath === 'string') return turboOutputPath;\n return turboOutputPath.find((cfg) => cfg.schemaName === schemaName)?.path;\n}\n\nfunction getTurboOutputPaths(turboOutputPath: string | TurboPath[]): string[] {\n return typeof turboOutputPath === 'string'\n ? [turboOutputPath]\n : turboOutputPath.map((cfg) => cfg.path);\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":["HASH_COMMENT","getHashComment","contents","node","comments","ts","getLeadingCommentRanges","pos","i","length","comment","slice","end","match","exec","CACHE_BUSTER","createDocumentHasher","context","callExpressionCache","WeakMap","symbolCallCache","Map","activeCalls","WeakSet","hashCallExpression","callExpression","schemaName","schemaKey","cached","get","has","hashable","add","result","computeCallExpressionHash","delete","schemaCache","set","documentText","getStaticStringValue","expression","unwrapExpression","isStringLiteral","isNoSubstitutionTemplateLiteral","text","arguments","fragmentHashes","getFragmentHashes","hash","crypto","createHash","addHashPart","schemaFingerprints","fragmentHash","documentHash","digest","fragmentsExpression","isArrayLiteralExpression","hashes","element","elements","isSpreadElement","spreadHashes","push","documentCall","resolveDocumentCallExpression","declarationExpression","resolveDeclarationInitializer","isCallExpression","symbol","getSymbol","undefined","resolveSymbolCallExpression","declaration","declarations","isVariableDeclaration","initializer","checker","getSymbolAtLocation","flags","SymbolFlags","Alias","getAliasedSymbol","isParenthesizedExpression","isAsExpression","isTypeAssertionExpression","isSatisfiesExpression","isNonNullExpression","part","update","GRAPHQL_DOCUMENT_START","hasGraphQLDocumentCandidate","sourceFile","includes","hasCandidate","visit","argument","isStringLiteralLike","isGraphQLDocumentCandidateText","test","line","split","trimmed","trimStart","startsWith","forEachChild","HEAP_SOFT_LIMIT_BYTES","traceCallToImportSource","program","cache","identifier","isIdentifier","isPropertyAccessExpression","traceKey","fileName","traces","getTypeChecker","importDeclaration","findImportDeclaration","moduleSpecifier","resolveModulePath","current","isImportDeclaration","parent","moduleName","containingFile","compilerOptions","getCompilerOptions","host","createCompilerHost","resolutionCache","createModuleResolutionCache","getCurrentDirectory","getCanonicalFileName","bind","resolved","resolveModuleName","resolvedModule","resolvedFileName","collectImportsFromSourceFile","pluginConfig","rootPath","turboOutputPath","shouldTreatImportsAsNodeNext","imports","tadaImportPaths","getTadaOutputPaths","paths","tadaOutputLocation","path","resolve","schemaConfig","schemas","statements","specifier","isTadaImport","importClause","getFullText","trim","adjustedSpecifier","endsWith","replace","importSpecifier","sourceFilePath","tadaOutputLocationPaths","resolvedImportPath","some","tadaOutputLocationPath","sourceDir","dirname","absoluteImportPath","tadaPath","async","_runTurbo","params","schemaNames","getSchemaNamesFromConfig","factory","programFactory","cachedDocumentsByPath","getCachedDocuments","getTurboOutputPath","cachedDocuments","readCachedTurboDocuments","cachePath","documents","fs","existsSync","readFileSync","createSourceFile","ScriptTarget","Latest","ScriptKind","TS","isInterfaceDeclaration","name","member","members","isPropertySignature","type","isNumericLiteral","JSON","stringify","documentType","getText","addSourceFile","fileId","sourceText","DECLARATION_OVERRIDE","scriptKind","externalFiles","createExternalFiles","kind","addVirtualFiles","container","build","pluginInfo","buildPluginInfo","turboOutputPaths","Set","getTurboOutputPaths","map","cfg","fileNames","rootFileNames","filter","shouldScanTurboFile","fileCount","uniqueGraphQLSources","importTraceCache","processSourceFile","filePath","warnings","calls","findAllCallExpressions","searchExternal","collectFragments","nodes","call","position","getSourcePosition","getStart","schema","message","size","file","col","graphqlSourcePath","graphqlSourceFile","getSourceFile","turboPath","wasOriginallyNodeNext","absolutePath","argumentKey","documentHasher","cachedDocument","isCached","returnType","getTypeAtLocation","getEscapedName","typeToString","BUILDER_FLAGS","isHeapOverSoftLimit","process","memoryUsage","heapUsed","forceGc","computeSchemaFingerprints","filesInBatch","sources","Array","from","values","fingerprints","configDir","configPath","getSchemaConfigForName","outputLocation","find","cachedGc","existing","globalThis","gc","v8","setFlagsFromString","vm","runInNewContext","runTurbo","expose","TypeFormatFlags","NoTruncation","NoTypeReduction","InTypeAlias","UseFullyQualifiedType","GenerateNam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BtG,EAAOlC,cAAclH,UAAc6C;IAC/E,IAAM8M,IAAiB9H,KAAgBA,EAAaH;IACpD,KAAKiI;MAAgB;;IAErB,IAAInR,SAAgB;IACpB;MACEA,IAAWwL,EAAGE,aAAavC,EAAKC,QAAQ4H,GAAWG,IAAiB;AACtE,MAAE;MACA;AACF;IAEA,IAAMrO,IAAOC,EAAOC,WAAW,UAAUuC,OAAOvF,GAAUqD,OAAO;IACjE0N,EAAa5O,IAAIX,GAAY,UAAUsB,EAAKrC,MAAM,GAAG;AACvD;EACA,OAAOsQ;AACT;;AAEA,SAAS5F,mBACPvC,GACApH;EAEA,IAA+B,mBAApBoH;IAA8B,OAAOA;;EAChD,OAAOA,EAAgBwI,MAAMxD,KAAQA,EAAIpM,eAAeA,KAAa2H;AACvE;;AAQA,IAAIkI;;AAEJ,SAASb;EACP,SAAiBnM,MAAbgN,GAAwB;IAC1B,IAAMC,IAAYC,WAAmCC;IACrD,IAAwB,qBAAbF;MACTD,IAAWC;;MAGX;QACEG,EAAGC,mBAAmB;QACtBL,IAAWM,EAAGC,gBAAgB;QAC9BH,EAAGC,mBAAmB;AACxB,QAAE;QACAL,IAAW;AACb;;AAEJ;EACA,IAAIA;IAAUA;;AAChB;;IAEaQ,IAAWC,EAAOnH;;AAE/B,IAAMwF,IACJhQ,EAAG4R,gBAAgBC,eACnB7R,EAAG4R,gBAAgBE,kBACnB9R,EAAG4R,gBAAgBG,cACnB/R,EAAG4R,gBAAgBI,wBACnBhS,EAAG4R,gBAAgBK,qCACnBjS,EAAG4R,gBAAgBM,qCACnBlS,EAAG4R,gBAAgBO,0BACnBnS,EAAG4R,gBAAgBQ;;AAErB,IAAMzF,IAAuB,gJAO3BlD;;"}
|
|
@@ -41,57 +41,69 @@ var l = t.expose((async function* _runDiagnostics(r) {
|
|
|
41
41
|
};
|
|
42
42
|
await l.addVirtualFiles(s);
|
|
43
43
|
}
|
|
44
|
-
var
|
|
44
|
+
var c = await a.loadRef(r.pluginConfig).load({
|
|
45
45
|
rootPath: t
|
|
46
46
|
});
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
var g = {
|
|
48
|
+
current: c.current,
|
|
49
|
+
multi: c.multi,
|
|
50
|
+
version: c.version,
|
|
51
|
+
errors: {
|
|
52
|
+
config: null,
|
|
53
|
+
load: new Map,
|
|
54
|
+
write: new Map
|
|
55
|
+
},
|
|
56
|
+
outputLocations: new Map,
|
|
57
|
+
checkStale() {}
|
|
58
|
+
};
|
|
59
|
+
var u = l.build();
|
|
60
|
+
var f = u.buildPluginInfo(r.pluginConfig);
|
|
61
|
+
var d = u.getSourceFiles();
|
|
50
62
|
yield {
|
|
51
63
|
kind: "FILE_COUNT",
|
|
52
|
-
fileCount:
|
|
64
|
+
fileCount: d.length
|
|
53
65
|
};
|
|
54
|
-
for (var
|
|
55
|
-
var
|
|
56
|
-
var h =
|
|
66
|
+
for (var v of d) {
|
|
67
|
+
var p = v.fileName.endsWith(".vue.ts") || v.fileName.endsWith(".svelte.ts");
|
|
68
|
+
var h = v.fileName;
|
|
57
69
|
f.config = {
|
|
58
70
|
...f.config,
|
|
59
|
-
shouldCheckForColocatedFragments:
|
|
60
|
-
trackFieldUsage:
|
|
71
|
+
shouldCheckForColocatedFragments: p ? !1 : f.config.shouldCheckForColocatedFragments ?? !1,
|
|
72
|
+
trackFieldUsage: p ? !1 : f.config.trackFieldUsage ?? !1
|
|
61
73
|
};
|
|
62
|
-
var
|
|
63
|
-
var
|
|
64
|
-
if (
|
|
65
|
-
for (var
|
|
66
|
-
if (!("messageText" in
|
|
74
|
+
var m = i.getGraphQLDiagnostics(h, g, f);
|
|
75
|
+
var y = [];
|
|
76
|
+
if (m && m.length) {
|
|
77
|
+
for (var C of m) {
|
|
78
|
+
if (!("messageText" in C) || "string" != typeof C.messageText || !C.file) {
|
|
67
79
|
continue;
|
|
68
80
|
}
|
|
69
|
-
var
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
} else if (
|
|
73
|
-
|
|
81
|
+
var F = "info";
|
|
82
|
+
if (C.category === e.DiagnosticCategory.Error) {
|
|
83
|
+
F = "error";
|
|
84
|
+
} else if (C.category === e.DiagnosticCategory.Warning) {
|
|
85
|
+
F = "warn";
|
|
74
86
|
}
|
|
75
|
-
var
|
|
76
|
-
start:
|
|
77
|
-
length:
|
|
87
|
+
var N = u.getSourcePosition(v, {
|
|
88
|
+
start: C.start || 1,
|
|
89
|
+
length: C.length || 1
|
|
78
90
|
});
|
|
79
|
-
h =
|
|
80
|
-
|
|
81
|
-
severity:
|
|
82
|
-
message:
|
|
83
|
-
file:
|
|
84
|
-
line:
|
|
85
|
-
col:
|
|
86
|
-
endLine:
|
|
87
|
-
endColumn:
|
|
91
|
+
h = N.fileName;
|
|
92
|
+
y.push({
|
|
93
|
+
severity: F,
|
|
94
|
+
message: C.messageText,
|
|
95
|
+
file: N.fileName,
|
|
96
|
+
line: N.line,
|
|
97
|
+
col: N.col,
|
|
98
|
+
endLine: N.endLine,
|
|
99
|
+
endColumn: N.endColumn
|
|
88
100
|
});
|
|
89
101
|
}
|
|
90
102
|
}
|
|
91
103
|
yield {
|
|
92
104
|
kind: "FILE_DIAGNOSTICS",
|
|
93
105
|
filePath: h,
|
|
94
|
-
messages:
|
|
106
|
+
messages: y
|
|
95
107
|
};
|
|
96
108
|
}
|
|
97
109
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-chunk3.js","sources":["../../src/commands/check/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport * as path from 'node:path';\n\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\nimport { loadRef } from '@gql.tada/internal';\nimport { getGraphQLDiagnostics } from '@0no-co/graphqlsp/api';\n\nimport { programFactory } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { Severity, DiagnosticMessage, DiagnosticSignal } from './types';\n\nexport interface DiagnosticsParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runDiagnostics(\n params: DiagnosticsParams\n): AsyncIterableIterator<DiagnosticSignal> {\n const projectPath = path.dirname(params.configPath);\n const factory = programFactory(params);\n\n const externalFiles = factory.createExternalFiles();\n if (externalFiles.length) {\n yield { kind: 'EXTERNAL_WARNING' };\n await factory.addVirtualFiles(externalFiles);\n }\n\n const
|
|
1
|
+
{"version":3,"file":"thread-chunk3.js","sources":["../../src/commands/check/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport * as path from 'node:path';\n\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\nimport { loadRef } from '@gql.tada/internal';\nimport { getGraphQLDiagnostics } from '@0no-co/graphqlsp/api';\n\nimport { programFactory } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { Severity, DiagnosticMessage, DiagnosticSignal } from './types';\n\nexport interface DiagnosticsParams {\n rootPath: string;\n tsconfigPath?: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runDiagnostics(\n params: DiagnosticsParams\n): AsyncIterableIterator<DiagnosticSignal> {\n const projectPath = path.dirname(params.configPath);\n const factory = programFactory(params);\n\n const externalFiles = factory.createExternalFiles();\n if (externalFiles.length) {\n yield { kind: 'EXTERNAL_WARNING' };\n await factory.addVirtualFiles(externalFiles);\n }\n\n const loadedRef = await loadRef(params.pluginConfig).load({ rootPath: projectPath });\n\n // TODO(@kitten): Align `SchemaRef` in `@0no-co/graphqlsp` back with `@gql.tada/internal`\n const schemaRef = {\n current: loadedRef.current,\n multi: loadedRef.multi,\n version: loadedRef.version,\n errors: {\n config: null,\n load: new Map<string | null, string>(),\n write: new Map<string, string>(),\n },\n outputLocations: new Map<string, number>(),\n checkStale() {},\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 for (const sourceFile of sourceFiles) {\n const isVueOrSvelte =\n sourceFile.fileName.endsWith('.vue.ts') || sourceFile.fileName.endsWith('.svelte.ts');\n let filePath = sourceFile.fileName;\n pluginInfo.config = {\n ...pluginInfo.config,\n shouldCheckForColocatedFragments: isVueOrSvelte\n ? false\n : (pluginInfo.config.shouldCheckForColocatedFragments ?? false),\n trackFieldUsage: isVueOrSvelte ? false : (pluginInfo.config.trackFieldUsage ?? false),\n };\n const diagnostics = getGraphQLDiagnostics(filePath, schemaRef, pluginInfo);\n const messages: DiagnosticMessage[] = [];\n\n if (diagnostics && diagnostics.length) {\n for (const diagnostic of diagnostics) {\n if (\n !('messageText' in diagnostic) ||\n typeof diagnostic.messageText !== 'string' ||\n !diagnostic.file\n ) {\n continue;\n }\n let severity: Severity = 'info';\n if (diagnostic.category === ts.DiagnosticCategory.Error) {\n severity = 'error';\n } else if (diagnostic.category === ts.DiagnosticCategory.Warning) {\n severity = 'warn';\n }\n const span = { start: diagnostic.start || 1, length: diagnostic.length || 1 };\n const position = container.getSourcePosition(sourceFile, span);\n filePath = position.fileName;\n messages.push({\n severity,\n message: diagnostic.messageText,\n file: position.fileName,\n line: position.line,\n col: position.col,\n endLine: position.endLine,\n endColumn: position.endColumn,\n });\n }\n }\n\n yield {\n kind: 'FILE_DIAGNOSTICS',\n filePath,\n messages,\n };\n }\n}\n\nexport const runDiagnostics = expose(_runDiagnostics);\n"],"names":["runDiagnostics","expose","async","_runDiagnostics","params","projectPath","path","dirname","configPath","factory","programFactory","externalFiles","createExternalFiles","length","kind","addVirtualFiles","loadedRef","loadRef","pluginConfig","load","rootPath","schemaRef","current","multi","version","errors","config","Map","write","outputLocations","checkStale","container","build","pluginInfo","buildPluginInfo","sourceFiles","getSourceFiles","fileCount","sourceFile","isVueOrSvelte","fileName","endsWith","filePath","shouldCheckForColocatedFragments","trackFieldUsage","diagnostics","getGraphQLDiagnostics","messages","diagnostic","messageText","file","severity","category","ts","DiagnosticCategory","Error","Warning","position","getSourcePosition","start","push","message","line","col","endLine","endColumn"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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IH,EAAWI,aAAaC,EAAGC,mBAAmBE;UACvDL,IAAW;;QAGb,IAAMM,IAAW1B,EAAU2B,kBAAkBpB,GADhC;UAAEqB,OAAOX,EAAWW,SAAS;UAAG9C,QAAQmC,EAAWnC,UAAU;;QAE1E6B,IAAWe,EAASjB;QACpBO,EAASa,KAAK;UACZT;UACAU,SAASb,EAAWC;UACpBC,MAAMO,EAASjB;UACfsB,MAAML,EAASK;UACfC,KAAKN,EAASM;UACdC,SAASP,EAASO;UAClBC,WAAWR,EAASQ;;AAExB;;UAGI;MACJnD,MAAM;MACN4B;MACAK;;AAEJ;AACF;;"}
|
|
@@ -6,13 +6,13 @@ import { loadRef as a } from "@gql.tada/internal";
|
|
|
6
6
|
|
|
7
7
|
import { getGraphQLDiagnostics as r } from "@0no-co/graphqlsp/api";
|
|
8
8
|
|
|
9
|
-
import { e as
|
|
9
|
+
import { e as n } from "./index-chunk2.mjs";
|
|
10
10
|
|
|
11
|
-
import { p as
|
|
11
|
+
import { p as o } from "./index-chunk.mjs";
|
|
12
12
|
|
|
13
|
-
var t =
|
|
14
|
-
var t = i.dirname(
|
|
15
|
-
var l = n
|
|
13
|
+
var t = n((async function* _runDiagnostics(n) {
|
|
14
|
+
var t = i.dirname(n.configPath);
|
|
15
|
+
var l = o(n);
|
|
16
16
|
var s = l.createExternalFiles();
|
|
17
17
|
if (s.length) {
|
|
18
18
|
yield {
|
|
@@ -20,57 +20,69 @@ var t = o((async function* _runDiagnostics(o) {
|
|
|
20
20
|
};
|
|
21
21
|
await l.addVirtualFiles(s);
|
|
22
22
|
}
|
|
23
|
-
var g = await a(
|
|
23
|
+
var g = await a(n.pluginConfig).load({
|
|
24
24
|
rootPath: t
|
|
25
25
|
});
|
|
26
|
-
var f =
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
var f = {
|
|
27
|
+
current: g.current,
|
|
28
|
+
multi: g.multi,
|
|
29
|
+
version: g.version,
|
|
30
|
+
errors: {
|
|
31
|
+
config: null,
|
|
32
|
+
load: new Map,
|
|
33
|
+
write: new Map
|
|
34
|
+
},
|
|
35
|
+
outputLocations: new Map,
|
|
36
|
+
checkStale() {}
|
|
37
|
+
};
|
|
38
|
+
var c = l.build();
|
|
39
|
+
var m = c.buildPluginInfo(n.pluginConfig);
|
|
40
|
+
var d = c.getSourceFiles();
|
|
29
41
|
yield {
|
|
30
42
|
kind: "FILE_COUNT",
|
|
31
|
-
fileCount:
|
|
43
|
+
fileCount: d.length
|
|
32
44
|
};
|
|
33
|
-
for (var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
45
|
+
for (var u of d) {
|
|
46
|
+
var p = u.fileName.endsWith(".vue.ts") || u.fileName.endsWith(".svelte.ts");
|
|
47
|
+
var v = u.fileName;
|
|
36
48
|
m.config = {
|
|
37
49
|
...m.config,
|
|
38
|
-
shouldCheckForColocatedFragments:
|
|
39
|
-
trackFieldUsage:
|
|
50
|
+
shouldCheckForColocatedFragments: p ? !1 : m.config.shouldCheckForColocatedFragments ?? !1,
|
|
51
|
+
trackFieldUsage: p ? !1 : m.config.trackFieldUsage ?? !1
|
|
40
52
|
};
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
if (
|
|
44
|
-
for (var
|
|
45
|
-
if (!("messageText" in
|
|
53
|
+
var h = r(v, f, m);
|
|
54
|
+
var C = [];
|
|
55
|
+
if (h && h.length) {
|
|
56
|
+
for (var y of h) {
|
|
57
|
+
if (!("messageText" in y) || "string" != typeof y.messageText || !y.file) {
|
|
46
58
|
continue;
|
|
47
59
|
}
|
|
48
|
-
var
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
} else if (
|
|
52
|
-
|
|
60
|
+
var F = "info";
|
|
61
|
+
if (y.category === e.DiagnosticCategory.Error) {
|
|
62
|
+
F = "error";
|
|
63
|
+
} else if (y.category === e.DiagnosticCategory.Warning) {
|
|
64
|
+
F = "warn";
|
|
53
65
|
}
|
|
54
|
-
var
|
|
55
|
-
start:
|
|
56
|
-
length:
|
|
66
|
+
var k = c.getSourcePosition(u, {
|
|
67
|
+
start: y.start || 1,
|
|
68
|
+
length: y.length || 1
|
|
57
69
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
severity:
|
|
61
|
-
message:
|
|
62
|
-
file:
|
|
63
|
-
line:
|
|
64
|
-
col:
|
|
65
|
-
endLine:
|
|
66
|
-
endColumn:
|
|
70
|
+
v = k.fileName;
|
|
71
|
+
C.push({
|
|
72
|
+
severity: F,
|
|
73
|
+
message: y.messageText,
|
|
74
|
+
file: k.fileName,
|
|
75
|
+
line: k.line,
|
|
76
|
+
col: k.col,
|
|
77
|
+
endLine: k.endLine,
|
|
78
|
+
endColumn: k.endColumn
|
|
67
79
|
});
|
|
68
80
|
}
|
|
69
81
|
}
|
|
70
82
|
yield {
|
|
71
83
|
kind: "FILE_DIAGNOSTICS",
|
|
72
|
-
filePath:
|
|
73
|
-
messages:
|
|
84
|
+
filePath: v,
|
|
85
|
+
messages: C
|
|
74
86
|
};
|
|
75
87
|
}
|
|
76
88
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-chunk3.mjs","sources":["../../src/commands/check/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport * as path from 'node:path';\n\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\nimport { loadRef } from '@gql.tada/internal';\nimport { getGraphQLDiagnostics } from '@0no-co/graphqlsp/api';\n\nimport { programFactory } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { Severity, DiagnosticMessage, DiagnosticSignal } from './types';\n\nexport interface DiagnosticsParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runDiagnostics(\n params: DiagnosticsParams\n): AsyncIterableIterator<DiagnosticSignal> {\n const projectPath = path.dirname(params.configPath);\n const factory = programFactory(params);\n\n const externalFiles = factory.createExternalFiles();\n if (externalFiles.length) {\n yield { kind: 'EXTERNAL_WARNING' };\n await factory.addVirtualFiles(externalFiles);\n }\n\n const
|
|
1
|
+
{"version":3,"file":"thread-chunk3.mjs","sources":["../../src/commands/check/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport * as path from 'node:path';\n\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\nimport { loadRef } from '@gql.tada/internal';\nimport { getGraphQLDiagnostics } from '@0no-co/graphqlsp/api';\n\nimport { programFactory } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { Severity, DiagnosticMessage, DiagnosticSignal } from './types';\n\nexport interface DiagnosticsParams {\n rootPath: string;\n tsconfigPath?: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runDiagnostics(\n params: DiagnosticsParams\n): AsyncIterableIterator<DiagnosticSignal> {\n const projectPath = path.dirname(params.configPath);\n const factory = programFactory(params);\n\n const externalFiles = factory.createExternalFiles();\n if (externalFiles.length) {\n yield { kind: 'EXTERNAL_WARNING' };\n await factory.addVirtualFiles(externalFiles);\n }\n\n const loadedRef = await loadRef(params.pluginConfig).load({ rootPath: projectPath });\n\n // TODO(@kitten): Align `SchemaRef` in `@0no-co/graphqlsp` back with `@gql.tada/internal`\n const schemaRef = {\n current: loadedRef.current,\n multi: loadedRef.multi,\n version: loadedRef.version,\n errors: {\n config: null,\n load: new Map<string | null, string>(),\n write: new Map<string, string>(),\n },\n outputLocations: new Map<string, number>(),\n checkStale() {},\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 for (const sourceFile of sourceFiles) {\n const isVueOrSvelte =\n sourceFile.fileName.endsWith('.vue.ts') || sourceFile.fileName.endsWith('.svelte.ts');\n let filePath = sourceFile.fileName;\n pluginInfo.config = {\n ...pluginInfo.config,\n shouldCheckForColocatedFragments: isVueOrSvelte\n ? false\n : (pluginInfo.config.shouldCheckForColocatedFragments ?? false),\n trackFieldUsage: isVueOrSvelte ? false : (pluginInfo.config.trackFieldUsage ?? false),\n };\n const diagnostics = getGraphQLDiagnostics(filePath, schemaRef, pluginInfo);\n const messages: DiagnosticMessage[] = [];\n\n if (diagnostics && diagnostics.length) {\n for (const diagnostic of diagnostics) {\n if (\n !('messageText' in diagnostic) ||\n typeof diagnostic.messageText !== 'string' ||\n !diagnostic.file\n ) {\n continue;\n }\n let severity: Severity = 'info';\n if (diagnostic.category === ts.DiagnosticCategory.Error) {\n severity = 'error';\n } else if (diagnostic.category === ts.DiagnosticCategory.Warning) {\n severity = 'warn';\n }\n const span = { start: diagnostic.start || 1, length: diagnostic.length || 1 };\n const position = container.getSourcePosition(sourceFile, span);\n filePath = position.fileName;\n messages.push({\n severity,\n message: diagnostic.messageText,\n file: position.fileName,\n line: position.line,\n col: position.col,\n endLine: position.endLine,\n endColumn: position.endColumn,\n });\n }\n }\n\n yield {\n kind: 'FILE_DIAGNOSTICS',\n filePath,\n messages,\n };\n }\n}\n\nexport const runDiagnostics = expose(_runDiagnostics);\n"],"names":["runDiagnostics","expose","async","_runDiagnostics","params","projectPath","path","dirname","configPath","factory","programFactory","externalFiles","createExternalFiles","length","kind","addVirtualFiles","loadedRef","loadRef","pluginConfig","load","rootPath","schemaRef","current","multi","version","errors","config","Map","write","outputLocations","checkStale","container","build","pluginInfo","buildPluginInfo","sourceFiles","getSourceFiles","fileCount","sourceFile","isVueOrSvelte","fileName","endsWith","filePath","shouldCheckForColocatedFragments","trackFieldUsage","diagnostics","getGraphQLDiagnostics","messages","diagnostic","messageText","file","severity","category","ts","DiagnosticCategory","Error","Warning","position","getSourcePosition","start","push","message","line","col","endLine","endColumn"],"mappings":";;;;;;;;;;;;IA4GaA,IAAiBC,GAzF9BC,gBAAgBC,gBACdC;EAEA,IAAMC,IAAcC,EAAKC,QAAQH,EAAOI;EACxC,IAAMC,IAAUC,EAAeN;EAE/B,IAAMO,IAAgBF,EAAQG;EAC9B,IAAID,EAAcE,QAAQ;UAClB;MAAEC,MAAM;;UACRL,EAAQM,gBA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EAASjB;UACfsB,MAAML,EAASK;UACfC,KAAKN,EAASM;UACdC,SAASP,EAASO;UAClBC,WAAWR,EAASQ;;AAExB;;UAGI;MACJnD,MAAM;MACN4B;MACAK;;AAEJ;AACF;;"}
|
package/dist/gql-tada-cli.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ interface OutputOptions {
|
|
|
11
11
|
/** The `tsconfig.json` to use for configurations and the TypeScript program.
|
|
12
12
|
* @defaultValue A `tsconfig.json` in the current or any parent directory. */
|
|
13
13
|
tsconfig: string | undefined;
|
|
14
|
+
/** Whether to disable terminal output when using the programmatic API.
|
|
15
|
+
* @defaultValue `false` */
|
|
16
|
+
silent?: boolean;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
/** Outputs the `gql.tada` output file manually.
|
|
@@ -62,6 +65,9 @@ interface SchemaOptions {
|
|
|
62
65
|
/** The `tsconfig.json` to use for configurations and the TypeScript program.
|
|
63
66
|
* @defaultValue A `tsconfig.json` in the current or any parent directory. */
|
|
64
67
|
tsconfig: string | undefined;
|
|
68
|
+
/** Whether to disable terminal output when using the programmatic API.
|
|
69
|
+
* @defaultValue `false` */
|
|
70
|
+
silent?: boolean;
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
/** Generates a GraphQL SDL file from a given GraphQL API URL or schema file.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gql.tada/cli-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"public": true,
|
|
5
5
|
"description": "Main logic for gql.tada’s CLI tool.",
|
|
6
6
|
"author": "0no.co <hi@0no.co>",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"wonka": "^6.3.4"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@0no-co/graphqlsp": "^1.
|
|
52
|
+
"@0no-co/graphqlsp": "^1.17.0",
|
|
53
53
|
"graphql": "^15.5.0 || ^16.0.0 || ^17.0.0",
|
|
54
|
-
"@gql.tada/internal": "1.0
|
|
54
|
+
"@gql.tada/internal": "1.1.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependenciesMeta": {
|
|
57
57
|
"@gql.tada/svelte-support": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@0no-co/graphqlsp": "^1.
|
|
65
|
+
"@0no-co/graphqlsp": "^1.16.0",
|
|
66
66
|
"graphql": "^15.5.0 || ^16.0.0 || ^17.0.0",
|
|
67
67
|
"typescript": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
68
68
|
"@gql.tada/svelte-support": "1.0.3",
|