@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
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { readdir, stat } from 'node:fs/promises';
|
|
2
2
|
import { join, relative } from 'node:path';
|
|
3
|
-
async function internalReadDirPathsRecursive(
|
|
3
|
+
async function internalReadDirPathsRecursive(dirPath, basePath) {
|
|
4
4
|
const dirContents = await readdir(dirPath);
|
|
5
5
|
const recursiveContents = (await Promise.all(dirContents.map(async (fileName) => {
|
|
6
6
|
const filePath = join(dirPath, fileName);
|
|
7
7
|
if ((await stat(filePath)).isDirectory()) {
|
|
8
|
-
return internalReadDirPathsRecursive(
|
|
9
|
-
dirPath: filePath,
|
|
10
|
-
basePath,
|
|
11
|
-
});
|
|
8
|
+
return internalReadDirPathsRecursive(filePath, basePath);
|
|
12
9
|
}
|
|
13
10
|
else {
|
|
14
11
|
return relative(basePath, filePath);
|
|
@@ -25,10 +22,7 @@ async function internalReadDirPathsRecursive({ dirPath, basePath, }) {
|
|
|
25
22
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
26
23
|
*/
|
|
27
24
|
export async function readDirRecursive(dirPath) {
|
|
28
|
-
return await internalReadDirPathsRecursive(
|
|
29
|
-
dirPath,
|
|
30
|
-
basePath: dirPath,
|
|
31
|
-
});
|
|
25
|
+
return await internalReadDirPathsRecursive(dirPath, dirPath);
|
|
32
26
|
}
|
|
33
27
|
/**
|
|
34
28
|
* Reads all files within a single directory and filters them by the given extension or extensions.
|
|
@@ -6,15 +6,11 @@ import { type PartialWithUndefined } from '@augment-vir/common';
|
|
|
6
6
|
* @category Package : @augment-vir/node
|
|
7
7
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
8
|
*/
|
|
9
|
-
export declare function doesPathContain(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* @default false
|
|
17
|
-
*/
|
|
18
|
-
allowSelf: boolean;
|
|
19
|
-
}>;
|
|
9
|
+
export declare function doesPathContain(potentialParentPath: string, potentialChildPath: string, options?: PartialWithUndefined<{
|
|
10
|
+
/**
|
|
11
|
+
* Set this to `true` to return `true` if the paths are exactly equal.
|
|
12
|
+
*
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
allowSelf: boolean;
|
|
20
16
|
}>): boolean;
|
|
@@ -7,7 +7,7 @@ import { isOperatingSystem, OperatingSystem } from '../os/operating-system.js';
|
|
|
7
7
|
* @category Package : @augment-vir/node
|
|
8
8
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
9
9
|
*/
|
|
10
|
-
export function doesPathContain(
|
|
10
|
+
export function doesPathContain(potentialParentPath, potentialChildPath, options = {}) {
|
|
11
11
|
if (!potentialParentPath || !potentialChildPath) {
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
@@ -8,7 +8,4 @@
|
|
|
8
8
|
* @returns `undefined` if no matches are found.
|
|
9
9
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
10
10
|
*/
|
|
11
|
-
export declare function resolveImportPath(
|
|
12
|
-
importerFilePath: string;
|
|
13
|
-
importPath: string;
|
|
14
|
-
}>): string | undefined;
|
|
11
|
+
export declare function resolveImportPath(importerFilePath: string, importPath: string): string | undefined;
|
|
@@ -15,14 +15,10 @@ import { replaceWithWindowsPathIfNeeded } from './os-path.js';
|
|
|
15
15
|
* @returns `undefined` if no matches are found.
|
|
16
16
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
17
17
|
*/
|
|
18
|
-
export function resolveImportPath(
|
|
18
|
+
export function resolveImportPath(importerFilePath, importPath) {
|
|
19
19
|
const foundTsconfig = readTsconfig(importerFilePath);
|
|
20
20
|
const mappedImportPath = foundTsconfig
|
|
21
|
-
? mapImportPath(
|
|
22
|
-
importPath,
|
|
23
|
-
tsconfig: foundTsconfig.tsconfig,
|
|
24
|
-
tsconfigPath: foundTsconfig.path,
|
|
25
|
-
})
|
|
21
|
+
? mapImportPath(importPath, foundTsconfig.tsconfig, foundTsconfig.path)
|
|
26
22
|
: importPath;
|
|
27
23
|
if (mappedImportPath.startsWith(sep) || mappedImportPath.startsWith('/')) {
|
|
28
24
|
/** Absolute import */
|
|
@@ -60,7 +56,7 @@ function mapFilePath(path) {
|
|
|
60
56
|
}
|
|
61
57
|
return path;
|
|
62
58
|
}
|
|
63
|
-
function mapImportPath(
|
|
59
|
+
function mapImportPath(importPath, tsconfig, tsconfigPath) {
|
|
64
60
|
const paths = tsconfig.options.paths;
|
|
65
61
|
if (!paths) {
|
|
66
62
|
return importPath;
|
|
@@ -16,8 +16,11 @@ export declare const ExtensionToRunner: Record<string, string | {
|
|
|
16
16
|
* @category Package : @augment-vir/node
|
|
17
17
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
18
18
|
*/
|
|
19
|
-
export declare function runCliScript(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
export declare function runCliScript(scriptPath: string,
|
|
20
|
+
/** This should just be `__filename` (for CJS) or `import.meta.filename` (for ESM). */
|
|
21
|
+
cliScriptFilePath: string,
|
|
22
|
+
/**
|
|
23
|
+
* This should be the bin name of the package that is calling this function. Set to `undefined`
|
|
24
|
+
* if there isn't one.
|
|
25
|
+
*/
|
|
26
|
+
binName: string | undefined): Promise<void>;
|
|
@@ -27,7 +27,14 @@ export const ExtensionToRunner = {
|
|
|
27
27
|
* @category Package : @augment-vir/node
|
|
28
28
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
29
29
|
*/
|
|
30
|
-
export async function runCliScript(
|
|
30
|
+
export async function runCliScript(scriptPath,
|
|
31
|
+
/** This should just be `__filename` (for CJS) or `import.meta.filename` (for ESM). */
|
|
32
|
+
cliScriptFilePath,
|
|
33
|
+
/**
|
|
34
|
+
* This should be the bin name of the package that is calling this function. Set to `undefined`
|
|
35
|
+
* if there isn't one.
|
|
36
|
+
*/
|
|
37
|
+
binName) {
|
|
31
38
|
const args = extractRelevantArgs({
|
|
32
39
|
rawArgs: process.argv,
|
|
33
40
|
binName,
|
|
@@ -126,20 +126,6 @@ export declare class ShellTarget extends ListenTarget<ShellStdoutEvent | ShellSt
|
|
|
126
126
|
readonly childProcess: ChildProcess;
|
|
127
127
|
constructor(childProcess: ChildProcess);
|
|
128
128
|
}
|
|
129
|
-
/**
|
|
130
|
-
* Options for {@link streamShellCommand}.
|
|
131
|
-
*
|
|
132
|
-
* @category Node : Terminal : Util
|
|
133
|
-
* @category Package : @augment-vir/node
|
|
134
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
135
|
-
*/
|
|
136
|
-
export type StreamShellCommandOptions = PartialWithUndefined<{
|
|
137
|
-
cwd: string;
|
|
138
|
-
env: NodeJS.ProcessEnv;
|
|
139
|
-
shell: string;
|
|
140
|
-
/** Automatically hook up stdout and stderr printing to the caller's console methods. */
|
|
141
|
-
hookUpToConsole: boolean;
|
|
142
|
-
}>;
|
|
143
129
|
/**
|
|
144
130
|
* Runs a shell command and returns a {@link ShellTarget} instance for directly hooking into shell
|
|
145
131
|
* events. This allows instant reactions to shell events but in a less convenient API compared to
|
|
@@ -151,7 +137,7 @@ export type StreamShellCommandOptions = PartialWithUndefined<{
|
|
|
151
137
|
* @see
|
|
152
138
|
* - {@link runShellCommand}: a higher level and more succinct way of running a shell command.
|
|
153
139
|
*/
|
|
154
|
-
export declare function streamShellCommand(command: string,
|
|
140
|
+
export declare function streamShellCommand(command: string, cwd?: string, shell?: string, env?: NodeJS.ProcessEnv, hookUpToConsole?: boolean): ShellTarget;
|
|
155
141
|
/**
|
|
156
142
|
* Options for {@link runShellCommand}.
|
|
157
143
|
*
|
|
@@ -159,14 +145,19 @@ export declare function streamShellCommand(command: string, { cwd, env, shell, h
|
|
|
159
145
|
* @category Package : @augment-vir/node
|
|
160
146
|
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
161
147
|
*/
|
|
162
|
-
export type RunShellCommandOptions =
|
|
148
|
+
export type RunShellCommandOptions = {
|
|
149
|
+
cwd?: string | undefined;
|
|
150
|
+
env?: NodeJS.ProcessEnv | undefined;
|
|
151
|
+
shell?: string | undefined;
|
|
152
|
+
/** Automatically hook up stdout and stderr printing to the caller's console methods. */
|
|
153
|
+
hookUpToConsole?: boolean | undefined;
|
|
163
154
|
/** @default false */
|
|
164
|
-
rejectOnError
|
|
155
|
+
rejectOnError?: boolean | undefined;
|
|
165
156
|
/** Callback to call whenever the shell logs to stdout. */
|
|
166
|
-
stdoutCallback
|
|
157
|
+
stdoutCallback?: (stdout: string, childProcess: ChildProcess) => MaybePromise<void> | undefined;
|
|
167
158
|
/** Callback to call whenever the shell logs to stderr. */
|
|
168
|
-
stderrCallback
|
|
169
|
-
}
|
|
159
|
+
stderrCallback?: (stderr: string, childProcess: ChildProcess) => MaybePromise<void> | undefined;
|
|
160
|
+
};
|
|
170
161
|
/**
|
|
171
162
|
* Runs a shell command and returns its output.
|
|
172
163
|
*
|
|
@@ -64,7 +64,7 @@ export class ShellTarget extends ListenTarget {
|
|
|
64
64
|
* @see
|
|
65
65
|
* - {@link runShellCommand}: a higher level and more succinct way of running a shell command.
|
|
66
66
|
*/
|
|
67
|
-
export function streamShellCommand(command,
|
|
67
|
+
export function streamShellCommand(command, cwd, shell = 'bash', env = process.env, hookUpToConsole = false) {
|
|
68
68
|
const stdio = hookUpToConsole ? [process.stdin] : undefined;
|
|
69
69
|
const childProcess = spawn(command, {
|
|
70
70
|
shell,
|
|
@@ -109,9 +109,7 @@ export function streamShellCommand(command, { cwd, env = process.env, shell = 'b
|
|
|
109
109
|
const exitCode = inputExitCode ?? undefined;
|
|
110
110
|
const exitSignal = inputExitSignal ?? undefined;
|
|
111
111
|
if ((exitCode !== undefined && exitCode !== 0) || exitSignal !== undefined) {
|
|
112
|
-
const execException =
|
|
113
|
-
cmd: command,
|
|
114
|
-
});
|
|
112
|
+
const execException = new Error(`Command failed: ${command}`);
|
|
115
113
|
if (exitCode != undefined) {
|
|
116
114
|
execException.code = exitCode;
|
|
117
115
|
}
|
|
@@ -119,6 +117,7 @@ export function streamShellCommand(command, { cwd, env = process.env, shell = 'b
|
|
|
119
117
|
if (exitSignal != undefined) {
|
|
120
118
|
execException.signal = exitSignal;
|
|
121
119
|
}
|
|
120
|
+
execException.cmd = command;
|
|
122
121
|
execException.killed = childProcess.killed;
|
|
123
122
|
execException.cwd = cwd;
|
|
124
123
|
shellTarget.dispatch(new ShellErrorEvent({
|
|
@@ -148,12 +147,7 @@ export async function runShellCommand(command, options = {}) {
|
|
|
148
147
|
let stdout = '';
|
|
149
148
|
let stderr = '';
|
|
150
149
|
const errors = [];
|
|
151
|
-
const shellTarget = streamShellCommand(command,
|
|
152
|
-
cwd: options.cwd,
|
|
153
|
-
shell: options.shell,
|
|
154
|
-
env: options.env,
|
|
155
|
-
hookUpToConsole: options.hookUpToConsole,
|
|
156
|
-
});
|
|
150
|
+
const shellTarget = streamShellCommand(command, options.cwd, options.shell, options.env, options.hookUpToConsole);
|
|
157
151
|
shellTarget.listen(ShellStdoutEvent, ({ detail: chunk }) => {
|
|
158
152
|
if (options.stdoutCallback) {
|
|
159
153
|
void options.stdoutCallback(chunk.toString(), shellTarget.childProcess);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/node",
|
|
3
|
-
"version": "31.73.
|
|
3
|
+
"version": "31.73.4",
|
|
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,9 +38,9 @@
|
|
|
38
38
|
"test:update": "npm test"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@augment-vir/assert": "^31.73.
|
|
42
|
-
"@augment-vir/common": "^31.73.
|
|
43
|
-
"@date-vir/duration": "^8.
|
|
41
|
+
"@augment-vir/assert": "^31.73.4",
|
|
42
|
+
"@augment-vir/common": "^31.73.4",
|
|
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",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"typed-event-target": "^4.3.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@augment-vir/test": "^31.73.
|
|
53
|
-
"@types/node": "^
|
|
52
|
+
"@augment-vir/test": "^31.73.4",
|
|
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",
|