@rdif/amber 0.0.0 → 0.3.37

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/bin/run.cjs ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ const fs = require("node:fs");
3
+ const path = require("node:path");
4
+ const { spawnSync } = require("node:child_process");
5
+
6
+ const { currentPlatformKey, formatSupportedPlatforms } = require("../lib/platform.cjs");
7
+ const { resolveInstalledBinary, resolveInstalledPackage } = require("../lib/installed-binary.cjs");
8
+
9
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
10
+ const platformKey = currentPlatformKey();
11
+ const packageName = pkg.amber.platform_packages[platformKey];
12
+
13
+ if (!packageName) {
14
+ console.error(
15
+ `${pkg.name} does not ship ${pkg.amber.entry_binary} for ${platformKey}. Supported platforms: ${formatSupportedPlatforms(
16
+ Object.keys(pkg.amber.platform_packages),
17
+ )}`,
18
+ );
19
+ process.exit(1);
20
+ }
21
+
22
+ const { packageRoot, packageJson } = resolveInstalledPackage(packageName);
23
+ const binaryPath = resolveInstalledBinary(packageName, pkg.amber.entry_binary);
24
+ const env = { ...process.env };
25
+ const runtimeBinDir = packageJson.amber?.runtime_bin_dir;
26
+
27
+ if (runtimeBinDir && !("AMBER_RUNTIME_BIN_DIR" in process.env)) {
28
+ env.AMBER_RUNTIME_BIN_DIR = path.join(packageRoot, runtimeBinDir);
29
+ }
30
+
31
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
32
+ stdio: "inherit",
33
+ env,
34
+ });
35
+
36
+ if (result.error) {
37
+ console.error(`failed to execute ${binaryPath}: ${result.error.message}`);
38
+ process.exit(1);
39
+ }
40
+
41
+ if (result.signal) {
42
+ process.kill(process.pid, result.signal);
43
+ }
44
+
45
+ process.exit(result.status ?? 1);
@@ -0,0 +1,32 @@
1
+ const fs = require("node:fs");
2
+ const path = require("node:path");
3
+
4
+ function resolveInstalledPackage(packageName) {
5
+ const packageJsonPath = require.resolve(`${packageName}/package.json`);
6
+ const packageRoot = path.dirname(packageJsonPath);
7
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
8
+
9
+ return {
10
+ packageRoot,
11
+ packageJson,
12
+ };
13
+ }
14
+
15
+ function resolveInstalledBinary(packageName, binaryName) {
16
+ const { packageRoot, packageJson } = resolveInstalledPackage(packageName);
17
+ const relativeBinaryPath =
18
+ typeof packageJson.bin === "string"
19
+ ? packageJson.bin
20
+ : packageJson.bin?.[binaryName];
21
+
22
+ if (!relativeBinaryPath) {
23
+ throw new Error(`${packageName} does not expose ${binaryName}`);
24
+ }
25
+
26
+ return path.join(packageRoot, relativeBinaryPath);
27
+ }
28
+
29
+ module.exports = {
30
+ resolveInstalledPackage,
31
+ resolveInstalledBinary,
32
+ };
@@ -0,0 +1,12 @@
1
+ function currentPlatformKey() {
2
+ return `${process.platform}-${process.arch}`;
3
+ }
4
+
5
+ function formatSupportedPlatforms(platforms) {
6
+ return platforms.sort().join(", ");
7
+ }
8
+
9
+ module.exports = {
10
+ currentPlatformKey,
11
+ formatSupportedPlatforms,
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdif/amber",
3
- "version": "0.0.0",
3
+ "version": "0.3.37",
4
4
  "description": "Amber CLI plus the local runtime binaries required by amber run",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -14,7 +14,25 @@
14
14
  "engines": {
15
15
  "node": ">=18"
16
16
  },
17
+ "bin": {
18
+ "amber": "./bin/run.cjs"
19
+ },
17
20
  "files": [
18
- "LICENSE"
19
- ]
21
+ "LICENSE",
22
+ "bin",
23
+ "lib"
24
+ ],
25
+ "optionalDependencies": {
26
+ "@rdif/amber-linux-x64": "0.3.37",
27
+ "@rdif/amber-linux-arm64": "0.3.37",
28
+ "@rdif/amber-darwin-arm64": "0.3.37"
29
+ },
30
+ "amber": {
31
+ "entry_binary": "amber",
32
+ "platform_packages": {
33
+ "linux-x64": "@rdif/amber-linux-x64",
34
+ "linux-arm64": "@rdif/amber-linux-arm64",
35
+ "darwin-arm64": "@rdif/amber-darwin-arm64"
36
+ }
37
+ }
20
38
  }