@graphql-tools/graphql-tag-pluck
Advanced tools
Comparing version 8.3.0 to 8.3.1-rc-20240514214700-bee855e45f76c90f1cbf154c0a1151674a1c880b
@@ -39,3 +39,13 @@ "use strict"; | ||
} | ||
function customBlockFromVue( | ||
// tslint:disable-next-line: no-implicit-dependencies | ||
vueTemplateCompiler, fileData, filePath, blockType) { | ||
const { descriptor } = vueTemplateCompiler.parse(fileData); | ||
const block = descriptor.customBlocks.find(b => b.type === blockType); | ||
if (block === undefined) { | ||
return; | ||
} | ||
return new graphql_1.Source(block.content.trim(), filePath, block.loc.start); | ||
} | ||
// tslint:disable-next-line: no-implicit-dependencies | ||
function parseWithSvelte(svelte2tsx, fileData) { | ||
@@ -68,3 +78,7 @@ const fileInTsx = svelte2tsx.svelte2tsx(fileData); | ||
const fileExt = extractExtension(filePath); | ||
let blockSource; | ||
if (fileExt === '.vue') { | ||
if (options.gqlVueBlock) { | ||
blockSource = await pluckVueFileCustomBlock(code, filePath, options.gqlVueBlock); | ||
} | ||
code = await pluckVueFileScript(code); | ||
@@ -78,3 +92,7 @@ } | ||
} | ||
return parseCode({ code, filePath, options }).map(t => new graphql_1.Source(t.content, filePath, t.loc.start)); | ||
const sources = parseCode({ code, filePath, options }).map(t => new graphql_1.Source(t.content, filePath, t.loc.start)); | ||
if (blockSource) { | ||
sources.push(blockSource); | ||
} | ||
return sources; | ||
}; | ||
@@ -94,3 +112,7 @@ exports.gqlPluckFromCodeString = gqlPluckFromCodeString; | ||
const fileExt = extractExtension(filePath); | ||
let blockSource; | ||
if (fileExt === '.vue') { | ||
if (options.gqlVueBlock) { | ||
blockSource = pluckVueFileCustomBlockSync(code, filePath, options.gqlVueBlock); | ||
} | ||
code = pluckVueFileScriptSync(code); | ||
@@ -104,3 +126,7 @@ } | ||
} | ||
return parseCode({ code, filePath, options }).map(t => new graphql_1.Source(t.content, filePath, t.loc.start)); | ||
const sources = parseCode({ code, filePath, options }).map(t => new graphql_1.Source(t.content, filePath, t.loc.start)); | ||
if (blockSource) { | ||
sources.push(blockSource); | ||
} | ||
return sources; | ||
}; | ||
@@ -169,7 +195,6 @@ exports.gqlPluckFromCodeStringSync = gqlPluckFromCodeStringSync; | ||
`)); | ||
async function pluckVueFileScript(fileData) { | ||
let vueTemplateCompiler; | ||
async function loadVueCompilerSync() { | ||
try { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
vueTemplateCompiler = await Promise.resolve().then(() => tslib_1.__importStar(require('@vue/compiler-sfc'))); | ||
return await Promise.resolve().then(() => tslib_1.__importStar(require('@vue/compiler-sfc'))); | ||
} | ||
@@ -179,9 +204,7 @@ catch (e) { | ||
} | ||
return parseWithVue(vueTemplateCompiler, fileData); | ||
} | ||
function pluckVueFileScriptSync(fileData) { | ||
let vueTemplateCompiler; | ||
function loadVueCompilerAsync() { | ||
try { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
vueTemplateCompiler = require('@vue/compiler-sfc'); | ||
return require('@vue/compiler-sfc'); | ||
} | ||
@@ -191,4 +214,19 @@ catch (e) { | ||
} | ||
} | ||
async function pluckVueFileScript(fileData) { | ||
const vueTemplateCompiler = await loadVueCompilerSync(); | ||
return parseWithVue(vueTemplateCompiler, fileData); | ||
} | ||
function pluckVueFileScriptSync(fileData) { | ||
const vueTemplateCompiler = loadVueCompilerAsync(); | ||
return parseWithVue(vueTemplateCompiler, fileData); | ||
} | ||
async function pluckVueFileCustomBlock(fileData, filePath, blockType) { | ||
const vueTemplateCompiler = await loadVueCompilerSync(); | ||
return customBlockFromVue(vueTemplateCompiler, fileData, filePath, blockType); | ||
} | ||
function pluckVueFileCustomBlockSync(fileData, filePath, blockType) { | ||
const vueTemplateCompiler = loadVueCompilerAsync(); | ||
return customBlockFromVue(vueTemplateCompiler, fileData, filePath, blockType); | ||
} | ||
async function pluckSvelteFileScript(fileData) { | ||
@@ -230,2 +268,3 @@ let svelte2tsx; | ||
try { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
astroCompiler = require('astrojs-compiler-sync'); | ||
@@ -232,0 +271,0 @@ } |
@@ -35,3 +35,13 @@ import { Source } from 'graphql'; | ||
} | ||
function customBlockFromVue( | ||
// tslint:disable-next-line: no-implicit-dependencies | ||
vueTemplateCompiler, fileData, filePath, blockType) { | ||
const { descriptor } = vueTemplateCompiler.parse(fileData); | ||
const block = descriptor.customBlocks.find(b => b.type === blockType); | ||
if (block === undefined) { | ||
return; | ||
} | ||
return new Source(block.content.trim(), filePath, block.loc.start); | ||
} | ||
// tslint:disable-next-line: no-implicit-dependencies | ||
function parseWithSvelte(svelte2tsx, fileData) { | ||
@@ -64,3 +74,7 @@ const fileInTsx = svelte2tsx.svelte2tsx(fileData); | ||
const fileExt = extractExtension(filePath); | ||
let blockSource; | ||
if (fileExt === '.vue') { | ||
if (options.gqlVueBlock) { | ||
blockSource = await pluckVueFileCustomBlock(code, filePath, options.gqlVueBlock); | ||
} | ||
code = await pluckVueFileScript(code); | ||
@@ -74,3 +88,7 @@ } | ||
} | ||
return parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start)); | ||
const sources = parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start)); | ||
if (blockSource) { | ||
sources.push(blockSource); | ||
} | ||
return sources; | ||
}; | ||
@@ -89,3 +107,7 @@ /** | ||
const fileExt = extractExtension(filePath); | ||
let blockSource; | ||
if (fileExt === '.vue') { | ||
if (options.gqlVueBlock) { | ||
blockSource = pluckVueFileCustomBlockSync(code, filePath, options.gqlVueBlock); | ||
} | ||
code = pluckVueFileScriptSync(code); | ||
@@ -99,3 +121,7 @@ } | ||
} | ||
return parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start)); | ||
const sources = parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start)); | ||
if (blockSource) { | ||
sources.push(blockSource); | ||
} | ||
return sources; | ||
}; | ||
@@ -162,7 +188,6 @@ export function parseCode({ code, filePath, options, }) { | ||
`)); | ||
async function pluckVueFileScript(fileData) { | ||
let vueTemplateCompiler; | ||
async function loadVueCompilerSync() { | ||
try { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
vueTemplateCompiler = await import('@vue/compiler-sfc'); | ||
return await import('@vue/compiler-sfc'); | ||
} | ||
@@ -172,9 +197,7 @@ catch (e) { | ||
} | ||
return parseWithVue(vueTemplateCompiler, fileData); | ||
} | ||
function pluckVueFileScriptSync(fileData) { | ||
let vueTemplateCompiler; | ||
function loadVueCompilerAsync() { | ||
try { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
vueTemplateCompiler = require('@vue/compiler-sfc'); | ||
return require('@vue/compiler-sfc'); | ||
} | ||
@@ -184,4 +207,19 @@ catch (e) { | ||
} | ||
} | ||
async function pluckVueFileScript(fileData) { | ||
const vueTemplateCompiler = await loadVueCompilerSync(); | ||
return parseWithVue(vueTemplateCompiler, fileData); | ||
} | ||
function pluckVueFileScriptSync(fileData) { | ||
const vueTemplateCompiler = loadVueCompilerAsync(); | ||
return parseWithVue(vueTemplateCompiler, fileData); | ||
} | ||
async function pluckVueFileCustomBlock(fileData, filePath, blockType) { | ||
const vueTemplateCompiler = await loadVueCompilerSync(); | ||
return customBlockFromVue(vueTemplateCompiler, fileData, filePath, blockType); | ||
} | ||
function pluckVueFileCustomBlockSync(fileData, filePath, blockType) { | ||
const vueTemplateCompiler = loadVueCompilerAsync(); | ||
return customBlockFromVue(vueTemplateCompiler, fileData, filePath, blockType); | ||
} | ||
async function pluckSvelteFileScript(fileData) { | ||
@@ -223,2 +261,3 @@ let svelte2tsx; | ||
try { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
astroCompiler = require('astrojs-compiler-sync'); | ||
@@ -225,0 +264,0 @@ } |
{ | ||
"name": "@graphql-tools/graphql-tag-pluck", | ||
"version": "8.3.0", | ||
"version": "8.3.1-rc-20240514214700-bee855e45f76c90f1cbf154c0a1151674a1c880b", | ||
"description": "Pluck graphql-tag template literals", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -86,2 +86,6 @@ import { Source } from 'graphql'; | ||
/** | ||
* The name of a custom Vue block that contains raw GraphQL to be plucked. | ||
*/ | ||
gqlVueBlock?: string; | ||
/** | ||
* Allows to use a global identifier instead of a module import. | ||
@@ -88,0 +92,0 @@ * ```js |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
66427
1612
2