From 3c236862deda97fa2c0da93d7a8ab99e446fce45 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Sat, 5 Oct 2024 10:41:08 +0200 Subject: [PATCH 1/3] Recursively create directories --- packages/graphqlsp/src/fieldUsage.ts | 4 ---- packages/graphqlsp/src/graphql/getSchema.ts | 13 +++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/graphqlsp/src/fieldUsage.ts b/packages/graphqlsp/src/fieldUsage.ts index 8f24fc1..45a8651 100644 --- a/packages/graphqlsp/src/fieldUsage.ts +++ b/packages/graphqlsp/src/fieldUsage.ts @@ -130,7 +130,6 @@ const crawlChainedExpressions = ( const isChained = ts.isPropertyAccessExpression(ref.expression) && arrayMethods.has(ref.expression.name.text); - console.log('[GRAPHQLSP]: ', isChained, ref.getFullText()); if (isChained) { const foundRef = ref.expression; const isReduce = foundRef.name.text === 'reduce'; @@ -250,7 +249,6 @@ const crawlScope = ( // - const pokemon = result.data.pokemon --> this initiates a new crawl with a renewed scope // - const { pokemon } = result.data --> this initiates a destructuring traversal which will // either end up in more destructuring traversals or a scope crawl - console.log('[GRAPHQLSP]: ', foundRef.getFullText()); while ( ts.isIdentifier(foundRef) || ts.isPropertyAccessExpression(foundRef) || @@ -301,7 +299,6 @@ const crawlScope = ( const res = []; const isSomeOrEvery = foundRef.name.text === 'some' || foundRef.name.text === 'every'; - console.log('[GRAPHQLSP]: ', foundRef.name.text); const chainedResults = crawlChainedExpressions( callExpression, pathParts, @@ -309,7 +306,6 @@ const crawlScope = ( source, info ); - console.log('[GRAPHQLSP]: ', chainedResults.length); if (chainedResults.length) { res.push(...chainedResults); } diff --git a/packages/graphqlsp/src/graphql/getSchema.ts b/packages/graphqlsp/src/graphql/getSchema.ts index a45007b..ea86d5f 100644 --- a/packages/graphqlsp/src/graphql/getSchema.ts +++ b/packages/graphqlsp/src/graphql/getSchema.ts @@ -76,14 +76,15 @@ async function saveTadaIntrospection( }); let output = tadaOutputLocation; - + console.log('OUTPUT'); if (await statFile(output, stat => stat.isDirectory())) { output = path.join(output, 'introspection.d.ts'); - } else if ( - !(await statFile(path.dirname(output), stat => stat.isDirectory())) - ) { - logger(`Output file is not inside a directory @ ${output}`); - return; + } else if (!(await statFile(output, p => !!p))) { + console.log('MAKING DIRECTORY', output); + await fs.mkdir(path.dirname(output), { recursive: true }); + if (await statFile(output, stat => stat.isDirectory())) { + output = path.join(output, 'introspection.d.ts'); + } } try { From 348cc0725f26253df3ae4f36d90f6dd0e4de9866 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Sat, 5 Oct 2024 10:41:34 +0200 Subject: [PATCH 2/3] Add chagneset --- .changeset/rotten-pugs-begin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rotten-pugs-begin.md diff --git a/.changeset/rotten-pugs-begin.md b/.changeset/rotten-pugs-begin.md new file mode 100644 index 0000000..e895c3c --- /dev/null +++ b/.changeset/rotten-pugs-begin.md @@ -0,0 +1,5 @@ +--- +'@0no-co/graphqlsp': patch +--- + +Recursively create directories if the target does not exist From 38cd3ecfc7e551dab3cd8200e3eddb9d11cef032 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Sat, 5 Oct 2024 10:47:20 +0200 Subject: [PATCH 3/3] Apply suggestions from code review --- packages/graphqlsp/src/graphql/getSchema.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/graphqlsp/src/graphql/getSchema.ts b/packages/graphqlsp/src/graphql/getSchema.ts index ea86d5f..1ec0a56 100644 --- a/packages/graphqlsp/src/graphql/getSchema.ts +++ b/packages/graphqlsp/src/graphql/getSchema.ts @@ -76,11 +76,9 @@ async function saveTadaIntrospection( }); let output = tadaOutputLocation; - console.log('OUTPUT'); if (await statFile(output, stat => stat.isDirectory())) { output = path.join(output, 'introspection.d.ts'); } else if (!(await statFile(output, p => !!p))) { - console.log('MAKING DIRECTORY', output); await fs.mkdir(path.dirname(output), { recursive: true }); if (await statFile(output, stat => stat.isDirectory())) { output = path.join(output, 'introspection.d.ts');