embedlabs 0.1.0-alpha.104 → 0.1.0-alpha.105
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/README.md +1 -1
- package/bin/install-progress.js +111 -1
- package/package.json +2 -5
package/README.md
CHANGED
package/bin/install-progress.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
4
|
import { arch, platform } from "node:os";
|
|
5
|
+
import { basename, dirname, join } from "node:path";
|
|
4
6
|
|
|
5
7
|
const phase = process.argv[2] ?? "postinstall";
|
|
6
8
|
const target = `${platform()}-${arch()}`;
|
|
9
|
+
if (phase === "preinstall") {
|
|
10
|
+
cleanupWindowsInstallState();
|
|
11
|
+
} else {
|
|
12
|
+
installCommandShim();
|
|
13
|
+
}
|
|
7
14
|
const steps = phase === "preinstall"
|
|
8
15
|
? [
|
|
9
16
|
[5, `install: initializing (${target})`],
|
|
@@ -48,6 +55,109 @@ function writeProgress(percent, message) {
|
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
57
|
|
|
58
|
+
function cleanupWindowsInstallState() {
|
|
59
|
+
stopOldBridgeProcess();
|
|
60
|
+
deleteLegacyBridgeScheduledTask();
|
|
61
|
+
cleanupOldCommandShims();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function stopOldBridgeProcess() {
|
|
65
|
+
if (platform() !== "win32") {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const imageName of ["embed-local-bridge.exe", "embed-local-bridge-fixed.exe"]) {
|
|
69
|
+
spawnSync("taskkill.exe", ["/IM", imageName, "/F"], { stdio: "ignore" });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function deleteLegacyBridgeScheduledTask() {
|
|
74
|
+
if (platform() !== "win32") {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
spawnSync("schtasks.exe", ["/Delete", "/TN", "EmbedLabsLocalBridge", "/F"], { stdio: "ignore" });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function cleanupOldCommandShims() {
|
|
81
|
+
const prefix = process.env.npm_config_prefix;
|
|
82
|
+
if (!prefix) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
for (const candidate of commandShimCandidates(prefix)) {
|
|
86
|
+
const filePath = join(prefix, candidate);
|
|
87
|
+
if (!existsSync(filePath) || !isEmbedLabsShim(filePath)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
rmSync(filePath, { force: true });
|
|
92
|
+
writeProgress(3, `install: removed stale command shim (${basename(filePath)})`);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
95
|
+
throw new Error(`stale EmbedLabs command shim is locked: ${filePath}; close running terminals or processes and retry npm install. ${message}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function commandShimCandidates(prefix) {
|
|
101
|
+
if (platform() === "win32") {
|
|
102
|
+
return ["embedlabs", "embedlabs.cmd", "embedlabs.ps1", "embedlabs.bat"];
|
|
103
|
+
}
|
|
104
|
+
return [join("bin", "embedlabs")];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function isEmbedLabsShim(filePath) {
|
|
108
|
+
try {
|
|
109
|
+
const body = readFileSync(filePath, "utf8").toLowerCase();
|
|
110
|
+
return body.includes("embedlabs")
|
|
111
|
+
&& (
|
|
112
|
+
body.includes("@kvell007\\embed-labs-cli")
|
|
113
|
+
|| body.includes("@kvell007/embed-labs-cli")
|
|
114
|
+
|| body.includes("node_modules\\embedlabs")
|
|
115
|
+
|| body.includes("node_modules/embedlabs")
|
|
116
|
+
|| body.includes("embed-labs-cli")
|
|
117
|
+
);
|
|
118
|
+
} catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function installCommandShim() {
|
|
124
|
+
const prefix = process.env.npm_config_prefix;
|
|
125
|
+
if (!prefix) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
cleanupOldCommandShims();
|
|
129
|
+
if (platform() === "win32") {
|
|
130
|
+
const target = join(prefix, "embedlabs.cmd");
|
|
131
|
+
writeFileSync(target, windowsCmdShim(), "utf8");
|
|
132
|
+
writeProgress(90, "install: command ready (embedlabs.cmd)");
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const target = join(prefix, "bin", "embedlabs");
|
|
136
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
137
|
+
writeFileSync(target, unixShellShim(), "utf8");
|
|
138
|
+
chmodSync(target, 0o755);
|
|
139
|
+
writeProgress(90, "install: command ready (embedlabs)");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function windowsCmdShim() {
|
|
143
|
+
return [
|
|
144
|
+
"@ECHO off",
|
|
145
|
+
"SETLOCAL",
|
|
146
|
+
"SET \"EMBEDLABS_ALIAS_DIR=%~dp0\"",
|
|
147
|
+
"node \"%EMBEDLABS_ALIAS_DIR%node_modules\\embedlabs\\bin\\embedlabs.js\" %*",
|
|
148
|
+
""
|
|
149
|
+
].join("\r\n");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function unixShellShim() {
|
|
153
|
+
return [
|
|
154
|
+
"#!/bin/sh",
|
|
155
|
+
"basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")",
|
|
156
|
+
"exec node \"$basedir/../lib/node_modules/embedlabs/bin/embedlabs.js\" \"$@\"",
|
|
157
|
+
""
|
|
158
|
+
].join("\n");
|
|
159
|
+
}
|
|
160
|
+
|
|
51
161
|
function sleep(ms) {
|
|
52
162
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
53
163
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "embedlabs",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.105",
|
|
4
4
|
"description": "EmbedLabs CLI alias package for local-first embedded agent testing.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
|
-
"bin": {
|
|
8
|
-
"embedlabs": "bin/embedlabs.js"
|
|
9
|
-
},
|
|
10
7
|
"scripts": {
|
|
11
8
|
"preinstall": "node bin/install-progress.js preinstall",
|
|
12
9
|
"postinstall": "node bin/install-progress.js postinstall"
|
|
@@ -16,7 +13,7 @@
|
|
|
16
13
|
"README.md"
|
|
17
14
|
],
|
|
18
15
|
"dependencies": {
|
|
19
|
-
"@kvell007/embed-labs-cli": "0.1.0-alpha.
|
|
16
|
+
"@kvell007/embed-labs-cli": "0.1.0-alpha.105"
|
|
20
17
|
},
|
|
21
18
|
"publishConfig": {
|
|
22
19
|
"access": "public",
|