@amr-m-abdelgawad/devctl 0.2.1 → 0.2.3
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/devctl.cjs +45 -25
- package/dist/devctl.js +115 -115
- package/package.json +1 -1
package/bin/devctl.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
-
const { closeSync, openSync, readSync } = require("
|
|
5
|
-
const { resolve } = require("
|
|
6
|
-
const { spawn } = require("
|
|
4
|
+
const { closeSync, openSync, readSync } = require("fs");
|
|
5
|
+
const { resolve } = require("path");
|
|
6
|
+
const { spawn } = require("child_process");
|
|
7
7
|
|
|
8
8
|
const SUPPORTED_TARGETS = new Set([
|
|
9
9
|
"darwin-arm64",
|
|
@@ -13,12 +13,16 @@ const SUPPORTED_TARGETS = new Set([
|
|
|
13
13
|
"win32-x64",
|
|
14
14
|
]);
|
|
15
15
|
|
|
16
|
-
function targetFor(platform
|
|
17
|
-
|
|
16
|
+
function targetFor(platform, arch) {
|
|
17
|
+
const p = platform !== undefined ? platform : process.platform;
|
|
18
|
+
const a = arch !== undefined ? arch : process.arch;
|
|
19
|
+
return `${p}-${a}`;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
function assertSupportedTarget(platform
|
|
21
|
-
const
|
|
22
|
+
function assertSupportedTarget(platform, arch) {
|
|
23
|
+
const p = platform !== undefined ? platform : process.platform;
|
|
24
|
+
const a = arch !== undefined ? arch : process.arch;
|
|
25
|
+
const target = targetFor(p, a);
|
|
22
26
|
if (!SUPPORTED_TARGETS.has(target)) {
|
|
23
27
|
throw new Error(
|
|
24
28
|
`devctl does not currently support ${target}. Supported targets: ${Array.from(SUPPORTED_TARGETS).join(", ")}.`,
|
|
@@ -27,13 +31,13 @@ function assertSupportedTarget(platform = process.platform, arch = process.arch)
|
|
|
27
31
|
return target;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
function resolveBunExecutable(resolveModule
|
|
34
|
+
function resolveBunExecutable(resolveModule) {
|
|
35
|
+
const res = resolveModule !== undefined ? resolveModule : require.resolve;
|
|
31
36
|
try {
|
|
32
|
-
return
|
|
37
|
+
return res("bun/bin/bun.exe", { paths: [__dirname] });
|
|
33
38
|
} catch (cause) {
|
|
34
39
|
throw new Error(
|
|
35
40
|
"The bundled Bun runtime is missing. Reinstall @amr-m-abdelgawad/devctl without --ignore-scripts and try again.",
|
|
36
|
-
{ cause },
|
|
37
41
|
);
|
|
38
42
|
}
|
|
39
43
|
}
|
|
@@ -43,36 +47,52 @@ function readFilePrefix(filePath) {
|
|
|
43
47
|
try {
|
|
44
48
|
const prefix = Buffer.alloc(512);
|
|
45
49
|
const bytesRead = readSync(descriptor, prefix, 0, prefix.length, 0);
|
|
46
|
-
return prefix.
|
|
50
|
+
return prefix.slice(0, bytesRead);
|
|
47
51
|
} finally {
|
|
48
52
|
closeSync(descriptor);
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
function assertInstalledBun(bunPath, readFile
|
|
53
|
-
const
|
|
54
|
-
|
|
56
|
+
function assertInstalledBun(bunPath, readFile, platform) {
|
|
57
|
+
const read = readFile !== undefined ? readFile : readFilePrefix;
|
|
58
|
+
const targetPlatform = platform !== undefined ? platform : process.platform;
|
|
59
|
+
let prefix;
|
|
60
|
+
try {
|
|
61
|
+
prefix = read(bunPath);
|
|
62
|
+
} catch (_) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const text = prefix.toString("utf8");
|
|
66
|
+
if (text.includes("Bun's postinstall script was not run")) {
|
|
55
67
|
throw new Error(
|
|
56
68
|
"The bundled Bun runtime was not installed because npm lifecycle scripts were disabled. " +
|
|
57
69
|
"Reinstall without --ignore-scripts, then run devctl again.",
|
|
58
70
|
);
|
|
59
71
|
}
|
|
72
|
+
if (targetPlatform !== "win32" && prefix.length >= 2 && prefix[0] === 0x4d && prefix[1] === 0x5a) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`devctl was installed for Windows (detected Windows binary at ${bunPath}), but is running inside ${targetPlatform}.\n` +
|
|
75
|
+
"When running inside WSL or Linux, install Node.js natively in WSL and run: npm install --global @amr-m-abdelgawad/devctl\n" +
|
|
76
|
+
"To run devctl in Windows, use PowerShell or Command Prompt instead.",
|
|
77
|
+
);
|
|
78
|
+
}
|
|
60
79
|
}
|
|
61
80
|
|
|
62
|
-
function launch(options
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
81
|
+
function launch(options) {
|
|
82
|
+
const opts = options !== undefined ? options : {};
|
|
83
|
+
const platform = opts.platform !== undefined ? opts.platform : process.platform;
|
|
84
|
+
const arch = opts.arch !== undefined ? opts.arch : process.arch;
|
|
85
|
+
const argv = opts.argv !== undefined ? opts.argv : process.argv.slice(2);
|
|
86
|
+
const env = opts.env !== undefined ? opts.env : process.env;
|
|
87
|
+
const cwd = opts.cwd !== undefined ? opts.cwd : process.cwd();
|
|
88
|
+
const spawnChild = opts.spawnChild !== undefined ? opts.spawnChild : spawn;
|
|
89
|
+
const resolveModule = opts.resolveModule !== undefined ? opts.resolveModule : require.resolve;
|
|
90
|
+
const readFile = opts.readFile !== undefined ? opts.readFile : readFilePrefix;
|
|
91
|
+
const entrypoint = opts.entrypoint !== undefined ? opts.entrypoint : resolve(__dirname, "../dist/devctl.js");
|
|
72
92
|
|
|
73
93
|
assertSupportedTarget(platform, arch);
|
|
74
94
|
const bunPath = resolveBunExecutable(resolveModule);
|
|
75
|
-
assertInstalledBun(bunPath, readFile);
|
|
95
|
+
assertInstalledBun(bunPath, readFile, platform);
|
|
76
96
|
|
|
77
97
|
return spawnChild(bunPath, [entrypoint, ...argv], {
|
|
78
98
|
cwd,
|