@augment-vir/node 31.73.1 → 31.73.2

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.
@@ -1,10 +1,26 @@
1
1
  import { assert, check } from '@augment-vir/assert';
2
2
  import { arrayToObject, getOrSet, log, safeMatch, } from '@augment-vir/common';
3
3
  import { join } from 'node:path';
4
+ import { isOperatingSystem, OperatingSystem } from '../os/operating-system.js';
4
5
  import { runShellCommand } from '../terminal/shell.js';
5
6
  function escape(input) {
6
7
  return input.replaceAll('"', String.raw `\"`).replaceAll('\n', '');
7
8
  }
9
+ function recursiveFlag({ recursive, followSymLinks, }) {
10
+ if (!recursive) {
11
+ return '';
12
+ }
13
+ else if (!followSymLinks) {
14
+ return '--recursive';
15
+ }
16
+ /**
17
+ * BSD `grep` (macOS) requires `-S` to follow symlinks while recursing, but GNU `grep` (Linux)
18
+ * has no `-S` flag and instead follows all symlinks with `-R`. Only one of these branches can
19
+ * run on a given operating system.
20
+ */
21
+ /* node:coverage ignore next */
22
+ return isOperatingSystem(OperatingSystem.Mac) ? '-RS' : '-R';
23
+ }
8
24
  /**
9
25
  * Run `grep`, matching patterns to specific lines in files or directories.
10
26
  *
@@ -75,7 +91,7 @@ export async function grep(grepSearchPattern, grepSearchLocation, options = {})
75
91
  ...(options.excludePatterns?.length
76
92
  ? options.excludePatterns.map((excludePattern) => `--exclude="${escape(excludePattern)}"`)
77
93
  : []),
78
- options.recursive ? (options.followSymLinks ? '-RS' : '--recursive') : '',
94
+ recursiveFlag(options),
79
95
  ...(options.excludeDirs?.length
80
96
  ? options.excludeDirs.map((excludeDir) => `--exclude-dir="${escape(excludeDir)}"`)
81
97
  : []),
@@ -100,13 +116,17 @@ export async function grep(grepSearchPattern, grepSearchLocation, options = {})
100
116
  return {};
101
117
  }
102
118
  else if (options.output?.countOnly) {
103
- return arrayToObject(trimmedOutput.split(/[\0\n]/), (entry) => {
119
+ return arrayToObject(trimmedOutput.split('\n'), (entry) => {
104
120
  /** Ignore empty strings. */
105
121
  /* node:coverage ignore next 3 */
106
122
  if (!entry) {
107
123
  return undefined;
108
124
  }
109
- const [, fileName, countString,] = safeMatch(entry, /(^.+):(\d+)$/);
125
+ /**
126
+ * GNU `grep` (Linux) separates the file name from its count with a null byte when
127
+ * `--null` is set, while BSD `grep` (macOS) uses a colon. Accept either.
128
+ */
129
+ const [, fileName, countString,] = safeMatch(entry, /^(.+)[\0:](\d+)$/);
110
130
  assert.isDefined(fileName, `Failed parse grep file name from: '${entry}'`);
111
131
  const count = Number(countString);
112
132
  assert.isNumber(count, `Failed to parse grep number from: '${entry}'`);
