@ingit/cli 0.5.1 → 0.6.3
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 +28 -0
- package/bin/auto-update.cjs +348 -0
- package/bin/ingit.cjs +65 -39
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -56,7 +56,35 @@ ingit --no-open # don't open the browser automatically
|
|
|
56
56
|
| `-p, --port <n>` | Preferred port (default `8449`; next free port if taken). |
|
|
57
57
|
| `--host <h>` | Host to bind (default `127.0.0.1`). |
|
|
58
58
|
| `--no-open` | Don't open the browser automatically. |
|
|
59
|
+
| `--no-auto-update` | Skip the automatic update check for this launch. |
|
|
59
60
|
| `-v, --version` | Print version. |
|
|
60
61
|
| `-h, --help` | Show help. |
|
|
61
62
|
|
|
62
63
|
`git` must be installed and on your `PATH`.
|
|
64
|
+
|
|
65
|
+
## Automatic updates
|
|
66
|
+
|
|
67
|
+
Global installations check npm's `latest` release when `ingit` starts. When a
|
|
68
|
+
newer version is available, the launcher runs the owning package manager's
|
|
69
|
+
global install command and starts the updated CLI with the same arguments:
|
|
70
|
+
|
|
71
|
+
| Package manager | Command (with the detected version) |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| npm | `npm install --global @ingit/cli@<version>` |
|
|
74
|
+
| pnpm | `pnpm add --global @ingit/cli@<version>` |
|
|
75
|
+
| Yarn Classic | `yarn global add @ingit/cli@<version>` |
|
|
76
|
+
| Bun | `bun add --global @ingit/cli@<version>` |
|
|
77
|
+
|
|
78
|
+
Turn off **Settings → Updates → Install updates automatically** to opt out.
|
|
79
|
+
The preference is saved on the server machine in
|
|
80
|
+
`$XDG_CONFIG_HOME/ingit/settings.json` (default `~/.config/ingit/settings.json`),
|
|
81
|
+
or `%APPDATA%\ingit\settings.json` on Windows. It applies across repositories
|
|
82
|
+
and browser sessions. `INGIT_AUTO_UPDATE=0` also disables updates, and
|
|
83
|
+
`ingit --no-auto-update` skips them for one launch.
|
|
84
|
+
|
|
85
|
+
Help/version commands and development builds skip checks. Local/temporary
|
|
86
|
+
installations are not updated globally, and ambiguous package-manager ownership
|
|
87
|
+
is left for manual updating. Registry checks time out after three seconds;
|
|
88
|
+
offline checks or failed installs report a warning and continue startup.
|
|
89
|
+
Updates never invoke sudo. If an install requires elevated permissions, update
|
|
90
|
+
it manually. Close other ingit processes first if Windows reports a locked binary.
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/auto-update.ts
|
|
40
|
+
var exports_auto_update = {};
|
|
41
|
+
__export(exports_auto_update, {
|
|
42
|
+
autoUpdate: () => autoUpdate,
|
|
43
|
+
detectGlobalInstallation: () => detectGlobalInstallation,
|
|
44
|
+
fetchLatestVersion: () => fetchLatestVersion,
|
|
45
|
+
runCommand: () => runCommand,
|
|
46
|
+
updateArguments: () => updateArguments
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(exports_auto_update);
|
|
49
|
+
var import_node_child_process = require("node:child_process");
|
|
50
|
+
var import_promises2 = require("node:fs/promises");
|
|
51
|
+
var import_node_os2 = require("node:os");
|
|
52
|
+
var import_node_path2 = require("node:path");
|
|
53
|
+
|
|
54
|
+
// ../server/src/app-settings.ts
|
|
55
|
+
var import_promises = require("node:fs/promises");
|
|
56
|
+
var import_node_os = require("node:os");
|
|
57
|
+
var import_node_path = require("node:path");
|
|
58
|
+
function appSettingsPath() {
|
|
59
|
+
const base = process.platform === "win32" ? process.env.APPDATA ?? import_node_path.join(import_node_os.homedir(), "AppData", "Roaming") : process.env.XDG_CONFIG_HOME ?? import_node_path.join(import_node_os.homedir(), ".config");
|
|
60
|
+
return import_node_path.join(base, "ingit", "settings.json");
|
|
61
|
+
}
|
|
62
|
+
async function readSettings(filePath) {
|
|
63
|
+
try {
|
|
64
|
+
const data = JSON.parse(await import_promises.readFile(filePath, "utf8"));
|
|
65
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
66
|
+
throw new Error("Invalid ingit settings file");
|
|
67
|
+
}
|
|
68
|
+
return data;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error.code === "ENOENT")
|
|
71
|
+
return {};
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function getAppSettings(filePath = appSettingsPath()) {
|
|
76
|
+
const data = await readSettings(filePath);
|
|
77
|
+
if (data.autoUpdate !== undefined && typeof data.autoUpdate !== "boolean") {
|
|
78
|
+
throw new Error("Invalid automatic update preference");
|
|
79
|
+
}
|
|
80
|
+
return { autoUpdate: data.autoUpdate ?? true };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/existing-server.ts
|
|
84
|
+
function parseVersion(version) {
|
|
85
|
+
const match = version.trim().match(/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/);
|
|
86
|
+
if (!match)
|
|
87
|
+
return null;
|
|
88
|
+
const core = match.slice(1, 4).map(Number);
|
|
89
|
+
if (core.some((part) => !Number.isSafeInteger(part)))
|
|
90
|
+
return null;
|
|
91
|
+
return { core, prerelease: match[4]?.split(".") ?? null };
|
|
92
|
+
}
|
|
93
|
+
function compareVersions(left, right) {
|
|
94
|
+
const a = parseVersion(left);
|
|
95
|
+
const b = parseVersion(right);
|
|
96
|
+
if (!a || !b)
|
|
97
|
+
return null;
|
|
98
|
+
for (let i = 0;i < a.core.length; i++) {
|
|
99
|
+
if (a.core[i] !== b.core[i])
|
|
100
|
+
return a.core[i] < b.core[i] ? -1 : 1;
|
|
101
|
+
}
|
|
102
|
+
if (a.prerelease === null || b.prerelease === null) {
|
|
103
|
+
if (a.prerelease === b.prerelease)
|
|
104
|
+
return 0;
|
|
105
|
+
return a.prerelease === null ? 1 : -1;
|
|
106
|
+
}
|
|
107
|
+
const count = Math.max(a.prerelease.length, b.prerelease.length);
|
|
108
|
+
for (let i = 0;i < count; i++) {
|
|
109
|
+
const aPart = a.prerelease[i];
|
|
110
|
+
const bPart = b.prerelease[i];
|
|
111
|
+
if (aPart === undefined || bPart === undefined) {
|
|
112
|
+
if (aPart === bPart)
|
|
113
|
+
return 0;
|
|
114
|
+
return aPart === undefined ? -1 : 1;
|
|
115
|
+
}
|
|
116
|
+
if (aPart === bPart)
|
|
117
|
+
continue;
|
|
118
|
+
const aNumeric = /^\d+$/.test(aPart);
|
|
119
|
+
const bNumeric = /^\d+$/.test(bPart);
|
|
120
|
+
if (aNumeric && bNumeric)
|
|
121
|
+
return Number(aPart) < Number(bPart) ? -1 : 1;
|
|
122
|
+
if (aNumeric !== bNumeric)
|
|
123
|
+
return aNumeric ? -1 : 1;
|
|
124
|
+
return aPart < bPart ? -1 : 1;
|
|
125
|
+
}
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/auto-update.ts
|
|
130
|
+
var PACKAGE = "@ingit/cli";
|
|
131
|
+
var REGISTRY = "https://registry.npmjs.org/@ingit%2fcli/latest";
|
|
132
|
+
var INSTALL_TIMEOUT = 120000;
|
|
133
|
+
var VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
134
|
+
var runCommand = (manager, args, install = false) => new Promise((resolve, reject) => {
|
|
135
|
+
const windowsShim = process.platform === "win32" && manager !== "bun";
|
|
136
|
+
const child = import_node_child_process.spawn(manager, args, {
|
|
137
|
+
cwd: import_node_os2.homedir(),
|
|
138
|
+
env: {
|
|
139
|
+
...process.env,
|
|
140
|
+
COREPACK_ENABLE_PROJECT_SPEC: "0",
|
|
141
|
+
COREPACK_ENABLE_DOWNLOAD_PROMPT: "0",
|
|
142
|
+
COREPACK_ENABLE_NETWORK: "0",
|
|
143
|
+
NO_UPDATE_NOTIFIER: "1"
|
|
144
|
+
},
|
|
145
|
+
shell: windowsShim,
|
|
146
|
+
stdio: ["ignore", install ? "inherit" : "pipe", install ? "inherit" : "ignore"],
|
|
147
|
+
windowsHide: true
|
|
148
|
+
});
|
|
149
|
+
let stdout = "";
|
|
150
|
+
child.stdout?.setEncoding("utf8").on("data", (chunk) => {
|
|
151
|
+
stdout += chunk;
|
|
152
|
+
});
|
|
153
|
+
const timer = setTimeout(() => {
|
|
154
|
+
child.kill("SIGKILL");
|
|
155
|
+
reject(new Error(`${manager} timed out`));
|
|
156
|
+
}, install ? INSTALL_TIMEOUT : 3000);
|
|
157
|
+
child.once("error", (error) => {
|
|
158
|
+
clearTimeout(timer);
|
|
159
|
+
reject(error);
|
|
160
|
+
});
|
|
161
|
+
child.once("close", (code) => {
|
|
162
|
+
clearTimeout(timer);
|
|
163
|
+
resolve({ code, stdout });
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
async function canonical(path) {
|
|
167
|
+
try {
|
|
168
|
+
return await import_promises2.realpath(path);
|
|
169
|
+
} catch {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function query(run, manager, args) {
|
|
174
|
+
try {
|
|
175
|
+
const result = await run(manager, args);
|
|
176
|
+
return result.code === 0 ? result.stdout.trim() : null;
|
|
177
|
+
} catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async function globalPackages(manager, run) {
|
|
182
|
+
if (manager === "bun") {
|
|
183
|
+
const bin = await query(run, manager, ["pm", "bin", "-g"]);
|
|
184
|
+
if (!bin || !import_node_path2.isAbsolute(bin))
|
|
185
|
+
return [];
|
|
186
|
+
const launcher = await canonical(import_node_path2.join(bin, "ingit"));
|
|
187
|
+
if (launcher?.endsWith(`${import_node_path2.sep}bin${import_node_path2.sep}ingit.cjs`))
|
|
188
|
+
return [import_node_path2.dirname(import_node_path2.dirname(launcher))];
|
|
189
|
+
if (process.platform !== "win32" || !await canonical(import_node_path2.join(bin, "ingit.exe")))
|
|
190
|
+
return [];
|
|
191
|
+
const listing = await query(run, manager, ["pm", "ls", "-g"]);
|
|
192
|
+
const root = listing?.split(/\r?\n/)[0]?.match(/^(.+) node_modules \(/)?.[1];
|
|
193
|
+
if (root && import_node_path2.isAbsolute(root))
|
|
194
|
+
return [import_node_path2.join(root, "node_modules", PACKAGE)];
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
if (manager === "pnpm") {
|
|
198
|
+
const output2 = await query(run, manager, ["list", "--global", "--depth=0", "--json"]);
|
|
199
|
+
try {
|
|
200
|
+
const groups = JSON.parse(output2 ?? "");
|
|
201
|
+
if (!Array.isArray(groups))
|
|
202
|
+
return [];
|
|
203
|
+
return groups.flatMap((group) => {
|
|
204
|
+
const dependency = group?.dependencies?.[PACKAGE];
|
|
205
|
+
if (!dependency || typeof group.path !== "string" || !import_node_path2.isAbsolute(group.path))
|
|
206
|
+
return [];
|
|
207
|
+
if (/^(link:|file:)/.test(dependency.version ?? ""))
|
|
208
|
+
return [];
|
|
209
|
+
return [import_node_path2.join(group.path, "node_modules", PACKAGE)];
|
|
210
|
+
});
|
|
211
|
+
} catch {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const output = await query(run, manager, manager === "yarn" ? ["global", "dir", "--silent"] : ["root", "--global"]);
|
|
216
|
+
if (!output || !import_node_path2.isAbsolute(output) || output.includes(`
|
|
217
|
+
`))
|
|
218
|
+
return [];
|
|
219
|
+
return [import_node_path2.join(output, ...manager === "yarn" ? ["node_modules"] : [], PACKAGE)];
|
|
220
|
+
}
|
|
221
|
+
async function detectGlobalInstallation(packageDir, run = runCommand) {
|
|
222
|
+
const current = await canonical(packageDir);
|
|
223
|
+
if (!current || !current.split(import_node_path2.sep).includes("node_modules"))
|
|
224
|
+
return null;
|
|
225
|
+
const managers = ["pnpm", "bun", "yarn", "npm"];
|
|
226
|
+
const matches = await Promise.all(managers.map(async (manager) => {
|
|
227
|
+
for (const candidate of await globalPackages(manager, run)) {
|
|
228
|
+
if (await canonical(candidate) !== current)
|
|
229
|
+
continue;
|
|
230
|
+
if (manager === "npm" || manager === "yarn") {
|
|
231
|
+
const root = await canonical(import_node_path2.dirname(import_node_path2.dirname(candidate)));
|
|
232
|
+
if (!root || import_node_path2.relative(root, current).startsWith(`..${import_node_path2.sep}`))
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
return { manager, packageDir: candidate };
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}));
|
|
239
|
+
const found = matches.filter((match) => match !== null);
|
|
240
|
+
return found.length === 1 ? found[0] : null;
|
|
241
|
+
}
|
|
242
|
+
function updateArguments(manager, version) {
|
|
243
|
+
if (version !== version.trim() || !VERSION.test(version))
|
|
244
|
+
throw new Error("Invalid update version");
|
|
245
|
+
const spec = `${PACKAGE}@${version}`;
|
|
246
|
+
return manager === "yarn" ? ["global", "add", spec] : [manager === "npm" ? "install" : "add", "--global", spec];
|
|
247
|
+
}
|
|
248
|
+
async function fetchLatestVersion(fetcher = fetch) {
|
|
249
|
+
const response = await fetcher(REGISTRY, {
|
|
250
|
+
headers: { Accept: "application/json" },
|
|
251
|
+
signal: AbortSignal.timeout(3000)
|
|
252
|
+
});
|
|
253
|
+
if (!response.ok)
|
|
254
|
+
return null;
|
|
255
|
+
const data = await response.json();
|
|
256
|
+
if (data?.name !== PACKAGE || typeof data.version !== "string" || !VERSION.test(data.version))
|
|
257
|
+
return null;
|
|
258
|
+
if (data.optionalDependencies?.[`${PACKAGE}-${process.platform}-${process.arch}`] !== data.version)
|
|
259
|
+
return null;
|
|
260
|
+
return data.version;
|
|
261
|
+
}
|
|
262
|
+
async function readManifest(packageDir) {
|
|
263
|
+
return JSON.parse(await import_promises2.readFile(import_node_path2.join(packageDir, "package.json"), "utf8"));
|
|
264
|
+
}
|
|
265
|
+
async function acquireLock(filePath) {
|
|
266
|
+
await import_promises2.mkdir(import_node_path2.dirname(filePath), { recursive: true });
|
|
267
|
+
const deadline = Date.now() + INSTALL_TIMEOUT + 5000;
|
|
268
|
+
while (Date.now() < deadline) {
|
|
269
|
+
try {
|
|
270
|
+
const file = await import_promises2.open(filePath, "wx", 384);
|
|
271
|
+
await file.writeFile(String(process.pid));
|
|
272
|
+
await file.close();
|
|
273
|
+
return () => import_promises2.rm(filePath, { force: true });
|
|
274
|
+
} catch (error) {
|
|
275
|
+
if (error.code !== "EEXIST")
|
|
276
|
+
throw error;
|
|
277
|
+
try {
|
|
278
|
+
const pid = Number(await import_promises2.readFile(filePath, "utf8"));
|
|
279
|
+
if (Number.isSafeInteger(pid) && pid > 0) {
|
|
280
|
+
try {
|
|
281
|
+
process.kill(pid, 0);
|
|
282
|
+
} catch (error2) {
|
|
283
|
+
if (error2.code === "ESRCH") {
|
|
284
|
+
await import_promises2.rm(filePath, { force: true });
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
} catch {}
|
|
290
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
async function autoUpdate({
|
|
296
|
+
packageDir,
|
|
297
|
+
args,
|
|
298
|
+
env = process.env,
|
|
299
|
+
settingsPath = appSettingsPath(),
|
|
300
|
+
run = runCommand,
|
|
301
|
+
latest = fetchLatestVersion,
|
|
302
|
+
log = console.log,
|
|
303
|
+
warn = console.warn
|
|
304
|
+
}) {
|
|
305
|
+
if (env.INGIT_AUTO_UPDATE === "0" || args.some((arg) => ["--no-auto-update", "--help", "-h", "--version", "-v"].includes(arg)))
|
|
306
|
+
return null;
|
|
307
|
+
let release = null;
|
|
308
|
+
try {
|
|
309
|
+
const manifest = await readManifest(packageDir);
|
|
310
|
+
if (manifest.name !== PACKAGE || manifest.private || !manifest.version)
|
|
311
|
+
return null;
|
|
312
|
+
if (!(await getAppSettings(settingsPath)).autoUpdate)
|
|
313
|
+
return null;
|
|
314
|
+
const version = await latest();
|
|
315
|
+
if (!version || compareVersions(manifest.version, version) !== -1)
|
|
316
|
+
return null;
|
|
317
|
+
const installation = await detectGlobalInstallation(packageDir, run);
|
|
318
|
+
if (!installation) {
|
|
319
|
+
warn(`ingit ${version} is available; automatic update skipped because this installation's global package manager could not be identified.`);
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
release = await acquireLock(import_node_path2.join(import_node_path2.dirname(settingsPath), "auto-update.lock"));
|
|
323
|
+
if (!release || !(await getAppSettings(settingsPath)).autoUpdate)
|
|
324
|
+
return null;
|
|
325
|
+
const installed = await readManifest(installation.packageDir);
|
|
326
|
+
const launcher = import_node_path2.join(installation.packageDir, "bin", "ingit.cjs");
|
|
327
|
+
if (installed.version && compareVersions(installed.version, version) !== -1)
|
|
328
|
+
return launcher;
|
|
329
|
+
const command = updateArguments(installation.manager, version);
|
|
330
|
+
log(`ingit: updating ${manifest.version} → ${version} (${installation.manager} ${command.join(" ")})`);
|
|
331
|
+
const result = await run(installation.manager, command, true);
|
|
332
|
+
if (result.code !== 0)
|
|
333
|
+
throw new Error(`${installation.manager} exited with code ${result.code ?? "unknown"}`);
|
|
334
|
+
for (const updated of await globalPackages(installation.manager, run)) {
|
|
335
|
+
const updatedManifest = await readManifest(updated);
|
|
336
|
+
if (updatedManifest.version === version) {
|
|
337
|
+
log(`ingit: updated to ${version}.`);
|
|
338
|
+
return await import_promises2.realpath(import_node_path2.join(updated, "bin", "ingit.cjs"));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
throw new Error("The package manager finished, but the new installation could not be verified");
|
|
342
|
+
} catch (error) {
|
|
343
|
+
warn(`ingit: automatic update skipped or failed (${error instanceof Error ? error.message : String(error)}). Continuing startup.`);
|
|
344
|
+
return null;
|
|
345
|
+
} finally {
|
|
346
|
+
await release?.().catch(() => {});
|
|
347
|
+
}
|
|
348
|
+
}
|
package/bin/ingit.cjs
CHANGED
|
@@ -9,50 +9,76 @@ const { spawnSync } = require('node:child_process')
|
|
|
9
9
|
const { chmodSync, existsSync } = require('node:fs')
|
|
10
10
|
const { join } = require('node:path')
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
binPath = localBinPath
|
|
31
|
-
} else {
|
|
32
|
-
console.error(`ingit: no prebuilt binary available for ${platform}-${arch}.`)
|
|
33
|
-
console.error(`Expected the optional dependency "${pkgName}" to be installed.`)
|
|
34
|
-
console.error(`For local testing, run "bun run --filter '@ingit/cli' release ${platformId}" from the repo root.`)
|
|
35
|
-
console.error('Supported: linux-x64, linux-arm64, darwin-x64, darwin-arm64, win32-x64.')
|
|
36
|
-
process.exit(1)
|
|
12
|
+
async function main() {
|
|
13
|
+
const args = process.argv.slice(2)
|
|
14
|
+
const skipUpdate = process.env.INGIT_SKIP_AUTO_UPDATE === '1'
|
|
15
|
+
delete process.env.INGIT_SKIP_AUTO_UPDATE
|
|
16
|
+
const updaterPath = join(__dirname, 'auto-update.cjs')
|
|
17
|
+
if (!skipUpdate && existsSync(updaterPath)) {
|
|
18
|
+
const { autoUpdate } = require(updaterPath)
|
|
19
|
+
const launcher = await autoUpdate({ packageDir: join(__dirname, '..'), args })
|
|
20
|
+
if (launcher) {
|
|
21
|
+
// Start a fresh launcher: pnpm can move the package to a new store path,
|
|
22
|
+
// and require.resolve would otherwise retain the old dependency paths.
|
|
23
|
+
const result = spawnSync(process.execPath, [launcher, ...args], {
|
|
24
|
+
stdio: 'inherit',
|
|
25
|
+
env: { ...process.env, INGIT_SKIP_AUTO_UPDATE: '1' },
|
|
26
|
+
})
|
|
27
|
+
if (result.error) throw result.error
|
|
28
|
+
process.exit(result.status === null ? 1 : result.status)
|
|
29
|
+
}
|
|
37
30
|
}
|
|
38
|
-
}
|
|
39
31
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
const platform = process.platform
|
|
33
|
+
const arch = process.arch
|
|
34
|
+
const pkgName = `@ingit/cli-${platform}-${arch}`
|
|
35
|
+
const platformId = `${platform}-${arch}`
|
|
36
|
+
const binaryName = platform === 'win32' ? 'ingit.exe' : 'ingit'
|
|
37
|
+
|
|
38
|
+
let binPath
|
|
43
39
|
try {
|
|
44
|
-
|
|
45
|
-
} catch
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
binPath = require.resolve(`${pkgName}/${binaryName}`)
|
|
41
|
+
} catch {
|
|
42
|
+
const localBinPath = join(
|
|
43
|
+
__dirname,
|
|
44
|
+
'..',
|
|
45
|
+
'release',
|
|
46
|
+
`cli-${platformId}`,
|
|
47
|
+
binaryName,
|
|
48
|
+
)
|
|
49
|
+
if (existsSync(localBinPath)) {
|
|
50
|
+
binPath = localBinPath
|
|
51
|
+
} else {
|
|
52
|
+
console.error(`ingit: no prebuilt binary available for ${platform}-${arch}.`)
|
|
53
|
+
console.error(`Expected the optional dependency "${pkgName}" to be installed.`)
|
|
54
|
+
console.error(`For local testing, run "bun run --filter '@ingit/cli' release ${platformId}" from the repo root.`)
|
|
55
|
+
console.error('Supported: linux-x64, linux-arm64, darwin-x64, darwin-arm64, win32-x64.')
|
|
56
|
+
process.exit(1)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// GitHub Actions artifacts do not preserve executable bits. Repair the mode in
|
|
61
|
+
// case the platform package was published from a downloaded artifact.
|
|
62
|
+
if (platform !== 'win32') {
|
|
63
|
+
try {
|
|
64
|
+
chmodSync(binPath, 0o755)
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(`ingit: failed to make the binary executable: ${error.message}`)
|
|
67
|
+
process.exit(1)
|
|
68
|
+
}
|
|
48
69
|
}
|
|
49
|
-
}
|
|
50
70
|
|
|
51
|
-
const result = spawnSync(binPath,
|
|
71
|
+
const result = spawnSync(binPath, args.filter((arg) => arg !== '--no-auto-update'), { stdio: 'inherit' })
|
|
52
72
|
|
|
53
|
-
if (result.error) {
|
|
54
|
-
|
|
55
|
-
|
|
73
|
+
if (result.error) {
|
|
74
|
+
console.error(`ingit: failed to launch binary: ${result.error.message}`)
|
|
75
|
+
process.exit(1)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
process.exit(result.status === null ? 1 : result.status)
|
|
56
79
|
}
|
|
57
80
|
|
|
58
|
-
|
|
81
|
+
main().catch((error) => {
|
|
82
|
+
console.error(`ingit: ${error.message}`)
|
|
83
|
+
process.exit(1)
|
|
84
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingit/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Local git history & graph viewer in your browser",
|
|
5
5
|
"bin": {
|
|
6
6
|
"ingit": "bin/ingit.cjs"
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"README.md"
|
|
11
11
|
],
|
|
12
12
|
"optionalDependencies": {
|
|
13
|
-
"@ingit/cli-linux-x64": "0.
|
|
14
|
-
"@ingit/cli-linux-arm64": "0.
|
|
15
|
-
"@ingit/cli-darwin-x64": "0.
|
|
16
|
-
"@ingit/cli-darwin-arm64": "0.
|
|
17
|
-
"@ingit/cli-win32-x64": "0.
|
|
13
|
+
"@ingit/cli-linux-x64": "0.6.3",
|
|
14
|
+
"@ingit/cli-linux-arm64": "0.6.3",
|
|
15
|
+
"@ingit/cli-darwin-x64": "0.6.3",
|
|
16
|
+
"@ingit/cli-darwin-arm64": "0.6.3",
|
|
17
|
+
"@ingit/cli-win32-x64": "0.6.3"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"engines": {
|