@graphql-codegen/cli 3.2.2-alpha-20230302095526-48dfe8bf9 → 3.2.2-alpha-20230303164721-1b08466b3
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/config.js +18 -44
- package/cjs/utils/file-system.js +1 -7
- package/esm/config.js +19 -44
- package/esm/utils/file-system.js +0 -5
- package/package.json +2 -1
- package/typings/utils/file-system.d.cts +0 -1
- package/typings/utils/file-system.d.ts +0 -1
package/cjs/config.js
CHANGED
|
@@ -10,14 +10,12 @@ const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
|
10
10
|
const cosmiconfig_1 = require("cosmiconfig");
|
|
11
11
|
const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
|
|
12
12
|
const graphql_1 = require("graphql");
|
|
13
|
-
const child_process_1 = require("child_process");
|
|
14
13
|
const string_env_interpolation_1 = require("string-env-interpolation");
|
|
15
14
|
const yaml_1 = tslib_1.__importDefault(require("yaml"));
|
|
16
15
|
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
17
16
|
const graphql_config_js_1 = require("./graphql-config.js");
|
|
18
17
|
const load_js_1 = require("./load.js");
|
|
19
|
-
const
|
|
20
|
-
const { lstat, rm } = fs_1.promises;
|
|
18
|
+
const { lstat } = fs_1.promises;
|
|
21
19
|
function generateSearchPlaces(moduleName) {
|
|
22
20
|
const extensions = ['json', 'yaml', 'yml', 'js', 'ts', 'config.js'];
|
|
23
21
|
// gives codegen.json...
|
|
@@ -29,7 +27,6 @@ function generateSearchPlaces(moduleName) {
|
|
|
29
27
|
exports.generateSearchPlaces = generateSearchPlaces;
|
|
30
28
|
function customLoader(ext) {
|
|
31
29
|
return async function loader(filepath, content) {
|
|
32
|
-
var _a;
|
|
33
30
|
if (typeof process !== 'undefined' && 'env' in process) {
|
|
34
31
|
content = (0, string_env_interpolation_1.env)(content);
|
|
35
32
|
}
|
|
@@ -49,6 +46,12 @@ function customLoader(ext) {
|
|
|
49
46
|
if (ext === 'js') {
|
|
50
47
|
return cosmiconfig_1.defaultLoaders['.js'](filepath, content);
|
|
51
48
|
}
|
|
49
|
+
if (ext === 'mts' || ext === 'cts') {
|
|
50
|
+
const jiti = require('jiti')(__filename, {
|
|
51
|
+
interopDefault: true,
|
|
52
|
+
});
|
|
53
|
+
return jiti(filepath);
|
|
54
|
+
}
|
|
52
55
|
if (ext === 'ts') {
|
|
53
56
|
try {
|
|
54
57
|
// #8437: conflict with `graphql-config` also using TypeScriptLoader(), causing a double `ts-node` register.
|
|
@@ -57,37 +60,10 @@ function customLoader(ext) {
|
|
|
57
60
|
}
|
|
58
61
|
catch (err) {
|
|
59
62
|
if (isRequireESMError(err)) {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
let inTempDir = [];
|
|
63
|
-
try {
|
|
64
|
-
inTempDir = await fs_1.promises.readdir(tempDir);
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
if (err.code === 'ENOENT') {
|
|
68
|
-
// tsc will create the directory if it doesn't exist.
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
throw err;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
let outDir = (0, path_1.join)(tempDir, new Date().getTime() + '-' + hash);
|
|
75
|
-
const previousOutDir = inTempDir.find(s => s.endsWith(hash));
|
|
76
|
-
if (previousOutDir) {
|
|
77
|
-
outDir = (0, path_1.join)(tempDir, previousOutDir);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
// We're compiling the file, because ts-node doesn't work perfectly with ESM.
|
|
81
|
-
(0, child_process_1.execSync)(`tsc ${filepath} --module commonjs --outDir ${outDir} --skipLibCheck`);
|
|
82
|
-
}
|
|
83
|
-
const newPath = (0, path_1.join)(outDir, (0, path_1.basename)(filepath).replace(/\.ts$/, '.js'));
|
|
84
|
-
const config = (_a = newPath, Promise.resolve().then(() => tslib_1.__importStar(require(_a)))).then(m => {
|
|
85
|
-
const config = m.default;
|
|
86
|
-
return 'default' in config ? config.default : config;
|
|
63
|
+
const jiti = require('jiti')(__filename, {
|
|
64
|
+
interopDefault: true,
|
|
87
65
|
});
|
|
88
|
-
|
|
89
|
-
await removeOldestDirInCache(inTempDir, tempDir, 10);
|
|
90
|
-
return config;
|
|
66
|
+
return jiti(filepath);
|
|
91
67
|
}
|
|
92
68
|
throw err;
|
|
93
69
|
}
|
|
@@ -107,6 +83,8 @@ async function loadCodegenConfig({ configFilePath, moduleName, searchPlaces: add
|
|
|
107
83
|
'.yml': customLoader('yaml'),
|
|
108
84
|
'.js': customLoader('js'),
|
|
109
85
|
'.ts': customLoader('ts'),
|
|
86
|
+
'.mts': customLoader('ts'),
|
|
87
|
+
'.cts': customLoader('ts'),
|
|
110
88
|
noExt: customLoader('yaml'),
|
|
111
89
|
...customLoaders,
|
|
112
90
|
},
|
|
@@ -124,6 +102,9 @@ async function loadContext(configFilePath) {
|
|
|
124
102
|
if (isRequireESMError(err)) {
|
|
125
103
|
// TODO: This needs a fix in graphql-config
|
|
126
104
|
}
|
|
105
|
+
else if (isMissingLoaderError(err)) {
|
|
106
|
+
// TODO: This also needs a fix in graphql-config
|
|
107
|
+
}
|
|
127
108
|
else {
|
|
128
109
|
throw err;
|
|
129
110
|
}
|
|
@@ -407,16 +388,9 @@ function shouldEmitLegacyCommonJSImports(config) {
|
|
|
407
388
|
return globalValue;
|
|
408
389
|
}
|
|
409
390
|
exports.shouldEmitLegacyCommonJSImports = shouldEmitLegacyCommonJSImports;
|
|
410
|
-
async function removeOldestDirInCache(inTempDir, tempDir, cacheLimit) {
|
|
411
|
-
if (inTempDir.length > cacheLimit) {
|
|
412
|
-
const oldest = inTempDir.sort((a, b) => {
|
|
413
|
-
const aTime = Number(a.split('-')[0]);
|
|
414
|
-
const bTime = Number(b.split('-')[0]);
|
|
415
|
-
return aTime - bTime;
|
|
416
|
-
})[0];
|
|
417
|
-
await rm((0, path_1.join)(tempDir, oldest), { recursive: true, force: true });
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
391
|
function isRequireESMError(err) {
|
|
421
392
|
return typeof err.stack === 'string' && err.stack.startsWith('Error [ERR_REQUIRE_ESM]:');
|
|
422
393
|
}
|
|
394
|
+
function isMissingLoaderError(err) {
|
|
395
|
+
return typeof err.stack === 'string' && err.stack.startsWith('Error: No loader specified for extension');
|
|
396
|
+
}
|
package/cjs/utils/file-system.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.mkdirp = exports.unlinkFile = exports.readFile = exports.writeFile = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
|
-
const os_1 = require("os");
|
|
6
|
-
const path_1 = require("path");
|
|
7
5
|
const { writeFile: fsWriteFile, readFile: fsReadFile, mkdir } = fs_1.promises;
|
|
8
6
|
function writeFile(filepath, content) {
|
|
9
7
|
return fsWriteFile(filepath, content);
|
|
@@ -21,7 +19,3 @@ function mkdirp(filePath) {
|
|
|
21
19
|
return mkdir(filePath, { recursive: true });
|
|
22
20
|
}
|
|
23
21
|
exports.mkdirp = mkdirp;
|
|
24
|
-
function getTempDir() {
|
|
25
|
-
return (0, path_1.join)((0, os_1.tmpdir)(), `graphql-codegen-cli`);
|
|
26
|
-
}
|
|
27
|
-
exports.getTempDir = getTempDir;
|
package/esm/config.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { createHash } from 'crypto';
|
|
2
2
|
import { promises } from 'fs';
|
|
3
3
|
import { createRequire } from 'module';
|
|
4
|
-
import {
|
|
4
|
+
import { resolve } from 'path';
|
|
5
5
|
import { createNoopProfiler, createProfiler, getCachedDocumentNodeFromSchema, } from '@graphql-codegen/plugin-helpers';
|
|
6
6
|
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
|
|
7
7
|
import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
|
|
8
8
|
import { print } from 'graphql';
|
|
9
|
-
import { execSync } from 'child_process';
|
|
10
9
|
import { env } from 'string-env-interpolation';
|
|
11
10
|
import yaml from 'yaml';
|
|
12
11
|
import yargs from 'yargs';
|
|
13
12
|
import { findAndLoadGraphQLConfig } from './graphql-config.js';
|
|
14
13
|
import { defaultDocumentsLoadOptions, defaultSchemaLoadOptions, loadDocuments, loadSchema } from './load.js';
|
|
15
|
-
|
|
16
|
-
const { lstat, rm } = promises;
|
|
14
|
+
const { lstat } = promises;
|
|
17
15
|
export function generateSearchPlaces(moduleName) {
|
|
18
16
|
const extensions = ['json', 'yaml', 'yml', 'js', 'ts', 'config.js'];
|
|
19
17
|
// gives codegen.json...
|
|
@@ -43,6 +41,12 @@ function customLoader(ext) {
|
|
|
43
41
|
if (ext === 'js') {
|
|
44
42
|
return defaultLoaders['.js'](filepath, content);
|
|
45
43
|
}
|
|
44
|
+
if (ext === 'mts' || ext === 'cts') {
|
|
45
|
+
const jiti = require('jiti')(__filename, {
|
|
46
|
+
interopDefault: true,
|
|
47
|
+
});
|
|
48
|
+
return jiti(filepath);
|
|
49
|
+
}
|
|
46
50
|
if (ext === 'ts') {
|
|
47
51
|
try {
|
|
48
52
|
// #8437: conflict with `graphql-config` also using TypeScriptLoader(), causing a double `ts-node` register.
|
|
@@ -51,37 +55,10 @@ function customLoader(ext) {
|
|
|
51
55
|
}
|
|
52
56
|
catch (err) {
|
|
53
57
|
if (isRequireESMError(err)) {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
let inTempDir = [];
|
|
57
|
-
try {
|
|
58
|
-
inTempDir = await promises.readdir(tempDir);
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
if (err.code === 'ENOENT') {
|
|
62
|
-
// tsc will create the directory if it doesn't exist.
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
throw err;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
let outDir = join(tempDir, new Date().getTime() + '-' + hash);
|
|
69
|
-
const previousOutDir = inTempDir.find(s => s.endsWith(hash));
|
|
70
|
-
if (previousOutDir) {
|
|
71
|
-
outDir = join(tempDir, previousOutDir);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// We're compiling the file, because ts-node doesn't work perfectly with ESM.
|
|
75
|
-
execSync(`tsc ${filepath} --module commonjs --outDir ${outDir} --skipLibCheck`);
|
|
76
|
-
}
|
|
77
|
-
const newPath = join(outDir, basename(filepath).replace(/\.ts$/, '.js'));
|
|
78
|
-
const config = import(newPath).then(m => {
|
|
79
|
-
const config = m.default;
|
|
80
|
-
return 'default' in config ? config.default : config;
|
|
58
|
+
const jiti = require('jiti')(__filename, {
|
|
59
|
+
interopDefault: true,
|
|
81
60
|
});
|
|
82
|
-
|
|
83
|
-
await removeOldestDirInCache(inTempDir, tempDir, 10);
|
|
84
|
-
return config;
|
|
61
|
+
return jiti(filepath);
|
|
85
62
|
}
|
|
86
63
|
throw err;
|
|
87
64
|
}
|
|
@@ -101,6 +78,8 @@ export async function loadCodegenConfig({ configFilePath, moduleName, searchPlac
|
|
|
101
78
|
'.yml': customLoader('yaml'),
|
|
102
79
|
'.js': customLoader('js'),
|
|
103
80
|
'.ts': customLoader('ts'),
|
|
81
|
+
'.mts': customLoader('ts'),
|
|
82
|
+
'.cts': customLoader('ts'),
|
|
104
83
|
noExt: customLoader('yaml'),
|
|
105
84
|
...customLoaders,
|
|
106
85
|
},
|
|
@@ -117,6 +96,9 @@ export async function loadContext(configFilePath) {
|
|
|
117
96
|
if (isRequireESMError(err)) {
|
|
118
97
|
// TODO: This needs a fix in graphql-config
|
|
119
98
|
}
|
|
99
|
+
else if (isMissingLoaderError(err)) {
|
|
100
|
+
// TODO: This also needs a fix in graphql-config
|
|
101
|
+
}
|
|
120
102
|
else {
|
|
121
103
|
throw err;
|
|
122
104
|
}
|
|
@@ -392,16 +374,9 @@ export function shouldEmitLegacyCommonJSImports(config) {
|
|
|
392
374
|
// }
|
|
393
375
|
return globalValue;
|
|
394
376
|
}
|
|
395
|
-
async function removeOldestDirInCache(inTempDir, tempDir, cacheLimit) {
|
|
396
|
-
if (inTempDir.length > cacheLimit) {
|
|
397
|
-
const oldest = inTempDir.sort((a, b) => {
|
|
398
|
-
const aTime = Number(a.split('-')[0]);
|
|
399
|
-
const bTime = Number(b.split('-')[0]);
|
|
400
|
-
return aTime - bTime;
|
|
401
|
-
})[0];
|
|
402
|
-
await rm(join(tempDir, oldest), { recursive: true, force: true });
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
377
|
function isRequireESMError(err) {
|
|
406
378
|
return typeof err.stack === 'string' && err.stack.startsWith('Error [ERR_REQUIRE_ESM]:');
|
|
407
379
|
}
|
|
380
|
+
function isMissingLoaderError(err) {
|
|
381
|
+
return typeof err.stack === 'string' && err.stack.startsWith('Error: No loader specified for extension');
|
|
382
|
+
}
|
package/esm/utils/file-system.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { promises, unlink as fsUnlink } from 'fs';
|
|
2
|
-
import { tmpdir } from 'os';
|
|
3
|
-
import { join } from 'path';
|
|
4
2
|
const { writeFile: fsWriteFile, readFile: fsReadFile, mkdir } = promises;
|
|
5
3
|
export function writeFile(filepath, content) {
|
|
6
4
|
return fsWriteFile(filepath, content);
|
|
@@ -14,6 +12,3 @@ export function unlinkFile(filePath, cb) {
|
|
|
14
12
|
export function mkdirp(filePath) {
|
|
15
13
|
return mkdir(filePath, { recursive: true });
|
|
16
14
|
}
|
|
17
|
-
export function getTempDir() {
|
|
18
|
-
return join(tmpdir(), `graphql-codegen-cli`);
|
|
19
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "3.2.2-alpha-
|
|
3
|
+
"version": "3.2.2-alpha-20230303164721-1b08466b3",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
6
6
|
"typescript": ">=3.0"
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"graphql-config": "^4.4.0",
|
|
32
32
|
"inquirer": "^8.0.0",
|
|
33
33
|
"is-glob": "^4.0.1",
|
|
34
|
+
"jiti": "^1.17.1",
|
|
34
35
|
"json-to-pretty-yaml": "^1.2.2",
|
|
35
36
|
"listr2": "^4.0.5",
|
|
36
37
|
"log-symbols": "^4.0.0",
|
|
@@ -2,4 +2,3 @@ export declare function writeFile(filepath: string, content: string): Promise<vo
|
|
|
2
2
|
export declare function readFile(filepath: string): Promise<string>;
|
|
3
3
|
export declare function unlinkFile(filePath: string, cb?: (err?: Error) => any): void;
|
|
4
4
|
export declare function mkdirp(filePath: string): Promise<string>;
|
|
5
|
-
export declare function getTempDir(): string;
|
|
@@ -2,4 +2,3 @@ export declare function writeFile(filepath: string, content: string): Promise<vo
|
|
|
2
2
|
export declare function readFile(filepath: string): Promise<string>;
|
|
3
3
|
export declare function unlinkFile(filePath: string, cb?: (err?: Error) => any): void;
|
|
4
4
|
export declare function mkdirp(filePath: string): Promise<string>;
|
|
5
|
-
export declare function getTempDir(): string;
|