Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-toolkit/graphql-tag-pluck

Package Overview
Dependencies
Maintainers
3
Versions
593
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-toolkit/graphql-tag-pluck - npm Package Compare versions

Comparing version 0.7.5-alpha-251d580.10 to 0.7.5-alpha-26c4c55.24

95

index.cjs.js

@@ -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-251d580.10+251d580",
"version": "0.7.5-alpha-26c4c55.24+26c4c55",
"description": "Pluck graphql-tag template literals",

@@ -13,2 +13,5 @@ "peerDependencies": {

"typings": "index.d.ts",
"typescript": {
"definition": "index.d.ts"
},
"dependencies": {

@@ -19,3 +22,6 @@ "@babel/parser": "7.7.5",

},
"optionalDependencies": {
"vue-template-compiler": "^2.6.10"
},
"sideEffects": false
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc