@augment-vir/node 31.0.0 → 31.1.0

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 (56) hide show
  1. package/dist/augments/fs/dir-contents.js +1 -1
  2. package/dist/augments/terminal/relevant-args.d.ts +1 -7
  3. package/dist/augments/terminal/relevant-args.js +1 -7
  4. package/dist/augments/terminal/run-cli-script.js +1 -5
  5. package/dist/augments/terminal/shell.js +1 -4
  6. package/dist/docker/containers/docker-command-inputs.js +1 -1
  7. package/dist/docker/containers/run-container.mock.js +1 -4
  8. package/dist/docker/docker-image.js +1 -6
  9. package/dist/prisma/model-data.js +2 -5
  10. package/dist/prisma/prisma-migrations.js +2 -7
  11. package/dist/prisma/run-prisma-command.js +3 -15
  12. package/dist/scripts/fix-ts-bin.script.d.ts +1 -0
  13. package/dist/scripts/fix-ts-bin.script.js +48 -0
  14. package/package.json +4 -4
  15. package/src/augments/docker.ts +118 -0
  16. package/src/augments/fs/dir-contents.ts +116 -0
  17. package/src/augments/fs/download.ts +31 -0
  18. package/src/augments/fs/json.ts +87 -0
  19. package/src/augments/fs/read-dir.ts +60 -0
  20. package/src/augments/fs/read-file.ts +18 -0
  21. package/src/augments/fs/symlink.ts +37 -0
  22. package/src/augments/fs/write.ts +18 -0
  23. package/src/augments/npm/query-workspace.ts +47 -0
  24. package/src/augments/npm/read-package-json.ts +28 -0
  25. package/src/augments/os/operating-system.ts +55 -0
  26. package/src/augments/path/ancestor.ts +78 -0
  27. package/src/augments/path/os-path.ts +45 -0
  28. package/src/augments/path/root.ts +14 -0
  29. package/src/augments/prisma.ts +174 -0
  30. package/src/augments/terminal/question.ts +142 -0
  31. package/src/augments/terminal/relevant-args.ts +81 -0
  32. package/src/augments/terminal/run-cli-script.ts +60 -0
  33. package/src/augments/terminal/shell.ts +312 -0
  34. package/src/docker/containers/container-info.ts +83 -0
  35. package/src/docker/containers/container-status.ts +110 -0
  36. package/src/docker/containers/copy-to-container.ts +34 -0
  37. package/src/docker/containers/docker-command-inputs.ts +119 -0
  38. package/src/docker/containers/kill-container.ts +25 -0
  39. package/src/docker/containers/run-command.ts +51 -0
  40. package/src/docker/containers/run-container.mock.ts +17 -0
  41. package/src/docker/containers/run-container.ts +92 -0
  42. package/src/docker/containers/try-or-kill-container.ts +18 -0
  43. package/src/docker/docker-image.ts +56 -0
  44. package/src/docker/docker-startup.ts +49 -0
  45. package/src/docker/run-docker-test.mock.ts +26 -0
  46. package/src/file-paths.mock.ts +29 -0
  47. package/src/index.ts +19 -0
  48. package/src/prisma/disable-ci-env.mock.ts +88 -0
  49. package/src/prisma/model-data.ts +213 -0
  50. package/src/prisma/prisma-client.ts +43 -0
  51. package/src/prisma/prisma-database.mock.ts +31 -0
  52. package/src/prisma/prisma-database.ts +35 -0
  53. package/src/prisma/prisma-errors.ts +45 -0
  54. package/src/prisma/prisma-migrations.ts +149 -0
  55. package/src/prisma/run-prisma-command.ts +59 -0
  56. package/src/scripts/fix-ts-bin.script.ts +60 -0
