@devcontainer-rs/cli 0.0.33

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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../launcher").run();
package/launcher.js ADDED
@@ -0,0 +1,161 @@
1
+ const fs = require("node:fs");
2
+ const path = require("node:path");
3
+ const { execFileSync, spawn } = require("node:child_process");
4
+
5
+ const runtimeConfig = require("./runtime-config");
6
+
7
+ function detectLibc(system = {}) {
8
+ if ((system.platform || process.platform) !== "linux") {
9
+ return null;
10
+ }
11
+
12
+ if (system.libc) {
13
+ return system.libc;
14
+ }
15
+
16
+ if (process.env.DEVCONTAINER_RS_LIBC) {
17
+ return process.env.DEVCONTAINER_RS_LIBC;
18
+ }
19
+
20
+ const report = process.report;
21
+ if (report && typeof report.getReport === "function") {
22
+ const glibcVersion = report.getReport()?.header?.glibcVersionRuntime;
23
+ if (glibcVersion) {
24
+ return "gnu";
25
+ }
26
+ }
27
+
28
+ try {
29
+ const output = execFileSync("getconf", ["GNU_LIBC_VERSION"], {
30
+ encoding: "utf8",
31
+ stdio: ["ignore", "pipe", "ignore"],
32
+ });
33
+ if (/glibc/i.test(output)) {
34
+ return "gnu";
35
+ }
36
+ } catch (_error) {
37
+ // fall through to ldd parsing
38
+ }
39
+
40
+ try {
41
+ const output = execFileSync("ldd", ["--version"], {
42
+ encoding: "utf8",
43
+ stdio: ["ignore", "pipe", "pipe"],
44
+ });
45
+ if (/musl/i.test(output)) {
46
+ return "musl";
47
+ }
48
+ if (/glibc|gnu libc|gnu c library/i.test(output)) {
49
+ return "gnu";
50
+ }
51
+ } catch (_error) {
52
+ // fall through to the default below
53
+ }
54
+
55
+ return "gnu";
56
+ }
57
+
58
+ function supportedPlatformList() {
59
+ return Object.keys(runtimeConfig.supportedTargets).join(", ");
60
+ }
61
+
62
+ function resolveBinaryPackage(system = {}) {
63
+ const platform = system.platform || process.platform;
64
+ const arch = system.arch || process.arch;
65
+
66
+ if (platform === "darwin" && arch === "x64") {
67
+ return runtimeConfig.supportedTargets["darwin-x64"];
68
+ }
69
+ if (platform === "darwin" && arch === "arm64") {
70
+ return runtimeConfig.supportedTargets["darwin-arm64"];
71
+ }
72
+ if (platform === "linux" && arch === "x64") {
73
+ const libc = detectLibc(system);
74
+ if (libc === "musl") {
75
+ return runtimeConfig.supportedTargets["linux-x64-musl"];
76
+ }
77
+ return runtimeConfig.supportedTargets["linux-x64-gnu"];
78
+ }
79
+
80
+ throw new Error(
81
+ `Unsupported platform ${platform}/${arch}. Supported platforms: ${supportedPlatformList()}`,
82
+ );
83
+ }
84
+
85
+ function resolveInstalledBinary(options = {}) {
86
+ const packageRoot = options.packageRoot || __dirname;
87
+ const system = options.system || {};
88
+ const target = resolveBinaryPackage(system);
89
+ const resolvePackageJson =
90
+ options.resolvePackageJson ||
91
+ ((packageName) =>
92
+ require.resolve(`${packageName}/package.json`, {
93
+ paths: [packageRoot],
94
+ }));
95
+
96
+ let packageJsonPath;
97
+ try {
98
+ packageJsonPath = resolvePackageJson(target.packageName);
99
+ } catch (error) {
100
+ throw new Error(
101
+ `The native package ${target.packageName} for ${target.target} is not installed.`,
102
+ { cause: error },
103
+ );
104
+ }
105
+
106
+ const binaryPath = path.join(
107
+ path.dirname(packageJsonPath),
108
+ runtimeConfig.binaryRelativePath,
109
+ );
110
+ try {
111
+ fs.accessSync(binaryPath, fs.constants.X_OK);
112
+ } catch (error) {
113
+ throw new Error(
114
+ `The native binary ${binaryPath} is missing or not executable.`,
115
+ { cause: error },
116
+ );
117
+ }
118
+
119
+ return {
120
+ ...target,
121
+ binaryPath,
122
+ };
123
+ }
124
+
125
+ function run(argv = process.argv.slice(2)) {
126
+ let resolved;
127
+ try {
128
+ resolved = resolveInstalledBinary();
129
+ } catch (error) {
130
+ console.error(error.message);
131
+ process.exit(1);
132
+ }
133
+
134
+ const child = spawn(resolved.binaryPath, argv, {
135
+ stdio: "inherit",
136
+ });
137
+
138
+ child.on("error", (error) => {
139
+ console.error(error.message);
140
+ process.exit(1);
141
+ });
142
+
143
+ child.on("exit", (code, signal) => {
144
+ if (signal) {
145
+ process.kill(process.pid, signal);
146
+ return;
147
+ }
148
+ process.exit(code ?? 1);
149
+ });
150
+ }
151
+
152
+ module.exports = {
153
+ detectLibc,
154
+ resolveBinaryPackage,
155
+ resolveInstalledBinary,
156
+ run,
157
+ };
158
+
159
+ if (require.main === module) {
160
+ run();
161
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@devcontainer-rs/cli",
3
+ "version": "0.0.33",
4
+ "description": "Rust-native devcontainer CLI wrapper package for the upstream @devcontainers/cli shape",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/jooh/devcontainer-rs.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/jooh/devcontainer-rs/issues"
12
+ },
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "bin": {
17
+ "devcontainer": "bin/devcontainer.js"
18
+ },
19
+ "files": [
20
+ "bin",
21
+ "launcher.js",
22
+ "runtime-config.js"
23
+ ],
24
+ "optionalDependencies": {
25
+ "@devcontainer-rs/devcontainer-darwin-arm64": "0.0.33"
26
+ }
27
+ }
@@ -0,0 +1,66 @@
1
+ const supportedTargets = {
2
+ "darwin-x64": {
3
+ target: "darwin-x64",
4
+ triple: "x86_64-apple-darwin",
5
+ archiveSuffix: "darwin-x64",
6
+ packageName: "@devcontainer-rs/devcontainer-darwin-x64",
7
+ packageSlug: "devcontainer-rs-devcontainer-darwin-x64",
8
+ os: "darwin",
9
+ cpu: "x64",
10
+ },
11
+ "darwin-arm64": {
12
+ target: "darwin-arm64",
13
+ triple: "aarch64-apple-darwin",
14
+ archiveSuffix: "darwin-arm64",
15
+ packageName: "@devcontainer-rs/devcontainer-darwin-arm64",
16
+ packageSlug: "devcontainer-rs-devcontainer-darwin-arm64",
17
+ os: "darwin",
18
+ cpu: "arm64",
19
+ },
20
+ "linux-x64-gnu": {
21
+ target: "linux-x64-gnu",
22
+ triple: "x86_64-unknown-linux-gnu",
23
+ archiveSuffix: "linux-x64-gnu",
24
+ packageName: "@devcontainer-rs/devcontainer-linux-x64-gnu",
25
+ packageSlug: "devcontainer-rs-devcontainer-linux-x64-gnu",
26
+ os: "linux",
27
+ cpu: "x64",
28
+ libc: "glibc",
29
+ },
30
+ "linux-x64-musl": {
31
+ target: "linux-x64-musl",
32
+ triple: "x86_64-unknown-linux-musl",
33
+ archiveSuffix: "linux-x64-musl",
34
+ packageName: "@devcontainer-rs/devcontainer-linux-x64-musl",
35
+ packageSlug: "devcontainer-rs-devcontainer-linux-x64-musl",
36
+ os: "linux",
37
+ cpu: "x64",
38
+ libc: "musl",
39
+ },
40
+ };
41
+
42
+ const wrapperPackages = {
43
+ "devcontainer-rs": {
44
+ packageName: "devcontainer-rs",
45
+ packageSlug: "devcontainer-rs",
46
+ description: "Rust-native devcontainer CLI wrapper package",
47
+ bin: {
48
+ "devcontainer-rs": "bin/devcontainer-rs.js",
49
+ devcontainer: "bin/devcontainer-rs.js",
50
+ },
51
+ },
52
+ cli: {
53
+ packageName: "@devcontainer-rs/cli",
54
+ packageSlug: "devcontainer-rs-cli",
55
+ description: "Rust-native devcontainer CLI wrapper package for the upstream @devcontainers/cli shape",
56
+ bin: {
57
+ devcontainer: "bin/devcontainer.js",
58
+ },
59
+ },
60
+ };
61
+
62
+ module.exports = {
63
+ binaryRelativePath: "bin/devcontainer",
64
+ supportedTargets,
65
+ wrapperPackages,
66
+ };