@augment-vir/node 30.0.0 → 30.0.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.
- package/README.md +7 -10
- package/dist/augments/docker.d.ts +49 -2
- package/dist/augments/docker.js +48 -2
- package/dist/augments/fs/download.d.ts +11 -0
- package/dist/augments/{download.js → fs/download.js} +7 -0
- package/dist/augments/fs/json.d.ts +42 -0
- package/dist/augments/fs/json.js +34 -0
- package/dist/augments/fs/read-dir.d.ts +11 -3
- package/dist/augments/fs/read-dir.js +11 -3
- package/dist/augments/fs/read-file.d.ts +8 -0
- package/dist/augments/fs/read-file.js +8 -0
- package/dist/augments/fs/symlink.d.ts +7 -0
- package/dist/augments/fs/symlink.js +7 -0
- package/dist/augments/fs/write.d.ts +4 -0
- package/dist/augments/fs/write.js +4 -0
- package/dist/augments/npm/query-workspace.d.ts +14 -0
- package/dist/augments/npm/query-workspace.js +8 -1
- package/dist/augments/npm/read-package-json.d.ts +9 -0
- package/dist/augments/npm/read-package-json.js +9 -0
- package/dist/augments/os/operating-system.d.ts +33 -0
- package/dist/augments/os/operating-system.js +35 -0
- package/dist/augments/path/ancestor.d.ts +19 -0
- package/dist/augments/path/ancestor.js +28 -0
- package/dist/augments/path/os-path.d.ts +19 -3
- package/dist/augments/path/os-path.js +19 -3
- package/dist/augments/path/root.d.ts +7 -0
- package/dist/augments/path/root.js +7 -0
- package/dist/augments/prisma.d.ts +137 -1
- package/dist/augments/prisma.js +135 -1
- package/dist/augments/terminal/question.d.ts +50 -0
- package/dist/augments/{console → terminal}/question.js +23 -2
- package/dist/augments/{shell.d.ts → terminal/shell.d.ts} +87 -4
- package/dist/augments/{shell.js → terminal/shell.js} +63 -3
- package/dist/docker/containers/container-info.d.ts +35 -6
- package/dist/docker/containers/container-info.js +1 -7
- package/dist/docker/containers/container-status.d.ts +15 -0
- package/dist/docker/containers/container-status.js +16 -1
- package/dist/docker/containers/copy-to-container.d.ts +7 -0
- package/dist/docker/containers/copy-to-container.js +1 -1
- package/dist/docker/containers/docker-command-inputs.d.ts +54 -0
- package/dist/docker/containers/docker-command-inputs.js +9 -0
- package/dist/docker/containers/kill-container.js +1 -1
- package/dist/docker/containers/run-command.d.ts +8 -2
- package/dist/docker/containers/run-command.js +1 -2
- package/dist/docker/containers/run-container.d.ts +7 -0
- package/dist/docker/containers/run-container.js +1 -1
- package/dist/docker/docker-image.js +4 -2
- package/dist/docker/docker-startup.js +1 -2
- package/dist/docker/run-docker-test.mock.d.ts +2 -0
- package/dist/docker/run-docker-test.mock.js +16 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/prisma/disable-ci-env.mock.d.ts +2 -0
- package/dist/prisma/disable-ci-env.mock.js +81 -0
- package/dist/prisma/model-data.d.ts +73 -0
- package/dist/prisma/model-data.js +70 -0
- package/dist/prisma/prisma-client.d.ts +0 -4
- package/dist/prisma/prisma-client.js +0 -4
- package/dist/prisma/prisma-errors.d.ts +25 -0
- package/dist/prisma/prisma-errors.js +25 -0
- package/dist/prisma/prisma-migrations.d.ts +12 -6
- package/dist/prisma/prisma-migrations.js +1 -7
- package/dist/prisma/run-prisma-command.d.ts +1 -1
- package/dist/prisma/run-prisma-command.js +1 -1
- package/package.json +23 -13
- package/dist/augments/console/question.d.ts +0 -14
- package/dist/augments/download.d.ts +0 -4
|
@@ -2,6 +2,13 @@ import { type Logger } from '@augment-vir/common';
|
|
|
2
2
|
import type { MaybePromise, PartialWithUndefined } from '@augment-vir/core';
|
|
3
3
|
import { ChildProcess } from 'node:child_process';
|
|
4
4
|
import { ListenTarget } from 'typed-event-target';
|
|
5
|
+
/**
|
|
6
|
+
* All output from {@link runShellCommand}.
|
|
7
|
+
*
|
|
8
|
+
* @category Node : Terminal : Util
|
|
9
|
+
* @category Package : @augment-vir/node
|
|
10
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
11
|
+
*/
|
|
5
12
|
export type ShellOutput = {
|
|
6
13
|
error: undefined | Error;
|
|
7
14
|
stderr: string;
|
|
@@ -17,6 +24,13 @@ declare const ShellStdoutEvent_base: (new (eventInitDict: import("typed-event-ta
|
|
|
17
24
|
readonly AT_TARGET: 2;
|
|
18
25
|
readonly BUBBLING_PHASE: 3;
|
|
19
26
|
}, "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE" | "prototype"> & Pick<import("typed-event-target").TypedCustomEvent<string | Buffer, "shell-stdout">, "type">;
|
|
27
|
+
/**
|
|
28
|
+
* An event that indicates that the shell command just wrote to stdout.
|
|
29
|
+
*
|
|
30
|
+
* @category Node : Terminal : Util
|
|
31
|
+
* @category Package : @augment-vir/node
|
|
32
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
33
|
+
*/
|
|
20
34
|
export declare class ShellStdoutEvent extends ShellStdoutEvent_base {
|
|
21
35
|
}
|
|
22
36
|
declare const ShellStderrEvent_base: (new (eventInitDict: import("typed-event-target").TypedCustomEventInit<string | Buffer>) => import("typed-event-target").TypedCustomEvent<string | Buffer, "shell-stderr">) & Pick<{
|
|
@@ -27,6 +41,13 @@ declare const ShellStderrEvent_base: (new (eventInitDict: import("typed-event-ta
|
|
|
27
41
|
readonly AT_TARGET: 2;
|
|
28
42
|
readonly BUBBLING_PHASE: 3;
|
|
29
43
|
}, "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE" | "prototype"> & Pick<import("typed-event-target").TypedCustomEvent<string | Buffer, "shell-stderr">, "type">;
|
|
44
|
+
/**
|
|
45
|
+
* An event that indicates that the shell command just wrote to stderr.
|
|
46
|
+
*
|
|
47
|
+
* @category Node : Terminal : Util
|
|
48
|
+
* @category Package : @augment-vir/node
|
|
49
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
50
|
+
*/
|
|
30
51
|
export declare class ShellStderrEvent extends ShellStderrEvent_base {
|
|
31
52
|
}
|
|
32
53
|
declare const ShellDoneEvent_base: (new (eventInitDict: import("typed-event-target").TypedCustomEventInit<{
|
|
@@ -47,8 +68,13 @@ declare const ShellDoneEvent_base: (new (eventInitDict: import("typed-event-targ
|
|
|
47
68
|
exitSignal: NodeJS.Signals | undefined;
|
|
48
69
|
}, "shell-done">, "type">;
|
|
49
70
|
/**
|
|
50
|
-
*
|
|
51
|
-
* other is defined, never both at the
|
|
71
|
+
* An event that indicates that the shell command is finished. This contains an exit code or an exit
|
|
72
|
+
* signal. Based on the Node.js documentation, either one or the other is defined, never both at the
|
|
73
|
+
* same time.
|
|
74
|
+
*
|
|
75
|
+
* @category Node : Terminal : Util
|
|
76
|
+
* @category Package : @augment-vir/node
|
|
77
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
52
78
|
*/
|
|
53
79
|
export declare class ShellDoneEvent extends ShellDoneEvent_base {
|
|
54
80
|
}
|
|
@@ -60,28 +86,85 @@ declare const ShellErrorEvent_base: (new (eventInitDict: import("typed-event-tar
|
|
|
60
86
|
readonly AT_TARGET: 2;
|
|
61
87
|
readonly BUBBLING_PHASE: 3;
|
|
62
88
|
}, "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE" | "prototype"> & Pick<import("typed-event-target").TypedCustomEvent<Error, "shell-error">, "type">;
|
|
89
|
+
/**
|
|
90
|
+
* An event that indicates that the shell command errored.
|
|
91
|
+
*
|
|
92
|
+
* @category Node : Terminal : Util
|
|
93
|
+
* @category Package : @augment-vir/node
|
|
94
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
95
|
+
*/
|
|
63
96
|
export declare class ShellErrorEvent extends ShellErrorEvent_base {
|
|
64
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* A shell command listen target that emits events.
|
|
100
|
+
*
|
|
101
|
+
* @category Node : Terminal : Util
|
|
102
|
+
* @category Package : @augment-vir/node
|
|
103
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
104
|
+
*/
|
|
65
105
|
export declare class ShellTarget extends ListenTarget<ShellStdoutEvent | ShellStderrEvent | ShellDoneEvent | ShellErrorEvent> {
|
|
66
106
|
readonly childProcess: ChildProcess;
|
|
67
107
|
constructor(childProcess: ChildProcess);
|
|
68
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Runs a shell command and returns a {@link ShellTarget} instance for directly hooking into shell
|
|
111
|
+
* events. This allows instant reactions to shell events but in a less convenient API compared to
|
|
112
|
+
* {@link runShellCommand}.
|
|
113
|
+
*
|
|
114
|
+
* @category Node : Terminal
|
|
115
|
+
* @category Package : @augment-vir/node
|
|
116
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
117
|
+
* @see
|
|
118
|
+
* - {@link runShellCommand}: a higher level and more succinct way of running a shell command.
|
|
119
|
+
*/
|
|
69
120
|
export declare function streamShellCommand(command: string, cwd?: string, shell?: string, env?: NodeJS.ProcessEnv, hookUpToConsole?: boolean): ShellTarget;
|
|
70
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Options for {@link runShellCommand}.
|
|
123
|
+
*
|
|
124
|
+
* @category Node : Terminal : Util
|
|
125
|
+
* @category Package : @augment-vir/node
|
|
126
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
127
|
+
*/
|
|
128
|
+
export type RunShellCommandOptions = {
|
|
71
129
|
cwd?: string | undefined;
|
|
72
130
|
env?: NodeJS.ProcessEnv | undefined;
|
|
73
131
|
shell?: string | undefined;
|
|
74
132
|
/** Automatically hook up stdout and stderr printing to the caller's console methods. */
|
|
75
133
|
hookUpToConsole?: boolean | undefined;
|
|
76
134
|
rejectOnError?: boolean | undefined;
|
|
135
|
+
/** Callback to call whenever the shell logs to stdout. */
|
|
77
136
|
stdoutCallback?: (stdout: string, childProcess: ChildProcess) => MaybePromise<void> | undefined;
|
|
137
|
+
/** Callback to call whenever the shell logs to stderr. */
|
|
78
138
|
stderrCallback?: (stderr: string, childProcess: ChildProcess) => MaybePromise<void> | undefined;
|
|
79
139
|
};
|
|
80
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Runs a shell command and returns its output.
|
|
142
|
+
*
|
|
143
|
+
* @category Node : Terminal
|
|
144
|
+
* @category Package : @augment-vir/node
|
|
145
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
146
|
+
* @see
|
|
147
|
+
* - {@link streamShellCommand}: a lower level way of running a shell command that allows instant reactions to shell events.
|
|
148
|
+
*/
|
|
149
|
+
export declare function runShellCommand(command: string, options?: RunShellCommandOptions): Promise<ShellOutput>;
|
|
150
|
+
/**
|
|
151
|
+
* Options for {@link logShellOutput}.
|
|
152
|
+
*
|
|
153
|
+
* @category Node : Terminal : Util
|
|
154
|
+
* @category Package : @augment-vir/node
|
|
155
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
156
|
+
*/
|
|
81
157
|
export type LogShellOutputOptions = PartialWithUndefined<{
|
|
82
158
|
logger: Logger;
|
|
83
159
|
withLabels: boolean;
|
|
84
160
|
ignoreError: boolean;
|
|
85
161
|
}>;
|
|
162
|
+
/**
|
|
163
|
+
* Log the output of running a shell command. This is useful for quick debugging of shell commands.
|
|
164
|
+
*
|
|
165
|
+
* @category Node : Terminal : Util
|
|
166
|
+
* @category Package : @augment-vir/node
|
|
167
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
168
|
+
*/
|
|
86
169
|
export declare function logShellOutput(shellOutput: PartialWithUndefined<Omit<ShellOutput, 'exitSignal'>>, { ignoreError, logger, withLabels, }?: LogShellOutputOptions): void;
|
|
87
170
|
export {};
|
|
@@ -1,18 +1,51 @@
|
|
|
1
1
|
import { combineErrors, log } from '@augment-vir/common';
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import { defineTypedCustomEvent, ListenTarget } from 'typed-event-target';
|
|
4
|
+
/**
|
|
5
|
+
* An event that indicates that the shell command just wrote to stdout.
|
|
6
|
+
*
|
|
7
|
+
* @category Node : Terminal : Util
|
|
8
|
+
* @category Package : @augment-vir/node
|
|
9
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
10
|
+
*/
|
|
4
11
|
export class ShellStdoutEvent extends defineTypedCustomEvent()('shell-stdout') {
|
|
5
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* An event that indicates that the shell command just wrote to stderr.
|
|
15
|
+
*
|
|
16
|
+
* @category Node : Terminal : Util
|
|
17
|
+
* @category Package : @augment-vir/node
|
|
18
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
19
|
+
*/
|
|
6
20
|
export class ShellStderrEvent extends defineTypedCustomEvent()('shell-stderr') {
|
|
7
21
|
}
|
|
8
22
|
/**
|
|
9
|
-
*
|
|
10
|
-
* other is defined, never both at the
|
|
23
|
+
* An event that indicates that the shell command is finished. This contains an exit code or an exit
|
|
24
|
+
* signal. Based on the Node.js documentation, either one or the other is defined, never both at the
|
|
25
|
+
* same time.
|
|
26
|
+
*
|
|
27
|
+
* @category Node : Terminal : Util
|
|
28
|
+
* @category Package : @augment-vir/node
|
|
29
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
11
30
|
*/
|
|
12
31
|
export class ShellDoneEvent extends defineTypedCustomEvent()('shell-done') {
|
|
13
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* An event that indicates that the shell command errored.
|
|
35
|
+
*
|
|
36
|
+
* @category Node : Terminal : Util
|
|
37
|
+
* @category Package : @augment-vir/node
|
|
38
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
39
|
+
*/
|
|
14
40
|
export class ShellErrorEvent extends defineTypedCustomEvent()('shell-error') {
|
|
15
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* A shell command listen target that emits events.
|
|
44
|
+
*
|
|
45
|
+
* @category Node : Terminal : Util
|
|
46
|
+
* @category Package : @augment-vir/node
|
|
47
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
48
|
+
*/
|
|
16
49
|
export class ShellTarget extends ListenTarget {
|
|
17
50
|
childProcess;
|
|
18
51
|
constructor(childProcess) {
|
|
@@ -20,6 +53,17 @@ export class ShellTarget extends ListenTarget {
|
|
|
20
53
|
this.childProcess = childProcess;
|
|
21
54
|
}
|
|
22
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Runs a shell command and returns a {@link ShellTarget} instance for directly hooking into shell
|
|
58
|
+
* events. This allows instant reactions to shell events but in a less convenient API compared to
|
|
59
|
+
* {@link runShellCommand}.
|
|
60
|
+
*
|
|
61
|
+
* @category Node : Terminal
|
|
62
|
+
* @category Package : @augment-vir/node
|
|
63
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
64
|
+
* @see
|
|
65
|
+
* - {@link runShellCommand}: a higher level and more succinct way of running a shell command.
|
|
66
|
+
*/
|
|
23
67
|
export function streamShellCommand(command, cwd, shell = 'bash', env = process.env, hookUpToConsole = false) {
|
|
24
68
|
const stdio = hookUpToConsole ? [process.stdin] : undefined;
|
|
25
69
|
const childProcess = spawn(command, { shell, cwd, env, stdio });
|
|
@@ -75,6 +119,15 @@ function prepareChunkForLogging(chunk, trimEndingLine) {
|
|
|
75
119
|
const stringified = chunk.toString();
|
|
76
120
|
return trimEndingLine ? stringified.replace(/\n$/, '') : stringified;
|
|
77
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Runs a shell command and returns its output.
|
|
124
|
+
*
|
|
125
|
+
* @category Node : Terminal
|
|
126
|
+
* @category Package : @augment-vir/node
|
|
127
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
128
|
+
* @see
|
|
129
|
+
* - {@link streamShellCommand}: a lower level way of running a shell command that allows instant reactions to shell events.
|
|
130
|
+
*/
|
|
78
131
|
export async function runShellCommand(command, options = {}) {
|
|
79
132
|
return new Promise((resolve, reject) => {
|
|
80
133
|
let stdout = '';
|
|
@@ -126,7 +179,7 @@ export async function runShellCommand(command, options = {}) {
|
|
|
126
179
|
shellTarget.listen(ShellDoneEvent, ({ detail: { exitCode, exitSignal } }) => {
|
|
127
180
|
shellTarget.destroy();
|
|
128
181
|
resolve({
|
|
129
|
-
error: combineErrors(errors),
|
|
182
|
+
error: errors.length ? combineErrors(errors) : undefined,
|
|
130
183
|
stdout,
|
|
131
184
|
stderr,
|
|
132
185
|
exitCode,
|
|
@@ -140,6 +193,13 @@ const defaultLogShellOutputOptions = {
|
|
|
140
193
|
logger: log,
|
|
141
194
|
withLabels: false,
|
|
142
195
|
};
|
|
196
|
+
/**
|
|
197
|
+
* Log the output of running a shell command. This is useful for quick debugging of shell commands.
|
|
198
|
+
*
|
|
199
|
+
* @category Node : Terminal : Util
|
|
200
|
+
* @category Package : @augment-vir/node
|
|
201
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
202
|
+
*/
|
|
143
203
|
export function logShellOutput(shellOutput, { ignoreError = defaultLogShellOutputOptions.ignoreError, logger = defaultLogShellOutputOptions.logger, withLabels = defaultLogShellOutputOptions.withLabels, } = defaultLogShellOutputOptions) {
|
|
144
204
|
logger.if(withLabels).info('exit code');
|
|
145
205
|
logger.if(shellOutput.exitCode != undefined || withLabels).plain(shellOutput.exitCode || 0);
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { JsonCompatibleArray, JsonCompatibleObject } from '@augment-vir/common';
|
|
2
|
+
import type { DockerContainerStatus } from './container-status.js';
|
|
3
|
+
/**
|
|
4
|
+
* Properties on {@link DockerContainerInfo}.State, retrieved from {@link getContainerInfo}.
|
|
5
|
+
*
|
|
6
|
+
* @category Node : Docker : Util
|
|
7
|
+
* @category Package : @augment-vir/node
|
|
8
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
9
|
+
*/
|
|
6
10
|
export type DockerContainerInfoState = {
|
|
7
|
-
Status:
|
|
11
|
+
Status: DockerContainerStatus;
|
|
8
12
|
Running: boolean;
|
|
9
13
|
Paused: boolean;
|
|
10
14
|
Restarting: boolean;
|
|
@@ -17,12 +21,37 @@ export type DockerContainerInfoState = {
|
|
|
17
21
|
FinishedAt: string;
|
|
18
22
|
};
|
|
19
23
|
/** This type signature is incomplete. Add to it as necessary. */
|
|
24
|
+
/**
|
|
25
|
+
* Properties on the output from {@link getContainerInfo}. Not all these properties are filled in all
|
|
26
|
+
* the way, particularly most of properties with nested objects.
|
|
27
|
+
*
|
|
28
|
+
* @category Node : Docker : Util
|
|
29
|
+
* @category Package : @augment-vir/node
|
|
30
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
31
|
+
*/
|
|
20
32
|
export type DockerContainerInfo = Readonly<{
|
|
21
33
|
Id: string;
|
|
22
34
|
Created: string;
|
|
23
35
|
Path: string;
|
|
24
36
|
Args: ReadonlyArray<string>;
|
|
25
37
|
State: DockerContainerInfoState;
|
|
38
|
+
Image: string;
|
|
39
|
+
ResolvConfPath: string;
|
|
40
|
+
HostnamePath: string;
|
|
41
|
+
HostsPath: string;
|
|
42
|
+
LogPath: string;
|
|
26
43
|
Name: string;
|
|
44
|
+
RestartCount: number;
|
|
45
|
+
Driver: string;
|
|
46
|
+
Platform: string;
|
|
47
|
+
MountLabel: string;
|
|
48
|
+
ProcessLabel: string;
|
|
49
|
+
AppArmorProfile: string;
|
|
50
|
+
ExecIDs: unknown;
|
|
51
|
+
HostConfig: JsonCompatibleObject;
|
|
52
|
+
GraphDriver: JsonCompatibleObject;
|
|
53
|
+
Mounts: JsonCompatibleArray;
|
|
54
|
+
Config: JsonCompatibleObject;
|
|
55
|
+
NetworkSettings: JsonCompatibleObject;
|
|
27
56
|
}>;
|
|
28
57
|
export declare function getContainerInfo(containerNameOrId: string): Promise<DockerContainerInfo | undefined>;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { runShellCommand } from '../../augments/shell.js';
|
|
2
|
-
/** There may be other possible values for Status. */
|
|
3
|
-
export var DockerContainerStatusEnum;
|
|
4
|
-
(function (DockerContainerStatusEnum) {
|
|
5
|
-
DockerContainerStatusEnum["exited"] = "exited";
|
|
6
|
-
DockerContainerStatusEnum["running"] = "running";
|
|
7
|
-
})(DockerContainerStatusEnum || (DockerContainerStatusEnum = {}));
|
|
1
|
+
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
8
2
|
export async function getContainerInfo(containerNameOrId) {
|
|
9
3
|
const command = `docker inspect '${containerNameOrId}'`;
|
|
10
4
|
const output = await runShellCommand(command);
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export declare function getContainerLogs(containerNameOrId: string, latestLineCount?: number): Promise<string>;
|
|
2
|
+
/**
|
|
3
|
+
* All possible statuses for an existing container.
|
|
4
|
+
*
|
|
5
|
+
* @category Node : Docker : Util
|
|
6
|
+
* @category Package : @augment-vir/node
|
|
7
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
|
+
*/
|
|
2
9
|
export declare enum DockerContainerStatus {
|
|
3
10
|
Created = "created",
|
|
4
11
|
Running = "running",
|
|
@@ -10,6 +17,14 @@ export declare enum DockerContainerStatus {
|
|
|
10
17
|
/** This is not a native Docker status but indicates that the container does not exist. */
|
|
11
18
|
Removed = "removed"
|
|
12
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Statuses from {@link DockerContainerStatus} that indicate that a container has been exited in some
|
|
22
|
+
* way.
|
|
23
|
+
*
|
|
24
|
+
* @category Node : Docker : Util
|
|
25
|
+
* @category Package : @augment-vir/node
|
|
26
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
27
|
+
*/
|
|
13
28
|
export declare const exitedDockerContainerStatuses: DockerContainerStatus[];
|
|
14
29
|
export declare function getContainerStatus(containerNameOrId: string): Promise<DockerContainerStatus>;
|
|
15
30
|
export declare function waitUntilContainerRunning(containerNameOrId: string, failureMessage?: string | undefined): Promise<void>;
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { assert, waitUntil } from '@augment-vir/assert';
|
|
2
|
-
import { runShellCommand } from '../../augments/shell.js';
|
|
2
|
+
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
3
3
|
export async function getContainerLogs(containerNameOrId, latestLineCount) {
|
|
4
4
|
const latestLinesArg = latestLineCount == undefined ? '' : `--tail ${latestLineCount}`;
|
|
5
5
|
const logResult = await runShellCommand(`docker logs ${latestLinesArg} '${containerNameOrId}'`, { rejectOnError: true });
|
|
6
6
|
return logResult.stdout;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* All possible statuses for an existing container.
|
|
10
|
+
*
|
|
11
|
+
* @category Node : Docker : Util
|
|
12
|
+
* @category Package : @augment-vir/node
|
|
13
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
14
|
+
*/
|
|
8
15
|
export var DockerContainerStatus;
|
|
9
16
|
(function (DockerContainerStatus) {
|
|
10
17
|
DockerContainerStatus["Created"] = "created";
|
|
@@ -17,6 +24,14 @@ export var DockerContainerStatus;
|
|
|
17
24
|
/** This is not a native Docker status but indicates that the container does not exist. */
|
|
18
25
|
DockerContainerStatus["Removed"] = "removed";
|
|
19
26
|
})(DockerContainerStatus || (DockerContainerStatus = {}));
|
|
27
|
+
/**
|
|
28
|
+
* Statuses from {@link DockerContainerStatus} that indicate that a container has been exited in some
|
|
29
|
+
* way.
|
|
30
|
+
*
|
|
31
|
+
* @category Node : Docker : Util
|
|
32
|
+
* @category Package : @augment-vir/node
|
|
33
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
34
|
+
*/
|
|
20
35
|
export const exitedDockerContainerStatuses = [
|
|
21
36
|
DockerContainerStatus.Dead,
|
|
22
37
|
DockerContainerStatus.Removed,
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameters for `docker.container.copyTo`.
|
|
3
|
+
*
|
|
4
|
+
* @category Node : Docker : Util
|
|
5
|
+
* @category Package : @augment-vir/node
|
|
6
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
7
|
+
*/
|
|
1
8
|
export type CopyToDockerContainerParams = {
|
|
2
9
|
hostPath: string;
|
|
3
10
|
containerAbsolutePath: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { addSuffix } from '@augment-vir/common';
|
|
2
2
|
import { stat } from 'node:fs/promises';
|
|
3
|
-
import { runShellCommand } from '../../augments/shell.js';
|
|
3
|
+
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
4
4
|
export async function copyToContainer({ containerAbsolutePath, hostPath, containerNameOrId, dockerFlags = [], }) {
|
|
5
5
|
const isDir = (await stat(hostPath)).isDirectory();
|
|
6
6
|
const suffix = isDir ? '/.' : '';
|
|
@@ -1,17 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Used for `type` in {@link DockerVolumeMap}. These types are apparently only relevant for running
|
|
3
|
+
* Docker on macOS and are potentially irrelevant now. It's likely best to leave the `type` property
|
|
4
|
+
* empty (`undefined`).
|
|
5
|
+
*
|
|
6
|
+
* @category Node : Docker : Util
|
|
7
|
+
* @category Package : @augment-vir/node
|
|
8
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
9
|
+
*/
|
|
1
10
|
export declare enum DockerVolumeMappingType {
|
|
2
11
|
Cached = "cached",
|
|
3
12
|
Delegated = "delegated"
|
|
4
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* A mapping of a single docker volume for mounting host files to a container.
|
|
16
|
+
*
|
|
17
|
+
* @category Node : Docker : Util
|
|
18
|
+
* @category Package : @augment-vir/node
|
|
19
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
20
|
+
*/
|
|
5
21
|
export type DockerVolumeMap = {
|
|
6
22
|
hostAbsolutePath: string;
|
|
7
23
|
containerAbsolutePath: string;
|
|
8
24
|
type?: DockerVolumeMappingType | undefined;
|
|
9
25
|
};
|
|
10
26
|
export declare function makeVolumeFlags(volumeMapping?: ReadonlyArray<DockerVolumeMap>): string;
|
|
27
|
+
/**
|
|
28
|
+
* A single docker container port mapping. This is usually used in an array.
|
|
29
|
+
*
|
|
30
|
+
* @category Node : Docker : Util
|
|
31
|
+
* @category Package : @augment-vir/node
|
|
32
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
33
|
+
*/
|
|
11
34
|
export type DockerPortMap = {
|
|
12
35
|
hostPort: number;
|
|
13
36
|
containerPort: number;
|
|
14
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* A set of environment mappings for a docker container.
|
|
40
|
+
*
|
|
41
|
+
* - Each key in this object represents the env var name within the Docker container.
|
|
42
|
+
* - Each `value` property can be either the value that the env var should be set to _or_ an existing
|
|
43
|
+
* env var's interpolation into the value.
|
|
44
|
+
* - If the value string is meant to be interpolated within the shell context, make sure to set
|
|
45
|
+
* `allowInterpolation` to `true`. Otherwise, it's best to leave it as `false`.
|
|
46
|
+
*
|
|
47
|
+
* @category Node : Docker : Util
|
|
48
|
+
* @category Package : @augment-vir/node
|
|
49
|
+
* @example
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* const envMapping: DockerEnvMap = {
|
|
53
|
+
* VAR_1: {
|
|
54
|
+
* value: 'hi',
|
|
55
|
+
* // set to false because this is a raw string value that is not meant to be interpolated
|
|
56
|
+
* allowInterpolation: false,
|
|
57
|
+
* },
|
|
58
|
+
* VAR_2: {
|
|
59
|
+
* // the value here will be interpolated from the current shell's value for `EXISTING_VAR`
|
|
60
|
+
* value: '$EXISTING_VAR',
|
|
61
|
+
* // set to true to allow '$EXISTING_VAR' to be interpolated by the shell
|
|
62
|
+
* allowInterpolation: true,
|
|
63
|
+
* },
|
|
64
|
+
* };
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
68
|
+
*/
|
|
15
69
|
export type DockerEnvMap<RequiredKeys extends string = string> = Readonly<Record<RequiredKeys | string, {
|
|
16
70
|
value: string;
|
|
17
71
|
allowInterpolation: boolean;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { wrapString } from '@augment-vir/common';
|
|
2
|
+
/**
|
|
3
|
+
* Used for `type` in {@link DockerVolumeMap}. These types are apparently only relevant for running
|
|
4
|
+
* Docker on macOS and are potentially irrelevant now. It's likely best to leave the `type` property
|
|
5
|
+
* empty (`undefined`).
|
|
6
|
+
*
|
|
7
|
+
* @category Node : Docker : Util
|
|
8
|
+
* @category Package : @augment-vir/node
|
|
9
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
10
|
+
*/
|
|
2
11
|
export var DockerVolumeMappingType;
|
|
3
12
|
(function (DockerVolumeMappingType) {
|
|
4
13
|
DockerVolumeMappingType["Cached"] = "cached";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runShellCommand } from '../../augments/shell.js';
|
|
1
|
+
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
2
2
|
import { waitUntilContainerExited, waitUntilContainerRemoved } from './container-status.js';
|
|
3
3
|
export async function killContainer(containerNameOrId, options = {}) {
|
|
4
4
|
await runShellCommand(`docker kill '${containerNameOrId}'`);
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { DockerEnvMap } from './docker-command-inputs.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for `docker.container.runCommand`.
|
|
4
|
+
*
|
|
5
|
+
* @category Node : Docker : Util
|
|
6
|
+
* @category Package : @augment-vir/node
|
|
7
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
|
+
*/
|
|
2
9
|
export type RunDockerContainerCommandParams = {
|
|
3
10
|
/** Creates an interactive shell connection. */
|
|
4
11
|
tty?: boolean | undefined;
|
|
@@ -8,5 +15,4 @@ export type RunDockerContainerCommandParams = {
|
|
|
8
15
|
executionEnv?: Record<string, string> | undefined;
|
|
9
16
|
dockerFlags?: ReadonlyArray<string> | undefined;
|
|
10
17
|
};
|
|
11
|
-
|
|
12
|
-
export declare function runContainerCommand({ tty, containerNameOrId, command, envMapping, executionEnv, dockerFlags, }: RunDockerContainerCommandParams): Promise<import("../../augments/shell.js").ShellOutput>;
|
|
18
|
+
export declare function runContainerCommand({ tty, containerNameOrId, command, envMapping, executionEnv, dockerFlags, }: RunDockerContainerCommandParams): Promise<import("../../augments/terminal/shell.js").ShellOutput>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { check } from '@augment-vir/assert';
|
|
2
|
-
import { runShellCommand } from '../../augments/shell.js';
|
|
2
|
+
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
3
3
|
import { makeEnvFlags } from './docker-command-inputs.js';
|
|
4
|
-
/** Run a command on a container that is already running. */
|
|
5
4
|
export async function runContainerCommand({ tty, containerNameOrId, command, envMapping, executionEnv, dockerFlags = [], }) {
|
|
6
5
|
const envFlags = makeEnvFlags(envMapping);
|
|
7
6
|
/** Can't test tty in automated tests. */
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { DockerEnvMap, DockerPortMap, DockerVolumeMap } from './docker-command-inputs.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for `docker.container.run`.
|
|
4
|
+
*
|
|
5
|
+
* @category Node : Docker : Util
|
|
6
|
+
* @category Package : @augment-vir/node
|
|
7
|
+
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
|
+
*/
|
|
2
9
|
export type RunDockerContainerParams = {
|
|
3
10
|
imageName: string;
|
|
4
11
|
detach: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { check } from '@augment-vir/assert';
|
|
2
|
-
import { runShellCommand } from '../../augments/shell.js';
|
|
2
|
+
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
3
3
|
import { updateImage } from '../docker-image.js';
|
|
4
4
|
import { waitUntilContainerRunning } from './container-status.js';
|
|
5
5
|
import { makeEnvFlags, makePortMapFlags, makeVolumeFlags, } from './docker-command-inputs.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ensureError } from '@augment-vir/core';
|
|
2
|
-
import { runShellCommand } from '../augments/shell.js';
|
|
2
|
+
import { runShellCommand } from '../augments/terminal/shell.js';
|
|
3
3
|
export async function updateImage(
|
|
4
4
|
/** @example 'alpine:3.20.2' */
|
|
5
5
|
imageName) {
|
|
@@ -21,7 +21,9 @@ export async function removeImageFromLocalRegistry(
|
|
|
21
21
|
/** @example 'alpine:3.20.2' */
|
|
22
22
|
imageName) {
|
|
23
23
|
try {
|
|
24
|
-
await runShellCommand(`docker image rm '${imageName}'`, {
|
|
24
|
+
await runShellCommand(`docker image rm '${imageName}'`, {
|
|
25
|
+
rejectOnError: true,
|
|
26
|
+
});
|
|
25
27
|
}
|
|
26
28
|
catch (caught) {
|
|
27
29
|
const error = ensureError(caught);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { waitUntil } from '@augment-vir/assert';
|
|
2
2
|
import { currentOperatingSystem, OperatingSystem } from '../augments/os/operating-system.js';
|
|
3
|
-
import { runShellCommand } from '../augments/shell.js';
|
|
3
|
+
import { runShellCommand } from '../augments/terminal/shell.js';
|
|
4
4
|
export async function isDockerRunning() {
|
|
5
5
|
const output = await runShellCommand('docker info');
|
|
6
6
|
return output.exitCode === 0;
|
|
@@ -20,7 +20,6 @@ const startDockerCommands = {
|
|
|
20
20
|
};
|
|
21
21
|
export async function startDocker() {
|
|
22
22
|
const command = startDockerCommands[currentOperatingSystem];
|
|
23
|
-
/** We */
|
|
24
23
|
/* node:coverage disable */
|
|
25
24
|
if (await isDockerRunning()) {
|
|
26
25
|
/** Docker is already running. Nothing to do. */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isOperatingSystem, OperatingSystem } from '../augments/os/operating-system.js';
|
|
2
|
+
export function dockerTest(callback) {
|
|
3
|
+
if (isOperatingSystem(OperatingSystem.Mac) && process.env.CI) {
|
|
4
|
+
/**
|
|
5
|
+
* We cannot test Docker on macOS GitHub Actions runners.
|
|
6
|
+
*
|
|
7
|
+
* @see
|
|
8
|
+
* - https://github.com/actions/runner-images/issues/8104
|
|
9
|
+
* - https://github.com/douglascamata/setup-docker-macos-action?tab=readme-ov-file#arm64-processors-m1-m2-m3-series-used-on-macos-14-images-are-unsupported
|
|
10
|
+
* - https://github.com/actions/runner-images/issues/2150
|
|
11
|
+
* - https://github.com/actions/runner/issues/1456
|
|
12
|
+
*/
|
|
13
|
+
return () => { };
|
|
14
|
+
}
|
|
15
|
+
return callback;
|
|
16
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from './augments/console/question.js';
|
|
2
1
|
export * from './augments/docker.js';
|
|
3
|
-
export * from './augments/download.js';
|
|
2
|
+
export * from './augments/fs/download.js';
|
|
4
3
|
export * from './augments/fs/json.js';
|
|
5
4
|
export * from './augments/fs/read-dir.js';
|
|
6
5
|
export * from './augments/fs/read-file.js';
|
|
@@ -13,4 +12,5 @@ export * from './augments/path/ancestor.js';
|
|
|
13
12
|
export * from './augments/path/os-path.js';
|
|
14
13
|
export * from './augments/path/root.js';
|
|
15
14
|
export * from './augments/prisma.js';
|
|
16
|
-
export * from './augments/
|
|
15
|
+
export * from './augments/terminal/question.js';
|
|
16
|
+
export * from './augments/terminal/shell.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from './augments/console/question.js';
|
|
2
1
|
export * from './augments/docker.js';
|
|
3
|
-
export * from './augments/download.js';
|
|
2
|
+
export * from './augments/fs/download.js';
|
|
4
3
|
export * from './augments/fs/json.js';
|
|
5
4
|
export * from './augments/fs/read-dir.js';
|
|
6
5
|
export * from './augments/fs/read-file.js';
|
|
@@ -13,4 +12,5 @@ export * from './augments/path/ancestor.js';
|
|
|
13
12
|
export * from './augments/path/os-path.js';
|
|
14
13
|
export * from './augments/path/root.js';
|
|
15
14
|
export * from './augments/prisma.js';
|
|
16
|
-
export * from './augments/
|
|
15
|
+
export * from './augments/terminal/question.js';
|
|
16
|
+
export * from './augments/terminal/shell.js';
|