localdeck 1.6.2 → 1.7.0
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/CHANGELOG.md +14 -0
- package/README.md +31 -11
- package/dashboard/assets/{index-CcN_iA3K.js → index-CbmaAEDy.js} +4 -4
- package/dashboard/index.html +1 -1
- package/dist/index-2da1tyad.js +135 -0
- package/dist/index-fmgnn6mt.js +70 -0
- package/dist/index.js +16 -1412
- package/dist/mcp-59a41rj3.js +6 -0
- package/dist/quarry-23qjnaj9.js +5 -0
- package/dist/update-zhsjwnrw.js +1 -0
- package/docs/commands.md +4 -0
- package/docs/quarry.md +49 -0
- package/package.json +3 -2
- package/quarry-extension.json +52 -0
- package/dist/index-xsyz4cc9.js +0 -9550
- package/dist/mcp-210n1fxv.js +0 -34244
- package/dist/update-hvkw7mkw.js +0 -171
package/dist/update-hvkw7mkw.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Api,
|
|
3
|
-
STATE_FILE,
|
|
4
|
-
assertUserRuntime,
|
|
5
|
-
findDaemon
|
|
6
|
-
} from "./index-xsyz4cc9.js";
|
|
7
|
-
|
|
8
|
-
// src/update.ts
|
|
9
|
-
import { spawn } from "node:child_process";
|
|
10
|
-
import fs from "node:fs";
|
|
11
|
-
import path from "node:path";
|
|
12
|
-
import { fileURLToPath } from "node:url";
|
|
13
|
-
function installationPrefix(packageRoot, globalRoot, platform = process.platform) {
|
|
14
|
-
const paths = platform === "win32" ? path.win32 : path.posix;
|
|
15
|
-
const root = paths.normalize(packageRoot);
|
|
16
|
-
const modules = paths.dirname(root);
|
|
17
|
-
const equal = (a, b) => platform === "win32" ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
18
|
-
if (paths.basename(root) !== "localdeck" || !equal(paths.basename(modules), "node_modules")) {
|
|
19
|
-
throw new Error("--update requires a global npm installation. Source checkouts and linked development builds must be updated manually.");
|
|
20
|
-
}
|
|
21
|
-
if (equal(modules, paths.normalize(globalRoot))) {
|
|
22
|
-
return platform === "win32" ? paths.dirname(modules) : paths.dirname(paths.dirname(modules));
|
|
23
|
-
}
|
|
24
|
-
if (platform !== "win32" && paths.basename(paths.dirname(modules)) === "lib")
|
|
25
|
-
return paths.dirname(paths.dirname(modules));
|
|
26
|
-
throw new Error("This is not the active global npm installation. Update it with the package manager and prefix used to install it.");
|
|
27
|
-
}
|
|
28
|
-
function npmCommand() {
|
|
29
|
-
const candidates = [
|
|
30
|
-
path.resolve(path.dirname(process.execPath), "node_modules/npm/bin/npm-cli.js"),
|
|
31
|
-
path.resolve(path.dirname(process.execPath), "../lib/node_modules/npm/bin/npm-cli.js")
|
|
32
|
-
];
|
|
33
|
-
for (const directory of (process.env.PATH ?? "").split(path.delimiter)) {
|
|
34
|
-
if (!directory)
|
|
35
|
-
continue;
|
|
36
|
-
candidates.push(path.join(directory, "node_modules/npm/bin/npm-cli.js"));
|
|
37
|
-
try {
|
|
38
|
-
const executable = fs.realpathSync(path.join(directory, "npm"));
|
|
39
|
-
if (path.basename(executable) === "npm-cli.js")
|
|
40
|
-
candidates.push(executable);
|
|
41
|
-
} catch {}
|
|
42
|
-
}
|
|
43
|
-
const cli = candidates.find((candidate) => fs.existsSync(candidate));
|
|
44
|
-
if (!cli)
|
|
45
|
-
throw new Error("npm was not found. Install Node.js with npm, then run localdeck --update again.");
|
|
46
|
-
return [process.execPath, cli];
|
|
47
|
-
}
|
|
48
|
-
async function execute(command, capture = false) {
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
const child = spawn(command[0], command.slice(1), { stdio: capture ? ["ignore", "pipe", "inherit"] : "inherit", shell: false });
|
|
51
|
-
let output = "";
|
|
52
|
-
child.stdout?.on("data", (chunk) => {
|
|
53
|
-
output += chunk.toString();
|
|
54
|
-
});
|
|
55
|
-
child.once("error", reject);
|
|
56
|
-
child.once("close", (code, signal) => code === 0 ? resolve(output.trim()) : reject(new Error(`Command failed (${signal ?? `exit ${code}`}).`)));
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function installationWritable(packageRoot, prefix, platform = process.platform) {
|
|
60
|
-
const paths = platform === "win32" ? path.win32 : path.posix;
|
|
61
|
-
for (const directory of [packageRoot, paths.dirname(packageRoot), platform === "win32" ? prefix : paths.join(prefix, "bin")]) {
|
|
62
|
-
try {
|
|
63
|
-
fs.accessSync(directory, fs.constants.W_OK | fs.constants.X_OK);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
const code = error.code;
|
|
66
|
-
if (code === "EACCES" || code === "EPERM")
|
|
67
|
-
return false;
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
async function installUpdate(options) {
|
|
74
|
-
const platform = options.platform ?? process.platform;
|
|
75
|
-
const run = options.execute ?? execute;
|
|
76
|
-
const command = [
|
|
77
|
-
...options.npm,
|
|
78
|
-
"install",
|
|
79
|
-
"--global",
|
|
80
|
-
"--prefix",
|
|
81
|
-
options.prefix,
|
|
82
|
-
"localdeck@latest",
|
|
83
|
-
"--registry=https://registry.npmjs.org/",
|
|
84
|
-
"--ignore-scripts"
|
|
85
|
-
];
|
|
86
|
-
if ((options.writable ?? installationWritable)(options.packageRoot, options.prefix, platform)) {
|
|
87
|
-
await run(command);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (platform !== "darwin" && platform !== "linux") {
|
|
91
|
-
throw new Error("The installation requires administrator access. Install localdeck@latest with npm in an administrator terminal, then restart LocalDeck as your normal user.");
|
|
92
|
-
}
|
|
93
|
-
if (!(options.interactive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY))) {
|
|
94
|
-
throw new Error("The installation requires administrator access. Run localdeck --update in an interactive terminal so npm can request permission. Do not run LocalDeck with sudo.");
|
|
95
|
-
}
|
|
96
|
-
(options.log ?? console.log)(`Administrator access is required to update ${options.prefix}. Only npm will run with sudo; LocalDeck will continue as your normal user.`);
|
|
97
|
-
await run(["/usr/bin/sudo", "-H", "--", ...command]);
|
|
98
|
-
}
|
|
99
|
-
async function applyUpdate(steps) {
|
|
100
|
-
await steps.install();
|
|
101
|
-
const version = await steps.validate();
|
|
102
|
-
await steps.stop();
|
|
103
|
-
await steps.start();
|
|
104
|
-
return version;
|
|
105
|
-
}
|
|
106
|
-
async function updateLocalDeck() {
|
|
107
|
-
assertUserRuntime();
|
|
108
|
-
const root = fs.realpathSync(path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."));
|
|
109
|
-
const npm = npmCommand();
|
|
110
|
-
const globalRoot = await execute([...npm, "root", "--global"], true);
|
|
111
|
-
const prefix = installationPrefix(root, globalRoot);
|
|
112
|
-
const bin = path.join(root, "bin/localdeck.js");
|
|
113
|
-
console.log(`Updating LocalDeck from npm in ${prefix}…`);
|
|
114
|
-
console.log("After installation, the daemon will restart. Managed services and public shares will stop; start them again when ready.");
|
|
115
|
-
let installedVersion = "";
|
|
116
|
-
const version = await applyUpdate({
|
|
117
|
-
install: async () => {
|
|
118
|
-
try {
|
|
119
|
-
await installUpdate({ npm, packageRoot: root, prefix });
|
|
120
|
-
} catch (error) {
|
|
121
|
-
throw new Error(`npm update failed. The daemon was not restarted. ${error instanceof Error ? error.message : error}`);
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
validate: async () => {
|
|
125
|
-
const version2 = await execute([process.execPath, bin, "--version"], true);
|
|
126
|
-
if (!/^\d+\.\d+\.\d+(?:[-+][\w.-]+)?$/.test(version2))
|
|
127
|
-
throw new Error("The updated CLI could not be verified. The daemon was not restarted.");
|
|
128
|
-
installedVersion = version2;
|
|
129
|
-
return version2;
|
|
130
|
-
},
|
|
131
|
-
stop: async () => {
|
|
132
|
-
const running = await findDaemon();
|
|
133
|
-
if (!running)
|
|
134
|
-
return;
|
|
135
|
-
await new Api(running.apiPort, globalThis.fetch, 30000).shutdown();
|
|
136
|
-
const deadline = Date.now() + 30000;
|
|
137
|
-
const ownsState = () => {
|
|
138
|
-
try {
|
|
139
|
-
return JSON.parse(fs.readFileSync(STATE_FILE, "utf8")).pid === running.pid;
|
|
140
|
-
} catch (error) {
|
|
141
|
-
if (error.code === "ENOENT")
|
|
142
|
-
return false;
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
while (ownsState()) {
|
|
147
|
-
if (Date.now() >= deadline)
|
|
148
|
-
throw new Error("Package updated, but the daemon did not stop within 30 seconds. Restart it manually.");
|
|
149
|
-
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
start: async () => {
|
|
153
|
-
try {
|
|
154
|
-
await execute([process.execPath, bin, "daemon", "start"]);
|
|
155
|
-
const running = await findDaemon();
|
|
156
|
-
if (running?.version !== installedVersion)
|
|
157
|
-
throw new Error("Unexpected daemon version");
|
|
158
|
-
} catch {
|
|
159
|
-
throw new Error("Package updated, but the daemon could not restart. Run localdeck daemon start to retry.");
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
console.log(`LocalDeck ${version} installed. The daemon has restarted.`);
|
|
164
|
-
}
|
|
165
|
-
export {
|
|
166
|
-
updateLocalDeck,
|
|
167
|
-
installationWritable,
|
|
168
|
-
installationPrefix,
|
|
169
|
-
installUpdate,
|
|
170
|
-
applyUpdate
|
|
171
|
-
};
|