Clone widgets that import a sibling JS module

A cloned bar widget is copied out on its own, so a relative JS import
lands in a directory without the file and the clone fails to load. Point
those imports back at the bundled module, the same way Qt.resolvedUrl()
references were already rewritten.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
David Heinemeier Hansson
2026-07-26 19:16:05 -07:00
co-authored by Claude Opus 5
parent c619865432
commit cc4771fd91
2 changed files with 61 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
#!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
require_command jq
require_command python3
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
mkdir -p "$TMPDIR/home/.config/omarchy"
clone() {
HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" PATH="$ROOT/bin:$PATH" \
omarchy-plugin-clone "$1" "$2" --name "$3"
}
# A bar widget that pulls in a sibling JS module clones into a directory that
# does not contain it, so the import has to be rewritten back to the bundled
# file or the cloned widget fails to load.
clone omarchy.clock local.clock-clone "Cloned Clock" >/dev/null
widget="$TMPDIR/home/.config/omarchy/plugins/local.clock-clone/Widget.qml"
[[ -f $widget ]] || fail "clone produces a widget file"
pass "clone produces a widget file"
grep -q 'moduleName: "local.clock-clone"' "$widget" ||
fail "clone rewrites the module name"
pass "clone rewrites the module name"
while read -r ref; do
[[ $ref == file://* ]] || fail "clone leaves a relative reference behind" "$ref"
done < <(grep -oE '(import|Qt\.resolvedUrl\() *"[^"]+"' "$widget" |
grep -oE '"[^"]+"' | tr -d '"' | grep -E '\.(js|qml)$')
pass "clone resolves every relative QML and JS reference to the bundled file"
for ref in $(grep -oE 'file://[^"]+\.(js|qml)' "$widget"); do
path=${ref#file://}
[[ -f $path ]] || fail "cloned reference points at a real file" "$ref"
done
pass "cloned references point at files that exist"
# The bundled widget genuinely has such an import, so the check above is not
# passing by accident.
grep -qE '^import "[^"/][^"]*\.js"' "$ROOT/shell/plugins/panels/clock/BarWidget.qml" ||
fail "the clock widget still imports a sibling JS module"
pass "the clock widget still imports a sibling JS module"