@graphql-codegen/cli 7.1.1 → 7.1.2-alpha-20260531161844-7bcc72c821cb2b20af802be9e68aab66a2cb203e
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/cjs/codegen.js +2 -7
- package/cjs/config.js +17 -2
- package/cjs/isESMModule.js +9 -0
- package/cjs/version.js +1 -1
- package/esm/codegen.js +1 -6
- package/esm/config.js +16 -1
- package/esm/isESMModule.js +6 -0
- package/esm/version.js +1 -1
- package/package.json +3 -3
- package/typings/isESMModule.d.cts +6 -0
- package/typings/isESMModule.d.ts +6 -0
package/cjs/codegen.js
CHANGED
|
@@ -14,22 +14,17 @@ const load_1 = require("@graphql-tools/load");
|
|
|
14
14
|
const merge_1 = require("@graphql-tools/merge");
|
|
15
15
|
const config_js_1 = require("./config.js");
|
|
16
16
|
const documentTransforms_js_1 = require("./documentTransforms.js");
|
|
17
|
+
const isESMModule_js_1 = require("./isESMModule.js");
|
|
17
18
|
const plugins_js_1 = require("./plugins.js");
|
|
18
19
|
const presets_js_1 = require("./presets.js");
|
|
19
20
|
const debugging_js_1 = require("./utils/debugging.js");
|
|
20
|
-
/**
|
|
21
|
-
* Poor mans ESM detection.
|
|
22
|
-
* Looking at this and you have a better method?
|
|
23
|
-
* Send a PR.
|
|
24
|
-
*/
|
|
25
|
-
const isESMModule = (typeof __dirname === 'string') === false;
|
|
26
21
|
const makeDefaultLoader = (from) => {
|
|
27
22
|
if (fs_1.default.statSync(from).isDirectory()) {
|
|
28
23
|
from = path_1.default.join(from, '__fake.js');
|
|
29
24
|
}
|
|
30
25
|
const relativeRequire = (0, module_1.createRequire)(from);
|
|
31
26
|
return async (mod) => {
|
|
32
|
-
return Promise.resolve(`${isESMModule
|
|
27
|
+
return Promise.resolve(`${isESMModule_js_1.isESMModule
|
|
33
28
|
? /**
|
|
34
29
|
* For ESM we currently have no "resolve path" solution
|
|
35
30
|
* as import.meta is unavailable in a CommonJS context
|
package/cjs/config.js
CHANGED
|
@@ -13,6 +13,7 @@ const tslib_1 = require("tslib");
|
|
|
13
13
|
const crypto_1 = require("crypto");
|
|
14
14
|
const fs_1 = require("fs");
|
|
15
15
|
const module_1 = require("module");
|
|
16
|
+
const url = tslib_1.__importStar(require("node:url"));
|
|
16
17
|
const path_1 = require("path");
|
|
17
18
|
const cosmiconfig_1 = require("cosmiconfig");
|
|
18
19
|
const graphql_1 = require("graphql");
|
|
@@ -22,6 +23,7 @@ const yaml_1 = tslib_1.__importDefault(require("yaml"));
|
|
|
22
23
|
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
23
24
|
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
24
25
|
const graphql_config_js_1 = require("./graphql-config.js");
|
|
26
|
+
const isESMModule_js_1 = require("./isESMModule.js");
|
|
25
27
|
const load_js_1 = require("./load.js");
|
|
26
28
|
const version_js_1 = require("./version.js");
|
|
27
29
|
const { lstat } = fs_1.promises;
|
|
@@ -198,9 +200,9 @@ function parseArgv(argv = process.argv) {
|
|
|
198
200
|
async function createContext(cliFlags = parseArgv(process.argv)) {
|
|
199
201
|
if (cliFlags.require && cliFlags.require.length > 0) {
|
|
200
202
|
const relativeRequire = (0, module_1.createRequire)(process.cwd());
|
|
201
|
-
await Promise.all(cliFlags.require.map(mod =>
|
|
203
|
+
await Promise.all(cliFlags.require.map(mod => safeDynamicImport(relativeRequire.resolve(mod, {
|
|
202
204
|
paths: [process.cwd()],
|
|
203
|
-
})
|
|
205
|
+
}))));
|
|
204
206
|
}
|
|
205
207
|
const customConfigPath = getCustomConfigPath(cliFlags);
|
|
206
208
|
const context = await loadContext(customConfigPath);
|
|
@@ -382,3 +384,16 @@ async function addMetadataToSources(documentFilesPromise, type) {
|
|
|
382
384
|
return doc;
|
|
383
385
|
}));
|
|
384
386
|
}
|
|
387
|
+
/**
|
|
388
|
+
* `safeDynamicImport` is a wrapper of dynamic `import()` to work across MacOS and Windows
|
|
389
|
+
* On native Windows (i.e. no WSL or CI), a filename may look like this: `C:\\Users\\path\\to\\file.ts`
|
|
390
|
+
* If used directly with `import()`, we'll see `ERR_UNSUPPORTED_ESM_URL_SCHEME` error because C: is not a valid protocol
|
|
391
|
+
* `url.pathToFileURL` turns the filename to `file:///C:/Users/path/to/file.ts`, which is import-able
|
|
392
|
+
*/
|
|
393
|
+
const safeDynamicImport = (absoluteFilename) => {
|
|
394
|
+
if (isESMModule_js_1.isESMModule) {
|
|
395
|
+
const { href: fileUrl } = url.pathToFileURL(absoluteFilename);
|
|
396
|
+
return Promise.resolve(`${fileUrl}`).then(s => tslib_1.__importStar(require(s)));
|
|
397
|
+
}
|
|
398
|
+
return Promise.resolve(`${absoluteFilename}`).then(s => tslib_1.__importStar(require(s)));
|
|
399
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isESMModule = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Poor mans ESM detection.
|
|
6
|
+
* Looking at this and you have a better method?
|
|
7
|
+
* Send a PR.
|
|
8
|
+
*/
|
|
9
|
+
exports.isESMModule = (typeof __dirname === 'string') === false;
|
package/cjs/version.js
CHANGED
package/esm/codegen.js
CHANGED
|
@@ -10,15 +10,10 @@ import { NoTypeDefinitionsFound } from '@graphql-tools/load';
|
|
|
10
10
|
import { mergeTypeDefs } from '@graphql-tools/merge';
|
|
11
11
|
import { ensureContext } from './config.js';
|
|
12
12
|
import { getDocumentTransform } from './documentTransforms.js';
|
|
13
|
+
import { isESMModule } from './isESMModule.js';
|
|
13
14
|
import { getPluginByName } from './plugins.js';
|
|
14
15
|
import { getPresetByName } from './presets.js';
|
|
15
16
|
import { debugLog, printLogs } from './utils/debugging.js';
|
|
16
|
-
/**
|
|
17
|
-
* Poor mans ESM detection.
|
|
18
|
-
* Looking at this and you have a better method?
|
|
19
|
-
* Send a PR.
|
|
20
|
-
*/
|
|
21
|
-
const isESMModule = (typeof __dirname === 'string') === false;
|
|
22
17
|
const makeDefaultLoader = (from) => {
|
|
23
18
|
if (fs.statSync(from).isDirectory()) {
|
|
24
19
|
from = path.join(from, '__fake.js');
|
package/esm/config.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'crypto';
|
|
2
2
|
import { promises } from 'fs';
|
|
3
3
|
import { createRequire } from 'module';
|
|
4
|
+
import * as url from 'node:url';
|
|
4
5
|
import { resolve } from 'path';
|
|
5
6
|
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
|
|
6
7
|
import { print } from 'graphql';
|
|
@@ -10,6 +11,7 @@ import yaml from 'yaml';
|
|
|
10
11
|
import yargs from 'yargs';
|
|
11
12
|
import { createNoopProfiler, createProfiler, getCachedDocumentNodeFromSchema, } from '@graphql-codegen/plugin-helpers';
|
|
12
13
|
import { findAndLoadGraphQLConfig } from './graphql-config.js';
|
|
14
|
+
import { isESMModule } from './isESMModule.js';
|
|
13
15
|
import { defaultDocumentsLoadOptions, defaultSchemaLoadOptions, loadDocuments, loadSchema, } from './load.js';
|
|
14
16
|
import { version } from './version.js';
|
|
15
17
|
const { lstat } = promises;
|
|
@@ -186,7 +188,7 @@ export function parseArgv(argv = process.argv) {
|
|
|
186
188
|
export async function createContext(cliFlags = parseArgv(process.argv)) {
|
|
187
189
|
if (cliFlags.require && cliFlags.require.length > 0) {
|
|
188
190
|
const relativeRequire = createRequire(process.cwd());
|
|
189
|
-
await Promise.all(cliFlags.require.map(mod =>
|
|
191
|
+
await Promise.all(cliFlags.require.map(mod => safeDynamicImport(relativeRequire.resolve(mod, {
|
|
190
192
|
paths: [process.cwd()],
|
|
191
193
|
}))));
|
|
192
194
|
}
|
|
@@ -369,3 +371,16 @@ async function addMetadataToSources(documentFilesPromise, type) {
|
|
|
369
371
|
return doc;
|
|
370
372
|
}));
|
|
371
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* `safeDynamicImport` is a wrapper of dynamic `import()` to work across MacOS and Windows
|
|
376
|
+
* On native Windows (i.e. no WSL or CI), a filename may look like this: `C:\\Users\\path\\to\\file.ts`
|
|
377
|
+
* If used directly with `import()`, we'll see `ERR_UNSUPPORTED_ESM_URL_SCHEME` error because C: is not a valid protocol
|
|
378
|
+
* `url.pathToFileURL` turns the filename to `file:///C:/Users/path/to/file.ts`, which is import-able
|
|
379
|
+
*/
|
|
380
|
+
const safeDynamicImport = (absoluteFilename) => {
|
|
381
|
+
if (isESMModule) {
|
|
382
|
+
const { href: fileUrl } = url.pathToFileURL(absoluteFilename);
|
|
383
|
+
return import(fileUrl);
|
|
384
|
+
}
|
|
385
|
+
return import(absoluteFilename);
|
|
386
|
+
};
|
package/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '7.1.
|
|
1
|
+
export const version = '7.1.2-alpha-20260531161844-7bcc72c821cb2b20af802be9e68aab66a2cb203e';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.2-alpha-20260531161844-7bcc72c821cb2b20af802be9e68aab66a2cb203e",
|
|
4
4
|
"peerDependenciesMeta": {
|
|
5
5
|
"@parcel/watcher": {
|
|
6
6
|
"optional": true
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"tslib": "^2.4.0",
|
|
44
44
|
"yaml": "^2.3.1",
|
|
45
45
|
"yargs": "^18.0.0",
|
|
46
|
+
"@graphql-codegen/core": "^6.1.0",
|
|
46
47
|
"@graphql-codegen/client-preset": "^6.0.1",
|
|
47
|
-
"@graphql-codegen/plugin-helpers": "^7.0.1"
|
|
48
|
-
"@graphql-codegen/core": "^6.1.0"
|
|
48
|
+
"@graphql-codegen/plugin-helpers": "^7.0.1"
|
|
49
49
|
},
|
|
50
50
|
"repository": {
|
|
51
51
|
"type": "git",
|