@graphql-codegen/cli 4.0.1-rc-20230601142157-34bca752f → 4.0.2-alpha-20230706143738-f59fb0497

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.
@@ -185,27 +185,39 @@ const findHighestCommonDirectory = async (files) => {
185
185
  };
186
186
  /**
187
187
  * Find the longest common prefix of an array of paths, where each item in
188
- * the array an array of path segments which comprise an absolute path when
189
- * joined together by a path separator
188
+ * the array is an array of path segments which comprise an absolute path when
189
+ * joined together by a path separator.
190
190
  *
191
191
  * Adapted from:
192
192
  * https://duncan-mcardle.medium.com/leetcode-problem-14-longest-common-prefix-javascript-3bc6a2f777c4
193
193
  *
194
- * @param splitPaths An array of arrays, where each item is a path split by its separator
195
- * @returns An array of path segments representing the longest common prefix of splitPaths
194
+ * This version has been adjusted to support Windows paths, by treating the drive letter
195
+ * as a separate segment and accounting for Windows-style backslashes as path separators.
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.
196
200
  */
197
201
  const longestCommonPrefix = (splitPaths) => {
198
202
  // Return early on empty input
199
203
  if (!splitPaths.length) {
200
204
  return [];
201
205
  }
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
+ }
202
214
  // Loop through the segments of the first path
203
215
  for (let i = 0; i <= splitPaths[0].length; i++) {
204
216
  // Check if this path segment is present in the same position of every path
205
217
  if (!splitPaths.every(string => string[i] === splitPaths[0][i])) {
206
218
  // If not, return the path segments up to and including the previous segment
207
- return splitPaths[0].slice(0, i);
219
+ return [driveLetter, ...splitPaths[0].slice(0, i)];
208
220
  }
209
221
  }
210
- return splitPaths[0];
222
+ return [driveLetter, ...splitPaths[0]];
211
223
  };
@@ -180,27 +180,39 @@ const findHighestCommonDirectory = async (files) => {
180
180
  };
181
181
  /**
182
182
  * Find the longest common prefix of an array of paths, where each item in
183
- * the array an array of path segments which comprise an absolute path when
184
- * joined together by a path separator
183
+ * the array is an array of path segments which comprise an absolute path when
184
+ * joined together by a path separator.
185
185
  *
186
186
  * Adapted from:
187
187
  * https://duncan-mcardle.medium.com/leetcode-problem-14-longest-common-prefix-javascript-3bc6a2f777c4
188
188
  *
189
- * @param splitPaths An array of arrays, where each item is a path split by its separator
190
- * @returns An array of path segments representing the longest common prefix of splitPaths
189
+ * This version has been adjusted to support Windows paths, by treating the drive letter
190
+ * as a separate segment and accounting for Windows-style backslashes as path separators.
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.
191
195
  */
192
196
  const longestCommonPrefix = (splitPaths) => {
193
197
  // Return early on empty input
194
198
  if (!splitPaths.length) {
195
199
  return [];
196
200
  }
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
+ }
197
209
  // Loop through the segments of the first path
198
210
  for (let i = 0; i <= splitPaths[0].length; i++) {
199
211
  // Check if this path segment is present in the same position of every path
200
212
  if (!splitPaths.every(string => string[i] === splitPaths[0][i])) {
201
213
  // If not, return the path segments up to and including the previous segment
202
- return splitPaths[0].slice(0, i);
214
+ return [driveLetter, ...splitPaths[0].slice(0, i)];
203
215
  }
204
216
  }
205
- return splitPaths[0];
217
+ return [driveLetter, ...splitPaths[0]];
206
218
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "4.0.1-rc-20230601142157-34bca752f",
3
+ "version": "4.0.2-alpha-20230706143738-f59fb0497",
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
  },