@primitivedotdev/cli 0.29.0 → 0.30.1

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.
@@ -1,3 +1,4 @@
1
+ import { spawnSync } from "node:child_process";
1
2
  //#region src/oclif/proxy-auto-detect.ts
2
3
  const PROXY_ENV_VARS = [
3
4
  "HTTP_PROXY",
@@ -15,7 +16,7 @@ function detectProxyVars(env) {
15
16
  return typeof value === "string" && value.length > 0;
16
17
  });
17
18
  }
18
- function applyProxyAutoDetect(options = {}) {
19
+ function restartWithProxyEnvIfNeeded(options = {}) {
19
20
  const env = options.env ?? process.env;
20
21
  const stderr = options.stderr ?? process.stderr;
21
22
  const detectedVars = detectProxyVars(env);
@@ -29,17 +30,42 @@ function applyProxyAutoDetect(options = {}) {
29
30
  detectedVars,
30
31
  reason: "node_use_env_proxy_already_set"
31
32
  };
32
- env.NODE_USE_ENV_PROXY = "1";
33
+ const argv = options.argv ?? process.argv;
34
+ const entrypoint = argv[1];
35
+ if (!entrypoint) return {
36
+ applied: false,
37
+ detectedVars,
38
+ reason: "missing_entrypoint"
39
+ };
40
+ const execPath = options.execPath ?? process.execPath;
41
+ const execArgv = options.execArgv ?? process.execArgv;
42
+ const spawn = options.spawn ?? spawnSync;
43
+ const exit = options.exit ?? ((code) => {
44
+ process.exit(code);
45
+ throw new Error("process.exit returned unexpectedly");
46
+ });
33
47
  if (!hintPrinted) {
34
48
  hintPrinted = true;
35
49
  const names = detectedVars.join("/");
36
- stderr.write(`primitive: proxy detected via ${names}, NODE_USE_ENV_PROXY=1 set automatically\n`);
50
+ stderr.write(`primitive: proxy detected via ${names}, restarting with NODE_USE_ENV_PROXY=1\n`);
37
51
  }
38
- return {
39
- applied: true,
40
- detectedVars,
41
- reason: "applied"
42
- };
52
+ const child = spawn(execPath, [
53
+ ...execArgv,
54
+ entrypoint,
55
+ ...argv.slice(2)
56
+ ], {
57
+ env: {
58
+ ...env,
59
+ NODE_USE_ENV_PROXY: "1"
60
+ },
61
+ stdio: "inherit"
62
+ });
63
+ if (child.error) throw child.error;
64
+ if (child.signal) {
65
+ (options.kill ?? process.kill)(options.pid ?? process.pid, child.signal);
66
+ return exit(1);
67
+ }
68
+ return exit(child.status ?? 1);
43
69
  }
44
70
  //#endregion
45
- export { _resetHintLatchForTest, applyProxyAutoDetect };
71
+ export { _resetHintLatchForTest, restartWithProxyEnvIfNeeded };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primitivedotdev/cli",
3
- "version": "0.29.0",
3
+ "version": "0.30.1",
4
4
  "description": "Official Primitive CLI: deploy Primitive Functions, send and inspect mail, manage endpoints, all from the terminal. Wraps the @primitivedotdev/sdk runtime client with one-shot commands.",
5
5
  "type": "module",
6
6
  "sideEffects": false,