@graphql-tools/graphql-tag-pluck
Advanced tools
Comparing version 8.3.2 to 8.3.3-rc-20241015101353-cc23e138ad6c3e2bc907716b1f8cb1ba3debfe8d
@@ -75,2 +75,11 @@ "use strict"; | ||
break; | ||
case '.gts': | ||
plugins.push('typescript'); | ||
break; | ||
case '.gjs': | ||
// .gjs files need to be parsed as TypeScript because Ember relies on decorators, which are handled by TypeScript. | ||
// without this, it throws a SyntaxError: Unexpected token, expected "{" | ||
// when native decorators are supported, we should remove this | ||
plugins.push('typescript'); | ||
break; | ||
default: | ||
@@ -77,0 +86,0 @@ plugins.push('jsx', ...dynamicFlowPlugins); |
@@ -31,2 +31,4 @@ "use strict"; | ||
'.astro', | ||
'.gts', | ||
'.gjs', | ||
]; | ||
@@ -66,2 +68,6 @@ // tslint:disable-next-line: no-implicit-dependencies | ||
} | ||
function transformGlimmerFile(glimmerSyntax, fileData) { | ||
const processor = new glimmerSyntax.Preprocessor(); | ||
return processor.process(fileData); | ||
} | ||
/** | ||
@@ -92,2 +98,5 @@ * Asynchronously plucks GraphQL template literals from a single file. | ||
} | ||
else if (fileExt === '.gts' || fileExt === '.gjs') { | ||
code = await pluckGlimmerFileScript(code); | ||
} | ||
const sources = parseCode({ code, filePath, options }).map(t => new graphql_1.Source(t.content, filePath, t.loc.start)); | ||
@@ -103,3 +112,3 @@ if (blockSource) { | ||
* | ||
* Supported file extensions include: `.js`, `.mjs`, `.cjs`, `.jsx`, `.ts`, `.mjs`, `.cjs`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`, `.astro` | ||
* Supported file extensions include: `.js`, `.mjs`, `.cjs`, `.jsx`, `.ts`, `.mjs`, `.cjs`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`, `.astro`, `.gts`, `.gjs` | ||
* | ||
@@ -126,2 +135,5 @@ * @param filePath Path to the file containing the code. Required to detect the file type | ||
} | ||
else if (fileExt === '.gts' || fileExt === '.gjs') { | ||
code = pluckGlimmerFileScriptSync(code); | ||
} | ||
const sources = parseCode({ code, filePath, options }).map(t => new graphql_1.Source(t.content, filePath, t.loc.start)); | ||
@@ -195,2 +207,14 @@ if (blockSource) { | ||
`)); | ||
const MissingGlimmerCompilerError = new Error((0, utils_js_1.freeText)(` | ||
GraphQL template literals cannot be plucked from a Glimmer template code without having the "content-tag" package installed. | ||
Please install it and try again. | ||
Via NPM: | ||
$ npm install content-tag | ||
Via Yarn: | ||
$ yarn add content-tag | ||
`)); | ||
async function loadVueCompilerAsync() { | ||
@@ -274,1 +298,21 @@ try { | ||
} | ||
async function pluckGlimmerFileScript(fileData) { | ||
let contentTag; | ||
try { | ||
contentTag = await Promise.resolve().then(() => tslib_1.__importStar(require('content-tag'))); | ||
} | ||
catch { | ||
throw MissingGlimmerCompilerError; | ||
} | ||
return transformGlimmerFile(contentTag, fileData); | ||
} | ||
function pluckGlimmerFileScriptSync(fileData) { | ||
let contentTag; | ||
try { | ||
contentTag = require('content-tag'); | ||
} | ||
catch { | ||
throw MissingGlimmerCompilerError; | ||
} | ||
return transformGlimmerFile(contentTag, fileData); | ||
} |
@@ -73,2 +73,11 @@ import { getExtNameFromFilePath } from './libs/extname.js'; | ||
break; | ||
case '.gts': | ||
plugins.push('typescript'); | ||
break; | ||
case '.gjs': | ||
// .gjs files need to be parsed as TypeScript because Ember relies on decorators, which are handled by TypeScript. | ||
// without this, it throws a SyntaxError: Unexpected token, expected "{" | ||
// when native decorators are supported, we should remove this | ||
plugins.push('typescript'); | ||
break; | ||
default: | ||
@@ -75,0 +84,0 @@ plugins.push('jsx', ...dynamicFlowPlugins); |
@@ -29,2 +29,4 @@ import { createRequire } from 'node:module'; | ||
'.astro', | ||
'.gts', | ||
'.gjs', | ||
]; | ||
@@ -64,2 +66,6 @@ // tslint:disable-next-line: no-implicit-dependencies | ||
} | ||
function transformGlimmerFile(glimmerSyntax, fileData) { | ||
const processor = new glimmerSyntax.Preprocessor(); | ||
return processor.process(fileData); | ||
} | ||
/** | ||
@@ -90,2 +96,5 @@ * Asynchronously plucks GraphQL template literals from a single file. | ||
} | ||
else if (fileExt === '.gts' || fileExt === '.gjs') { | ||
code = await pluckGlimmerFileScript(code); | ||
} | ||
const sources = parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start)); | ||
@@ -100,3 +109,3 @@ if (blockSource) { | ||
* | ||
* Supported file extensions include: `.js`, `.mjs`, `.cjs`, `.jsx`, `.ts`, `.mjs`, `.cjs`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`, `.astro` | ||
* Supported file extensions include: `.js`, `.mjs`, `.cjs`, `.jsx`, `.ts`, `.mjs`, `.cjs`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`, `.astro`, `.gts`, `.gjs` | ||
* | ||
@@ -123,2 +132,5 @@ * @param filePath Path to the file containing the code. Required to detect the file type | ||
} | ||
else if (fileExt === '.gts' || fileExt === '.gjs') { | ||
code = pluckGlimmerFileScriptSync(code); | ||
} | ||
const sources = parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start)); | ||
@@ -190,2 +202,14 @@ if (blockSource) { | ||
`)); | ||
const MissingGlimmerCompilerError = new Error(freeText(` | ||
GraphQL template literals cannot be plucked from a Glimmer template code without having the "content-tag" package installed. | ||
Please install it and try again. | ||
Via NPM: | ||
$ npm install content-tag | ||
Via Yarn: | ||
$ yarn add content-tag | ||
`)); | ||
async function loadVueCompilerAsync() { | ||
@@ -269,1 +293,21 @@ try { | ||
} | ||
async function pluckGlimmerFileScript(fileData) { | ||
let contentTag; | ||
try { | ||
contentTag = await import('content-tag'); | ||
} | ||
catch { | ||
throw MissingGlimmerCompilerError; | ||
} | ||
return transformGlimmerFile(contentTag, fileData); | ||
} | ||
function pluckGlimmerFileScriptSync(fileData) { | ||
let contentTag; | ||
try { | ||
contentTag = require('content-tag'); | ||
} | ||
catch { | ||
throw MissingGlimmerCompilerError; | ||
} | ||
return transformGlimmerFile(contentTag, fileData); | ||
} |
{ | ||
"name": "@graphql-tools/graphql-tag-pluck", | ||
"version": "8.3.2", | ||
"version": "8.3.3-rc-20241015101353-cc23e138ad6c3e2bc907716b1f8cb1ba3debfe8d", | ||
"description": "Pluck graphql-tag template literals", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -131,3 +131,3 @@ import { Source } from 'graphql'; | ||
* | ||
* Supported file extensions include: `.js`, `.mjs`, `.cjs`, `.jsx`, `.ts`, `.mjs`, `.cjs`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`, `.astro` | ||
* Supported file extensions include: `.js`, `.mjs`, `.cjs`, `.jsx`, `.ts`, `.mjs`, `.cjs`, `.tsx`, `.flow`, `.flow.js`, `.flow.jsx`, `.vue`, `.svelte`, `.astro`, `.gts`, `.gjs` | ||
* | ||
@@ -134,0 +134,0 @@ * @param filePath Path to the file containing the code. Required to detect the file type |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
70017
1712
2