@primitivedotdev/cli
Advanced tools
+6
-6
| #!/usr/bin/env node | ||
| import { execute } from "@oclif/core"; | ||
| import { applyProxyAutoDetect } from "../dist/oclif/proxy-auto-detect.js"; | ||
| import { restartWithProxyEnvIfNeeded } from "../dist/oclif/proxy-auto-detect.js"; | ||
| // Auto-set NODE_USE_ENV_PROXY=1 when HTTP(S)_PROXY is in the env. | ||
| // Must run before any network init (e.g. before oclif loads commands | ||
| // that touch fetch). See proxy-auto-detect.ts for the full rationale. | ||
| applyProxyAutoDetect(); | ||
| // Auto-restart with NODE_USE_ENV_PROXY=1 when HTTP(S)_PROXY is in the env. | ||
| // Node reads NODE_USE_ENV_PROXY during process startup, so mutating | ||
| // process.env inside this process is too late for built-in fetch. | ||
| restartWithProxyEnvIfNeeded(); | ||
| const { execute } = await import("@oclif/core"); | ||
| await execute({ dir: import.meta.url }); |
@@ -0,1 +1,2 @@ | ||
| import { spawnSync } from "node:child_process"; | ||
| //#region src/oclif/proxy-auto-detect.ts | ||
@@ -18,3 +19,3 @@ const PROXY_ENV_VARS = [ | ||
| } | ||
| function applyProxyAutoDetect(options = {}) { | ||
| function restartWithProxyEnvIfNeeded(options = {}) { | ||
| const env = options.env ?? process.env; | ||
@@ -33,15 +34,40 @@ const stderr = options.stderr ?? process.stderr; | ||
| }; | ||
| env.NODE_USE_ENV_PROXY = "1"; | ||
| const argv = options.argv ?? process.argv; | ||
| const entrypoint = argv[1]; | ||
| if (!entrypoint) return { | ||
| applied: false, | ||
| detectedVars, | ||
| reason: "missing_entrypoint" | ||
| }; | ||
| const execPath = options.execPath ?? process.execPath; | ||
| const execArgv = options.execArgv ?? process.execArgv; | ||
| const spawn = options.spawn ?? spawnSync; | ||
| const exit = options.exit ?? ((code) => { | ||
| process.exit(code); | ||
| throw new Error("process.exit returned unexpectedly"); | ||
| }); | ||
| if (!hintPrinted) { | ||
| hintPrinted = true; | ||
| const names = detectedVars.join("/"); | ||
| stderr.write(`primitive: proxy detected via ${names}, NODE_USE_ENV_PROXY=1 set automatically\n`); | ||
| stderr.write(`primitive: proxy detected via ${names}, restarting with NODE_USE_ENV_PROXY=1\n`); | ||
| } | ||
| return { | ||
| applied: true, | ||
| detectedVars, | ||
| reason: "applied" | ||
| }; | ||
| const child = spawn(execPath, [ | ||
| ...execArgv, | ||
| entrypoint, | ||
| ...argv.slice(2) | ||
| ], { | ||
| env: { | ||
| ...env, | ||
| NODE_USE_ENV_PROXY: "1" | ||
| }, | ||
| stdio: "inherit" | ||
| }); | ||
| if (child.error) throw child.error; | ||
| if (child.signal) { | ||
| (options.kill ?? process.kill)(options.pid ?? process.pid, child.signal); | ||
| return exit(1); | ||
| } | ||
| return exit(child.status ?? 1); | ||
| } | ||
| //#endregion | ||
| export { _resetHintLatchForTest, applyProxyAutoDetect }; | ||
| export { _resetHintLatchForTest, restartWithProxyEnvIfNeeded }; |
+1
-1
| { | ||
| "name": "@primitivedotdev/cli", | ||
| "version": "0.30.0", | ||
| "version": "0.30.1", | ||
| "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,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
599658
2.58%16153
2.21%24
4.35%