@graphql-codegen/cli 4.0.1 → 4.0.2-alpha-20230725231005-5bc75d7f6
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 +18 -11
- package/esm/utils/watcher.js +19 -12
- 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,22 +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)))
|
|
171
|
-
.map(patterned => micromatch_1.default.scan(patterned).base)
|
|
172
|
-
|
|
177
|
+
.map(patterned => micromatch_1.default.scan(patterned).base)
|
|
178
|
+
.map(path => (0, path_1.normalize)(path)); // Added normalization here
|
|
173
179
|
return (async (maybeValidPath) => {
|
|
174
|
-
(0,
|
|
180
|
+
const normalizedPath = (0, path_1.normalize)(maybeValidPath); // Normalize the path before checking accessibility
|
|
181
|
+
(0, debugging_js_1.debugLog)(`[Watcher] Longest common prefix of all files: ${normalizedPath}...`);
|
|
175
182
|
try {
|
|
176
|
-
await (0, file_system_js_1.access)(
|
|
177
|
-
return
|
|
183
|
+
await (0, file_system_js_1.access)(normalizedPath); // Access the normalized path
|
|
184
|
+
return normalizedPath;
|
|
178
185
|
}
|
|
179
186
|
catch {
|
|
180
|
-
log(`[Watcher] Longest common prefix (${
|
|
181
|
-
log(`[Watcher] Watching current working directory (${process.cwd()}) instead`);
|
|
182
|
-
return process.cwd();
|
|
187
|
+
log(`[Watcher] Longest common prefix (${normalizedPath}) is not accessible`);
|
|
188
|
+
log(`[Watcher] Watching current working directory (${(0, path_1.normalize)(process.cwd())}) instead`);
|
|
189
|
+
return (0, path_1.normalize)(process.cwd());
|
|
183
190
|
}
|
|
184
191
|
})(longestCommonPrefix(dirPaths.map(path => path.split(path_1.sep))).join(path_1.sep));
|
|
185
192
|
};
|
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,22 +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)))
|
|
166
|
-
.map(patterned => mm.scan(patterned).base)
|
|
167
|
-
|
|
172
|
+
.map(patterned => mm.scan(patterned).base)
|
|
173
|
+
.map(path => normalize(path)); // Added normalization here
|
|
168
174
|
return (async (maybeValidPath) => {
|
|
169
|
-
|
|
175
|
+
const normalizedPath = normalize(maybeValidPath); // Normalize the path before checking accessibility
|
|
176
|
+
debugLog(`[Watcher] Longest common prefix of all files: ${normalizedPath}...`);
|
|
170
177
|
try {
|
|
171
|
-
await access(
|
|
172
|
-
return
|
|
178
|
+
await access(normalizedPath); // Access the normalized path
|
|
179
|
+
return normalizedPath;
|
|
173
180
|
}
|
|
174
181
|
catch {
|
|
175
|
-
log(`[Watcher] Longest common prefix (${
|
|
176
|
-
log(`[Watcher] Watching current working directory (${process.cwd()}) instead`);
|
|
177
|
-
return process.cwd();
|
|
182
|
+
log(`[Watcher] Longest common prefix (${normalizedPath}) is not accessible`);
|
|
183
|
+
log(`[Watcher] Watching current working directory (${normalize(process.cwd())}) instead`);
|
|
184
|
+
return normalize(process.cwd());
|
|
178
185
|
}
|
|
179
186
|
})(longestCommonPrefix(dirPaths.map(path => path.split(sep))).join(sep));
|
|
180
187
|
};
|
package/package.json
CHANGED