@saleso.innovations/bridge 0.1.35 → 0.1.36
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/dist/update.d.ts.map +1 -1
- package/dist/update.js +32 -3
- package/package.json +1 -1
package/dist/update.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,sBAAsB,GAAG;IACnC,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,sBAAsB,GAAG;IACnC,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AA+BF,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,IAAI,CA2C1E"}
|
package/dist/update.js
CHANGED
|
@@ -4,14 +4,42 @@ import { homedir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { BRIDGE_PACKAGE, bridgeCliPath, ensureBridgeNpmRegistry, readInstalledBridgeVersion, resolveBridgeInstallDir, } from "./bridgePaths.js";
|
|
6
6
|
import { NPM_PUBLIC_REGISTRY } from "./constants.js";
|
|
7
|
+
function resolveNpmPath() {
|
|
8
|
+
const pathParts = [
|
|
9
|
+
process.env.PATH,
|
|
10
|
+
"/usr/local/bin",
|
|
11
|
+
"/usr/bin",
|
|
12
|
+
"/bin",
|
|
13
|
+
process.env.HOME ? `${process.env.HOME}/.local/bin` : null,
|
|
14
|
+
process.env.HOME ? `${process.env.HOME}/.nvm/current/bin` : null,
|
|
15
|
+
].filter((value) => Boolean(value));
|
|
16
|
+
const env = { ...process.env, PATH: pathParts.join(":") };
|
|
17
|
+
const lookup = spawnSync("which", ["npm"], { encoding: "utf8", env });
|
|
18
|
+
return {
|
|
19
|
+
executable: lookup.status === 0 && lookup.stdout.trim() ? lookup.stdout.trim() : "npm",
|
|
20
|
+
env,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function formatNpmInstallFailure(result) {
|
|
24
|
+
const detail = [result.stderr, result.stdout].filter(Boolean).join("\n").trim();
|
|
25
|
+
if (detail) {
|
|
26
|
+
const tail = detail.length > 500 ? `…${detail.slice(-500)}` : detail;
|
|
27
|
+
return `npm install failed:\n${tail}`;
|
|
28
|
+
}
|
|
29
|
+
if (result.error) {
|
|
30
|
+
return `npm install failed: ${result.error.message}`;
|
|
31
|
+
}
|
|
32
|
+
return "npm install failed (no output; npm may be missing from the bridge service PATH)";
|
|
33
|
+
}
|
|
7
34
|
export function runBridgeUpdate(options = {}) {
|
|
8
35
|
const tag = options.tag ?? "latest";
|
|
9
36
|
const bridgeDir = resolveBridgeInstallDir();
|
|
10
37
|
const beforeVersion = readInstalledBridgeVersion(bridgeDir);
|
|
11
38
|
mkdirSync(bridgeDir, { recursive: true });
|
|
12
39
|
ensureBridgeNpmRegistry(bridgeDir);
|
|
40
|
+
const { executable: npmExecutable, env } = resolveNpmPath();
|
|
13
41
|
console.log(`Updating ${BRIDGE_PACKAGE}@${tag} in ${bridgeDir} (registry: ${NPM_PUBLIC_REGISTRY})...`);
|
|
14
|
-
const npm = spawnSync(
|
|
42
|
+
const npm = spawnSync(npmExecutable, [
|
|
15
43
|
"install",
|
|
16
44
|
"--prefix",
|
|
17
45
|
bridgeDir,
|
|
@@ -21,9 +49,10 @@ export function runBridgeUpdate(options = {}) {
|
|
|
21
49
|
"--no-fund",
|
|
22
50
|
"--no-audit",
|
|
23
51
|
"--omit=dev",
|
|
24
|
-
], {
|
|
52
|
+
], { encoding: "utf8", env });
|
|
25
53
|
if (npm.status !== 0) {
|
|
26
|
-
|
|
54
|
+
console.error(formatNpmInstallFailure(npm));
|
|
55
|
+
throw new Error(formatNpmInstallFailure(npm));
|
|
27
56
|
}
|
|
28
57
|
const cliPath = bridgeCliPath(bridgeDir);
|
|
29
58
|
linkBridgeCli(cliPath);
|