@graphql-codegen/cli 6.1.0-alpha-20251107131717-adc4d901f6e53e023001b84e0cef353e6dad8629 → 6.1.0
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 +10 -12
- package/cjs/config.js +15 -13
- package/cjs/utils/patterns.js +9 -15
- package/cjs/utils/watcher.js +9 -13
- package/esm/codegen.js +12 -14
- package/esm/config.js +15 -12
- package/esm/utils/patterns.js +9 -15
- package/esm/utils/watcher.js +9 -13
- package/package.json +5 -5
- package/typings/codegen.d.cts +1 -3
- package/typings/codegen.d.ts +1 -3
- package/typings/config.d.cts +13 -1
- package/typings/config.d.ts +13 -1
- package/typings/utils/patterns.d.cts +9 -8
- package/typings/utils/patterns.d.ts +9 -8
package/cjs/codegen.js
CHANGED
|
@@ -51,7 +51,7 @@ function createCache() {
|
|
|
51
51
|
return value;
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
async function executeCodegen(input
|
|
54
|
+
async function executeCodegen(input) {
|
|
55
55
|
const context = (0, config_js_1.ensureContext)(input);
|
|
56
56
|
const config = context.getConfig();
|
|
57
57
|
const pluginContext = context.getPluginContext();
|
|
@@ -150,14 +150,7 @@ async function executeCodegen(input, options = { onlyGeneratesKeys: {} }) {
|
|
|
150
150
|
{
|
|
151
151
|
title: 'Generate outputs',
|
|
152
152
|
task: (ctx, task) => {
|
|
153
|
-
const
|
|
154
|
-
const foundGeneratesKeys = originalGeneratesKeys.filter(generatesKey => options.onlyGeneratesKeys[generatesKey]);
|
|
155
|
-
const effectiveGeneratesKeys = foundGeneratesKeys.length === 0 ? originalGeneratesKeys : foundGeneratesKeys;
|
|
156
|
-
const hasFilteredDownGeneratesKeys = originalGeneratesKeys.length > effectiveGeneratesKeys.length;
|
|
157
|
-
if (hasFilteredDownGeneratesKeys) {
|
|
158
|
-
(0, debugging_js_1.debugLog)(`[CLI] Generating partial config:\n${effectiveGeneratesKeys.map(key => `- ${key}`).join('\n')}`);
|
|
159
|
-
}
|
|
160
|
-
const generateTasks = effectiveGeneratesKeys.map(filename => {
|
|
153
|
+
const generateTasks = Object.keys(generates).map(filename => {
|
|
161
154
|
const outputConfig = generates[filename];
|
|
162
155
|
const hasPreset = !!outputConfig.preset;
|
|
163
156
|
const title = `Generate to ${filename}`;
|
|
@@ -252,12 +245,17 @@ async function executeCodegen(input, options = { onlyGeneratesKeys: {} }) {
|
|
|
252
245
|
const name = Object.keys(plugin)[0];
|
|
253
246
|
return [name, pkg];
|
|
254
247
|
}));
|
|
248
|
+
const importExtension = (0, plugin_helpers_1.normalizeImportExtension)({
|
|
249
|
+
emitLegacyCommonJSImports: config.emitLegacyCommonJSImports,
|
|
250
|
+
importExtension: config.importExtension,
|
|
251
|
+
});
|
|
255
252
|
const mergedConfig = {
|
|
256
253
|
...rootConfig,
|
|
257
254
|
...(typeof outputFileTemplateConfig === 'string'
|
|
258
255
|
? { value: outputFileTemplateConfig }
|
|
259
256
|
: outputFileTemplateConfig),
|
|
260
|
-
|
|
257
|
+
importExtension,
|
|
258
|
+
emitLegacyCommonJSImports: config.emitLegacyCommonJSImports ?? true,
|
|
261
259
|
};
|
|
262
260
|
const documentTransforms = Array.isArray(outputConfig.documentTransforms)
|
|
263
261
|
? await Promise.all(outputConfig.documentTransforms.map(async (config, index) => {
|
|
@@ -295,8 +293,8 @@ async function executeCodegen(input, options = { onlyGeneratesKeys: {} }) {
|
|
|
295
293
|
const process = async (outputArgs) => {
|
|
296
294
|
const output = await (0, core_1.codegen)({
|
|
297
295
|
...outputArgs,
|
|
298
|
-
|
|
299
|
-
emitLegacyCommonJSImports:
|
|
296
|
+
importExtension,
|
|
297
|
+
emitLegacyCommonJSImports: config.emitLegacyCommonJSImports ?? true,
|
|
300
298
|
cache,
|
|
301
299
|
});
|
|
302
300
|
result.push({
|
package/cjs/config.js
CHANGED
|
@@ -9,7 +9,6 @@ exports.parseArgv = parseArgv;
|
|
|
9
9
|
exports.createContext = createContext;
|
|
10
10
|
exports.updateContextWithCliFlags = updateContextWithCliFlags;
|
|
11
11
|
exports.ensureContext = ensureContext;
|
|
12
|
-
exports.shouldEmitLegacyCommonJSImports = shouldEmitLegacyCommonJSImports;
|
|
13
12
|
const tslib_1 = require("tslib");
|
|
14
13
|
const crypto_1 = require("crypto");
|
|
15
14
|
const fs_1 = require("fs");
|
|
@@ -178,6 +177,18 @@ function buildOptions() {
|
|
|
178
177
|
type: 'boolean',
|
|
179
178
|
default: false,
|
|
180
179
|
},
|
|
180
|
+
'emit-legacy-common-js-imports': {
|
|
181
|
+
describe: 'Emit legacy CommonJS imports (deprecated, use import-extension instead)',
|
|
182
|
+
type: 'boolean',
|
|
183
|
+
},
|
|
184
|
+
'import-extension': {
|
|
185
|
+
describe: 'Extension to append to imports (e.g., .js, .mjs, or empty string for no extension)',
|
|
186
|
+
type: 'string',
|
|
187
|
+
},
|
|
188
|
+
'ignore-no-documents': {
|
|
189
|
+
describe: 'Suppress errors for no documents',
|
|
190
|
+
type: 'boolean',
|
|
191
|
+
},
|
|
181
192
|
};
|
|
182
193
|
}
|
|
183
194
|
function parseArgv(argv = process.argv) {
|
|
@@ -225,6 +236,9 @@ function updateContextWithCliFlags(context, cliFlags) {
|
|
|
225
236
|
// for some reason parsed value is `'false'` string so this ensure it always is a boolean.
|
|
226
237
|
config.emitLegacyCommonJSImports = cliFlags['emit-legacy-common-js-imports'] === true;
|
|
227
238
|
}
|
|
239
|
+
if (cliFlags['import-extension'] !== undefined) {
|
|
240
|
+
config.importExtension = cliFlags['import-extension'];
|
|
241
|
+
}
|
|
228
242
|
if (cliFlags.project) {
|
|
229
243
|
context.useProject(cliFlags.project);
|
|
230
244
|
}
|
|
@@ -352,15 +366,3 @@ function addHashToDocumentFiles(documentFilesPromise) {
|
|
|
352
366
|
return doc;
|
|
353
367
|
}));
|
|
354
368
|
}
|
|
355
|
-
function shouldEmitLegacyCommonJSImports(config) {
|
|
356
|
-
const globalValue = config.emitLegacyCommonJSImports === undefined ? true : !!config.emitLegacyCommonJSImports;
|
|
357
|
-
// const outputConfig = config.generates[outputPath];
|
|
358
|
-
// if (!outputConfig) {
|
|
359
|
-
// debugLog(`Couldn't find a config of ${outputPath}`);
|
|
360
|
-
// return globalValue;
|
|
361
|
-
// }
|
|
362
|
-
// if (isConfiguredOutput(outputConfig) && typeof outputConfig.emitLegacyCommonJSImports === 'boolean') {
|
|
363
|
-
// return outputConfig.emitLegacyCommonJSImports;
|
|
364
|
-
// }
|
|
365
|
-
return globalValue;
|
|
366
|
-
}
|
package/cjs/utils/patterns.js
CHANGED
|
@@ -39,12 +39,9 @@ exports.allAffirmativePatternsFromPatternSets = allAffirmativePatternsFromPatter
|
|
|
39
39
|
* a match even if it would be negated by some pattern in documents or schemas
|
|
40
40
|
* * The trigger returns true if any output target's local patterns result in
|
|
41
41
|
* a match, after considering the precedence of any global and local negations
|
|
42
|
-
*
|
|
43
|
-
* The result is a function that when given an absolute path,
|
|
44
|
-
* it will tell which generates blocks' keys are affected so we can re-run for those keys
|
|
45
42
|
*/
|
|
46
43
|
const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
47
|
-
const localMatchers =
|
|
44
|
+
const localMatchers = localPatternSets.map(localPatternSet => {
|
|
48
45
|
return (path) => {
|
|
49
46
|
// Is path negated by any negating watch pattern?
|
|
50
47
|
if (matchesAnyNegatedPattern(path, [...globalPatternSet.watch.negated, ...localPatternSet.watch.negated])) {
|
|
@@ -57,7 +54,7 @@ const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
57
54
|
...localPatternSet.watch.affirmative,
|
|
58
55
|
])) {
|
|
59
56
|
// Immediately return true: Watch pattern takes priority, even if documents or schema would negate it
|
|
60
|
-
return
|
|
57
|
+
return true;
|
|
61
58
|
}
|
|
62
59
|
// Does path match documents patterns (without being negated)?
|
|
63
60
|
if (matchesAnyAffirmativePattern(path, [
|
|
@@ -65,7 +62,7 @@ const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
65
62
|
...localPatternSet.documents.affirmative,
|
|
66
63
|
]) &&
|
|
67
64
|
!matchesAnyNegatedPattern(path, [...globalPatternSet.documents.negated, ...localPatternSet.documents.negated])) {
|
|
68
|
-
return
|
|
65
|
+
return true;
|
|
69
66
|
}
|
|
70
67
|
// Does path match schemas patterns (without being negated)?
|
|
71
68
|
if (matchesAnyAffirmativePattern(path, [
|
|
@@ -73,25 +70,22 @@ const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
73
70
|
...localPatternSet.schemas.affirmative,
|
|
74
71
|
]) &&
|
|
75
72
|
!matchesAnyNegatedPattern(path, [...globalPatternSet.schemas.negated, ...localPatternSet.schemas.negated])) {
|
|
76
|
-
return
|
|
73
|
+
return true;
|
|
77
74
|
}
|
|
78
75
|
// Otherwise, there is no match
|
|
79
76
|
return false;
|
|
80
77
|
};
|
|
81
78
|
});
|
|
79
|
+
/**
|
|
80
|
+
* Return `true` if `path` should trigger a rebuild
|
|
81
|
+
*/
|
|
82
82
|
return ({ path: absolutePath }) => {
|
|
83
83
|
if (!(0, path_1.isAbsolute)(absolutePath)) {
|
|
84
84
|
throw new Error('shouldRebuild trigger should be called with absolute path');
|
|
85
85
|
}
|
|
86
86
|
const path = (0, path_1.relative)(process.cwd(), absolutePath);
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
const result = matcher(path);
|
|
90
|
-
if (result) {
|
|
91
|
-
generatesKeysToRebuild[result] = true;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return generatesKeysToRebuild;
|
|
87
|
+
const shouldRebuild = localMatchers.some(matcher => matcher(path));
|
|
88
|
+
return shouldRebuild;
|
|
95
89
|
};
|
|
96
90
|
};
|
|
97
91
|
exports.makeShouldRebuild = makeShouldRebuild;
|
package/cjs/utils/watcher.js
CHANGED
|
@@ -26,14 +26,10 @@ const createWatcher = (initialContext, onNext) => {
|
|
|
26
26
|
(0, debugging_js_1.debugLog)(`[Watcher] Starting watcher...`);
|
|
27
27
|
let config = initialContext.getConfig();
|
|
28
28
|
const globalPatternSet = (0, patterns_js_1.makeGlobalPatternSet)(initialContext);
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
localPatternSetArray.push(patternSet);
|
|
34
|
-
return res;
|
|
35
|
-
}, {});
|
|
36
|
-
const allAffirmativePatterns = (0, patterns_js_1.allAffirmativePatternsFromPatternSets)([globalPatternSet, ...localPatternSetArray]);
|
|
29
|
+
const localPatternSets = Object.keys(config.generates)
|
|
30
|
+
.map(filename => (0, plugin_helpers_1.normalizeOutputParam)(config.generates[filename]))
|
|
31
|
+
.map(conf => (0, patterns_js_1.makeLocalPatternSet)(conf));
|
|
32
|
+
const allAffirmativePatterns = (0, patterns_js_1.allAffirmativePatternsFromPatternSets)([globalPatternSet, ...localPatternSets]);
|
|
37
33
|
const shouldRebuild = (0, patterns_js_1.makeShouldRebuild)({ globalPatternSet, localPatternSets });
|
|
38
34
|
let watcherSubscription;
|
|
39
35
|
const runWatcher = async (abortSignal) => {
|
|
@@ -49,9 +45,9 @@ const createWatcher = (initialContext, onNext) => {
|
|
|
49
45
|
}
|
|
50
46
|
(0, debugging_js_1.debugLog)(`[Watcher] Parcel watcher loaded...`);
|
|
51
47
|
let isShutdown = false;
|
|
52
|
-
const debouncedExec = (0, debounce_1.default)((
|
|
48
|
+
const debouncedExec = (0, debounce_1.default)(() => {
|
|
53
49
|
if (!isShutdown) {
|
|
54
|
-
(0, codegen_js_1.executeCodegen)(initialContext
|
|
50
|
+
(0, codegen_js_1.executeCodegen)(initialContext)
|
|
55
51
|
.then(({ result, error }) => {
|
|
56
52
|
// FIXME: this is a quick fix to stop `onNext` (writeOutput) from
|
|
57
53
|
// removing all files when there is an error.
|
|
@@ -90,11 +86,11 @@ const createWatcher = (initialContext, onNext) => {
|
|
|
90
86
|
}
|
|
91
87
|
}
|
|
92
88
|
watcherSubscription = await parcelWatcher.subscribe(watchDirectory, async (_, events) => {
|
|
89
|
+
// it doesn't matter what has changed, need to run whole process anyway
|
|
93
90
|
await Promise.all(
|
|
94
91
|
// NOTE: @parcel/watcher always provides path as an absolute path
|
|
95
92
|
events.map(async ({ type: eventName, path }) => {
|
|
96
|
-
|
|
97
|
-
if (Object.keys(generatesKeysToRebuild).length === 0) {
|
|
93
|
+
if (!shouldRebuild({ path })) {
|
|
98
94
|
return;
|
|
99
95
|
}
|
|
100
96
|
(0, hooks_js_1.lifecycleHooks)(config.hooks).onWatchTriggered(eventName, path);
|
|
@@ -115,7 +111,7 @@ const createWatcher = (initialContext, onNext) => {
|
|
|
115
111
|
config = newParsedConfig;
|
|
116
112
|
initialContext.updateConfig(config);
|
|
117
113
|
}
|
|
118
|
-
debouncedExec(
|
|
114
|
+
debouncedExec();
|
|
119
115
|
}));
|
|
120
116
|
}, { ignore: ignored });
|
|
121
117
|
(0, debugging_js_1.debugLog)(`[Watcher] Started`);
|
package/esm/codegen.js
CHANGED
|
@@ -3,11 +3,11 @@ import { createRequire } from 'module';
|
|
|
3
3
|
import { cpus } from 'os';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { codegen } from '@graphql-codegen/core';
|
|
6
|
-
import { getCachedDocumentNodeFromSchema, normalizeConfig, normalizeInstanceOrArray, normalizeOutputParam, } from '@graphql-codegen/plugin-helpers';
|
|
6
|
+
import { getCachedDocumentNodeFromSchema, normalizeConfig, normalizeImportExtension, normalizeInstanceOrArray, normalizeOutputParam, } from '@graphql-codegen/plugin-helpers';
|
|
7
7
|
import { NoTypeDefinitionsFound } from '@graphql-tools/load';
|
|
8
8
|
import { GraphQLError } from 'graphql';
|
|
9
9
|
import { Listr } from 'listr2';
|
|
10
|
-
import { ensureContext
|
|
10
|
+
import { ensureContext } from './config.js';
|
|
11
11
|
import { getPluginByName } from './plugins.js';
|
|
12
12
|
import { getPresetByName } from './presets.js';
|
|
13
13
|
import { debugLog, printLogs } from './utils/debugging.js';
|
|
@@ -47,7 +47,7 @@ function createCache() {
|
|
|
47
47
|
return value;
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
export async function executeCodegen(input
|
|
50
|
+
export async function executeCodegen(input) {
|
|
51
51
|
const context = ensureContext(input);
|
|
52
52
|
const config = context.getConfig();
|
|
53
53
|
const pluginContext = context.getPluginContext();
|
|
@@ -146,14 +146,7 @@ export async function executeCodegen(input, options = { onlyGeneratesKeys: {} })
|
|
|
146
146
|
{
|
|
147
147
|
title: 'Generate outputs',
|
|
148
148
|
task: (ctx, task) => {
|
|
149
|
-
const
|
|
150
|
-
const foundGeneratesKeys = originalGeneratesKeys.filter(generatesKey => options.onlyGeneratesKeys[generatesKey]);
|
|
151
|
-
const effectiveGeneratesKeys = foundGeneratesKeys.length === 0 ? originalGeneratesKeys : foundGeneratesKeys;
|
|
152
|
-
const hasFilteredDownGeneratesKeys = originalGeneratesKeys.length > effectiveGeneratesKeys.length;
|
|
153
|
-
if (hasFilteredDownGeneratesKeys) {
|
|
154
|
-
debugLog(`[CLI] Generating partial config:\n${effectiveGeneratesKeys.map(key => `- ${key}`).join('\n')}`);
|
|
155
|
-
}
|
|
156
|
-
const generateTasks = effectiveGeneratesKeys.map(filename => {
|
|
149
|
+
const generateTasks = Object.keys(generates).map(filename => {
|
|
157
150
|
const outputConfig = generates[filename];
|
|
158
151
|
const hasPreset = !!outputConfig.preset;
|
|
159
152
|
const title = `Generate to ${filename}`;
|
|
@@ -248,12 +241,17 @@ export async function executeCodegen(input, options = { onlyGeneratesKeys: {} })
|
|
|
248
241
|
const name = Object.keys(plugin)[0];
|
|
249
242
|
return [name, pkg];
|
|
250
243
|
}));
|
|
244
|
+
const importExtension = normalizeImportExtension({
|
|
245
|
+
emitLegacyCommonJSImports: config.emitLegacyCommonJSImports,
|
|
246
|
+
importExtension: config.importExtension,
|
|
247
|
+
});
|
|
251
248
|
const mergedConfig = {
|
|
252
249
|
...rootConfig,
|
|
253
250
|
...(typeof outputFileTemplateConfig === 'string'
|
|
254
251
|
? { value: outputFileTemplateConfig }
|
|
255
252
|
: outputFileTemplateConfig),
|
|
256
|
-
|
|
253
|
+
importExtension,
|
|
254
|
+
emitLegacyCommonJSImports: config.emitLegacyCommonJSImports ?? true,
|
|
257
255
|
};
|
|
258
256
|
const documentTransforms = Array.isArray(outputConfig.documentTransforms)
|
|
259
257
|
? await Promise.all(outputConfig.documentTransforms.map(async (config, index) => {
|
|
@@ -291,8 +289,8 @@ export async function executeCodegen(input, options = { onlyGeneratesKeys: {} })
|
|
|
291
289
|
const process = async (outputArgs) => {
|
|
292
290
|
const output = await codegen({
|
|
293
291
|
...outputArgs,
|
|
294
|
-
|
|
295
|
-
emitLegacyCommonJSImports:
|
|
292
|
+
importExtension,
|
|
293
|
+
emitLegacyCommonJSImports: config.emitLegacyCommonJSImports ?? true,
|
|
296
294
|
cache,
|
|
297
295
|
});
|
|
298
296
|
result.push({
|
package/esm/config.js
CHANGED
|
@@ -165,6 +165,18 @@ export function buildOptions() {
|
|
|
165
165
|
type: 'boolean',
|
|
166
166
|
default: false,
|
|
167
167
|
},
|
|
168
|
+
'emit-legacy-common-js-imports': {
|
|
169
|
+
describe: 'Emit legacy CommonJS imports (deprecated, use import-extension instead)',
|
|
170
|
+
type: 'boolean',
|
|
171
|
+
},
|
|
172
|
+
'import-extension': {
|
|
173
|
+
describe: 'Extension to append to imports (e.g., .js, .mjs, or empty string for no extension)',
|
|
174
|
+
type: 'string',
|
|
175
|
+
},
|
|
176
|
+
'ignore-no-documents': {
|
|
177
|
+
describe: 'Suppress errors for no documents',
|
|
178
|
+
type: 'boolean',
|
|
179
|
+
},
|
|
168
180
|
};
|
|
169
181
|
}
|
|
170
182
|
export function parseArgv(argv = process.argv) {
|
|
@@ -212,6 +224,9 @@ export function updateContextWithCliFlags(context, cliFlags) {
|
|
|
212
224
|
// for some reason parsed value is `'false'` string so this ensure it always is a boolean.
|
|
213
225
|
config.emitLegacyCommonJSImports = cliFlags['emit-legacy-common-js-imports'] === true;
|
|
214
226
|
}
|
|
227
|
+
if (cliFlags['import-extension'] !== undefined) {
|
|
228
|
+
config.importExtension = cliFlags['import-extension'];
|
|
229
|
+
}
|
|
215
230
|
if (cliFlags.project) {
|
|
216
231
|
context.useProject(cliFlags.project);
|
|
217
232
|
}
|
|
@@ -338,15 +353,3 @@ function addHashToDocumentFiles(documentFilesPromise) {
|
|
|
338
353
|
return doc;
|
|
339
354
|
}));
|
|
340
355
|
}
|
|
341
|
-
export function shouldEmitLegacyCommonJSImports(config) {
|
|
342
|
-
const globalValue = config.emitLegacyCommonJSImports === undefined ? true : !!config.emitLegacyCommonJSImports;
|
|
343
|
-
// const outputConfig = config.generates[outputPath];
|
|
344
|
-
// if (!outputConfig) {
|
|
345
|
-
// debugLog(`Couldn't find a config of ${outputPath}`);
|
|
346
|
-
// return globalValue;
|
|
347
|
-
// }
|
|
348
|
-
// if (isConfiguredOutput(outputConfig) && typeof outputConfig.emitLegacyCommonJSImports === 'boolean') {
|
|
349
|
-
// return outputConfig.emitLegacyCommonJSImports;
|
|
350
|
-
// }
|
|
351
|
-
return globalValue;
|
|
352
|
-
}
|
package/esm/utils/patterns.js
CHANGED
|
@@ -34,12 +34,9 @@ export const allAffirmativePatternsFromPatternSets = (patternSets) => {
|
|
|
34
34
|
* a match even if it would be negated by some pattern in documents or schemas
|
|
35
35
|
* * The trigger returns true if any output target's local patterns result in
|
|
36
36
|
* a match, after considering the precedence of any global and local negations
|
|
37
|
-
*
|
|
38
|
-
* The result is a function that when given an absolute path,
|
|
39
|
-
* it will tell which generates blocks' keys are affected so we can re-run for those keys
|
|
40
37
|
*/
|
|
41
38
|
export const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
42
|
-
const localMatchers =
|
|
39
|
+
const localMatchers = localPatternSets.map(localPatternSet => {
|
|
43
40
|
return (path) => {
|
|
44
41
|
// Is path negated by any negating watch pattern?
|
|
45
42
|
if (matchesAnyNegatedPattern(path, [...globalPatternSet.watch.negated, ...localPatternSet.watch.negated])) {
|
|
@@ -52,7 +49,7 @@ export const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
52
49
|
...localPatternSet.watch.affirmative,
|
|
53
50
|
])) {
|
|
54
51
|
// Immediately return true: Watch pattern takes priority, even if documents or schema would negate it
|
|
55
|
-
return
|
|
52
|
+
return true;
|
|
56
53
|
}
|
|
57
54
|
// Does path match documents patterns (without being negated)?
|
|
58
55
|
if (matchesAnyAffirmativePattern(path, [
|
|
@@ -60,7 +57,7 @@ export const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
60
57
|
...localPatternSet.documents.affirmative,
|
|
61
58
|
]) &&
|
|
62
59
|
!matchesAnyNegatedPattern(path, [...globalPatternSet.documents.negated, ...localPatternSet.documents.negated])) {
|
|
63
|
-
return
|
|
60
|
+
return true;
|
|
64
61
|
}
|
|
65
62
|
// Does path match schemas patterns (without being negated)?
|
|
66
63
|
if (matchesAnyAffirmativePattern(path, [
|
|
@@ -68,25 +65,22 @@ export const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
68
65
|
...localPatternSet.schemas.affirmative,
|
|
69
66
|
]) &&
|
|
70
67
|
!matchesAnyNegatedPattern(path, [...globalPatternSet.schemas.negated, ...localPatternSet.schemas.negated])) {
|
|
71
|
-
return
|
|
68
|
+
return true;
|
|
72
69
|
}
|
|
73
70
|
// Otherwise, there is no match
|
|
74
71
|
return false;
|
|
75
72
|
};
|
|
76
73
|
});
|
|
74
|
+
/**
|
|
75
|
+
* Return `true` if `path` should trigger a rebuild
|
|
76
|
+
*/
|
|
77
77
|
return ({ path: absolutePath }) => {
|
|
78
78
|
if (!isAbsolute(absolutePath)) {
|
|
79
79
|
throw new Error('shouldRebuild trigger should be called with absolute path');
|
|
80
80
|
}
|
|
81
81
|
const path = relative(process.cwd(), absolutePath);
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
const result = matcher(path);
|
|
85
|
-
if (result) {
|
|
86
|
-
generatesKeysToRebuild[result] = true;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return generatesKeysToRebuild;
|
|
82
|
+
const shouldRebuild = localMatchers.some(matcher => matcher(path));
|
|
83
|
+
return shouldRebuild;
|
|
90
84
|
};
|
|
91
85
|
};
|
|
92
86
|
/**
|
package/esm/utils/watcher.js
CHANGED
|
@@ -22,14 +22,10 @@ export const createWatcher = (initialContext, onNext) => {
|
|
|
22
22
|
debugLog(`[Watcher] Starting watcher...`);
|
|
23
23
|
let config = initialContext.getConfig();
|
|
24
24
|
const globalPatternSet = makeGlobalPatternSet(initialContext);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
localPatternSetArray.push(patternSet);
|
|
30
|
-
return res;
|
|
31
|
-
}, {});
|
|
32
|
-
const allAffirmativePatterns = allAffirmativePatternsFromPatternSets([globalPatternSet, ...localPatternSetArray]);
|
|
25
|
+
const localPatternSets = Object.keys(config.generates)
|
|
26
|
+
.map(filename => normalizeOutputParam(config.generates[filename]))
|
|
27
|
+
.map(conf => makeLocalPatternSet(conf));
|
|
28
|
+
const allAffirmativePatterns = allAffirmativePatternsFromPatternSets([globalPatternSet, ...localPatternSets]);
|
|
33
29
|
const shouldRebuild = makeShouldRebuild({ globalPatternSet, localPatternSets });
|
|
34
30
|
let watcherSubscription;
|
|
35
31
|
const runWatcher = async (abortSignal) => {
|
|
@@ -45,9 +41,9 @@ export const createWatcher = (initialContext, onNext) => {
|
|
|
45
41
|
}
|
|
46
42
|
debugLog(`[Watcher] Parcel watcher loaded...`);
|
|
47
43
|
let isShutdown = false;
|
|
48
|
-
const debouncedExec = debounce((
|
|
44
|
+
const debouncedExec = debounce(() => {
|
|
49
45
|
if (!isShutdown) {
|
|
50
|
-
executeCodegen(initialContext
|
|
46
|
+
executeCodegen(initialContext)
|
|
51
47
|
.then(({ result, error }) => {
|
|
52
48
|
// FIXME: this is a quick fix to stop `onNext` (writeOutput) from
|
|
53
49
|
// removing all files when there is an error.
|
|
@@ -86,11 +82,11 @@ export const createWatcher = (initialContext, onNext) => {
|
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
watcherSubscription = await parcelWatcher.subscribe(watchDirectory, async (_, events) => {
|
|
85
|
+
// it doesn't matter what has changed, need to run whole process anyway
|
|
89
86
|
await Promise.all(
|
|
90
87
|
// NOTE: @parcel/watcher always provides path as an absolute path
|
|
91
88
|
events.map(async ({ type: eventName, path }) => {
|
|
92
|
-
|
|
93
|
-
if (Object.keys(generatesKeysToRebuild).length === 0) {
|
|
89
|
+
if (!shouldRebuild({ path })) {
|
|
94
90
|
return;
|
|
95
91
|
}
|
|
96
92
|
lifecycleHooks(config.hooks).onWatchTriggered(eventName, path);
|
|
@@ -111,7 +107,7 @@ export const createWatcher = (initialContext, onNext) => {
|
|
|
111
107
|
config = newParsedConfig;
|
|
112
108
|
initialContext.updateConfig(config);
|
|
113
109
|
}
|
|
114
|
-
debouncedExec(
|
|
110
|
+
debouncedExec();
|
|
115
111
|
}));
|
|
116
112
|
}, { ignore: ignored });
|
|
117
113
|
debugLog(`[Watcher] Started`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "6.1.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"peerDependenciesMeta": {
|
|
5
5
|
"@parcel/watcher": {
|
|
6
6
|
"optional": true
|
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
"@babel/generator": "^7.18.13",
|
|
15
15
|
"@babel/template": "^7.18.10",
|
|
16
16
|
"@babel/types": "^7.18.13",
|
|
17
|
-
"@graphql-codegen/client-preset": "^5.
|
|
17
|
+
"@graphql-codegen/client-preset": "^5.2.0",
|
|
18
18
|
"@graphql-codegen/core": "^5.0.0",
|
|
19
|
-
"@graphql-codegen/plugin-helpers": "^6.
|
|
19
|
+
"@graphql-codegen/plugin-helpers": "^6.1.0",
|
|
20
20
|
"@graphql-tools/apollo-engine-loader": "^8.0.0",
|
|
21
21
|
"@graphql-tools/code-file-loader": "^8.0.0",
|
|
22
22
|
"@graphql-tools/git-loader": "^8.0.0",
|
|
23
|
-
"@graphql-tools/github-loader": "^
|
|
23
|
+
"@graphql-tools/github-loader": "^9.0.0",
|
|
24
24
|
"@graphql-tools/graphql-file-loader": "^8.0.0",
|
|
25
25
|
"@graphql-tools/json-file-loader": "^8.0.0",
|
|
26
26
|
"@graphql-tools/load": "^8.1.0",
|
|
27
|
-
"@graphql-tools/url-loader": "^
|
|
27
|
+
"@graphql-tools/url-loader": "^9.0.0",
|
|
28
28
|
"@graphql-tools/utils": "^10.0.0",
|
|
29
29
|
"@inquirer/prompts": "^7.8.2",
|
|
30
30
|
"@whatwg-node/fetch": "^0.10.0",
|
package/typings/codegen.d.cts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { CodegenContext } from './config.cjs';
|
|
3
|
-
export declare function executeCodegen(input: CodegenContext | Types.Config
|
|
4
|
-
onlyGeneratesKeys: Record<string, true>;
|
|
5
|
-
}): Promise<{
|
|
3
|
+
export declare function executeCodegen(input: CodegenContext | Types.Config): Promise<{
|
|
6
4
|
result: Types.FileOutput[];
|
|
7
5
|
error: Error | null;
|
|
8
6
|
}>;
|
package/typings/codegen.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { CodegenContext } from './config.js';
|
|
3
|
-
export declare function executeCodegen(input: CodegenContext | Types.Config
|
|
4
|
-
onlyGeneratesKeys: Record<string, true>;
|
|
5
|
-
}): Promise<{
|
|
3
|
+
export declare function executeCodegen(input: CodegenContext | Types.Config): Promise<{
|
|
6
4
|
result: Types.FileOutput[];
|
|
7
5
|
error: Error | null;
|
|
8
6
|
}>;
|
package/typings/config.d.cts
CHANGED
|
@@ -16,6 +16,7 @@ export type YamlCliFlags = {
|
|
|
16
16
|
debug?: boolean;
|
|
17
17
|
ignoreNoDocuments?: boolean;
|
|
18
18
|
emitLegacyCommonJSImports?: boolean;
|
|
19
|
+
importExtension?: '' | `.${string}`;
|
|
19
20
|
};
|
|
20
21
|
export declare function generateSearchPlaces(moduleName: string): string[];
|
|
21
22
|
export type CodegenConfigLoader = (filepath: string, content: string) => Promise<Types.Config> | Types.Config;
|
|
@@ -103,6 +104,18 @@ export declare function buildOptions(): {
|
|
|
103
104
|
type: "boolean";
|
|
104
105
|
default: boolean;
|
|
105
106
|
};
|
|
107
|
+
'emit-legacy-common-js-imports': {
|
|
108
|
+
describe: string;
|
|
109
|
+
type: "boolean";
|
|
110
|
+
};
|
|
111
|
+
'import-extension': {
|
|
112
|
+
describe: string;
|
|
113
|
+
type: "string";
|
|
114
|
+
};
|
|
115
|
+
'ignore-no-documents': {
|
|
116
|
+
describe: string;
|
|
117
|
+
type: "boolean";
|
|
118
|
+
};
|
|
106
119
|
};
|
|
107
120
|
export declare function parseArgv(argv?: string[]): YamlCliFlags;
|
|
108
121
|
export declare function createContext(cliFlags?: YamlCliFlags): Promise<CodegenContext>;
|
|
@@ -137,4 +150,3 @@ export declare class CodegenContext {
|
|
|
137
150
|
loadDocuments(pointer: Types.OperationDocument[]): Promise<Types.DocumentFile[]>;
|
|
138
151
|
}
|
|
139
152
|
export declare function ensureContext(input: CodegenContext | Types.Config): CodegenContext;
|
|
140
|
-
export declare function shouldEmitLegacyCommonJSImports(config: Types.Config): boolean;
|
package/typings/config.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type YamlCliFlags = {
|
|
|
16
16
|
debug?: boolean;
|
|
17
17
|
ignoreNoDocuments?: boolean;
|
|
18
18
|
emitLegacyCommonJSImports?: boolean;
|
|
19
|
+
importExtension?: '' | `.${string}`;
|
|
19
20
|
};
|
|
20
21
|
export declare function generateSearchPlaces(moduleName: string): string[];
|
|
21
22
|
export type CodegenConfigLoader = (filepath: string, content: string) => Promise<Types.Config> | Types.Config;
|
|
@@ -103,6 +104,18 @@ export declare function buildOptions(): {
|
|
|
103
104
|
type: "boolean";
|
|
104
105
|
default: boolean;
|
|
105
106
|
};
|
|
107
|
+
'emit-legacy-common-js-imports': {
|
|
108
|
+
describe: string;
|
|
109
|
+
type: "boolean";
|
|
110
|
+
};
|
|
111
|
+
'import-extension': {
|
|
112
|
+
describe: string;
|
|
113
|
+
type: "string";
|
|
114
|
+
};
|
|
115
|
+
'ignore-no-documents': {
|
|
116
|
+
describe: string;
|
|
117
|
+
type: "boolean";
|
|
118
|
+
};
|
|
106
119
|
};
|
|
107
120
|
export declare function parseArgv(argv?: string[]): YamlCliFlags;
|
|
108
121
|
export declare function createContext(cliFlags?: YamlCliFlags): Promise<CodegenContext>;
|
|
@@ -137,4 +150,3 @@ export declare class CodegenContext {
|
|
|
137
150
|
loadDocuments(pointer: Types.OperationDocument[]): Promise<Types.DocumentFile[]>;
|
|
138
151
|
}
|
|
139
152
|
export declare function ensureContext(input: CodegenContext | Types.Config): CodegenContext;
|
|
140
|
-
export declare function shouldEmitLegacyCommonJSImports(config: Types.Config): boolean;
|
|
@@ -25,16 +25,13 @@ export declare const allAffirmativePatternsFromPatternSets: (patternSets: Patter
|
|
|
25
25
|
* a match even if it would be negated by some pattern in documents or schemas
|
|
26
26
|
* * The trigger returns true if any output target's local patterns result in
|
|
27
27
|
* a match, after considering the precedence of any global and local negations
|
|
28
|
-
*
|
|
29
|
-
* The result is a function that when given an absolute path,
|
|
30
|
-
* it will tell which generates blocks' keys are affected so we can re-run for those keys
|
|
31
28
|
*/
|
|
32
29
|
export declare const makeShouldRebuild: ({ globalPatternSet, localPatternSets, }: {
|
|
33
30
|
globalPatternSet: PatternSet;
|
|
34
|
-
localPatternSets:
|
|
35
|
-
}) => (
|
|
31
|
+
localPatternSets: PatternSet[];
|
|
32
|
+
}) => ({ path: absolutePath }: {
|
|
36
33
|
path: string;
|
|
37
|
-
}) =>
|
|
34
|
+
}) => boolean;
|
|
38
35
|
/**
|
|
39
36
|
* Create the pattern set for the "global" (top level) config.
|
|
40
37
|
*
|
|
@@ -55,7 +52,11 @@ export declare const makeGlobalPatternSet: (initialContext: CodegenContext) => {
|
|
|
55
52
|
* patterns will be mixed into the pattern set of their respective gobal pattern
|
|
56
53
|
* set equivalents.
|
|
57
54
|
*/
|
|
58
|
-
export declare const makeLocalPatternSet: (conf: Types.ConfiguredOutput) =>
|
|
55
|
+
export declare const makeLocalPatternSet: (conf: Types.ConfiguredOutput) => {
|
|
56
|
+
watch: SortedPatterns<string>;
|
|
57
|
+
documents: SortedPatterns<string>;
|
|
58
|
+
schemas: SortedPatterns<string>;
|
|
59
|
+
};
|
|
59
60
|
/**
|
|
60
61
|
* Given a list of micromatch patterns, sort them into `patterns` (all of them),
|
|
61
62
|
* `affirmative` (only the affirmative patterns), and `negated` (only the negated patterns)
|
|
@@ -82,7 +83,7 @@ type SortedPatterns<PP extends string | NegatedPattern = string | NegatedPattern
|
|
|
82
83
|
* patterns which are separable into "watch" (always takes precedence), "documents",
|
|
83
84
|
* and "schemas". This type can hold sorted versions of these patterns.
|
|
84
85
|
*/
|
|
85
|
-
|
|
86
|
+
type PatternSet = {
|
|
86
87
|
watch: SortedPatterns;
|
|
87
88
|
documents: SortedPatterns;
|
|
88
89
|
schemas: SortedPatterns;
|
|
@@ -25,16 +25,13 @@ export declare const allAffirmativePatternsFromPatternSets: (patternSets: Patter
|
|
|
25
25
|
* a match even if it would be negated by some pattern in documents or schemas
|
|
26
26
|
* * The trigger returns true if any output target's local patterns result in
|
|
27
27
|
* a match, after considering the precedence of any global and local negations
|
|
28
|
-
*
|
|
29
|
-
* The result is a function that when given an absolute path,
|
|
30
|
-
* it will tell which generates blocks' keys are affected so we can re-run for those keys
|
|
31
28
|
*/
|
|
32
29
|
export declare const makeShouldRebuild: ({ globalPatternSet, localPatternSets, }: {
|
|
33
30
|
globalPatternSet: PatternSet;
|
|
34
|
-
localPatternSets:
|
|
35
|
-
}) => (
|
|
31
|
+
localPatternSets: PatternSet[];
|
|
32
|
+
}) => ({ path: absolutePath }: {
|
|
36
33
|
path: string;
|
|
37
|
-
}) =>
|
|
34
|
+
}) => boolean;
|
|
38
35
|
/**
|
|
39
36
|
* Create the pattern set for the "global" (top level) config.
|
|
40
37
|
*
|
|
@@ -55,7 +52,11 @@ export declare const makeGlobalPatternSet: (initialContext: CodegenContext) => {
|
|
|
55
52
|
* patterns will be mixed into the pattern set of their respective gobal pattern
|
|
56
53
|
* set equivalents.
|
|
57
54
|
*/
|
|
58
|
-
export declare const makeLocalPatternSet: (conf: Types.ConfiguredOutput) =>
|
|
55
|
+
export declare const makeLocalPatternSet: (conf: Types.ConfiguredOutput) => {
|
|
56
|
+
watch: SortedPatterns<string>;
|
|
57
|
+
documents: SortedPatterns<string>;
|
|
58
|
+
schemas: SortedPatterns<string>;
|
|
59
|
+
};
|
|
59
60
|
/**
|
|
60
61
|
* Given a list of micromatch patterns, sort them into `patterns` (all of them),
|
|
61
62
|
* `affirmative` (only the affirmative patterns), and `negated` (only the negated patterns)
|
|
@@ -82,7 +83,7 @@ type SortedPatterns<PP extends string | NegatedPattern = string | NegatedPattern
|
|
|
82
83
|
* patterns which are separable into "watch" (always takes precedence), "documents",
|
|
83
84
|
* and "schemas". This type can hold sorted versions of these patterns.
|
|
84
85
|
*/
|
|
85
|
-
|
|
86
|
+
type PatternSet = {
|
|
86
87
|
watch: SortedPatterns;
|
|
87
88
|
documents: SortedPatterns;
|
|
88
89
|
schemas: SortedPatterns;
|