@graphql-toolkit/graphql-tag-pluck
Advanced tools
Comparing version 0.7.5-alpha-80a7ba8.2 to 0.7.5-alpha-82e33fe.21
@@ -86,2 +86,5 @@ 'use strict'; | ||
break; | ||
case '.vue': | ||
plugins.push('vue'); | ||
break; | ||
default: | ||
@@ -100,2 +103,11 @@ plugins.push('jsx', ...dynamicFlowPlugins); | ||
const getExtNameFromFilePath = (filePath) => { | ||
const partials = filePath.split('.'); | ||
let ext = '.' + partials.pop(); | ||
if (partials.length > 1 && partials[partials.length - 1] == 'flow') { | ||
ext = '.' + partials.pop() + ext; | ||
} | ||
return ext; | ||
}; | ||
// Will use the shortest indention as an axis | ||
@@ -128,52 +140,2 @@ const freeText = text => { | ||
const parseCode = async (code, config) => { | ||
// The 'typescript' plug-in has few bugs... It's just better to use the native one | ||
// even though it affects performance | ||
if (config.plugins.includes('typescript')) { | ||
let ts; | ||
try { | ||
ts = await new Promise(function (resolve) { resolve(_interopNamespace(require('typescript'))); }); | ||
} | ||
catch (e) { | ||
throw Error(freeText(` | ||
GraphQL template literals cannot be plucked from a TypeScript code without having the "typescript" package installed. | ||
Please install it and try again. | ||
Via NPM: | ||
$ npm install typescript | ||
Via Yarn: | ||
$ yarn add typescript | ||
`)); | ||
} | ||
code = ts.transpileModule(code, { | ||
compilerOptions: { | ||
target: ts.ScriptTarget.ES2018, | ||
// "preserve" mode would be more correct, but it will keep not transpile generic | ||
// React.Components which are provided with null or undefined e.g. <Foo<undefined />> | ||
jsx: config.plugins.includes('jsx') && ts.JsxEmit.React, | ||
}, | ||
}).outputText; | ||
const plugins = config.plugins.slice(); | ||
const tsIndex = plugins.indexOf('typescript'); | ||
plugins.splice(tsIndex, 1); | ||
config = { ...config, plugins }; | ||
} | ||
const ast = parser.parse(code, config); | ||
// Necessary to get the original code in case it was transformed by TypeScript | ||
ast['code'] = code; | ||
return ast; | ||
}; | ||
const getExtNameFromFilePath = (filePath) => { | ||
const partials = filePath.split('.'); | ||
let ext = '.' + partials.pop(); | ||
if (partials.length > 1 && partials[partials.length - 1] == 'flow') { | ||
ext = '.' + partials.pop() + ext; | ||
} | ||
return ext; | ||
}; | ||
const defaults = { | ||
@@ -391,3 +353,3 @@ modules: [ | ||
const gqlExtensions = ['.graphqls', '.graphql', '.gqls', '.gql']; | ||
const jsExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx']; | ||
const jsExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx', '.vue']; | ||
const supportedExtensions = [...gqlExtensions, ...jsExtensions]; | ||
@@ -397,2 +359,24 @@ supportedExtensions.toString = function toString() { | ||
}; | ||
async function pluckVueFileScript(fileData) { | ||
let vueTemplateCompiler; | ||
try { | ||
vueTemplateCompiler = await new Promise(function (resolve) { resolve(_interopNamespace(require('vue-template-compiler'))); }); | ||
} | ||
catch (e) { | ||
throw Error(freeText(` | ||
GraphQL template literals cannot be plucked from a Vue template code without having the "vue-template-compiler" package installed. | ||
Please install it and try again. | ||
Via NPM: | ||
$ npm install vue-template-compiler | ||
Via Yarn: | ||
$ yarn add vue-template-compiler | ||
`)); | ||
} | ||
const parsed = vueTemplateCompiler.parseComponent(fileData); | ||
return parsed.script ? parsed.script.content : ''; | ||
} | ||
const gqlPluckFromFile = async (filePath, options = {}) => { | ||
@@ -414,3 +398,6 @@ if (typeof filePath != 'string') { | ||
options = { ...options, fileExt }; | ||
const code = fs.readFileSync(filePath, { encoding: 'utf8' }); | ||
let code = fs.readFileSync(filePath, { encoding: 'utf8' }); | ||
if (fileExt === '.vue') { | ||
code = await pluckVueFileScript(code); | ||
} | ||
return gqlPluckFromCodeString(code, options); | ||
@@ -434,4 +421,4 @@ }; | ||
const out = { returnValue: null }; | ||
const ast = await parseCode(code, generateConfig(code, options)); | ||
const visitor = createVisitor(ast['code'], out, options); | ||
const ast = parser.parse(code, generateConfig(code, options)); | ||
const visitor = createVisitor(code, out, options); | ||
traverse(ast, visitor); | ||
@@ -438,0 +425,0 @@ return out.returnValue; |
@@ -61,2 +61,5 @@ import { parse } from '@babel/parser'; | ||
break; | ||
case '.vue': | ||
plugins.push('vue'); | ||
break; | ||
default: | ||
@@ -75,2 +78,11 @@ plugins.push('jsx', ...dynamicFlowPlugins); | ||
const getExtNameFromFilePath = (filePath) => { | ||
const partials = filePath.split('.'); | ||
let ext = '.' + partials.pop(); | ||
if (partials.length > 1 && partials[partials.length - 1] == 'flow') { | ||
ext = '.' + partials.pop() + ext; | ||
} | ||
return ext; | ||
}; | ||
// Will use the shortest indention as an axis | ||
@@ -103,52 +115,2 @@ const freeText = text => { | ||
const parseCode = async (code, config) => { | ||
// The 'typescript' plug-in has few bugs... It's just better to use the native one | ||
// even though it affects performance | ||
if (config.plugins.includes('typescript')) { | ||
let ts; | ||
try { | ||
ts = await import('typescript'); | ||
} | ||
catch (e) { | ||
throw Error(freeText(` | ||
GraphQL template literals cannot be plucked from a TypeScript code without having the "typescript" package installed. | ||
Please install it and try again. | ||
Via NPM: | ||
$ npm install typescript | ||
Via Yarn: | ||
$ yarn add typescript | ||
`)); | ||
} | ||
code = ts.transpileModule(code, { | ||
compilerOptions: { | ||
target: ts.ScriptTarget.ES2018, | ||
// "preserve" mode would be more correct, but it will keep not transpile generic | ||
// React.Components which are provided with null or undefined e.g. <Foo<undefined />> | ||
jsx: config.plugins.includes('jsx') && ts.JsxEmit.React, | ||
}, | ||
}).outputText; | ||
const plugins = config.plugins.slice(); | ||
const tsIndex = plugins.indexOf('typescript'); | ||
plugins.splice(tsIndex, 1); | ||
config = { ...config, plugins }; | ||
} | ||
const ast = parse(code, config); | ||
// Necessary to get the original code in case it was transformed by TypeScript | ||
ast['code'] = code; | ||
return ast; | ||
}; | ||
const getExtNameFromFilePath = (filePath) => { | ||
const partials = filePath.split('.'); | ||
let ext = '.' + partials.pop(); | ||
if (partials.length > 1 && partials[partials.length - 1] == 'flow') { | ||
ext = '.' + partials.pop() + ext; | ||
} | ||
return ext; | ||
}; | ||
const defaults = { | ||
@@ -366,3 +328,3 @@ modules: [ | ||
const gqlExtensions = ['.graphqls', '.graphql', '.gqls', '.gql']; | ||
const jsExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx']; | ||
const jsExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx', '.vue']; | ||
const supportedExtensions = [...gqlExtensions, ...jsExtensions]; | ||
@@ -372,2 +334,24 @@ supportedExtensions.toString = function toString() { | ||
}; | ||
async function pluckVueFileScript(fileData) { | ||
let vueTemplateCompiler; | ||
try { | ||
vueTemplateCompiler = await import('vue-template-compiler'); | ||
} | ||
catch (e) { | ||
throw Error(freeText(` | ||
GraphQL template literals cannot be plucked from a Vue template code without having the "vue-template-compiler" package installed. | ||
Please install it and try again. | ||
Via NPM: | ||
$ npm install vue-template-compiler | ||
Via Yarn: | ||
$ yarn add vue-template-compiler | ||
`)); | ||
} | ||
const parsed = vueTemplateCompiler.parseComponent(fileData); | ||
return parsed.script ? parsed.script.content : ''; | ||
} | ||
const gqlPluckFromFile = async (filePath, options = {}) => { | ||
@@ -389,3 +373,6 @@ if (typeof filePath != 'string') { | ||
options = { ...options, fileExt }; | ||
const code = readFileSync(filePath, { encoding: 'utf8' }); | ||
let code = readFileSync(filePath, { encoding: 'utf8' }); | ||
if (fileExt === '.vue') { | ||
code = await pluckVueFileScript(code); | ||
} | ||
return gqlPluckFromCodeString(code, options); | ||
@@ -409,4 +396,4 @@ }; | ||
const out = { returnValue: null }; | ||
const ast = await parseCode(code, generateConfig(code, options)); | ||
const visitor = createVisitor(ast['code'], out, options); | ||
const ast = parse(code, generateConfig(code, options)); | ||
const visitor = createVisitor(code, out, options); | ||
traverse(ast, visitor); | ||
@@ -413,0 +400,0 @@ return out.returnValue; |
{ | ||
"name": "@graphql-toolkit/graphql-tag-pluck", | ||
"version": "0.7.5-alpha-80a7ba8.2+80a7ba8", | ||
"version": "0.7.5-alpha-82e33fe.21+82e33fe", | ||
"description": "Pluck graphql-tag template literals", | ||
@@ -13,8 +13,14 @@ "peerDependencies": { | ||
"typings": "index.d.ts", | ||
"typescript": { | ||
"definition": "index.d.ts" | ||
}, | ||
"dependencies": { | ||
"@babel/parser": "7.7.4", | ||
"@babel/parser": "7.7.5", | ||
"@babel/traverse": "7.7.4", | ||
"@babel/types": "7.7.4" | ||
}, | ||
"optionalDependencies": { | ||
"vue-template-compiler": "^2.6.10" | ||
}, | ||
"sideEffects": false | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
33843
5
9
848
+ Added@babel/parser@7.7.5(transitive)
+ Addedde-indent@1.0.2(transitive)
+ Addedhe@1.2.0(transitive)
+ Addedvue-template-compiler@2.7.16(transitive)
- Removed@babel/parser@7.7.4(transitive)
Updated@babel/parser@7.7.5