Skip to content

Commit d9bc145

Browse files
committed
Update hyperclayjs
1 parent cbcdd40 commit d9bc145

4 files changed

Lines changed: 125 additions & 23 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @jest-environment jsdom
3+
*
4+
* The loader's only wire into the readiness contract is `exportModule?.markReady?.()`.
5+
* Both calls are optional-chained, so a rename on either side, or a dropped call,
6+
* yields a loader that loads every module correctly, never settles hyperclay.ready,
7+
* never fires hyperclay:ready, and leaves the rest of the suite green. The symptom
8+
* then surfaces in a vendored plugin that silently stops binding, which is the bug
9+
* the readiness contract exists to remove. So pin the linkage rather than the name.
10+
*
11+
* src/hyperclay.js is generated from build/hyperclay.template.js and the generator
12+
* copies this region verbatim, so asserting both files also catches a template edit
13+
* that was never regenerated.
14+
*/
15+
16+
import fs from 'fs';
17+
import path from 'path';
18+
19+
const SOURCES = [
20+
['generated loader', 'src/hyperclay.js'],
21+
['loader template', 'build/hyperclay.template.js']
22+
];
23+
24+
const read = relative => fs.readFileSync(path.join(__dirname, '..', relative), 'utf8');
25+
26+
const calledNames = source =>
27+
[...source.matchAll(/exportModule\?\.(\w+)\?\.\(/g)].map(match => match[1]);
28+
29+
const loadExportToWindow = async () => {
30+
let mod;
31+
await jest.isolateModulesAsync(async () => {
32+
mod = await import('../src/core/exportToWindow.js');
33+
});
34+
return mod;
35+
};
36+
37+
describe('the loader is wired to the readiness contract', () => {
38+
afterEach(() => {
39+
delete window.__hyperclayNoAutoExport;
40+
delete window.hyperclay;
41+
delete window.h;
42+
});
43+
44+
test.each(SOURCES)('%s settles the contract on both the success and failure path', (_label, relative) => {
45+
const names = calledNames(read(relative));
46+
expect(names).toContain('markReady');
47+
expect(names).toContain('markFailed');
48+
});
49+
50+
test.each(SOURCES)('every capability %s calls is really exported by exportToWindow.js', async (_label, relative) => {
51+
const exportModule = await loadExportToWindow();
52+
const names = calledNames(read(relative));
53+
54+
expect(names.length).toBeGreaterThan(0);
55+
for (const name of names) {
56+
expect(typeof exportModule[name]).toBe('function');
57+
}
58+
});
59+
});

‎scripts/purge-cdn-cache.sh‎

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
# `npm publish --dry-run` still runs the publish/postpublish lifecycle scripts —
5+
# npm's publish.js guards only the upload with `if (!dryRun)`. Without this guard
6+
# every release purged jsdelivr twice: once during the pre-publish dry run, when
7+
# the new version did not exist on the registry yet so the wait loop below could
8+
# not possibly succeed, and once for real. The dry-run pass purged the @latest
9+
# alias while it still resolved to the PREVIOUS version, which makes jsdelivr
10+
# re-fetch and re-cache the old build under @latest.
11+
if [ "${npm_config_dry_run:-}" = "true" ]; then
12+
echo "npm publish --dry-run — skipping CDN purge"
13+
exit 0
14+
fi
15+
416
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || true)
517

618
if [ -z "$PREV_TAG" ]; then
@@ -24,18 +36,29 @@ echo "$FILES" | sed 's/^/ /'
2436
echo ""
2537

2638
echo "Waiting for npm registry to serve $CURRENT_VERSION as @latest..."
39+
LATEST=""
40+
REGISTRY_READY=0
2741
for i in $(seq 1 24); do
2842
LATEST=$(curl -fsS "https://registry.npmjs.org/hyperclayjs/latest" 2>/dev/null | node -p "JSON.parse(require('fs').readFileSync(0,'utf8')).version" 2>/dev/null || echo "")
2943
if [ "$LATEST" = "$CURRENT_VERSION" ]; then
3044
echo " npm registry updated after ~$((i * 5))s"
45+
REGISTRY_READY=1
3146
break
3247
fi
33-
if [ "$i" -eq 24 ]; then
34-
echo " Warning: npm still shows $LATEST after 120s, purging anyway"
35-
fi
3648
sleep 5
3749
done
3850

51+
# Purging while the registry still answers with the old version is worse than
52+
# not purging: jsdelivr re-resolves @latest, gets the old version back, and
53+
# caches that fresh. Leaving the existing cache to expire is the safer failure.
54+
if [ "$REGISTRY_READY" -eq 0 ]; then
55+
echo ""
56+
echo "WARNING: npm still shows ${LATEST:-unknown} after 120s — NOT purging."
57+
echo "Purging now would re-cache the old build under @latest, which production loads."
58+
echo "Re-run once the registry has caught up: bash scripts/purge-cdn-cache.sh"
59+
exit 0
60+
fi
61+
3962
# jsdelivr purge API tolerates ~60 requests/min; purge sequentially at 1/s,
4063
# back off on 429 (5s, 10s, 20s), log a hard failure and move on after 3 tries.
4164
FAILED=0
@@ -83,3 +106,23 @@ if [ "$FAILED" -gt 0 ]; then
83106
echo "WARNING: $FAILED purge(s) failed — stale files may persist on the CDN for up to 7 days."
84107
echo "Purge manually: curl https://purge.jsdelivr.net/npm/hyperclayjs@latest/<path>"
85108
fi
109+
110+
# A 2xx from the purge API only means the request was accepted. Production loads
111+
# hyperclayjs from the unpinned @latest, so confirm the alias actually moved.
112+
echo ""
113+
printf "Verifying jsdelivr @latest now serves %s... " "$CURRENT_VERSION"
114+
SERVED=""
115+
for i in $(seq 1 12); do
116+
SERVED=$(curl -fsS "https://cdn.jsdelivr.net/npm/hyperclayjs@latest/package.json" 2>/dev/null | node -p "JSON.parse(require('fs').readFileSync(0,'utf8')).version" 2>/dev/null || echo "")
117+
[ "$SERVED" = "$CURRENT_VERSION" ] && break
118+
sleep 5
119+
done
120+
121+
if [ "$SERVED" = "$CURRENT_VERSION" ]; then
122+
echo "✓"
123+
else
124+
echo "✗"
125+
echo "WARNING: jsdelivr @latest still serves ${SERVED:-unknown}, expected $CURRENT_VERSION."
126+
echo "Production loads hyperclayjs from @latest, so it may still be running the old build."
127+
echo "Re-run: bash scripts/purge-cdn-cache.sh"
128+
fi

0 commit comments

Comments
 (0)