@@ -0,0 +1,110 @@
1
+ import {assert, waitUntil} from '@augment-vir/assert';
2
+ import {runShellCommand} from '../../augments/terminal/shell.js';
3
+
4
+ export async function getContainerLogs(
5
+ containerNameOrId: string,
6
+ latestLineCount?: number,
7
+ ): Promise<string> {
8
+ const latestLinesArg = latestLineCount == undefined ? '' : `--tail ${latestLineCount}`;
9
+ const logResult = await runShellCommand(
10
+ `docker logs ${latestLinesArg} '${containerNameOrId}'`,
11
+ {rejectOnError: true},
12
+ );
13
+ return logResult.stdout;
14
+ }
15
+
16
+ /**
17
+ * All possible statuses for an existing container.
18
+ *
19
+ * @category Node : Docker : Util
20
+ * @category Package : @augment-vir/node
21
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
22
+ */
23
+ export enum DockerContainerStatus {
24
+ Created = 'created',
25
+ Running = 'running',
26
+ Paused = 'paused',
27
+ Restarting = 'restarting',
28
+ Exited = 'exited',
29
+ Removing = 'removing',
30
+ Dead = 'dead',
31
+
32
+ /** This is not a native Docker status but indicates that the container does not exist. */
33
+ Removed = 'removed',
34
+ }
35
+
36
+ /**
37
+ * Statuses from {@link DockerContainerStatus} that indicate that a container has been exited in some
38
+ * way.
39
+ *
40
+ * @category Node : Docker : Util
41
+ * @category Package : @augment-vir/node
42
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
43
+ */
44
+ export const exitedDockerContainerStatuses = [
45
+ DockerContainerStatus.Dead,
46
+ DockerContainerStatus.Removed,
47
+ DockerContainerStatus.Exited,
48
+ ];
49
+
50
+ export async function getContainerStatus(
51
+ containerNameOrId: string,
52
+ ): Promise<DockerContainerStatus> {
53
+ const statusResult = await runShellCommand(
54
+ `docker container inspect -f '{{.State.Status}}' '${containerNameOrId}'`,
55
+ );
56
+
57
+ if (statusResult.exitCode !== 0) {
58
+ return DockerContainerStatus.Removed;
59
+ }
60
+
61
+ const status = statusResult.stdout.trim();
62
+ assert.isEnumValue(status, DockerContainerStatus, 'Unexpected container status value');
63
+
64
+ return status;
65
+ }
66
+
67
+ export async function waitUntilContainerRunning(
68
+ containerNameOrId: string,
69
+ failureMessage?: string | undefined,
70
+ ): Promise<void> {
71
+ await waitUntil.isTrue(
72
+ async (): Promise<boolean> => {
73
+ /** Check if logs can be accessed yet. */
74
+ await getContainerLogs(containerNameOrId, 1);
75
+ const status = await getContainerStatus(containerNameOrId);
76
+
77
+ return status === DockerContainerStatus.Running;
78
+ },
79
+ {},
80
+ failureMessage,
81
+ );
82
+ }
83
+
84
+ export async function waitUntilContainerRemoved(
85
+ containerNameOrId: string,
86
+ failureMessage?: string | undefined,
87
+ ): Promise<void> {
88
+ await waitUntil.isTrue(
89
+ async (): Promise<boolean> => {
90
+ const status = await getContainerStatus(containerNameOrId);
91
+ return status === DockerContainerStatus.Removed;
92
+ },
93
+ {},
94
+ failureMessage,
95
+ );
96
+ }
97
+
98
+ export async function waitUntilContainerExited(
99
+ containerNameOrId: string,
100
+ failureMessage?: string | undefined,
101
+ ): Promise<void> {
102
+ await waitUntil.isTrue(
103
+ async (): Promise<boolean> => {
104
+ const status = await getContainerStatus(containerNameOrId);
105
+ return exitedDockerContainerStatuses.includes(status);
106
+ },
107
+ {},
108
+ failureMessage,
109
+ );
110
+ }
@@ -0,0 +1,34 @@
1
+ import {addSuffix} from '@augment-vir/common';
2
+ import {stat} from 'node:fs/promises';
3
+ import {runShellCommand} from '../../augments/terminal/shell.js';
4
+
5
+ /**
6
+ * Parameters for `docker.container.copyTo`.
7
+ *
8
+ * @category Node : Docker : Util
9
+ * @category Package : @augment-vir/node
10
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
11
+ */
12
+ export type CopyToDockerContainerParams = {
13
+ hostPath: string;
14
+ containerAbsolutePath: string;
15
+ containerNameOrId: string;
16
+ dockerFlags?: ReadonlyArray<string>;
17
+ };
18
+
19
+ export async function copyToContainer({
20
+ containerAbsolutePath,
21
+ hostPath,
22
+ containerNameOrId,
23
+ dockerFlags = [],
24
+ }: CopyToDockerContainerParams): Promise<void> {
25
+ const isDir = (await stat(hostPath)).isDirectory();
26
+ const suffix = isDir ? '/.' : '';
27
+ const fullHostPath = addSuffix({value: hostPath, suffix});
28
+ const extraInputs: string = dockerFlags.join(' ');
29
+
30
+ await runShellCommand(
31
+ `docker cp ${extraInputs} '${fullHostPath}' '${containerNameOrId}:${containerAbsolutePath}'`,
32
+ {rejectOnError: true},
33
+ );
34
+ }
@@ -0,0 +1,119 @@
1
+ import {wrapString} from '@augment-vir/common';
2
+
3
+ /**
4
+ * Used for `type` in {@link DockerVolumeMap}. These types are apparently only relevant for running
5
+ * Docker on macOS and are potentially irrelevant now. It's likely best to leave the `type` property
6
+ * empty (`undefined`).
7
+ *
8
+ * @category Node : Docker : Util
9
+ * @category Package : @augment-vir/node
10
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
11
+ */
12
+ export enum DockerVolumeMappingType {
13
+ Cached = 'cached',
14
+ Delegated = 'delegated',
15
+ }
16
+
17
+ /**
18
+ * A mapping of a single docker volume for mounting host files to a container.
19
+ *
20
+ * @category Node : Docker : Util
21
+ * @category Package : @augment-vir/node
22
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
23
+ */
24
+ export type DockerVolumeMap = {
25
+ hostAbsolutePath: string;
26
+ containerAbsolutePath: string;
27
+ type?: DockerVolumeMappingType | undefined;
28
+ };
29
+
30
+ export function makeVolumeFlags(volumeMapping?: ReadonlyArray<DockerVolumeMap>): string {
31
+ if (!volumeMapping) {
32
+ return '';
33
+ }
34
+
35
+ const parts = volumeMapping.map((volume) => {
36
+ const mountType = volume.type ? `:${volume.type}` : '';
37
+ return `-v '${volume.hostAbsolutePath}':'${volume.containerAbsolutePath}'${mountType}`;
38
+ });
39
+
40
+ return parts.join(' ');
41
+ }
42
+ /**
43
+ * A single docker container port mapping. This is usually used in an array.
44
+ *
45
+ * @category Node : Docker : Util
46
+ * @category Package : @augment-vir/node
47
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
48
+ */
49
+ export type DockerPortMap = {
50
+ hostPort: number;
51
+ containerPort: number;
52
+ };
53
+
54
+ /**
55
+ * A set of environment mappings for a docker container.
56
+ *
57
+ * - Each key in this object represents the env var name within the Docker container.
58
+ * - Each `value` property can be either the value that the env var should be set to _or_ an existing
59
+ * env var's interpolation into the value.
60
+ * - If the value string is meant to be interpolated within the shell context, make sure to set
61
+ * `allowInterpolation` to `true`. Otherwise, it's best to leave it as `false`.
62
+ *
63
+ * @category Node : Docker : Util
64
+ * @category Package : @augment-vir/node
65
+ * @example
66
+ *
67
+ * ```ts
68
+ * const envMapping: DockerEnvMap = {
69
+ * VAR_1: {
70
+ * value: 'hi',
71
+ * // set to false because this is a raw string value that is not meant to be interpolated
72
+ * allowInterpolation: false,
73
+ * },
74
+ * VAR_2: {
75
+ * // the value here will be interpolated from the current shell's value for `EXISTING_VAR`
76
+ * value: '$EXISTING_VAR',
77
+ * // set to true to allow '$EXISTING_VAR' to be interpolated by the shell
78
+ * allowInterpolation: true,
79
+ * },
80
+ * };
81
+ * ```
82
+ *
83
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
84
+ */
85
+ export type DockerEnvMap<RequiredKeys extends string = string> = Readonly<
86
+ Record<
87
+ RequiredKeys | string,
88
+ {
89
+ value: string;
90
+ allowInterpolation: boolean;
91
+ }
92
+ >
93
+ >;
94
+
95
+ export function makePortMapFlags(portMapping?: ReadonlyArray<DockerPortMap> | undefined): string {
96
+ if (!portMapping) {
97
+ return '';
98
+ }
99
+
100
+ return portMapping
101
+ .map((portMap) => {
102
+ return `-p ${portMap.hostPort}:${portMap.containerPort}`;
103
+ })
104
+ .join(' ');
105
+ }
106
+
107
+ export function makeEnvFlags(envMapping?: DockerEnvMap | undefined): string {
108
+ if (!envMapping) {
109
+ return '';
110
+ }
111
+ const flags: ReadonlyArray<string> = Object.entries(envMapping).map(
112
+ ([key, {value, allowInterpolation}]) => {
113
+ const quote = allowInterpolation ? '"' : "'";
114
+ return `-e ${key}=${wrapString({value, wrapper: quote})}`;
115
+ },
116
+ );
117
+
118
+ return flags.join(' ');
119
+ }
@@ -0,0 +1,25 @@
1
+ import type {PartialWithUndefined} from '@augment-vir/core';
2
+ import {runShellCommand} from '../../augments/terminal/shell.js';
3
+ import {waitUntilContainerExited, waitUntilContainerRemoved} from './container-status.js';
4
+
5
+ export async function killContainer(
6
+ containerNameOrId: string,
7
+ options: PartialWithUndefined<{
8
+ /**
9
+ * If set to `true`, the container will be killed but won't be removed. (You'll still see it
10
+ * in your Docker Dashboard but it'll have a status of exited.)
11
+ *
12
+ * @default false
13
+ */
14
+ keepContainer: boolean;
15
+ }> = {},
16
+ ): Promise<void> {
17
+ await runShellCommand(`docker kill '${containerNameOrId}'`);
18
+
19
+ if (options.keepContainer) {
20
+ await waitUntilContainerExited(containerNameOrId);
21
+ } else {
22
+ await runShellCommand(`docker rm '${containerNameOrId}'`);
23
+ await waitUntilContainerRemoved(containerNameOrId);
24
+ }
25
+ }
@@ -0,0 +1,51 @@
1
+ import {check} from '@augment-vir/assert';
2
+ import {runShellCommand} from '../../augments/terminal/shell.js';
3
+ import {DockerEnvMap, makeEnvFlags} from './docker-command-inputs.js';
4
+
5
+ /**
6
+ * Parameters for `docker.container.runCommand`.
7
+ *
8
+ * @category Node : Docker : Util
9
+ * @category Package : @augment-vir/node
10
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
11
+ */
12
+ export type RunDockerContainerCommandParams = {
13
+ /** Creates an interactive shell connection. */
14
+ tty?: boolean | undefined;
15
+ containerNameOrId: string;
16
+ command: string;
17
+ envMapping?: DockerEnvMap | undefined;
18
+ executionEnv?: Record<string, string> | undefined;
19
+ dockerFlags?: ReadonlyArray<string> | undefined;
20
+ };
21
+
22
+ export async function runContainerCommand({
23
+ tty,
24
+ containerNameOrId,
25
+ command,
26
+ envMapping,
27
+ executionEnv,
28
+ dockerFlags = [],
29
+ }: RunDockerContainerCommandParams) {
30
+ const envFlags = makeEnvFlags(envMapping);
31
+ /** Can't test tty in automated tests. */
32
+ /* node:coverage ignore next 1 */
33
+ const ttyFlag = tty ? '-it' : '';
34
+
35
+ const fullCommand = [
36
+ 'docker',
37
+ 'exec',
38
+ ttyFlag,
39
+ envFlags,
40
+ ...dockerFlags,
41
+ containerNameOrId,
42
+ command,
43
+ ]
44
+ .filter(check.isTruthy)
45
+ .join(' ');
46
+
47
+ return await runShellCommand(fullCommand, {
48
+ env: executionEnv,
49
+ rejectOnError: true,
50
+ });
51
+ }
@@ -0,0 +1,17 @@
1
+ import {docker} from '../../augments/docker.js';
2
+ import {RunDockerContainerParams} from './run-container.js';
3
+
4
+ export async function runMockLongLivingContainer(
5
+ containerName: string,
6
+ args: Partial<RunDockerContainerParams> = {},
7
+ ) {
8
+ await docker.container.run({
9
+ containerName: containerName,
10
+ detach: true,
11
+ imageName: 'alpine:3.20.2',
12
+ dockerFlags: ['-i', '-t'],
13
+ command: 'sh',
14
+ platform: 'amd64',
15
+ ...args,
16
+ });
17
+ }
@@ -0,0 +1,92 @@
1
+ import {check} from '@augment-vir/assert';
2
+ import {runShellCommand} from '../../augments/terminal/shell.js';
3
+ import {updateImage} from '../docker-image.js';
4
+ import {waitUntilContainerRunning} from './container-status.js';
5
+ import {
6
+ DockerEnvMap,
7
+ DockerPortMap,
8
+ DockerVolumeMap,
9
+ makeEnvFlags,
10
+ makePortMapFlags,
11
+ makeVolumeFlags,
12
+ } from './docker-command-inputs.js';
13
+ import {killContainer} from './kill-container.js';
14
+
15
+ /**
16
+ * Parameters for `docker.container.run`.
17
+ *
18
+ * @category Node : Docker : Util
19
+ * @category Package : @augment-vir/node
20
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
21
+ */
22
+ export type RunDockerContainerParams = {
23
+ imageName: string;
24
+ detach: boolean;
25
+ command?: string;
26
+ containerName: string;
27
+ volumeMapping?: ReadonlyArray<DockerVolumeMap> | undefined;
28
+ portMapping?: ReadonlyArray<DockerPortMap> | undefined;
29
+ envMapping?: DockerEnvMap | undefined;
30
+ executionEnv?: Record<string, string>;
31
+ removeWhenDone?: boolean;
32
+ dockerFlags?: ReadonlyArray<string>;
33
+ useCurrentUser?: boolean;
34
+ platform?: string;
35
+ };
36
+
37
+ export async function runContainer({
38
+ containerName,
39
+ imageName,
40
+ detach,
41
+ command,
42
+ portMapping,
43
+ volumeMapping,
44
+ envMapping,
45
+ executionEnv,
46
+ removeWhenDone,
47
+ useCurrentUser,
48
+ dockerFlags = [],
49
+ platform,
50
+ }: RunDockerContainerParams) {
51
+ try {
52
+ const portMapFlags = makePortMapFlags(portMapping);
53
+ const envFlags = makeEnvFlags(envMapping);
54
+ const detachFlag = detach ? '-d' : '';
55
+ const volumeMapFlags = makeVolumeFlags(volumeMapping);
56
+ const rmFlag = removeWhenDone ? '--rm' : '';
57
+ const userFlag = useCurrentUser ? '--user "$(id -u)":"$(id -g)"' : '';
58
+
59
+ await updateImage(imageName, platform);
60
+
61
+ const fullCommand = [
62
+ 'docker',
63
+ 'run',
64
+ portMapFlags,
65
+ userFlag,
66
+ volumeMapFlags,
67
+ envFlags,
68
+ rmFlag,
69
+ detachFlag,
70
+ `--name='${containerName}'`,
71
+ ...dockerFlags,
72
+ imageName,
73
+ command,
74
+ ]
75
+ .filter(check.isTruthy)
76
+ .join(' ');
77
+
78
+ await runShellCommand(fullCommand, {
79
+ env: executionEnv,
80
+ rejectOnError: true,
81
+ });
82
+
83
+ if (removeWhenDone) {
84
+ await killContainer(containerName);
85
+ } else if (detach) {
86
+ await waitUntilContainerRunning(containerName);
87
+ }
88
+ } catch (error) {
89
+ await killContainer(containerName);
90
+ throw error;
91
+ }
92
+ }
@@ -0,0 +1,18 @@
1
+ import {type MaybePromise} from '@augment-vir/core';
2
+ import {killContainer} from './kill-container.js';
3
+
4
+ /**
5
+ * Runs a callback (which presumably runs a command within the given `containerName`) and kills the
6
+ * given `containerName` container if the callback fails.
7
+ */
8
+ export async function tryOrKillContainer<T>(
9
+ containerNameOrId: string,
10
+ callback: (containerNameOrId: string) => MaybePromise<T>,
11
+ ): Promise<Awaited<T>> {
12
+ try {
13
+ return await callback(containerNameOrId);
14
+ } catch (error) {
15
+ await killContainer(containerNameOrId);
16
+ throw error;
17
+ }
18
+ }
@@ -0,0 +1,56 @@
1
+ import {wrapString} from '@augment-vir/common';
2
+ import {ensureError} from '@augment-vir/core';
3
+ import {runShellCommand} from '../augments/terminal/shell.js';
4
+
5
+ export async function updateImage(
6
+ /** @example 'alpine:3.20.2' */
7
+ imageName: string,
8
+ platform?: string,
9
+ ) {
10
+ if (await isImageInLocalRegistry(imageName)) {
11
+ /** If image already exists then we don't need to update it. */
12
+ return;
13
+ }
14
+
15
+ const command = [
16
+ 'docker',
17
+ 'pull',
18
+ ...(platform ? ['--platform', platform] : []),
19
+ wrapString({value: imageName, wrapper: "'"}),
20
+ ].join(' ');
21
+
22
+ await runShellCommand(command, {
23
+ rejectOnError: true,
24
+ });
25
+ }
26
+
27
+ export async function isImageInLocalRegistry(
28
+ /** @example 'alpine:3.20.2' */
29
+ imageName: string,
30
+ ): Promise<boolean> {
31
+ const output = await runShellCommand(`docker inspect '${imageName}'`);
32
+
33
+ return output.exitCode === 0;
34
+ }
35
+
36
+ export async function removeImageFromLocalRegistry(
37
+ /** @example 'alpine:3.20.2' */
38
+ imageName: string,
39
+ ) {
40
+ try {
41
+ await runShellCommand(`docker image rm '${imageName}'`, {
42
+ rejectOnError: true,
43
+ });
44
+ } catch (caught) {
45
+ const error = ensureError(caught);
46
+
47
+ if (error.message.includes('No such image:')) {
48
+ /** Ignore the case where the image has already been deleted. */
49
+ return;
50
+ }
51
+
52
+ /** An edge case that I don't know how to intentionally trigger. */
53
+ /* node:coverage ignore next 2 */
54
+ throw error;
55
+ }
56
+ }
@@ -0,0 +1,49 @@
1
+ import {waitUntil} from '@augment-vir/assert';
2
+ import {currentOperatingSystem, OperatingSystem} from '../augments/os/operating-system.js';
3
+ import {runShellCommand} from '../augments/terminal/shell.js';
4
+
5
+ export async function isDockerRunning() {
6
+ const output = await runShellCommand('docker info');
7
+
8
+ return output.exitCode === 0;
9
+ }
10
+
11
+ const startDockerCommands: Record<OperatingSystem, string> = {
12
+ /**
13
+ * Officially supported for the following distros:
14
+ *
15
+ * - [Ubuntu](https://docs.docker.com/desktop/install/ubuntu/#launch-docker-desktop)
16
+ * - [Debian](https://docs.docker.com/desktop/install/debian/#launch-docker-desktop)
17
+ * - [Fedora](https://docs.docker.com/desktop/install/fedora/#launch-docker-desktop)
18
+ * - [Arch](https://docs.docker.com/desktop/install/archlinux/#launch-docker-desktop)
19
+ */
20
+ [OperatingSystem.Linux]: 'systemctl --user start docker-desktop',
21
+ [OperatingSystem.Mac]: 'open -a Docker',
22
+ [OperatingSystem.Windows]: String.raw`/c/Program\ Files/Docker/Docker/Docker\ Desktop.exe`,
23
+ };
24
+
25
+ export async function startDocker() {
26
+ const command = startDockerCommands[currentOperatingSystem];
27
+
28
+ /* node:coverage disable */
29
+ if (await isDockerRunning()) {
30
+ /** Docker is already running. Nothing to do. */
31
+ return;
32
+ }
33
+
34
+ await waitUntil.isTrue(
35
+ async () => {
36
+ await runShellCommand(command, {rejectOnError: true});
37
+ return isDockerRunning();
38
+ },
39
+ {
40
+ interval: {
41
+ seconds: 1,
42
+ },
43
+ timeout: {
44
+ minutes: 1,
45
+ },
46
+ },
47
+ 'Failed to start Docker.',
48
+ );
49
+ }
@@ -0,0 +1,26 @@
1
+ import {type MaybePromise} from '@augment-vir/common';
2
+ import {isOperatingSystem, OperatingSystem} from '../augments/os/operating-system.js';
3
+
4
+ export function dockerTest(callback: () => MaybePromise<void>) {
5
+ if (!isOperatingSystem(OperatingSystem.Linux) && process.env.CI) {
6
+ /**
7
+ * We cannot test Docker on macOS GitHub Actions runners.
8
+ *
9
+ * @see
10
+ * - https://github.com/actions/runner-images/issues/8104
11
+ * - 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
12
+ * - https://github.com/actions/runner-images/issues/2150
13
+ * - https://github.com/actions/runner/issues/1456
14
+ */
15
+ /**
16
+ * We cannot test Docker on Windows GitHub Actions runners because Docker cannot run in
17
+ * Linux container mode on Windows GitHub Actions runners.
18
+ *
19
+ * @see
20
+ * - https://github.com/orgs/community/discussions/25491#discussioncomment-3248089
21
+ */
22
+ return () => {};
23
+ }
24
+
25
+ return callback;
26
+ }
@@ -0,0 +1,29 @@
1
+ import {dirname, join} from 'node:path';
2
+
3
+ export const monoRepoDirPath = dirname(dirname(dirname(import.meta.dirname)));
4
+ export const notCommittedDirPath = join(monoRepoDirPath, '.not-committed');
5
+
6
+ export const nodePackageDir = dirname(import.meta.dirname);
7
+
8
+ export const testFilesDir = join(nodePackageDir, 'test-files');
9
+ const longRunningFileDir = join(testFilesDir, 'long-running-test-file');
10
+ export const dirContentsTestDir = join(testFilesDir, 'dir-contents-test');
11
+ export const longRunningFilePath = join(longRunningFileDir, 'long-running-file.ts');
12
+ export const longRunningFileWithStderr = join(
13
+ longRunningFileDir,
14
+ 'long-running-file-with-stderr.ts',
15
+ );
16
+ export const workspaceQueryDir = join(testFilesDir, 'workspace-query');
17
+ export const workspaceQueryPackageJsonPath = join(workspaceQueryDir, 'package.json');
18
+ export const tempWorkspaceQueryFile = join(workspaceQueryDir, 'temp-workspace-query-output.ts');
19
+
20
+ export const recursiveFileReadDir = join(testFilesDir, 'recursive-reading');
21
+
22
+ export const invalidPackageDirPath = join(testFilesDir, 'invalid-package');
23
+
24
+ export const testPrismaSchemaPath = join(testFilesDir, 'schema.prisma');
25
+ export const testPrismaSchema2Path = join(testFilesDir, 'schema2.prisma');
26
+ export const testInvalidPrismaSchemaPath = join(testFilesDir, 'invalid-schema.prisma');
27
+ export const testSqliteDbPath = join(notCommittedDirPath, 'dev.db');
28
+ export const generatedPrismaClientDirPath = join(nodePackageDir, 'node_modules', '.prisma');
29
+ export const testPrismaMigrationsDirPath = join(testFilesDir, 'migrations');
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ export * from './augments/docker.js';
2
+ export * from './augments/fs/dir-contents.js';
3
+ export * from './augments/fs/download.js';
4
+ export * from './augments/fs/json.js';
5
+ export * from './augments/fs/read-dir.js';
6
+ export * from './augments/fs/read-file.js';
7
+ export * from './augments/fs/symlink.js';
8
+ export * from './augments/fs/write.js';
9
+ export * from './augments/npm/query-workspace.js';
10
+ export * from './augments/npm/read-package-json.js';
11
+ export * from './augments/os/operating-system.js';
12
+ export * from './augments/path/ancestor.js';
13
+ export * from './augments/path/os-path.js';
14
+ export * from './augments/path/root.js';
15
+ export * from './augments/prisma.js';
16
+ export * from './augments/terminal/question.js';
17
+ export * from './augments/terminal/relevant-args.js';
18
+ export * from './augments/terminal/run-cli-script.js';
19
+ export * from './augments/terminal/shell.js';