@graphql-codegen/cli 4.0.2-alpha-20230706143738-f59fb0497 → 4.0.2-alpha-20230725234859-7c312d8e7
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/utils/watcher.js +23 -27
- package/esm/utils/watcher.js +24 -28
- package/package.json +1 -1
package/cjs/utils/watcher.js
CHANGED
|
@@ -34,7 +34,15 @@ const createWatcher = (initialContext, onNext) => {
|
|
|
34
34
|
let watcherSubscription;
|
|
35
35
|
const runWatcher = async (abortSignal) => {
|
|
36
36
|
const watchDirectory = await findHighestCommonDirectory(allAffirmativePatterns);
|
|
37
|
-
|
|
37
|
+
// Try to load the parcel watcher, but don't fail if it's not available.
|
|
38
|
+
let parcelWatcher;
|
|
39
|
+
try {
|
|
40
|
+
parcelWatcher = await Promise.resolve().then(() => tslib_1.__importStar(require('@parcel/watcher')));
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
log(`Parcel watcher not found. To use this feature, please make sure to provide @parcel/watcher as a peer dependency.`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
38
46
|
(0, debugging_js_1.debugLog)(`[Watcher] Parcel watcher loaded...`);
|
|
39
47
|
let isShutdown = false;
|
|
40
48
|
const debouncedExec = (0, debounce_1.default)(() => {
|
|
@@ -164,19 +172,21 @@ exports.createWatcher = createWatcher;
|
|
|
164
172
|
* @param files List of relative and/or absolute file paths (or micromatch patterns)
|
|
165
173
|
*/
|
|
166
174
|
const findHighestCommonDirectory = async (files) => {
|
|
167
|
-
// Map files to a list of basePaths, where "base" is the result of mm.scan(pathOrPattern)
|
|
168
|
-
// e.g. mm.scan("/**/foo/bar").base -> "/" ; mm.scan("/foo/bar/**/fizz/*.graphql") -> /foo/bar
|
|
169
175
|
const dirPaths = files
|
|
170
176
|
.map(filePath => ((0, path_1.isAbsolute)(filePath) ? filePath : (0, path_1.resolve)(filePath)))
|
|
177
|
+
.map(filePath => (0, path_1.normalize)(filePath)) // Normalize the file paths
|
|
171
178
|
.map(patterned => micromatch_1.default.scan(patterned).base);
|
|
172
|
-
//
|
|
179
|
+
// Log the dirPaths for debugging
|
|
180
|
+
(0, debugging_js_1.debugLog)(`[Watcher] dirPaths: ${JSON.stringify(dirPaths)}`);
|
|
173
181
|
return (async (maybeValidPath) => {
|
|
174
182
|
(0, debugging_js_1.debugLog)(`[Watcher] Longest common prefix of all files: ${maybeValidPath}...`);
|
|
175
183
|
try {
|
|
176
184
|
await (0, file_system_js_1.access)(maybeValidPath);
|
|
185
|
+
(0, debugging_js_1.debugLog)(`[Watcher] Access to ${maybeValidPath} successful.`);
|
|
177
186
|
return maybeValidPath;
|
|
178
187
|
}
|
|
179
|
-
catch {
|
|
188
|
+
catch (error) {
|
|
189
|
+
(0, debugging_js_1.debugLog)(`[Watcher] Error accessing path: ${error.message}`);
|
|
180
190
|
log(`[Watcher] Longest common prefix (${maybeValidPath}) is not accessible`);
|
|
181
191
|
log(`[Watcher] Watching current working directory (${process.cwd()}) instead`);
|
|
182
192
|
return process.cwd();
|
|
@@ -185,39 +195,25 @@ const findHighestCommonDirectory = async (files) => {
|
|
|
185
195
|
};
|
|
186
196
|
/**
|
|
187
197
|
* Find the longest common prefix of an array of paths, where each item in
|
|
188
|
-
* the array
|
|
189
|
-
* joined together by a path separator
|
|
198
|
+
* the array an array of path segments which comprise an absolute path when
|
|
199
|
+
* joined together by a path separator
|
|
190
200
|
*
|
|
191
201
|
* Adapted from:
|
|
192
202
|
* https://duncan-mcardle.medium.com/leetcode-problem-14-longest-common-prefix-javascript-3bc6a2f777c4
|
|
193
203
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* @param splitPaths An array of arrays, where each item is a path split by its separator.
|
|
198
|
-
* The first item is treated separately as it could be a drive letter in Windows.
|
|
199
|
-
* @returns An array of path segments representing the longest common prefix of splitPaths.
|
|
204
|
+
* @param splitPaths An array of arrays, where each item is a path split by its separator
|
|
205
|
+
* @returns An array of path segments representing the longest common prefix of splitPaths
|
|
200
206
|
*/
|
|
201
207
|
const longestCommonPrefix = (splitPaths) => {
|
|
202
|
-
// Return early on empty input
|
|
203
208
|
if (!splitPaths.length) {
|
|
204
209
|
return [];
|
|
205
210
|
}
|
|
206
|
-
// Added: handle Windows drive letters
|
|
207
|
-
const driveLetter = splitPaths[0][0];
|
|
208
|
-
if (driveLetter && splitPaths.every(string => string[0] === driveLetter)) {
|
|
209
|
-
splitPaths = splitPaths.map(path => path.slice(1));
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
return [];
|
|
213
|
-
}
|
|
214
|
-
// Loop through the segments of the first path
|
|
215
211
|
for (let i = 0; i <= splitPaths[0].length; i++) {
|
|
216
|
-
// Check if this path segment is present in the same position of every path
|
|
217
212
|
if (!splitPaths.every(string => string[i] === splitPaths[0][i])) {
|
|
218
|
-
|
|
219
|
-
return
|
|
213
|
+
(0, debugging_js_1.debugLog)(`[Watcher] longestCommonPrefix at index ${i}: ${splitPaths[0].slice(0, i).join(path_1.sep)}`);
|
|
214
|
+
return splitPaths[0].slice(0, i);
|
|
220
215
|
}
|
|
221
216
|
}
|
|
222
|
-
|
|
217
|
+
(0, debugging_js_1.debugLog)(`[Watcher] longestCommonPrefix: ${splitPaths[0].join(path_1.sep)}`);
|
|
218
|
+
return splitPaths[0];
|
|
223
219
|
};
|
package/esm/utils/watcher.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join, isAbsolute, relative, resolve, sep } from 'path';
|
|
1
|
+
import { join, isAbsolute, relative, resolve, sep, normalize } from 'path';
|
|
2
2
|
import { normalizeOutputParam } from '@graphql-codegen/plugin-helpers';
|
|
3
3
|
import debounce from 'debounce';
|
|
4
4
|
import mm from 'micromatch';
|
|
@@ -30,7 +30,15 @@ export const createWatcher = (initialContext, onNext) => {
|
|
|
30
30
|
let watcherSubscription;
|
|
31
31
|
const runWatcher = async (abortSignal) => {
|
|
32
32
|
const watchDirectory = await findHighestCommonDirectory(allAffirmativePatterns);
|
|
33
|
-
|
|
33
|
+
// Try to load the parcel watcher, but don't fail if it's not available.
|
|
34
|
+
let parcelWatcher;
|
|
35
|
+
try {
|
|
36
|
+
parcelWatcher = await import('@parcel/watcher');
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
log(`Parcel watcher not found. To use this feature, please make sure to provide @parcel/watcher as a peer dependency.`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
34
42
|
debugLog(`[Watcher] Parcel watcher loaded...`);
|
|
35
43
|
let isShutdown = false;
|
|
36
44
|
const debouncedExec = debounce(() => {
|
|
@@ -159,19 +167,21 @@ export const createWatcher = (initialContext, onNext) => {
|
|
|
159
167
|
* @param files List of relative and/or absolute file paths (or micromatch patterns)
|
|
160
168
|
*/
|
|
161
169
|
const findHighestCommonDirectory = async (files) => {
|
|
162
|
-
// Map files to a list of basePaths, where "base" is the result of mm.scan(pathOrPattern)
|
|
163
|
-
// e.g. mm.scan("/**/foo/bar").base -> "/" ; mm.scan("/foo/bar/**/fizz/*.graphql") -> /foo/bar
|
|
164
170
|
const dirPaths = files
|
|
165
171
|
.map(filePath => (isAbsolute(filePath) ? filePath : resolve(filePath)))
|
|
172
|
+
.map(filePath => normalize(filePath)) // Normalize the file paths
|
|
166
173
|
.map(patterned => mm.scan(patterned).base);
|
|
167
|
-
//
|
|
174
|
+
// Log the dirPaths for debugging
|
|
175
|
+
debugLog(`[Watcher] dirPaths: ${JSON.stringify(dirPaths)}`);
|
|
168
176
|
return (async (maybeValidPath) => {
|
|
169
177
|
debugLog(`[Watcher] Longest common prefix of all files: ${maybeValidPath}...`);
|
|
170
178
|
try {
|
|
171
179
|
await access(maybeValidPath);
|
|
180
|
+
debugLog(`[Watcher] Access to ${maybeValidPath} successful.`);
|
|
172
181
|
return maybeValidPath;
|
|
173
182
|
}
|
|
174
|
-
catch {
|
|
183
|
+
catch (error) {
|
|
184
|
+
debugLog(`[Watcher] Error accessing path: ${error.message}`);
|
|
175
185
|
log(`[Watcher] Longest common prefix (${maybeValidPath}) is not accessible`);
|
|
176
186
|
log(`[Watcher] Watching current working directory (${process.cwd()}) instead`);
|
|
177
187
|
return process.cwd();
|
|
@@ -180,39 +190,25 @@ const findHighestCommonDirectory = async (files) => {
|
|
|
180
190
|
};
|
|
181
191
|
/**
|
|
182
192
|
* Find the longest common prefix of an array of paths, where each item in
|
|
183
|
-
* the array
|
|
184
|
-
* joined together by a path separator
|
|
193
|
+
* the array an array of path segments which comprise an absolute path when
|
|
194
|
+
* joined together by a path separator
|
|
185
195
|
*
|
|
186
196
|
* Adapted from:
|
|
187
197
|
* https://duncan-mcardle.medium.com/leetcode-problem-14-longest-common-prefix-javascript-3bc6a2f777c4
|
|
188
198
|
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* @param splitPaths An array of arrays, where each item is a path split by its separator.
|
|
193
|
-
* The first item is treated separately as it could be a drive letter in Windows.
|
|
194
|
-
* @returns An array of path segments representing the longest common prefix of splitPaths.
|
|
199
|
+
* @param splitPaths An array of arrays, where each item is a path split by its separator
|
|
200
|
+
* @returns An array of path segments representing the longest common prefix of splitPaths
|
|
195
201
|
*/
|
|
196
202
|
const longestCommonPrefix = (splitPaths) => {
|
|
197
|
-
// Return early on empty input
|
|
198
203
|
if (!splitPaths.length) {
|
|
199
204
|
return [];
|
|
200
205
|
}
|
|
201
|
-
// Added: handle Windows drive letters
|
|
202
|
-
const driveLetter = splitPaths[0][0];
|
|
203
|
-
if (driveLetter && splitPaths.every(string => string[0] === driveLetter)) {
|
|
204
|
-
splitPaths = splitPaths.map(path => path.slice(1));
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
return [];
|
|
208
|
-
}
|
|
209
|
-
// Loop through the segments of the first path
|
|
210
206
|
for (let i = 0; i <= splitPaths[0].length; i++) {
|
|
211
|
-
// Check if this path segment is present in the same position of every path
|
|
212
207
|
if (!splitPaths.every(string => string[i] === splitPaths[0][i])) {
|
|
213
|
-
|
|
214
|
-
return
|
|
208
|
+
debugLog(`[Watcher] longestCommonPrefix at index ${i}: ${splitPaths[0].slice(0, i).join(sep)}`);
|
|
209
|
+
return splitPaths[0].slice(0, i);
|
|
215
210
|
}
|
|
216
211
|
}
|
|
217
|
-
|
|
212
|
+
debugLog(`[Watcher] longestCommonPrefix: ${splitPaths[0].join(sep)}`);
|
|
213
|
+
return splitPaths[0];
|
|
218
214
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "4.0.2-alpha-
|
|
3
|
+
"version": "4.0.2-alpha-20230725234859-7c312d8e7",
|
|
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
|
},
|