@@ -74,5 +74,6 @@ function mapImportPath(importPath, tsconfig, tsconfigPath) {
74
74
  if (!mappedPaths[0]) {
75
75
  return importPath;
76
76
  }
77
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
77
78
  return resolve(tsconfig.options.baseUrl || dirname(tsconfigPath), mappedPaths[0]);
78
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/node",
3
- "version": "31.73.1",
3
+ "version": "31.73.2",
4
4
  "description": "A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.",
5
5
  "keywords": [
6
6
  "augment",
@@ -38,25 +38,25 @@
38
38
  "test:update": "npm test"
39
39
  },
40
40
  "dependencies": {
41
- "@augment-vir/assert": "^31.73.1",
42
- "@augment-vir/common": "^31.73.1",
43
- "@date-vir/duration": "^8.3.2",
41
+ "@augment-vir/assert": "^31.73.2",
42
+ "@augment-vir/common": "^31.73.2",
43
+ "@date-vir/duration": "^8.5.0",
44
44
  "ansi-styles": "^6.2.3",
45
45
  "sanitize-filename": "^1.6.4",
46
46
  "terminate": "^2.8.0",
47
- "tsx": "^4.22.3",
48
- "type-fest": "^5.6.0",
49
- "typed-event-target": "^4.3.0"
47
+ "tsx": "^4.22.4",
48
+ "type-fest": "^5.7.0",
49
+ "typed-event-target": "^4.3.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@augment-vir/test": "^31.73.1",
53
- "@types/node": "^25.9.1",
52
+ "@augment-vir/test": "^31.73.2",
53
+ "@types/node": "^25.9.3",
54
54
  "@web/dev-server-esbuild": "^1.0.5",
55
55
  "@web/test-runner": "^0.20.2",
56
56
  "@web/test-runner-playwright": "^0.11.1",
57
57
  "c8": "^11.0.0",
58
58
  "istanbul-smart-text-reporter": "^1.1.5",
59
- "typescript": "^5.9.3"
59
+ "typescript": "^6.0.3"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "typescript": "*"
@@ -9,6 +9,7 @@ import {
9
9
  } from '@augment-vir/common';
10
10
  import {join} from 'node:path';
11
11
  import {type IsEqual, type RequireExactlyOne} from 'type-fest';
12
+ import {isOperatingSystem, OperatingSystem} from '../os/operating-system.js';
12
13
  import {runShellCommand} from '../terminal/shell.js';
13
14
 
14
15
  /**
@@ -178,6 +179,25 @@ function escape(input: string) {
178
179
  return input.replaceAll('"', String.raw`\"`).replaceAll('\n', '');
179
180
  }
180
181
 
182
+ function recursiveFlag({
183
+ recursive,
184
+ followSymLinks,
185
+ }: Readonly<Pick<GrepOptions, 'recursive' | 'followSymLinks'>>): string {
186
+ if (!recursive) {
187
+ return '';
188
+ } else if (!followSymLinks) {
189
+ return '--recursive';
190
+ }
191
+
192
+ /**
193
+ * BSD `grep` (macOS) requires `-S` to follow symlinks while recursing, but GNU `grep` (Linux)
194
+ * has no `-S` flag and instead follows all symlinks with `-R`. Only one of these branches can
195
+ * run on a given operating system.
196
+ */
197
+ /* node:coverage ignore next */
198
+ return isOperatingSystem(OperatingSystem.Mac) ? '-RS' : '-R';
199
+ }
200
+
181
201
  /**
182
202
  * Output of {@link grep}. Each key is an absolute file path. Values are array of matches lines for
183
203
  * that file.
@@ -279,7 +299,7 @@ export async function grep<const CountOnly extends boolean = false>(
279
299
  (excludePattern) => `--exclude="${escape(excludePattern)}"`,
280
300
  )
281
301
  : []),
282
- options.recursive ? (options.followSymLinks ? '-RS' : '--recursive') : '',
302
+ recursiveFlag(options),
283
303
  ...(options.excludeDirs?.length
284
304
  ? options.excludeDirs.map((excludeDir) => `--exclude-dir="${escape(excludeDir)}"`)
285
305
  : []),
@@ -308,7 +328,7 @@ export async function grep<const CountOnly extends boolean = false>(
308
328
  return {};
309
329
  } else if (options.output?.countOnly) {
310
330
  return arrayToObject(
311
- trimmedOutput.split(/[\0\n]/),
331
+ trimmedOutput.split('\n'),
312
332
  (entry) => {
313
333
  /** Ignore empty strings. */
314
334
  /* node:coverage ignore next 3 */
@@ -316,11 +336,15 @@ export async function grep<const CountOnly extends boolean = false>(
316
336
  return undefined;
317
337
  }
318
338
 
339
+ /**
340
+ * GNU `grep` (Linux) separates the file name from its count with a null byte when
341
+ * `--null` is set, while BSD `grep` (macOS) uses a colon. Accept either.
342
+ */
319
343
  const [
320
344
  ,
321
345
  fileName,
322
346
  countString,
323
- ] = safeMatch(entry, /(^.+):(\d+)$/);
347
+ ] = safeMatch(entry, /^(.+)[\0:](\d+)$/);
324
348
 
325
349
  assert.isDefined(fileName, `Failed parse grep file name from: '${entry}'`);
326
350
 
@@ -115,5 +115,6 @@ function mapImportPath(
115
115
  return importPath;
116
116
  }
117
117
 
118
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
118
119
  return resolve(tsconfig.options.baseUrl || dirname(tsconfigPath), mappedPaths[0]);
119
120
  }