@graphql-tools/graphql-tag-pluck 7.2.0 → 7.2.1

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 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
@@ -448,7 +448,7 @@ function getDefault(module) {
448
448
  return module.default || module;
449
449
  }
450
450
  const traverse = getDefault(traversePkg);
451
- const supportedExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx', '.vue'];
451
+ const supportedExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx', '.vue', '.svelte'];
452
452
  // tslint:disable-next-line: no-implicit-dependencies
453
453
  function parseWithVue(vueTemplateCompiler, fileData) {
454
454
  const { descriptor } = vueTemplateCompiler.parse(fileData);
@@ -456,10 +456,15 @@ function parseWithVue(vueTemplateCompiler, fileData) {
456
456
  ? vueTemplateCompiler.compileScript(descriptor, { id: Date.now().toString() }).content
457
457
  : '';
458
458
  }
459
+ // tslint:disable-next-line: no-implicit-dependencies
460
+ function parseWithSvelte(svelte2tsx, fileData) {
461
+ const fileInTsx = svelte2tsx.svelte2tsx(fileData);
462
+ return fileInTsx.code;
463
+ }
459
464
  /**
460
465
  * Asynchronously plucks GraphQL template literals from a single file.
461
466
  *
462
- * Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`
467
+ * Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`
463
468
  *
464
469
  * @param filePath Path to the file containing the code. Required to detect the file type
465
470
  * @param code The contents of the file being parsed.
@@ -471,12 +476,15 @@ const gqlPluckFromCodeString = async (filePath, code, options = {}) => {
471
476
  if (fileExt === '.vue') {
472
477
  code = await pluckVueFileScript(code);
473
478
  }
479
+ else if (fileExt === '.svelte') {
480
+ code = await pluckSvelteFileScript(code);
481
+ }
474
482
  return parseCode({ code, filePath, options }).map(t => new graphql.Source(t.content, filePath, t.loc.start));
475
483
  };
476
484
  /**
477
485
  * Synchronously plucks GraphQL template literals from a single file
478
486
  *
479
- * Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`
487
+ * Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`
480
488
  *
481
489
  * @param filePath Path to the file containing the code. Required to detect the file type
482
490
  * @param code The contents of the file being parsed.
@@ -488,6 +496,9 @@ const gqlPluckFromCodeStringSync = (filePath, code, options = {}) => {
488
496
  if (fileExt === '.vue') {
489
497
  code = pluckVueFileScriptSync(code);
490
498
  }
499
+ else if (fileExt === '.svelte') {
500
+ code = pluckSvelteFileScriptSync(code);
501
+ }
491
502
  return parseCode({ code, filePath, options }).map(t => new graphql.Source(t.content, filePath, t.loc.start));
492
503
  };
493
504
  function parseCode({ code, filePath, options, }) {
@@ -526,6 +537,18 @@ const MissingVueTemplateCompilerError = new Error(freeText(`
526
537
 
527
538
  $ yarn add @vue/compiler-sfc
528
539
  `));
540
+ const MissingSvelteTemplateCompilerError = new Error(freeText(`
541
+ GraphQL template literals cannot be plucked from a Svelte template code without having the "svelte2tsx" & "svelte" package installed.
542
+ Please install it and try again.
543
+
544
+ Via NPM:
545
+
546
+ $ npm install svelte2tsx svelte
547
+
548
+ Via Yarn:
549
+
550
+ $ yarn add svelte2tsx svelte
551
+ `));
529
552
  async function pluckVueFileScript(fileData) {
530
553
  let vueTemplateCompiler;
531
554
  try {
@@ -548,6 +571,28 @@ function pluckVueFileScriptSync(fileData) {
548
571
  }
549
572
  return parseWithVue(vueTemplateCompiler, fileData);
550
573
  }
574
+ async function pluckSvelteFileScript(fileData) {
575
+ let svelte2tsx;
576
+ try {
577
+ // eslint-disable-next-line import/no-extraneous-dependencies
578
+ svelte2tsx = await new Promise(function (resolve) { resolve(_interopNamespace(require('svelte2tsx'))); });
579
+ }
580
+ catch (e) {
581
+ throw MissingSvelteTemplateCompilerError;
582
+ }
583
+ return parseWithSvelte(svelte2tsx, fileData);
584
+ }
585
+ function pluckSvelteFileScriptSync(fileData) {
586
+ let svelte2tsx;
587
+ try {
588
+ // eslint-disable-next-line import/no-extraneous-dependencies
589
+ svelte2tsx = require('svelte2tsx');
590
+ }
591
+ catch (e) {
592
+ throw MissingSvelteTemplateCompilerError;
593
+ }
594
+ return parseWithSvelte(svelte2tsx, fileData);
595
+ }
551
596
 
552
597
  exports.gqlPluckFromCodeString = gqlPluckFromCodeString;
553
598
  exports.gqlPluckFromCodeStringSync = gqlPluckFromCodeStringSync;
package/index.mjs CHANGED
@@ -423,7 +423,7 @@ function getDefault(module) {
423
423
  return module.default || module;
424
424
  }
425
425
  const traverse = getDefault(traversePkg);
426
- const supportedExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx', '.vue'];
426
+ const supportedExtensions = ['.js', '.jsx', '.ts', '.tsx', '.flow', '.flow.js', '.flow.jsx', '.vue', '.svelte'];
427
427
  // tslint:disable-next-line: no-implicit-dependencies
428
428
  function parseWithVue(vueTemplateCompiler, fileData) {
429
429
  const { descriptor } = vueTemplateCompiler.parse(fileData);
@@ -431,10 +431,15 @@ function parseWithVue(vueTemplateCompiler, fileData) {
431
431
  ? vueTemplateCompiler.compileScript(descriptor, { id: Date.now().toString() }).content
432
432
  : '';
433
433
  }
434
+ // tslint:disable-next-line: no-implicit-dependencies
435
+ function parseWithSvelte(svelte2tsx, fileData) {
436
+ const fileInTsx = svelte2tsx.svelte2tsx(fileData);
437
+ return fileInTsx.code;
438
+ }
434
439
  /**
435
440
  * Asynchronously plucks GraphQL template literals from a single file.
436
441
  *
437
- * Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`
442
+ * Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`
438
443
  *
439
444
  * @param filePath Path to the file containing the code. Required to detect the file type
440
445
  * @param code The contents of the file being parsed.
@@ -446,12 +451,15 @@ const gqlPluckFromCodeString = async (filePath, code, options = {}) => {
446
451
  if (fileExt === '.vue') {
447
452
  code = await pluckVueFileScript(code);
448
453
  }
454
+ else if (fileExt === '.svelte') {
455
+ code = await pluckSvelteFileScript(code);
456
+ }
449
457
  return parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start));
450
458
  };
451
459
  /**
452
460
  * Synchronously plucks GraphQL template literals from a single file
453
461
  *
454
- * Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`
462
+ * Supported file extensions include: `.js`, `.jsx`, `.ts`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`
455
463
  *
456
464
  * @param filePath Path to the file containing the code. Required to detect the file type
457
465
  * @param code The contents of the file being parsed.
@@ -463,6 +471,9 @@ const gqlPluckFromCodeStringSync = (filePath, code, options = {}) => {
463
471
  if (fileExt === '.vue') {
464
472
  code = pluckVueFileScriptSync(code);
465
473
  }
474
+ else if (fileExt === '.svelte') {
475
+ code = pluckSvelteFileScriptSync(code);
476
+ }
466
477
  return parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start));
467
478
  };
468
479
  function parseCode({ code, filePath, options, }) {
@@ -501,6 +512,18 @@ const MissingVueTemplateCompilerError = new Error(freeText(`
501
512
 
502
513
  $ yarn add @vue/compiler-sfc
503
514
  `));
515
+ const MissingSvelteTemplateCompilerError = new Error(freeText(`
516
+ GraphQL template literals cannot be plucked from a Svelte template code without having the "svelte2tsx" & "svelte" package installed.
517
+ Please install it and try again.
518
+
519
+ Via NPM:
520
+
521
+ $ npm install svelte2tsx svelte
522
+
523
+ Via Yarn:
524
+
525
+ $ yarn add svelte2tsx svelte
526
+ `));
504
527
  async function pluckVueFileScript(fileData) {
505
528
  let vueTemplateCompiler;
506
529
  try {
@@ -523,5 +546,27 @@ function pluckVueFileScriptSync(fileData) {
523
546
  }
524
547
  return parseWithVue(vueTemplateCompiler, fileData);
525
548
  }
549
+ async function pluckSvelteFileScript(fileData) {
550
+ let svelte2tsx;
551
+ try {
552
+ // eslint-disable-next-line import/no-extraneous-dependencies
553
+ svelte2tsx = await import('svelte2tsx');
554
+ }
555
+ catch (e) {
556
+ throw MissingSvelteTemplateCompilerError;
557
+ }
558
+ return parseWithSvelte(svelte2tsx, fileData);
559
+ }
560
+ function pluckSvelteFileScriptSync(fileData) {
561
+ let svelte2tsx;
562
+ try {
563
+ // eslint-disable-next-line import/no-extraneous-dependencies
564
+ svelte2tsx = require('svelte2tsx');
565
+ }
566
+ catch (e) {
567
+ throw MissingSvelteTemplateCompilerError;
568
+ }
569
+ return parseWithSvelte(svelte2tsx, fileData);
570
+ }
526
571
 
527
572
  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.0",
3
+ "version": "7.2.1",
4
4
  "description": "Pluck graphql-tag template literals",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {