@aneuhold/core-ts-lib 2.2.5 → 2.2.7

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.
Files changed (39) hide show
  1. package/lib/index.d.ts +3 -4
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.js +1 -2
  4. package/lib/index.js.map +1 -1
  5. package/lib/index.ts +5 -7
  6. package/lib/interfaces/ITracer.d.ts.map +1 -1
  7. package/lib/interfaces/ITracer.js.map +1 -1
  8. package/lib/interfaces/ITracer.ts +8 -2
  9. package/lib/services/ArrayService.d.ts.map +1 -1
  10. package/lib/services/ArrayService.js.map +1 -1
  11. package/lib/services/ArrayService.ts +4 -1
  12. package/lib/services/DateService/DateService.d.ts.map +1 -1
  13. package/lib/services/DateService/DateService.js +3 -1
  14. package/lib/services/DateService/DateService.js.map +1 -1
  15. package/lib/services/DateService/DateService.spec.ts +98 -0
  16. package/lib/services/DateService/DateService.ts +25 -7
  17. package/lib/services/DependencyService.d.ts.map +1 -1
  18. package/lib/services/DependencyService.js +3 -1
  19. package/lib/services/DependencyService.js.map +1 -1
  20. package/lib/services/DependencyService.ts +32 -10
  21. package/lib/services/FileSystemService/FileSystemService.d.ts +4 -30
  22. package/lib/services/FileSystemService/FileSystemService.d.ts.map +1 -1
  23. package/lib/services/FileSystemService/FileSystemService.js +7 -64
  24. package/lib/services/FileSystemService/FileSystemService.js.map +1 -1
  25. package/lib/services/FileSystemService/FileSystemService.spec.ts +133 -0
  26. package/lib/services/FileSystemService/FileSystemService.ts +32 -117
  27. package/lib/services/PackageService.d.ts.map +1 -1
  28. package/lib/services/PackageService.js +8 -4
  29. package/lib/services/PackageService.js.map +1 -1
  30. package/lib/services/PackageService.ts +90 -27
  31. package/lib/utils/ErrorUtils.d.ts.map +1 -1
  32. package/lib/utils/ErrorUtils.js.map +1 -1
  33. package/lib/utils/ErrorUtils.ts +3 -1
  34. package/package.json +1 -1
  35. package/lib/services/FileSystemService/GlobMatchingService.d.ts +0 -48
  36. package/lib/services/FileSystemService/GlobMatchingService.d.ts.map +0 -1
  37. package/lib/services/FileSystemService/GlobMatchingService.js +0 -129
  38. package/lib/services/FileSystemService/GlobMatchingService.js.map +0 -1
  39. package/lib/services/FileSystemService/GlobMatchingService.ts +0 -153
