Prompt step by step for the missing base image, ISO, npm deps and Chromium

Offer to build the base QCOW2, download the ISO, run npm ci and install
Chromium (from the npmmirror mirror by default). Let Playwright locate its
own Chromium so macOS works.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
guofangandClaude Sonnet 5.5 committed 2026-11-02 20:53:50 +08:00
1 parent b37d1e002c
commit 1476b4a3de
3 files changed
+77 -13

No files matched your search

+52 -2
View File
@@ -156,6 +156,36 @@ The Windows ISO is found automatically in install-iso/ by matching
EOF
}
# Ask a yes/no question on the terminal; fails when there is none or the answer
# is not yes. stdout carries the printed path, so all dialogue goes to /dev/tty.
ask_yes_no() {
local answer
{ : </dev/tty >/dev/tty; } 2>/dev/null || return 1
printf '%s [y/N] ' "$1" >/dev/tty
read -r answer </dev/tty || return 1
[[ "$answer" == [yY] || "$answer" == [yY][eE][sS] ]]
}
# Print the base QCOW2 path. When the image does not exist and a terminal is
# attached, offer to run build-windows-base.sh, which in turn offers to download
# the ISO. The builder sets VM_IMAGE_NO_PROMPT so its own lookups never ask.
windows_base_path() {
local qcow2 builder="${images_dir}/build-windows-base.sh"
if qcow2="$(windows_qcow2_path 2>/dev/null)" && [[ -f "$qcow2" ]]; then
printf '%s\n' "$qcow2"
return 0
fi
windows_qcow2_path >/dev/null || true
if [[ -z "${VM_IMAGE_NO_PROMPT:-}" && -x "$builder" ]] && ask_yes_no "Build the Windows 11 base image now with build-windows-base.sh?"; then
# stdout carries the path, so the build's output goes to the terminal.
"$builder" >/dev/tty 2>&1 </dev/tty || return 1
windows_qcow2_path
return
fi
# Name the expected path if the ISO fixes it; the caller reports it missing.
windows_qcow2_path 2>/dev/null
}
print_image_path() {
local target="$1"
local media="${2:-qcow2}"
@@ -171,7 +201,7 @@ print_image_path() {
if [[ "$media" == iso ]]; then
windows_iso_path
else
windows_qcow2_path
windows_base_path
fi
;;
*)
@@ -416,7 +446,27 @@ download_windows_iso() {
printf 'Error: node is required to get the Windows 11 ISO URL.\n' >&2
exit 1
fi
url="$(node "${images_dir}/nodejs/get-windows-iso-url.js" --arch "$windows_arch")"
if [[ ! -d "${images_dir}/nodejs/node_modules/playwright-core" ]]; then
printf 'Error: the Node.js dependencies are not installed (npm ci has not been run in %s/nodejs).\n' \
"$images_dir" >&2
command -v npm >/dev/null 2>&1 || { printf 'Error: npm is required; install Node.js with npm.\n' >&2; exit 1; }
ask_yes_no "Run npm ci in ${images_dir}/nodejs now?" || exit 1
(cd "${images_dir}/nodejs" && npm ci) || exit 1
fi
local status=0
url="$(node "${images_dir}/nodejs/get-windows-iso-url.js" --arch "$windows_arch")" || status=$?
if ((status == 2)) && [[ -z "${CHROME_PATH:-}" ]]; then
# Exit status 2 means Chromium was not found (the script has said so).
ask_yes_no "Install Chromium with playwright-core now?" || exit 1
# Default to the npmmirror mirror (the official CDN is slow in China); set
# PLAYWRIGHT_DOWNLOAD_HOST to override it.
(cd "${images_dir}/nodejs" \
&& PLAYWRIGHT_DOWNLOAD_HOST="${PLAYWRIGHT_DOWNLOAD_HOST:-https://cdn.npmmirror.com/binaries/playwright}" \
npx playwright-core install chromium) || exit 1
url="$(node "${images_dir}/nodejs/get-windows-iso-url.js" --arch "$windows_arch")" || exit 1
elif ((status != 0)); then
exit "$status"
fi
[[ -n "$url" ]] || { printf 'Error: no Windows 11 ISO URL.\n' >&2; exit 1; }
name="${url%%\?*}"
name="${name##*/}"