@augment-vir/node 31.73.3 → 31.73.4
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/dist/augments/fs/grep.d.ts +2 -2
- package/dist/augments/fs/grep.js +107 -559
- package/dist/augments/fs/read-dir.js +3 -9
- package/dist/augments/path/contains.d.ts +7 -11
- package/dist/augments/path/contains.js +1 -1
- package/dist/augments/path/resolve-import.d.ts +1 -4
- package/dist/augments/path/resolve-import.js +3 -7
- package/dist/augments/terminal/run-cli-script.d.ts +8 -5
- package/dist/augments/terminal/run-cli-script.js +8 -1
- package/dist/augments/terminal/shell.d.ts +11 -20
- package/dist/augments/terminal/shell.js +4 -10
- package/package.json +6 -6
- package/src/augments/fs/grep.ts +135 -810
- package/src/augments/fs/read-dir.ts +3 -12
- package/src/augments/path/contains.ts +6 -10
- package/src/augments/path/resolve-import.ts +10 -14
- package/src/augments/terminal/run-cli-script.ts +10 -5
- package/src/augments/terminal/shell.ts +27 -47
|
@@ -2,20 +2,14 @@ import {readdir, stat} from 'node:fs/promises';
|
|
|
2
2
|
import {join, relative} from 'node:path';
|
|
3
3
|
import {type RequireExactlyOne} from 'type-fest';
|
|
4
4
|
|
|
5
|
-
async function internalReadDirPathsRecursive({
|
|
6
|
-
dirPath,
|
|
7
|
-
basePath,
|
|
8
|
-
}: Readonly<{dirPath: string; basePath: string}>): Promise<string[]> {
|
|
5
|
+
async function internalReadDirPathsRecursive(dirPath: string, basePath: string): Promise<string[]> {
|
|
9
6
|
const dirContents = await readdir(dirPath);
|
|
10
7
|
const recursiveContents: string[] = (
|
|
11
8
|
await Promise.all(
|
|
12
9
|
dirContents.map(async (fileName): Promise<string | ReadonlyArray<string>> => {
|
|
13
10
|
const filePath = join(dirPath, fileName);
|
|
14
11
|
if ((await stat(filePath)).isDirectory()) {
|
|
15
|
-
return internalReadDirPathsRecursive(
|
|
16
|
-
dirPath: filePath,
|
|
17
|
-
basePath,
|
|
18
|
-
});
|
|
12
|
+
return internalReadDirPathsRecursive(filePath, basePath);
|
|
19
13
|
} else {
|
|
20
14
|
return relative(basePath, filePath);
|
|
21
15
|
}
|
|
@@ -35,10 +29,7 @@ async function internalReadDirPathsRecursive({
|
|
|
35
29
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
36
30
|
*/
|
|
37
31
|
export async function readDirRecursive(dirPath: string): Promise<string[]> {
|
|
38
|
-
return await internalReadDirPathsRecursive(
|
|
39
|
-
dirPath,
|
|
40
|
-
basePath: dirPath,
|
|
41
|
-
});
|
|
32
|
+
return await internalReadDirPathsRecursive(dirPath, dirPath);
|
|
42
33
|
}
|
|
43
34
|
|
|
44
35
|
/**
|
|
@@ -9,22 +9,18 @@ import {isOperatingSystem, OperatingSystem} from '../os/operating-system.js';
|
|
|
9
9
|
* @category Package : @augment-vir/node
|
|
10
10
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
11
11
|
*/
|
|
12
|
-
export function doesPathContain(
|
|
13
|
-
potentialParentPath,
|
|
14
|
-
potentialChildPath,
|
|
15
|
-
options
|
|
16
|
-
}: Readonly<{
|
|
17
|
-
potentialParentPath: string;
|
|
18
|
-
potentialChildPath: string;
|
|
19
|
-
options?: PartialWithUndefined<{
|
|
12
|
+
export function doesPathContain(
|
|
13
|
+
potentialParentPath: string,
|
|
14
|
+
potentialChildPath: string,
|
|
15
|
+
options: PartialWithUndefined<{
|
|
20
16
|
/**
|
|
21
17
|
* Set this to `true` to return `true` if the paths are exactly equal.
|
|
22
18
|
*
|
|
23
19
|
* @default false
|
|
24
20
|
*/
|
|
25
21
|
allowSelf: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
22
|
+
}> = {},
|
|
23
|
+
): boolean {
|
|
28
24
|
if (!potentialParentPath || !potentialChildPath) {
|
|
29
25
|
return false;
|
|
30
26
|
}
|
|
@@ -17,18 +17,14 @@ import {replaceWithWindowsPathIfNeeded} from './os-path.js';
|
|
|
17
17
|
* @returns `undefined` if no matches are found.
|
|
18
18
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
19
19
|
*/
|
|
20
|
-
export function resolveImportPath(
|
|
21
|
-
importerFilePath,
|
|
22
|
-
importPath,
|
|
23
|
-
|
|
20
|
+
export function resolveImportPath(
|
|
21
|
+
importerFilePath: string,
|
|
22
|
+
importPath: string,
|
|
23
|
+
): string | undefined {
|
|
24
24
|
const foundTsconfig = readTsconfig(importerFilePath);
|
|
25
25
|
|
|
26
26
|
const mappedImportPath = foundTsconfig
|
|
27
|
-
? mapImportPath(
|
|
28
|
-
importPath,
|
|
29
|
-
tsconfig: foundTsconfig.tsconfig,
|
|
30
|
-
tsconfigPath: foundTsconfig.path,
|
|
31
|
-
})
|
|
27
|
+
? mapImportPath(importPath, foundTsconfig.tsconfig, foundTsconfig.path)
|
|
32
28
|
: importPath;
|
|
33
29
|
|
|
34
30
|
if (mappedImportPath.startsWith(sep) || mappedImportPath.startsWith('/')) {
|
|
@@ -85,11 +81,11 @@ function mapFilePath(path: string): string {
|
|
|
85
81
|
return path;
|
|
86
82
|
}
|
|
87
83
|
|
|
88
|
-
function mapImportPath(
|
|
89
|
-
importPath,
|
|
90
|
-
tsconfig,
|
|
91
|
-
tsconfigPath,
|
|
92
|
-
|
|
84
|
+
function mapImportPath(
|
|
85
|
+
importPath: string,
|
|
86
|
+
tsconfig: ParsedCommandLine,
|
|
87
|
+
tsconfigPath: string,
|
|
88
|
+
): string {
|
|
93
89
|
const paths = tsconfig.options.paths;
|
|
94
90
|
if (!paths) {
|
|
95
91
|
return importPath;
|
|
@@ -30,11 +30,16 @@ export const ExtensionToRunner: Record<string, string | {npx: string}> = {
|
|
|
30
30
|
* @category Package : @augment-vir/node
|
|
31
31
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
32
32
|
*/
|
|
33
|
-
export async function runCliScript(
|
|
34
|
-
scriptPath,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
export async function runCliScript(
|
|
34
|
+
scriptPath: string,
|
|
35
|
+
/** This should just be `__filename` (for CJS) or `import.meta.filename` (for ESM). */
|
|
36
|
+
cliScriptFilePath: string,
|
|
37
|
+
/**
|
|
38
|
+
* This should be the bin name of the package that is calling this function. Set to `undefined`
|
|
39
|
+
* if there isn't one.
|
|
40
|
+
*/
|
|
41
|
+
binName: string | undefined,
|
|
42
|
+
) {
|
|
38
43
|
const args = extractRelevantArgs({
|
|
39
44
|
rawArgs: process.argv,
|
|
40
45
|
binName,
|
|
@@ -75,21 +75,6 @@ export class ShellTarget extends ListenTarget<
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
/**
|
|
79
|
-
* Options for {@link streamShellCommand}.
|
|
80
|
-
*
|
|
81
|
-
* @category Node : Terminal : Util
|
|
82
|
-
* @category Package : @augment-vir/node
|
|
83
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
84
|
-
*/
|
|
85
|
-
export type StreamShellCommandOptions = PartialWithUndefined<{
|
|
86
|
-
cwd: string;
|
|
87
|
-
env: NodeJS.ProcessEnv;
|
|
88
|
-
shell: string;
|
|
89
|
-
/** Automatically hook up stdout and stderr printing to the caller's console methods. */
|
|
90
|
-
hookUpToConsole: boolean;
|
|
91
|
-
}>;
|
|
92
|
-
|
|
93
78
|
/**
|
|
94
79
|
* Runs a shell command and returns a {@link ShellTarget} instance for directly hooking into shell
|
|
95
80
|
* events. This allows instant reactions to shell events but in a less convenient API compared to
|
|
@@ -103,12 +88,10 @@ export type StreamShellCommandOptions = PartialWithUndefined<{
|
|
|
103
88
|
*/
|
|
104
89
|
export function streamShellCommand(
|
|
105
90
|
command: string,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
hookUpToConsole = false,
|
|
111
|
-
}: StreamShellCommandOptions = {},
|
|
91
|
+
cwd?: string,
|
|
92
|
+
shell = 'bash',
|
|
93
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
94
|
+
hookUpToConsole = false,
|
|
112
95
|
): ShellTarget {
|
|
113
96
|
const stdio = hookUpToConsole ? [process.stdin] : undefined;
|
|
114
97
|
|
|
@@ -164,11 +147,8 @@ export function streamShellCommand(
|
|
|
164
147
|
const exitSignal: NodeJS.Signals | undefined = inputExitSignal ?? undefined;
|
|
165
148
|
|
|
166
149
|
if ((exitCode !== undefined && exitCode !== 0) || exitSignal !== undefined) {
|
|
167
|
-
const execException: ExecException & {cwd?: string | undefined} =
|
|
168
|
-
|
|
169
|
-
{
|
|
170
|
-
cmd: command,
|
|
171
|
-
},
|
|
150
|
+
const execException: ExecException & {cwd?: string | undefined} = new Error(
|
|
151
|
+
`Command failed: ${command}`,
|
|
172
152
|
);
|
|
173
153
|
if (exitCode != undefined) {
|
|
174
154
|
execException.code = exitCode;
|
|
@@ -177,6 +157,7 @@ export function streamShellCommand(
|
|
|
177
157
|
if (exitSignal != undefined) {
|
|
178
158
|
execException.signal = exitSignal;
|
|
179
159
|
}
|
|
160
|
+
execException.cmd = command;
|
|
180
161
|
execException.killed = childProcess.killed;
|
|
181
162
|
execException.cwd = cwd;
|
|
182
163
|
shellTarget.dispatch(
|
|
@@ -205,21 +186,19 @@ export function streamShellCommand(
|
|
|
205
186
|
* @category Package : @augment-vir/node
|
|
206
187
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
207
188
|
*/
|
|
208
|
-
export type RunShellCommandOptions =
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
) => MaybePromise<void> | undefined;
|
|
222
|
-
}>;
|
|
189
|
+
export type RunShellCommandOptions = {
|
|
190
|
+
cwd?: string | undefined;
|
|
191
|
+
env?: NodeJS.ProcessEnv | undefined;
|
|
192
|
+
shell?: string | undefined;
|
|
193
|
+
/** Automatically hook up stdout and stderr printing to the caller's console methods. */
|
|
194
|
+
hookUpToConsole?: boolean | undefined;
|
|
195
|
+
/** @default false */
|
|
196
|
+
rejectOnError?: boolean | undefined;
|
|
197
|
+
/** Callback to call whenever the shell logs to stdout. */
|
|
198
|
+
stdoutCallback?: (stdout: string, childProcess: ChildProcess) => MaybePromise<void> | undefined;
|
|
199
|
+
/** Callback to call whenever the shell logs to stderr. */
|
|
200
|
+
stderrCallback?: (stderr: string, childProcess: ChildProcess) => MaybePromise<void> | undefined;
|
|
201
|
+
};
|
|
223
202
|
|
|
224
203
|
/**
|
|
225
204
|
* Runs a shell command and returns its output.
|
|
@@ -239,12 +218,13 @@ export async function runShellCommand(
|
|
|
239
218
|
let stderr = '';
|
|
240
219
|
const errors: Error[] = [];
|
|
241
220
|
|
|
242
|
-
const shellTarget = streamShellCommand(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
221
|
+
const shellTarget = streamShellCommand(
|
|
222
|
+
command,
|
|
223
|
+
options.cwd,
|
|
224
|
+
options.shell,
|
|
225
|
+
options.env,
|
|
226
|
+
options.hookUpToConsole,
|
|
227
|
+
);
|
|
248
228
|
|
|
249
229
|
shellTarget.listen(ShellStdoutEvent, ({detail: chunk}) => {
|
|
250
230
|
if (options.stdoutCallback) {
|