awesome-emulator-cli 0.1.1 → 0.1.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 +8 -0
- package/dist/cli.js +15 -2
- package/dist/emulator-image.d.ts +2 -0
- package/dist/emulator-image.js +33 -17
- package/dist/emulator-options.d.ts +8 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -2
- package/dist/process.d.ts +1 -1
- package/dist/process.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,14 @@ npx awesome-emulator run -- npm test
|
|
|
21
21
|
|
|
22
22
|
`run` starts the emulator, supplies the connection settings to the child process, then stops the container. Use `--version` to select a release and `--port 0` to choose a free local port. Run `npx awesome-emulator --help` for all options.
|
|
23
23
|
|
|
24
|
+
Child commands run without a shell by default, so each argument is passed as data. On Windows, `.cmd` and `.bat` launchers such as `npm`, and shell built-ins such as `echo` and `dir`, require an explicit shell opt-in:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npx awesome-emulator run --shell -- npm test
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Use `--shell` only with trusted command and argument values. Shell metacharacters are interpreted in this mode. Node.js API callers can opt in with `runWithEmulator(command, args, { shell: true })` under the same restriction.
|
|
31
|
+
|
|
24
32
|
## Use from Node.js
|
|
25
33
|
|
|
26
34
|
Use the API when your test harness needs to control the emulator lifecycle directly:
|
package/dist/cli.js
CHANGED
|
@@ -4,13 +4,14 @@ import { FORWARDED_SIGNALS, getSignalExitCode } from "./signals.js";
|
|
|
4
4
|
function usage() {
|
|
5
5
|
console.log(`Usage:
|
|
6
6
|
awesome-emulator start [options]
|
|
7
|
-
awesome-emulator run [options] -- <command> [args...]
|
|
7
|
+
awesome-emulator run [options] [--shell] -- <command> [args...]
|
|
8
8
|
|
|
9
9
|
Options:
|
|
10
10
|
-v, --version <version> AWS Emulator version (default: 1.0.522)
|
|
11
11
|
-p, --port <port> Host port; 0 chooses an available port (default: 9297)
|
|
12
12
|
-t, --telemetry <on|off> Telemetry setting (default: on)
|
|
13
13
|
--memory <limit> Container memory limit (default: 2g)
|
|
14
|
+
--shell (run only) Enable .cmd/.bat and built-ins; trusted values only
|
|
14
15
|
-h, --help Show this help`);
|
|
15
16
|
}
|
|
16
17
|
function parse(argv) {
|
|
@@ -32,6 +33,12 @@ function parse(argv) {
|
|
|
32
33
|
}
|
|
33
34
|
if (token === "-h" || token === "--help")
|
|
34
35
|
return { help: true };
|
|
36
|
+
if (token === "--shell") {
|
|
37
|
+
if (command !== "run")
|
|
38
|
+
throw new Error("--shell can only be used with the run command.");
|
|
39
|
+
options.shell = true;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
35
42
|
const optionNames = {
|
|
36
43
|
"-v": "version", "--version": "version",
|
|
37
44
|
"-p": "port", "--port": "port",
|
|
@@ -77,7 +84,13 @@ async function main(signal) {
|
|
|
77
84
|
return runWithEmulator(program, args, { ...parsed.options, signal });
|
|
78
85
|
}
|
|
79
86
|
if (parsed.command === "start") {
|
|
80
|
-
const emulator = await startEmulator({
|
|
87
|
+
const emulator = await startEmulator({
|
|
88
|
+
version: parsed.options.version,
|
|
89
|
+
port: parsed.options.port,
|
|
90
|
+
telemetry: parsed.options.telemetry,
|
|
91
|
+
memory: parsed.options.memory,
|
|
92
|
+
signal,
|
|
93
|
+
});
|
|
81
94
|
try {
|
|
82
95
|
if (!signal.aborted) {
|
|
83
96
|
console.log(JSON.stringify({
|
package/dist/emulator-image.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export type EmulatorArchitecture = {
|
|
|
3
3
|
rpm: "x86_64" | "aarch64";
|
|
4
4
|
};
|
|
5
5
|
export declare function getArchitecture(): EmulatorArchitecture;
|
|
6
|
+
export declare function createEmulatorDockerfile(): string;
|
|
7
|
+
export declare function createEmulatorImageTag(version: string, architecture: EmulatorArchitecture, dockerfile: string): string;
|
|
6
8
|
export declare function ensureEmulatorImage(version: string, architecture: EmulatorArchitecture, signal?: AbortSignal): Promise<string>;
|
package/dist/emulator-image.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
3
|
import os from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
@@ -13,20 +14,8 @@ export function getArchitecture() {
|
|
|
13
14
|
return { docker: "arm64", rpm: "aarch64" };
|
|
14
15
|
throw new Error(`AWS Emulator is not available for this architecture: ${process.arch}.`);
|
|
15
16
|
}
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
const image = `awesome-emulator-cli:${version}-${architecture.docker}`;
|
|
19
|
-
try {
|
|
20
|
-
await docker(["image", "inspect", image], { capture: true, signal });
|
|
21
|
-
throwIfAborted(signal);
|
|
22
|
-
return image;
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
throwIfAborted(signal);
|
|
26
|
-
// Build the official Linux package into a local image on first use.
|
|
27
|
-
}
|
|
28
|
-
const context = await mkdtemp(path.join(os.tmpdir(), "awesome-emulator-cli-"));
|
|
29
|
-
const dockerfile = `FROM public.ecr.aws/amazonlinux/amazonlinux:2023-minimal
|
|
17
|
+
export function createEmulatorDockerfile() {
|
|
18
|
+
return `FROM public.ecr.aws/amazonlinux/amazonlinux:2023-minimal
|
|
30
19
|
ARG AWS_EMULATOR_VERSION
|
|
31
20
|
ARG AWS_EMULATOR_RPM_ARCH
|
|
32
21
|
RUN set -eu; \\
|
|
@@ -37,21 +26,48 @@ RUN set -eu; \\
|
|
|
37
26
|
curl -fsSLo /tmp/aws-emulator.rpm.sig ${PACKAGE_ROOT}/aws-emulator-\${AWS_EMULATOR_VERSION}-1-\${AWS_EMULATOR_RPM_ARCH}.rpm.sig; \\
|
|
38
27
|
curl -fsSLo /tmp/aws-publishing.asc ${PACKAGE_SIGNING_KEY}; \\
|
|
39
28
|
gpg --batch --import /tmp/aws-publishing.asc; \\
|
|
40
|
-
fingerprint="$(gpg --batch --with-colons --fingerprint
|
|
29
|
+
fingerprint="$(gpg --batch --with-colons --fingerprint "${PACKAGE_SIGNING_FINGERPRINT}" | awk -F: '$1 == "fpr" { print $10; exit }')"; \\
|
|
41
30
|
test "$fingerprint" = "${PACKAGE_SIGNING_FINGERPRINT}"; \\
|
|
42
|
-
gpg --batch --
|
|
31
|
+
gpg --batch --export "$fingerprint" > /tmp/aws-publishing.gpg; \\
|
|
32
|
+
gpgv --keyring /tmp/aws-publishing.gpg /tmp/aws-emulator.rpm.sig /tmp/aws-emulator.rpm; \\
|
|
43
33
|
dnf remove -y gnupg2-smime; \\
|
|
44
34
|
dnf swap -y gnupg2-full gnupg2-minimal; \\
|
|
45
35
|
rpm -i /tmp/aws-emulator.rpm; \\
|
|
46
36
|
mkdir -p /home/emulator/.aws/emulator; \\
|
|
47
37
|
chown -R 1000:1000 /home/emulator; \\
|
|
48
|
-
rm -rf "$GNUPGHOME" /tmp/aws-emulator.rpm /tmp/aws-emulator.rpm.sig /tmp/aws-publishing.asc; \\
|
|
38
|
+
rm -rf "$GNUPGHOME" /tmp/aws-emulator.rpm /tmp/aws-emulator.rpm.sig /tmp/aws-publishing.asc /tmp/aws-publishing.gpg; \\
|
|
49
39
|
dnf clean all
|
|
50
40
|
USER 1000:1000
|
|
51
41
|
ENV HOME=/home/emulator
|
|
52
42
|
EXPOSE ${CONTAINER_PORT}
|
|
53
43
|
ENTRYPOINT ["aws-emulator", "-b", "0.0.0.0"]
|
|
54
44
|
`;
|
|
45
|
+
}
|
|
46
|
+
export function createEmulatorImageTag(version, architecture, dockerfile) {
|
|
47
|
+
const buildDefinitionHash = createHash("sha256")
|
|
48
|
+
.update(JSON.stringify({
|
|
49
|
+
dockerfile,
|
|
50
|
+
version,
|
|
51
|
+
dockerArchitecture: architecture.docker,
|
|
52
|
+
rpmArchitecture: architecture.rpm,
|
|
53
|
+
}))
|
|
54
|
+
.digest("hex");
|
|
55
|
+
return `awesome-emulator-cli:${version}-${architecture.docker}-${buildDefinitionHash}`;
|
|
56
|
+
}
|
|
57
|
+
export async function ensureEmulatorImage(version, architecture, signal) {
|
|
58
|
+
throwIfAborted(signal);
|
|
59
|
+
const dockerfile = createEmulatorDockerfile();
|
|
60
|
+
const image = createEmulatorImageTag(version, architecture, dockerfile);
|
|
61
|
+
try {
|
|
62
|
+
await docker(["image", "inspect", image], { capture: true, signal });
|
|
63
|
+
throwIfAborted(signal);
|
|
64
|
+
return image;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
throwIfAborted(signal);
|
|
68
|
+
// Build the official Linux package into a local image on first use.
|
|
69
|
+
}
|
|
70
|
+
const context = await mkdtemp(path.join(os.tmpdir(), "awesome-emulator-cli-"));
|
|
55
71
|
try {
|
|
56
72
|
throwIfAborted(signal);
|
|
57
73
|
await writeFile(path.join(context, "Dockerfile"), dockerfile, "utf8");
|
|
@@ -6,6 +6,14 @@ export type StartEmulatorOptions = {
|
|
|
6
6
|
startupTimeoutMs?: number;
|
|
7
7
|
signal?: AbortSignal;
|
|
8
8
|
};
|
|
9
|
+
export type RunWithEmulatorOptions = StartEmulatorOptions & {
|
|
10
|
+
/**
|
|
11
|
+
* Run the child command through a shell. Shell metacharacters in command or
|
|
12
|
+
* arguments are interpreted, so only enable this for trusted values.
|
|
13
|
+
* Defaults to false.
|
|
14
|
+
*/
|
|
15
|
+
shell?: boolean;
|
|
16
|
+
};
|
|
9
17
|
export type ResolvedEmulatorOptions = {
|
|
10
18
|
version: string;
|
|
11
19
|
requestedPort: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type EmulatorEnvironment } from "./emulator-environment.js";
|
|
2
|
-
import { type StartEmulatorOptions } from "./emulator-options.js";
|
|
3
|
-
export type { StartEmulatorOptions } from "./emulator-options.js";
|
|
2
|
+
import { type RunWithEmulatorOptions, type StartEmulatorOptions } from "./emulator-options.js";
|
|
3
|
+
export type { RunWithEmulatorOptions, StartEmulatorOptions } from "./emulator-options.js";
|
|
4
4
|
export type { EmulatorEnvironment } from "./emulator-environment.js";
|
|
5
5
|
export type EmulatorSession = {
|
|
6
6
|
version: string;
|
|
@@ -24,4 +24,4 @@ export declare function startEmulator(options?: StartEmulatorOptions): Promise<E
|
|
|
24
24
|
/**
|
|
25
25
|
* Run a child process with AWS Emulator settings and stop the emulator afterward.
|
|
26
26
|
*/
|
|
27
|
-
export declare function runWithEmulator(command: string, args?: string[], options?:
|
|
27
|
+
export declare function runWithEmulator(command: string, args?: string[], options?: RunWithEmulatorOptions): Promise<number>;
|
package/dist/index.js
CHANGED
|
@@ -151,8 +151,9 @@ export async function startEmulator(options = {}) {
|
|
|
151
151
|
export async function runWithEmulator(command, args = [], options = {}) {
|
|
152
152
|
if (!command)
|
|
153
153
|
throw new Error("A command is required.");
|
|
154
|
-
|
|
154
|
+
const { shell = false, ...emulatorOptions } = options;
|
|
155
|
+
return withEmulator(() => startEmulator(emulatorOptions), async (emulator) => {
|
|
155
156
|
const childEnvironment = createChildEnvironment(process.env, emulator.environment);
|
|
156
|
-
return runCommand(command, args, childEnvironment,
|
|
157
|
+
return runCommand(command, args, childEnvironment, emulatorOptions.signal, shell);
|
|
157
158
|
});
|
|
158
159
|
}
|
package/dist/process.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function runCommand(command: string, args: string[], env: NodeJS.ProcessEnv, signal?: AbortSignal): Promise<number>;
|
|
1
|
+
export declare function runCommand(command: string, args: string[], env: NodeJS.ProcessEnv, signal?: AbortSignal, shell?: boolean): Promise<number>;
|
package/dist/process.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { FORWARDED_SIGNALS, getSignalExitCode, isForwardedSignal } from "./signals.js";
|
|
3
|
-
export function runCommand(command, args, env, signal) {
|
|
3
|
+
export function runCommand(command, args, env, signal, shell = false) {
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
5
5
|
const child = spawn(command, args, {
|
|
6
6
|
env,
|
|
7
7
|
stdio: "inherit",
|
|
8
|
-
shell
|
|
8
|
+
shell,
|
|
9
9
|
windowsHide: false,
|
|
10
10
|
});
|
|
11
11
|
let receivedSignal;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "awesome-emulator-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Awesome Emulator CLI for use with AWS Emulator in local tests from npm scripts or Node.js. It runs the upstream Linux package in Docker.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|