@graphql-tools/graphql-tag-pluck 7.2.0 → 7.2.3
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/index.d.ts +2 -2
- package/index.js +51 -3
- package/index.mjs +51 -3
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -104,7 +104,7 @@ export interface GraphQLTagPluckOptions {
|
|
|
104
104
|
/**
|
|
105
105
|
* Asynchronously plucks GraphQL template literals from a single file.
|
|
106
106
|
*
|
|
107
|
-
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`
|
|
107
|
+
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`
|
|
108
108
|
*
|
|
109
109
|
* @param filePath Path to the file containing the code. Required to detect the file type
|
|
110
110
|
* @param code The contents of the file being parsed.
|
|
@@ -114,7 +114,7 @@ export declare const gqlPluckFromCodeString: (filePath: string, code: string, op
|
|
|
114
114
|
/**
|
|
115
115
|
* Synchronously plucks GraphQL template literals from a single file
|
|
116
116
|
*
|
|
117
|
-
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`
|
|
117
|
+
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`
|
|
118
118
|
*
|
|
119
119
|
* @param filePath Path to the file containing the code. Required to detect the file type
|
|
120
120
|
* @param code The contents of the file being parsed.
|
package/index.js
CHANGED
|
@@ -96,6 +96,9 @@ function generateConfig(filePath, code, _options) {
|
|
|
96
96
|
case '.vue':
|
|
97
97
|
plugins.push('typescript', 'vue');
|
|
98
98
|
break;
|
|
99
|
+
case '.svelte':
|
|
100
|
+
plugins.push('typescript', 'svelte');
|
|
101
|
+
break;
|
|
99
102
|
default:
|
|
100
103
|
plugins.push('jsx', ...dynamicFlowPlugins);
|
|
101
104
|
break;
|
|
@@ -448,7 +451,7 @@ function getDefault(module) {
|
|
|
448
451
|
return module.default || module;
|
|
449
452
|
}
|
|
450
453
|
const traverse = getDefault(traversePkg);
|
|
451
|
-
const supportedExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx', '.vue'];
|
|
454
|
+
const supportedExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx', '.vue', '.svelte'];
|
|
452
455
|
// tslint:disable-next-line: no-implicit-dependencies
|
|
453
456
|
function parseWithVue(vueTemplateCompiler, fileData) {
|
|
454
457
|
const { descriptor } = vueTemplateCompiler.parse(fileData);
|
|
@@ -456,10 +459,15 @@ function parseWithVue(vueTemplateCompiler, fileData) {
|
|
|
456
459
|
? vueTemplateCompiler.compileScript(descriptor, { id: Date.now().toString() }).content
|
|
457
460
|
: '';
|
|
458
461
|
}
|
|
462
|
+
// tslint:disable-next-line: no-implicit-dependencies
|
|
463
|
+
function parseWithSvelte(svelte2tsx, fileData) {
|
|
464
|
+
const fileInTsx = svelte2tsx.svelte2tsx(fileData);
|
|
465
|
+
return fileInTsx.code;
|
|
466
|
+
}
|
|
459
467
|
/**
|
|
460
468
|
* Asynchronously plucks GraphQL template literals from a single file.
|
|
461
469
|
*
|
|
462
|
-
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`
|
|
470
|
+
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`
|
|
463
471
|
*
|
|
464
472
|
* @param filePath Path to the file containing the code. Required to detect the file type
|
|
465
473
|
* @param code The contents of the file being parsed.
|
|
@@ -471,12 +479,15 @@ const gqlPluckFromCodeString = async (filePath, code, options = {}) => {
|
|
|
471
479
|
if (fileExt === '.vue') {
|
|
472
480
|
code = await pluckVueFileScript(code);
|
|
473
481
|
}
|
|
482
|
+
else if (fileExt === '.svelte') {
|
|
483
|
+
code = await pluckSvelteFileScript(code);
|
|
484
|
+
}
|
|
474
485
|
return parseCode({ code, filePath, options }).map(t => new graphql.Source(t.content, filePath, t.loc.start));
|
|
475
486
|
};
|
|
476
487
|
/**
|
|
477
488
|
* Synchronously plucks GraphQL template literals from a single file
|
|
478
489
|
*
|
|
479
|
-
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`
|
|
490
|
+
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`
|
|
480
491
|
*
|
|
481
492
|
* @param filePath Path to the file containing the code. Required to detect the file type
|
|
482
493
|
* @param code The contents of the file being parsed.
|
|
@@ -488,6 +499,9 @@ const gqlPluckFromCodeStringSync = (filePath, code, options = {}) => {
|
|
|
488
499
|
if (fileExt === '.vue') {
|
|
489
500
|
code = pluckVueFileScriptSync(code);
|
|
490
501
|
}
|
|
502
|
+
else if (fileExt === '.svelte') {
|
|
503
|
+
code = pluckSvelteFileScriptSync(code);
|
|
504
|
+
}
|
|
491
505
|
return parseCode({ code, filePath, options }).map(t => new graphql.Source(t.content, filePath, t.loc.start));
|
|
492
506
|
};
|
|
493
507
|
function parseCode({ code, filePath, options, }) {
|
|
@@ -526,6 +540,18 @@ const MissingVueTemplateCompilerError = new Error(freeText(`
|
|
|
526
540
|
|
|
527
541
|
$ yarn add @vue/compiler-sfc
|
|
528
542
|
`));
|
|
543
|
+
const MissingSvelteTemplateCompilerError = new Error(freeText(`
|
|
544
|
+
GraphQL template literals cannot be plucked from a Svelte template code without having the "svelte2tsx" & "svelte" package installed.
|
|
545
|
+
Please install it and try again.
|
|
546
|
+
|
|
547
|
+
Via NPM:
|
|
548
|
+
|
|
549
|
+
$ npm install svelte2tsx svelte
|
|
550
|
+
|
|
551
|
+
Via Yarn:
|
|
552
|
+
|
|
553
|
+
$ yarn add svelte2tsx svelte
|
|
554
|
+
`));
|
|
529
555
|
async function pluckVueFileScript(fileData) {
|
|
530
556
|
let vueTemplateCompiler;
|
|
531
557
|
try {
|
|
@@ -548,6 +574,28 @@ function pluckVueFileScriptSync(fileData) {
|
|
|
548
574
|
}
|
|
549
575
|
return parseWithVue(vueTemplateCompiler, fileData);
|
|
550
576
|
}
|
|
577
|
+
async function pluckSvelteFileScript(fileData) {
|
|
578
|
+
let svelte2tsx;
|
|
579
|
+
try {
|
|
580
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
581
|
+
svelte2tsx = await new Promise(function (resolve) { resolve(_interopNamespace(require('svelte2tsx'))); });
|
|
582
|
+
}
|
|
583
|
+
catch (e) {
|
|
584
|
+
throw MissingSvelteTemplateCompilerError;
|
|
585
|
+
}
|
|
586
|
+
return parseWithSvelte(svelte2tsx, fileData);
|
|
587
|
+
}
|
|
588
|
+
function pluckSvelteFileScriptSync(fileData) {
|
|
589
|
+
let svelte2tsx;
|
|
590
|
+
try {
|
|
591
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
592
|
+
svelte2tsx = require('svelte2tsx');
|
|
593
|
+
}
|
|
594
|
+
catch (e) {
|
|
595
|
+
throw MissingSvelteTemplateCompilerError;
|
|
596
|
+
}
|
|
597
|
+
return parseWithSvelte(svelte2tsx, fileData);
|
|
598
|
+
}
|
|
551
599
|
|
|
552
600
|
exports.gqlPluckFromCodeString = gqlPluckFromCodeString;
|
|
553
601
|
exports.gqlPluckFromCodeStringSync = gqlPluckFromCodeStringSync;
|
package/index.mjs
CHANGED
|
@@ -71,6 +71,9 @@ function generateConfig(filePath, code, _options) {
|
|
|
71
71
|
case '.vue':
|
|
72
72
|
plugins.push('typescript', 'vue');
|
|
73
73
|
break;
|
|
74
|
+
case '.svelte':
|
|
75
|
+
plugins.push('typescript', 'svelte');
|
|
76
|
+
break;
|
|
74
77
|
default:
|
|
75
78
|
plugins.push('jsx', ...dynamicFlowPlugins);
|
|
76
79
|
break;
|
|
@@ -423,7 +426,7 @@ function getDefault(module) {
|
|
|
423
426
|
return module.default || module;
|
|
424
427
|
}
|
|
425
428
|
const traverse = getDefault(traversePkg);
|
|
426
|
-
const supportedExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx', '.vue'];
|
|
429
|
+
const supportedExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx', '.vue', '.svelte'];
|
|
427
430
|
// tslint:disable-next-line: no-implicit-dependencies
|
|
428
431
|
function parseWithVue(vueTemplateCompiler, fileData) {
|
|
429
432
|
const { descriptor } = vueTemplateCompiler.parse(fileData);
|
|
@@ -431,10 +434,15 @@ function parseWithVue(vueTemplateCompiler, fileData) {
|
|
|
431
434
|
? vueTemplateCompiler.compileScript(descriptor, { id: Date.now().toString() }).content
|
|
432
435
|
: '';
|
|
433
436
|
}
|
|
437
|
+
// tslint:disable-next-line: no-implicit-dependencies
|
|
438
|
+
function parseWithSvelte(svelte2tsx, fileData) {
|
|
439
|
+
const fileInTsx = svelte2tsx.svelte2tsx(fileData);
|
|
440
|
+
return fileInTsx.code;
|
|
441
|
+
}
|
|
434
442
|
/**
|
|
435
443
|
* Asynchronously plucks GraphQL template literals from a single file.
|
|
436
444
|
*
|
|
437
|
-
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`
|
|
445
|
+
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`
|
|
438
446
|
*
|
|
439
447
|
* @param filePath Path to the file containing the code. Required to detect the file type
|
|
440
448
|
* @param code The contents of the file being parsed.
|
|
@@ -446,12 +454,15 @@ const gqlPluckFromCodeString = async (filePath, code, options = {}) => {
|
|
|
446
454
|
if (fileExt === '.vue') {
|
|
447
455
|
code = await pluckVueFileScript(code);
|
|
448
456
|
}
|
|
457
|
+
else if (fileExt === '.svelte') {
|
|
458
|
+
code = await pluckSvelteFileScript(code);
|
|
459
|
+
}
|
|
449
460
|
return parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start));
|
|
450
461
|
};
|
|
451
462
|
/**
|
|
452
463
|
* Synchronously plucks GraphQL template literals from a single file
|
|
453
464
|
*
|
|
454
|
-
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`
|
|
465
|
+
* Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`
|
|
455
466
|
*
|
|
456
467
|
* @param filePath Path to the file containing the code. Required to detect the file type
|
|
457
468
|
* @param code The contents of the file being parsed.
|
|
@@ -463,6 +474,9 @@ const gqlPluckFromCodeStringSync = (filePath, code, options = {}) => {
|
|
|
463
474
|
if (fileExt === '.vue') {
|
|
464
475
|
code = pluckVueFileScriptSync(code);
|
|
465
476
|
}
|
|
477
|
+
else if (fileExt === '.svelte') {
|
|
478
|
+
code = pluckSvelteFileScriptSync(code);
|
|
479
|
+
}
|
|
466
480
|
return parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start));
|
|
467
481
|
};
|
|
468
482
|
function parseCode({ code, filePath, options, }) {
|
|
@@ -501,6 +515,18 @@ const MissingVueTemplateCompilerError = new Error(freeText(`
|
|
|
501
515
|
|
|
502
516
|
$ yarn add @vue/compiler-sfc
|
|
503
517
|
`));
|
|
518
|
+
const MissingSvelteTemplateCompilerError = new Error(freeText(`
|
|
519
|
+
GraphQL template literals cannot be plucked from a Svelte template code without having the "svelte2tsx" & "svelte" package installed.
|
|
520
|
+
Please install it and try again.
|
|
521
|
+
|
|
522
|
+
Via NPM:
|
|
523
|
+
|
|
524
|
+
$ npm install svelte2tsx svelte
|
|
525
|
+
|
|
526
|
+
Via Yarn:
|
|
527
|
+
|
|
528
|
+
$ yarn add svelte2tsx svelte
|
|
529
|
+
`));
|
|
504
530
|
async function pluckVueFileScript(fileData) {
|
|
505
531
|
let vueTemplateCompiler;
|
|
506
532
|
try {
|
|
@@ -523,5 +549,27 @@ function pluckVueFileScriptSync(fileData) {
|
|
|
523
549
|
}
|
|
524
550
|
return parseWithVue(vueTemplateCompiler, fileData);
|
|
525
551
|
}
|
|
552
|
+
async function pluckSvelteFileScript(fileData) {
|
|
553
|
+
let svelte2tsx;
|
|
554
|
+
try {
|
|
555
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
556
|
+
svelte2tsx = await import('svelte2tsx');
|
|
557
|
+
}
|
|
558
|
+
catch (e) {
|
|
559
|
+
throw MissingSvelteTemplateCompilerError;
|
|
560
|
+
}
|
|
561
|
+
return parseWithSvelte(svelte2tsx, fileData);
|
|
562
|
+
}
|
|
563
|
+
function pluckSvelteFileScriptSync(fileData) {
|
|
564
|
+
let svelte2tsx;
|
|
565
|
+
try {
|
|
566
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
567
|
+
svelte2tsx = require('svelte2tsx');
|
|
568
|
+
}
|
|
569
|
+
catch (e) {
|
|
570
|
+
throw MissingSvelteTemplateCompilerError;
|
|
571
|
+
}
|
|
572
|
+
return parseWithSvelte(svelte2tsx, fileData);
|
|
573
|
+
}
|
|
526
574
|
|
|
527
575
|
export { gqlPluckFromCodeString, gqlPluckFromCodeStringSync, parseCode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/graphql-tag-pluck",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.3",
|
|
4
4
|
"description": "Pluck graphql-tag template literals",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@babel/parser": "^7.16.8",
|
|
11
11
|
"@babel/traverse": "^7.16.8",
|
|
12
12
|
"@babel/types": "^7.16.8",
|
|
13
|
-
"@graphql-tools/utils": "8.6.
|
|
13
|
+
"@graphql-tools/utils": "8.6.6",
|
|
14
14
|
"tslib": "~2.3.0"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|