@@ -31,7 +31,10 @@ export default class PackageService {
31
31
  await PackageService.replaceMonorepoImportsWithNpmSpecifiers();
32
32
  const { packageName, version: currentVersion } =
33
33
  await PackageService.updateJsrFromPackageJson();
34
- const successfulDryRun = await PackageService.publishJsrDryRun(packageName, currentVersion);
34
+ const successfulDryRun = await PackageService.publishJsrDryRun(
35
+ packageName,
36
+ currentVersion
37
+ );
35
38
  await PackageService.revertGitChanges();
36
39
 
37
40
  if (!successfulDryRun) {
@@ -64,7 +67,8 @@ export default class PackageService {
64
67
  * on the npm registry.
65
68
  */
66
69
  static async validateNpmPublish(): Promise<void> {
67
- const { packageName, version: currentVersion } = await PackageService.getPackageInfo();
70
+ const { packageName, version: currentVersion } =
71
+ await PackageService.getPackageInfo();
68
72
 
69
73
  const successfulDryRun = await PackageService.publishNpmDryRun();
70
74
  if (!successfulDryRun) {
@@ -97,7 +101,9 @@ export default class PackageService {
97
101
 
98
102
  try {
99
103
  const { packageName, version } = await PackageService.getPackageInfo();
100
- const packageJsonData = JSON.parse(await readFile(packageJsonPath, 'utf-8')) as PackageJson;
104
+ const packageJsonData = JSON.parse(
105
+ await readFile(packageJsonPath, 'utf-8')
106
+ ) as PackageJson;
101
107
  const jsrJsonData = JSON.parse(
102
108
  await readFile(jsrJsonPath, 'utf-8')
103
109
  ) as JsonWithVersionProperty;
@@ -106,10 +112,15 @@ export default class PackageService {
106
112
  jsrJsonData.version = version;
107
113
 
108
114
  // Resolve wildcard dependencies in package.json for JSR compatibility
109
- await this.resolveWildcardDependenciesInPackageJson(packageJsonData, packageJsonPath);
115
+ await this.resolveWildcardDependenciesInPackageJson(
116
+ packageJsonData,
117
+ packageJsonPath
118
+ );
110
119
 
111
120
  await writeFile(jsrJsonPath, JSON.stringify(jsrJsonData, null, 2));
112
- DR.logger.info('Updated jsr.json from package.json to version ' + version);
121
+ DR.logger.info(
122
+ 'Updated jsr.json from package.json to version ' + version
123
+ );
113
124
 
114
125
  return {
115
126
  packageName,
@@ -117,7 +128,9 @@ export default class PackageService {
117
128
  };
118
129
  } catch (error) {
119
130
  const errorString = ErrorUtils.getErrorString(error);
120
- DR.logger.error(`Failed to update jsr.json from package.json: ${errorString}`);
131
+ DR.logger.error(
132
+ `Failed to update jsr.json from package.json: ${errorString}`
133
+ );
121
134
  throw error;
122
135
  }
123
136
  }
@@ -139,13 +152,16 @@ export default class PackageService {
139
152
  const childPackages = await DependencyService.getChildPackageJsons('../');
140
153
 
141
154
  // Helper function to resolve dependencies
142
- const resolveDependencies = (deps: Record<string, string> | undefined): void => {
155
+ const resolveDependencies = (
156
+ deps: Record<string, string> | undefined
157
+ ): void => {
143
158
  if (!deps) return;
144
159
 
145
160
  for (const [depName, depVersion] of Object.entries(deps)) {
146
161
  if (depVersion === '*' && depName in childPackages) {
147
162
  // Replace wildcard with "*" + actual version from the monorepo
148
- deps[depName] = `*${childPackages[depName].packageJsonContents.version}`;
163
+ deps[depName] =
164
+ `*${childPackages[depName].packageJsonContents.version}`;
149
165
  }
150
166
  }
151
167
  };
@@ -157,12 +173,19 @@ export default class PackageService {
157
173
  resolveDependencies(packageJsonData.optionalDependencies);
158
174
 
159
175
  // Write the updated package.json
160
- await writeFile(packageJsonPath, JSON.stringify(packageJsonData, null, 2));
176
+ await writeFile(
177
+ packageJsonPath,
178
+ JSON.stringify(packageJsonData, null, 2)
179
+ );
161
180
 
162
- DR.logger.info('Resolved wildcard dependencies in package.json for JSR compatibility');
181
+ DR.logger.info(
182
+ 'Resolved wildcard dependencies in package.json for JSR compatibility'
183
+ );
163
184
  } catch (error) {
164
185
  const errorString = ErrorUtils.getErrorString(error);
165
- DR.logger.error(`Failed to resolve wildcard dependencies: ${errorString}`);
186
+ DR.logger.error(
187
+ `Failed to resolve wildcard dependencies: ${errorString}`
188
+ );
166
189
  throw error;
167
190
  }
168
191
  }
@@ -185,13 +208,17 @@ export default class PackageService {
185
208
 
186
209
  DR.logger.info('Running `jsr publish --dry-run`');
187
210
  try {
188
- const { stdout, stderr } = await execAsync('jsr publish --allow-dirty --dry-run');
211
+ const { stdout, stderr } = await execAsync(
212
+ 'jsr publish --allow-dirty --dry-run'
213
+ );
189
214
  if (stderr) {
190
215
  DR.logger.info(stderr);
191
216
  }
192
217
  DR.logger.info(stdout);
193
218
  } catch (error) {
194
- DR.logger.error(`Failed to run 'jsr publish --dry-run': ${ErrorUtils.getErrorString(error)}`);
219
+ DR.logger.error(
220
+ `Failed to run 'jsr publish --dry-run': ${ErrorUtils.getErrorString(error)}`
221
+ );
195
222
  return false;
196
223
  }
197
224
  return true;
@@ -239,7 +266,9 @@ export default class PackageService {
239
266
  }
240
267
 
241
268
  try {
242
- const packageJsonData = JSON.parse(await readFile(packageJsonPath, 'utf-8')) as PackageJson;
269
+ const packageJsonData = JSON.parse(
270
+ await readFile(packageJsonPath, 'utf-8')
271
+ ) as PackageJson;
243
272
 
244
273
  return {
245
274
  packageName: packageJsonData.name,
@@ -280,7 +309,9 @@ export default class PackageService {
280
309
  packageName: string,
281
310
  currentVersion: string
282
311
  ): Promise<void> {
283
- DR.logger.info(`Checking npm registry for existing versions of ${packageName}...`);
312
+ DR.logger.info(
313
+ `Checking npm registry for existing versions of ${packageName}...`
314
+ );
284
315
 
285
316
  try {
286
317
  const { stdout } = await execAsync(`npm view ${packageName}`);
@@ -289,19 +320,28 @@ export default class PackageService {
289
320
  const latestVersionMatch = stdout.match(/latest:\s*([^\s|]+)/);
290
321
  if (latestVersionMatch) {
291
322
  const latestVersion = latestVersionMatch[1];
292
- PackageService.checkVersionConflict(currentVersion, latestVersion, 'npm');
323
+ PackageService.checkVersionConflict(
324
+ currentVersion,
325
+ latestVersion,
326
+ 'npm'
327
+ );
293
328
  }
294
329
  } catch (error) {
295
330
  const errorString = ErrorUtils.getErrorString(error);
296
331
 
297
332
  // If the package doesn't exist on npm, that's fine for first publish
298
333
  if (errorString.includes('404') || errorString.includes('not found')) {
299
- DR.logger.info('Package not found on npm - this appears to be a first publish.');
334
+ DR.logger.info(
335
+ 'Package not found on npm - this appears to be a first publish.'
336
+ );
300
337
  return;
301
338
  }
302
339
 
303
340
  // Re-throw version conflict errors
304
- if (errorString.includes('already exists') || errorString.includes('is lower than')) {
341
+ if (
342
+ errorString.includes('already exists') ||
343
+ errorString.includes('is lower than')
344
+ ) {
305
345
  throw error;
306
346
  }
307
347
 
@@ -375,7 +415,9 @@ export default class PackageService {
375
415
  // Get all TypeScript files in the src directory
376
416
  const allFiles = await FileSystemService.getAllFilePathsRelative(srcDir);
377
417
  const tsFiles = allFiles
378
- .filter((filePath) => filePath.endsWith('.ts') && !filePath.endsWith('.spec.ts'))
418
+ .filter(
419
+ (filePath) => filePath.endsWith('.ts') && !filePath.endsWith('.spec.ts')
420
+ )
379
421
  .map((filePath) => path.join(srcDir, filePath));
380
422
 
381
423
  DR.logger.info(
@@ -417,7 +459,9 @@ export default class PackageService {
417
459
  );
418
460
  }
419
461
  } catch (error) {
420
- DR.logger.error(`Failed to process file ${filePath}: ${ErrorUtils.getErrorString(error)}`);
462
+ DR.logger.error(
463
+ `Failed to process file ${filePath}: ${ErrorUtils.getErrorString(error)}`
464
+ );
421
465
  }
422
466
  }
423
467
 
@@ -427,11 +471,15 @@ export default class PackageService {
427
471
  }
428
472
 
429
473
  private static async revertGitChanges(): Promise<void> {
430
- DR.logger.info('Reverting changes made to jsr.json, package.json, and source files');
474
+ DR.logger.info(
475
+ 'Reverting changes made to jsr.json, package.json, and source files'
476
+ );
431
477
  try {
432
478
  await execAsync('git checkout -- jsr.json package.json src/');
433
479
  } catch (error) {
434
- DR.logger.error(`Failed to revert changes: ${ErrorUtils.getErrorString(error)}`);
480
+ DR.logger.error(
481
+ `Failed to revert changes: ${ErrorUtils.getErrorString(error)}`
482
+ );
435
483
  }
436
484
  }
437
485
 
@@ -457,19 +505,31 @@ export default class PackageService {
457
505
  if (latestVersionMatch) {
458
506
  const latestVersion = latestVersionMatch[1];
459
507
 
460
- PackageService.checkVersionConflict(currentVersion, latestVersion, 'JSR');
508
+ PackageService.checkVersionConflict(
509
+ currentVersion,
510
+ latestVersion,
511
+ 'JSR'
512
+ );
461
513
  }
462
514
  } catch (error) {
463
515
  const errorString = ErrorUtils.getErrorString(error);
464
516
 
465
517
  // If the package doesn't exist on JSR, that's fine for first publish
466
- if (errorString.includes('Package not found') || errorString.includes('404')) {
467
- DR.logger.info('Package not found on JSR - this appears to be a first publish.');
518
+ if (
519
+ errorString.includes('Package not found') ||
520
+ errorString.includes('404')
521
+ ) {
522
+ DR.logger.info(
523
+ 'Package not found on JSR - this appears to be a first publish.'
524
+ );
468
525
  return;
469
526
  }
470
527
 
471
528
  // Re-throw version conflict errors
472
- if (errorString.includes('already exists') || errorString.includes('is lower than')) {
529
+ if (
530
+ errorString.includes('already exists') ||
531
+ errorString.includes('is lower than')
532
+ ) {
473
533
  throw error;
474
534
  }
475
535
 
@@ -495,7 +555,10 @@ export default class PackageService {
495
555
  );
496
556
 
497
557
  // Compare versions using semver-like comparison
498
- const comparison = StringService.compareSemanticVersions(currentVersion, latestVersion);
558
+ const comparison = StringService.compareSemanticVersions(
559
+ currentVersion,
560
+ latestVersion
561
+ );
499
562
 
500
563
  if (comparison === 0) {
501
564
  throw new Error(
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorUtils.d.ts","sourceRoot":"","sources":["../../src/utils/ErrorUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,eAAe,EAAE,MAAM;IAQlE;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM;IAI/D;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;CAS9C"}
1
+ {"version":3,"file":"ErrorUtils.d.ts","sourceRoot":"","sources":["../../src/utils/ErrorUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,eAAe,EAAE,MAAM;IAUlE;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM;IAI/D;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;CAS9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorUtils.js","sourceRoot":"","sources":["../../src/utils/ErrorUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,SAAmB,EAAE,eAAuB;QAChE,IAAI,WAAW,GAAG,EAAE,CAAC;QACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7C,WAAW,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;QACrC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,GAAG,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/E,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,YAAoB,EAAE,eAAuB;QAC7D,UAAU,CAAC,cAAc,CAAC,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;OAKG;IACH,MAA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,CAAC;YACN,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;CACF"}
@@ -13,7 +13,9 @@ export default class ErrorUtils {
13
13
  for (let i = 0; i < errorList.length; i += 1) {
14
14
  errorString += `${errorList[i]}\n`;
15
15
  }
16
- throw new Error(`${errorString}${JSON.stringify(erroneousObject, null, 2)}`);
16
+ throw new Error(
17
+ `${errorString}${JSON.stringify(erroneousObject, null, 2)}`
18
+ );
17
19
  }
18
20
 
19
21
  /**
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@aneuhold/core-ts-lib",
3
3
  "author": "Anton G. Neuhold Jr.",
4
4
  "license": "MIT",
5
- "version": "2.2.5",
5
+ "version": "2.2.7",
6
6
  "description": "A core library for all of my TypeScript projects",
7
7
  "type": "module",
8
8
  "scripts": {
@@ -1,48 +0,0 @@
1
- /**
2
- * A service for handling glob-like pattern matching operations.
3
- * Supports common glob patterns like **, *, and exact matches.
4
- *
5
- * Inspired by the isaacs/node-glob library (ISC License)
6
- * but simplified for basic use cases.
7
- */
8
- export default class GlobMatchingService {
9
- /**
10
- * Gets files matching the include patterns while excluding those that match exclude patterns.
11
- * Uses simple glob-like matching for common patterns.
12
- *
13
- * @param allFiles Array of all file paths to filter
14
- * @param rootPath The root directory path for computing relative paths
15
- * @param includePatterns Array of glob-like patterns to include
16
- * @param excludePatterns Array of glob-like patterns to exclude
17
- */
18
- static getMatchingFiles(allFiles: string[], rootPath: string, includePatterns: string[], excludePatterns: string[]): string[];
19
- /**
20
- * Simple glob-like pattern matching for common use cases.
21
- * Supports:
22
- * - ** for any number of directories (globstar)
23
- * - * for any characters except path separators
24
- * - Exact matches
25
- *
26
- * @param filePath The file path to test
27
- * @param pattern The pattern to match against
28
- */
29
- static matchesPattern(filePath: string, pattern: string): boolean;
30
- /**
31
- * Match path segments against pattern segments with support for globstar (**).
32
- *
33
- * The idea is that each segment doesn't cross path separators. It should
34
- * be split by '/' and then matched segment by segment.
35
- *
36
- * @param pathSegments Array of path segments
37
- * @param patternSegments Array of pattern segments
38
- */
39
- private static matchSegments;
40
- /**
41
- * Match a single segment with support for * wildcard
42
- *
43
- * @param pathSegment Single path segment
44
- * @param patternSegment Single pattern segment
45
- */
46
- private static matchSingleSegment;
47
- }
48
- //# sourceMappingURL=GlobMatchingService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GlobMatchingService.d.ts","sourceRoot":"","sources":["../../../src/services/FileSystemService/GlobMatchingService.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACtC;;;;;;;;OAQG;IACH,MAAM,CAAC,gBAAgB,CACrB,QAAQ,EAAE,MAAM,EAAE,EAClB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EAAE,EACzB,eAAe,EAAE,MAAM,EAAE,GACxB,MAAM,EAAE;IAcX;;;;;;;;;OASG;IACH,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;IAiBjE;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAuD5B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAiBlC"}
@@ -1,129 +0,0 @@
1
- import path from 'path';
2
- /**
3
- * A service for handling glob-like pattern matching operations.
4
- * Supports common glob patterns like **, *, and exact matches.
5
- *
6
- * Inspired by the isaacs/node-glob library (ISC License)
7
- * but simplified for basic use cases.
8
- */
9
- export default class GlobMatchingService {
10
- /**
11
- * Gets files matching the include patterns while excluding those that match exclude patterns.
12
- * Uses simple glob-like matching for common patterns.
13
- *
14
- * @param allFiles Array of all file paths to filter
15
- * @param rootPath The root directory path for computing relative paths
16
- * @param includePatterns Array of glob-like patterns to include
17
- * @param excludePatterns Array of glob-like patterns to exclude
18
- */
19
- static getMatchingFiles(allFiles, rootPath, includePatterns, excludePatterns) {
20
- return allFiles.filter((filePath) => {
21
- const relativePath = path.relative(rootPath, filePath);
22
- // Check if file matches any exclude pattern
23
- if (excludePatterns.some((pattern) => this.matchesPattern(relativePath, pattern))) {
24
- return false;
25
- }
26
- // Check if file matches any include pattern
27
- return includePatterns.some((pattern) => this.matchesPattern(relativePath, pattern));
28
- });
29
- }
30
- /**
31
- * Simple glob-like pattern matching for common use cases.
32
- * Supports:
33
- * - ** for any number of directories (globstar)
34
- * - * for any characters except path separators
35
- * - Exact matches
36
- *
37
- * @param filePath The file path to test
38
- * @param pattern The pattern to match against
39
- */
40
- static matchesPattern(filePath, pattern) {
41
- // Normalize path separators to forward slashes
42
- const normalizedPath = filePath.replace(/\\/g, '/');
43
- const normalizedPattern = pattern.replace(/\\/g, '/');
44
- // Handle special case of **/* which should match everything
45
- if (normalizedPattern === '**/*') {
46
- return true;
47
- }
48
- // Split into segments for more precise matching
49
- const pathSegments = normalizedPath.split('/');
50
- const patternSegments = normalizedPattern.split('/');
51
- return this.matchSegments(pathSegments, patternSegments);
52
- }
53
- /**
54
- * Match path segments against pattern segments with support for globstar (**).
55
- *
56
- * The idea is that each segment doesn't cross path separators. It should
57
- * be split by '/' and then matched segment by segment.
58
- *
59
- * @param pathSegments Array of path segments
60
- * @param patternSegments Array of pattern segments
61
- */
62
- static matchSegments(pathSegments, patternSegments) {
63
- let pathIndex = 0;
64
- let patternIndex = 0;
65
- while (pathIndex < pathSegments.length && patternIndex < patternSegments.length) {
66
- const pathSegment = pathSegments[pathIndex];
67
- const patternSegment = patternSegments[patternIndex];
68
- if (patternSegment === '**') {
69
- // Handle globstar - it can match zero or more segments
70
- patternIndex++;
71
- // If ** is the last segment, it matches everything remaining
72
- if (patternIndex >= patternSegments.length) {
73
- return true;
74
- }
75
- // Try to match the rest of the pattern against remaining path segments
76
- const remainingPattern = patternSegments.slice(patternIndex);
77
- // Try matching from current position onwards
78
- for (let i = pathIndex; i <= pathSegments.length; i++) {
79
- const remainingPath = pathSegments.slice(i);
80
- if (this.matchSegments(remainingPath, remainingPattern)) {
81
- return true;
82
- }
83
- }
84
- return false;
85
- }
86
- else if (this.matchSingleSegment(pathSegment, patternSegment)) {
87
- // Regular segment match
88
- pathIndex++;
89
- patternIndex++;
90
- }
91
- else {
92
- return false;
93
- }
94
- }
95
- // Check if we've consumed both path and pattern completely
96
- // or if remaining pattern segments are only globstars
97
- const remainingPattern = patternSegments.slice(patternIndex);
98
- const pathConsumed = pathIndex >= pathSegments.length;
99
- const patternConsumed = patternIndex >= patternSegments.length;
100
- if (pathConsumed && patternConsumed) {
101
- return true;
102
- }
103
- if (pathConsumed && remainingPattern.every((seg) => seg === '**')) {
104
- return true;
105
- }
106
- return false;
107
- }
108
- /**
109
- * Match a single segment with support for * wildcard
110
- *
111
- * @param pathSegment Single path segment
112
- * @param patternSegment Single pattern segment
113
- */
114
- static matchSingleSegment(pathSegment, patternSegment) {
115
- if (patternSegment === '*') {
116
- return true;
117
- }
118
- if (patternSegment === pathSegment) {
119
- return true;
120
- }
121
- // Convert pattern to regex for more complex matching
122
- const regexPattern = patternSegment
123
- .replace(/\./g, '\\.') // Escape dots
124
- .replace(/\*/g, '[^/]*'); // * matches anything except slashes
125
- const regex = new RegExp(`^${regexPattern}$`);
126
- return regex.test(pathSegment);
127
- }
128
- }
129
- //# sourceMappingURL=GlobMatchingService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GlobMatchingService.js","sourceRoot":"","sources":["../../../src/services/FileSystemService/GlobMatchingService.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACtC;;;;;;;;OAQG;IACH,MAAM,CAAC,gBAAgB,CACrB,QAAkB,EAClB,QAAgB,EAChB,eAAyB,EACzB,eAAyB;QAEzB,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE;YAClC,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC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I,gBAAgB,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,EAAE,CAAC;YAClE,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,kBAAkB,CAAC,WAAmB,EAAE,cAAsB;QAC3E,IAAI,cAAc,KAAK,GAAG,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,cAAc,KAAK,WAAW,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,qDAAqD;QACrD,MAAM,YAAY,GAAG,cAAc;aAChC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,cAAc;aACpC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,oCAAoC;QAEhE,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,YAAY,GAAG,CAAC,CAAC;QAC9C,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACjC,CAAC;CACF"}
@@ -1,153 +0,0 @@
1
- import path from 'path';
2
-
3
- /**
4
- * A service for handling glob-like pattern matching operations.
5
- * Supports common glob patterns like **, *, and exact matches.
6
- *
7
- * Inspired by the isaacs/node-glob library (ISC License)
8
- * but simplified for basic use cases.
9
- */
10
- export default class GlobMatchingService {
11
- /**
12
- * Gets files matching the include patterns while excluding those that match exclude patterns.
13
- * Uses simple glob-like matching for common patterns.
14
- *
15
- * @param allFiles Array of all file paths to filter
16
- * @param rootPath The root directory path for computing relative paths
17
- * @param includePatterns Array of glob-like patterns to include
18
- * @param excludePatterns Array of glob-like patterns to exclude
19
- */
20
- static getMatchingFiles(
21
- allFiles: string[],
22
- rootPath: string,
23
- includePatterns: string[],
24
- excludePatterns: string[]
25
- ): string[] {
26
- return allFiles.filter((filePath) => {
27
- const relativePath = path.relative(rootPath, filePath);
28
-
29
- // Check if file matches any exclude pattern
30
- if (excludePatterns.some((pattern) => this.matchesPattern(relativePath, pattern))) {
31
- return false;
32
- }
33
-
34
- // Check if file matches any include pattern
35
- return includePatterns.some((pattern) => this.matchesPattern(relativePath, pattern));
36
- });
37
- }
38
-
39
- /**
40
- * Simple glob-like pattern matching for common use cases.
41
- * Supports:
42
- * - ** for any number of directories (globstar)
43
- * - * for any characters except path separators
44
- * - Exact matches
45
- *
46
- * @param filePath The file path to test
47
- * @param pattern The pattern to match against
48
- */
49
- static matchesPattern(filePath: string, pattern: string): boolean {
50
- // Normalize path separators to forward slashes
51
- const normalizedPath = filePath.replace(/\\/g, '/');
52
- const normalizedPattern = pattern.replace(/\\/g, '/');
53
-
54
- // Handle special case of **/* which should match everything
55
- if (normalizedPattern === '**/*') {
56
- return true;
57
- }
58
-
59
- // Split into segments for more precise matching
60
- const pathSegments = normalizedPath.split('/');
61
- const patternSegments = normalizedPattern.split('/');
62
-
63
- return this.matchSegments(pathSegments, patternSegments);
64
- }
65
-
66
- /**
67
- * Match path segments against pattern segments with support for globstar (**).
68
- *
69
- * The idea is that each segment doesn't cross path separators. It should
70
- * be split by '/' and then matched segment by segment.
71
- *
72
- * @param pathSegments Array of path segments
73
- * @param patternSegments Array of pattern segments
74
- */
75
- private static matchSegments(pathSegments: string[], patternSegments: string[]): boolean {
76
- let pathIndex = 0;
77
- let patternIndex = 0;
78
-
79
- while (pathIndex < pathSegments.length && patternIndex < patternSegments.length) {
80
- const pathSegment = pathSegments[pathIndex];
81
- const patternSegment = patternSegments[patternIndex];
82
-
83
- if (patternSegment === '**') {
84
- // Handle globstar - it can match zero or more segments
85
- patternIndex++;
86
-
87
- // If ** is the last segment, it matches everything remaining
88
- if (patternIndex >= patternSegments.length) {
89
- return true;
90
- }
91
-
92
- // Try to match the rest of the pattern against remaining path segments
93
- const remainingPattern = patternSegments.slice(patternIndex);
94
-
95
- // Try matching from current position onwards
96
- for (let i = pathIndex; i <= pathSegments.length; i++) {
97
- const remainingPath = pathSegments.slice(i);
98
- if (this.matchSegments(remainingPath, remainingPattern)) {
99
- return true;
100
- }
101
- }
102
-
103
- return false;
104
- } else if (this.matchSingleSegment(pathSegment, patternSegment)) {
105
- // Regular segment match
106
- pathIndex++;
107
- patternIndex++;
108
- } else {
109
- return false;
110
- }
111
- }
112
-
113
- // Check if we've consumed both path and pattern completely
114
- // or if remaining pattern segments are only globstars
115
- const remainingPattern = patternSegments.slice(patternIndex);
116
- const pathConsumed = pathIndex >= pathSegments.length;
117
- const patternConsumed = patternIndex >= patternSegments.length;
118
-
119
- if (pathConsumed && patternConsumed) {
120
- return true;
121
- }
122
-
123
- if (pathConsumed && remainingPattern.every((seg) => seg === '**')) {
124
- return true;
125
- }
126
-
127
- return false;
128
- }
129
-
130
- /**
131
- * Match a single segment with support for * wildcard
132
- *
133
- * @param pathSegment Single path segment
134
- * @param patternSegment Single pattern segment
135
- */
136
- private static matchSingleSegment(pathSegment: string, patternSegment: string): boolean {
137
- if (patternSegment === '*') {
138
- return true;
139
- }
140
-
141
- if (patternSegment === pathSegment) {
142
- return true;
143
- }
144
-
145
- // Convert pattern to regex for more complex matching
146
- const regexPattern = patternSegment
147
- .replace(/\./g, '\\.') // Escape dots
148
- .replace(/\*/g, '[^/]*'); // * matches anything except slashes
149
-
150
- const regex = new RegExp(`^${regexPattern}$`);
151
- return regex.test(pathSegment);
152
- }
153
- }