wizards 0.9.0 → 0.9.1
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/install.sh +102 -5
- package/package.json +1 -1
package/install.sh
CHANGED
|
@@ -75,8 +75,11 @@ main() {
|
|
|
75
75
|
LOCAL_BIN="$HOME/.local/bin"
|
|
76
76
|
|
|
77
77
|
style
|
|
78
|
-
trap 'printf "%s" "$SHOW"' EXIT
|
|
78
|
+
trap 'unlock; printf "%s" "$SHOW"' EXIT
|
|
79
79
|
trap 'failed' ERR
|
|
80
|
+
# A signal ends it through the EXIT trap, which gives the lock back.
|
|
81
|
+
trap 'exit 130' INT
|
|
82
|
+
trap 'exit 143' TERM HUP
|
|
80
83
|
|
|
81
84
|
command -v curl >/dev/null 2>&1 || die "curl is needed and was not found."
|
|
82
85
|
command -v tar >/dev/null 2>&1 || die "tar is needed and was not found."
|
|
@@ -85,6 +88,7 @@ main() {
|
|
|
85
88
|
|
|
86
89
|
banner
|
|
87
90
|
printf '%s Installing into %s\n%s\n' "${GRAY}┌$RESET" "$BOLD$(tilde "$HOME_DIR")$RESET" "$BAR"
|
|
91
|
+
lock
|
|
88
92
|
platform
|
|
89
93
|
package
|
|
90
94
|
node
|
|
@@ -95,6 +99,7 @@ main() {
|
|
|
95
99
|
printf '%s %s\n\n' "${GRAY}└$RESET" "Installed. Next, a few questions to set it up."
|
|
96
100
|
printf '%s' "$SHOW"
|
|
97
101
|
trap - EXIT ERR
|
|
102
|
+
unlock
|
|
98
103
|
# --local goes on to the setup: it is the setup's account step that keeps the install off
|
|
99
104
|
# the account. The questions need a terminal; stdin may be the pipe this script came through.
|
|
100
105
|
SETUP_ARGS=""
|
|
@@ -313,6 +318,7 @@ die() {
|
|
|
313
318
|
[ "${TTY:-0}" = 1 ] && printf '\r\033[K'
|
|
314
319
|
printf '%s %s\n' "${RED:-}■${RESET:-}" "$1" >&2
|
|
315
320
|
trap - EXIT ERR
|
|
321
|
+
unlock
|
|
316
322
|
exit 1
|
|
317
323
|
}
|
|
318
324
|
|
|
@@ -378,6 +384,52 @@ download() {
|
|
|
378
384
|
wait "$pid"
|
|
379
385
|
}
|
|
380
386
|
|
|
387
|
+
# --- one install at a time ------------------------------------------------------------------
|
|
388
|
+
|
|
389
|
+
# An update the studio starts, `wizards update`, an install by hand and the runtime's own updates
|
|
390
|
+
# (autoupdate.ts) may come together; two of them in runtime/ at once leave a runtime with files
|
|
391
|
+
# missing. The lock is a folder, which only one of them can make, with its owner's pid in it.
|
|
392
|
+
# A second install waits for the first, then does its own.
|
|
393
|
+
LOCK_WAIT="${ENGENTY_WIZARDS_LOCK_WAIT:-900}"
|
|
394
|
+
|
|
395
|
+
lock() {
|
|
396
|
+
STEP="Waiting for the other install"
|
|
397
|
+
LOCK="$HOME_DIR/install.lock"
|
|
398
|
+
local waited=0 owner said=""
|
|
399
|
+
while ! mkdir "$LOCK" 2>/dev/null; do
|
|
400
|
+
owner="$(cat "$LOCK/pid" 2>/dev/null || true)"
|
|
401
|
+
# Its owner ended without giving it back (killed), or never wrote its pid.
|
|
402
|
+
if { [ -n "$owner" ] && ! kill -0 "$owner" 2>/dev/null; } ||
|
|
403
|
+
{ [ -z "$owner" ] && [ "$waited" -ge 10 ]; }; then
|
|
404
|
+
rm -rf "$LOCK"
|
|
405
|
+
continue
|
|
406
|
+
fi
|
|
407
|
+
if [ "$waited" -ge "$LOCK_WAIT" ]; then
|
|
408
|
+
die "Another install (pid ${owner:-?}) is still running after ${LOCK_WAIT}s. Try again when it is done."
|
|
409
|
+
fi
|
|
410
|
+
if [ -z "$said" ]; then
|
|
411
|
+
printf '%s %s\n' "${MAGENTA}◒$RESET" "Another install is running (pid ${owner:-?}): waiting for it"
|
|
412
|
+
said=1
|
|
413
|
+
fi
|
|
414
|
+
sleep 1
|
|
415
|
+
waited=$((waited + 1))
|
|
416
|
+
done
|
|
417
|
+
printf '%s\n' "$$" >"$LOCK/pid"
|
|
418
|
+
LOCKED=1
|
|
419
|
+
[ -n "$said" ] && done_step "The other install is done"
|
|
420
|
+
return 0
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
# Gives the lock back, and takes along what this install left half done.
|
|
424
|
+
unlock() {
|
|
425
|
+
[ -z "${STAGE:-}" ] || rm -rf "$STAGE"
|
|
426
|
+
STAGE=""
|
|
427
|
+
if [ -n "${LOCKED:-}" ]; then
|
|
428
|
+
rm -rf "$LOCK"
|
|
429
|
+
LOCKED=""
|
|
430
|
+
fi
|
|
431
|
+
}
|
|
432
|
+
|
|
381
433
|
# --- the steps -------------------------------------------------------------------------------
|
|
382
434
|
|
|
383
435
|
platform() {
|
|
@@ -418,6 +470,31 @@ sha256_of() {
|
|
|
418
470
|
fi
|
|
419
471
|
}
|
|
420
472
|
|
|
473
|
+
# Whether the npm prefix $1 holds every package its package-lock.json names (the ones for other
|
|
474
|
+
# machines aside); what is missing goes to stdout.
|
|
475
|
+
complete() {
|
|
476
|
+
PREFIX="$1" "$NODE_DIR/bin/node" -e '
|
|
477
|
+
const { existsSync, readFileSync } = require("fs");
|
|
478
|
+
const { join } = require("path");
|
|
479
|
+
const prefix = process.env.PREFIX;
|
|
480
|
+
let packages;
|
|
481
|
+
try {
|
|
482
|
+
packages = JSON.parse(readFileSync(join(prefix, "package-lock.json"), "utf8")).packages;
|
|
483
|
+
} catch {
|
|
484
|
+
console.log("npm wrote no package-lock.json");
|
|
485
|
+
process.exit(1);
|
|
486
|
+
}
|
|
487
|
+
const missing = Object.entries(packages || {})
|
|
488
|
+
.filter(([where, p]) => where && !p.optional && !p.devOptional && !p.dev && !p.peer)
|
|
489
|
+
.filter(([where]) => !existsSync(join(prefix, where, "package.json")))
|
|
490
|
+
.map(([where]) => where);
|
|
491
|
+
if (missing.length || !Object.keys(packages || {}).length) {
|
|
492
|
+
console.log("missing", missing.length, "packages:", missing.slice(0, 20).join(" "));
|
|
493
|
+
process.exit(1);
|
|
494
|
+
}
|
|
495
|
+
'
|
|
496
|
+
}
|
|
497
|
+
|
|
421
498
|
node() {
|
|
422
499
|
STEP="Installing Node $NODE_VERSION"
|
|
423
500
|
if [ -x "$NODE_DIR/bin/node" ] && [ "$("$NODE_DIR/bin/node" --version 2>/dev/null)" = "v$NODE_VERSION" ]; then
|
|
@@ -481,20 +558,32 @@ package() {
|
|
|
481
558
|
|
|
482
559
|
runtime() {
|
|
483
560
|
STEP="Installing engenty wizards"
|
|
484
|
-
local dir="$HOME_DIR/runtime" stage previous path
|
|
561
|
+
local dir="$HOME_DIR/runtime" stage previous path old
|
|
485
562
|
# An install of the package under its old name is replaced, not kept beside the new one.
|
|
486
563
|
if [ -d "$dir/node_modules/$OLD_NAME" ]; then
|
|
487
564
|
rm -rf "$dir"
|
|
488
565
|
fi
|
|
489
566
|
mkdir -p "$dir"
|
|
567
|
+
# What an install that was stopped halfway left: its npm prefix, or a version it was replacing.
|
|
568
|
+
# Old enough that no installer from before the lock is still writing into it.
|
|
569
|
+
find "$dir" -maxdepth 1 -name '.staging-*' -mmin +30 -exec rm -rf {} + 2>/dev/null || true
|
|
490
570
|
# Each version has its folder (runtime/<version>/, an npm prefix); `current` names the one the
|
|
491
571
|
# command starts, and a version that runs keeps its files. npm is a script that asks for
|
|
492
572
|
# `node`: ours comes first on the PATH. No install scripts run; the runtime works without
|
|
493
573
|
# them. --legacy-peer-deps: no peers on top, which nothing here uses (about 70 MB less).
|
|
494
574
|
stage="$(mktemp -d "$dir/.staging-XXXXXX")"
|
|
495
|
-
|
|
575
|
+
STAGE="$stage"
|
|
576
|
+
if ! spin "Installing engenty wizards (about 650 MB on disk, a minute or two)" \
|
|
496
577
|
env PATH="$NODE_DIR/bin:$PATH" "$NODE_DIR/bin/npm" install --prefix "$stage" \
|
|
497
|
-
--omit=dev --ignore-scripts --legacy-peer-deps --no-audit --no-fund --loglevel=error "$SPEC"
|
|
578
|
+
--omit=dev --ignore-scripts --legacy-peer-deps --no-audit --no-fund --loglevel=error "$SPEC"; then
|
|
579
|
+
rm -rf "$stage"
|
|
580
|
+
failed
|
|
581
|
+
fi
|
|
582
|
+
# npm stopped halfway leaves packages out; only a whole install takes a version's place.
|
|
583
|
+
if ! complete "$stage" >>"$LOG" 2>&1; then
|
|
584
|
+
rm -rf "$stage"
|
|
585
|
+
die "npm did not install everything engenty wizards needs (the log names what is missing). Run the installer again."
|
|
586
|
+
fi
|
|
498
587
|
# The runtime under its name, or under the one it had up to 0.7.4 (`--version 0.7.4`). The
|
|
499
588
|
# package `wizards` of now is only the launcher: no runtime in it.
|
|
500
589
|
if [ -f "$stage/node_modules/$PACKAGE_NAME/package.json" ]; then
|
|
@@ -514,9 +603,17 @@ runtime() {
|
|
|
514
603
|
rm -rf "$dir/node_modules" "$dir/package.json" "$dir/package-lock.json"
|
|
515
604
|
fi
|
|
516
605
|
previous="$(readlink "$dir/current" 2>/dev/null || true)"
|
|
517
|
-
|
|
606
|
+
# The version that is there already steps aside in one move and goes once the new one is in,
|
|
607
|
+
# so the folder holds one whole runtime or the other, never half of one.
|
|
608
|
+
old=""
|
|
609
|
+
if [ -e "$dir/$INSTALLED" ]; then
|
|
610
|
+
old="$(mktemp -d "$dir/.staging-XXXXXX")"
|
|
611
|
+
mv "$dir/$INSTALLED" "$old/"
|
|
612
|
+
fi
|
|
518
613
|
mv "$stage" "$dir/$INSTALLED"
|
|
614
|
+
STAGE=""
|
|
519
615
|
ln -sfn "$INSTALLED" "$dir/current"
|
|
616
|
+
[ -z "$old" ] || rm -rf "$old"
|
|
520
617
|
# For a command written before the version folders (an older bin/wizards or npx wizards).
|
|
521
618
|
ln -sfn "current/node_modules" "$dir/node_modules"
|
|
522
619
|
# This version and the one before stay; older ones go.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wizards",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Make a wish. Get your wizard. It guides you step by step. Let AI do the work. Runs on your machine, on the AI subscription you already have.",
|
|
5
5
|
"license": "FSL-1.1-MIT AND CC-BY-4.0",
|
|
6
6
|
"homepage": "https://engenty.ai",
|