@absolutejs/absolute 0.20.0-beta.4 → 0.20.0-beta.40

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.
Files changed (109) hide show
  1. package/README.md +200 -0
  2. package/dist/angular/browser.js +15 -1
  3. package/dist/angular/browser.js.map +3 -3
  4. package/dist/angular/components/core/streamingSlotRegistrar.js +1 -1
  5. package/dist/angular/components/core/streamingSlotRegistry.js +2 -2
  6. package/dist/angular/index.js +361 -30
  7. package/dist/angular/index.js.map +9 -6
  8. package/dist/angular/server.js +361 -30
  9. package/dist/angular/server.js.map +9 -6
  10. package/dist/build.js +2093 -1114
  11. package/dist/build.js.map +20 -16
  12. package/dist/cli/config/server.js +4 -0
  13. package/dist/cli/index.js +6235 -1278
  14. package/dist/dev/client/cssUtils.ts +16 -2
  15. package/dist/dev/client/handlers/rebuild.ts +11 -1
  16. package/dist/dev/client/hmrClient.ts +35 -3
  17. package/dist/dev/client/hmrTiming.ts +16 -7
  18. package/dist/dev/client/syncDevtools.ts +237 -0
  19. package/dist/dev/serverBootstrap.js +28 -0
  20. package/dist/index.js +2925 -1670
  21. package/dist/index.js.map +37 -31
  22. package/dist/mobile/browser.js +123 -1
  23. package/dist/mobile/browser.js.map +6 -4
  24. package/dist/mobile/index.js +4185 -294
  25. package/dist/mobile/index.js.map +38 -18
  26. package/dist/mobile/remoteMacAgentEntry.js +14 -14
  27. package/dist/mobile/shellAuth.js +36 -0
  28. package/dist/mobile/shellBootstrap.js +837 -0
  29. package/dist/mobile/shellExpoDevices.js +99 -0
  30. package/dist/mobile/shellSync.js +173 -0
  31. package/dist/react/index.js +5 -1
  32. package/dist/react/index.js.map +3 -3
  33. package/dist/react/server.js +5 -1
  34. package/dist/react/server.js.map +3 -3
  35. package/dist/src/angular/pageHandler.d.ts +3 -0
  36. package/dist/src/build/pwa.d.ts +16 -0
  37. package/dist/src/cli/config/server.d.ts +1 -1
  38. package/dist/src/cli/instanceStatus.d.ts +1 -0
  39. package/dist/src/cli/scripts/dev.d.ts +2 -0
  40. package/dist/src/core/devBuild.d.ts +1 -0
  41. package/dist/src/core/pageHandlers.d.ts +11 -2
  42. package/dist/src/core/prepare.d.ts +376 -0
  43. package/dist/src/dev/clientManager.d.ts +1 -0
  44. package/dist/src/dev/devCert.d.ts +6 -4
  45. package/dist/src/dev/serverEntryCopies.d.ts +3 -0
  46. package/dist/src/mobile/androidEmulatorController.d.ts +14 -2
  47. package/dist/src/mobile/androidRelease.d.ts +6 -0
  48. package/dist/src/mobile/androidTestReport.d.ts +14 -0
  49. package/dist/src/mobile/androidUpgradeConformance.d.ts +47 -0
  50. package/dist/src/mobile/androidWebView.d.ts +1 -0
  51. package/dist/src/mobile/browser.d.ts +1 -0
  52. package/dist/src/mobile/buildPipeline.d.ts +1 -0
  53. package/dist/src/mobile/capacitorBundle.d.ts +22 -1
  54. package/dist/src/mobile/ciWorkflow.d.ts +26 -0
  55. package/dist/src/mobile/client.d.ts +4 -0
  56. package/dist/src/mobile/config.d.ts +4 -1
  57. package/dist/src/mobile/devDeviceAdapter.d.ts +3 -0
  58. package/dist/src/mobile/deviceCapabilities.d.ts +46 -0
  59. package/dist/src/mobile/expoBridge.d.ts +91 -0
  60. package/dist/src/mobile/expoProject.d.ts +16 -0
  61. package/dist/src/mobile/index.d.ts +13 -0
  62. package/dist/src/mobile/iosDeviceAcceptance.d.ts +32 -0
  63. package/dist/src/mobile/iosPhysicalDeviceTransport.d.ts +16 -0
  64. package/dist/src/mobile/iosRelease.d.ts +4 -1
  65. package/dist/src/mobile/iosSimulatorController.d.ts +20 -2
  66. package/dist/src/mobile/iosTestReport.d.ts +24 -0
  67. package/dist/src/mobile/mobileBundleInspection.d.ts +55 -0
  68. package/dist/src/mobile/mobileInspect.d.ts +136 -0
  69. package/dist/src/mobile/mobilePreview.d.ts +174 -0
  70. package/dist/src/mobile/mobilePreviewClient.d.ts +1 -0
  71. package/dist/src/mobile/nativeAuth.d.ts +17 -0
  72. package/dist/src/mobile/nativeBackgroundSync.d.ts +4 -0
  73. package/dist/src/mobile/nativeDeviceCapabilities.d.ts +6 -0
  74. package/dist/src/mobile/nativeTestReport.d.ts +91 -0
  75. package/dist/src/mobile/releaseArtifact.d.ts +2 -0
  76. package/dist/src/mobile/releaseDoctor.d.ts +23 -1
  77. package/dist/src/mobile/remoteMacProtocol.d.ts +11 -0
  78. package/dist/src/mobile/shellAuth.d.ts +15 -0
  79. package/dist/src/mobile/shellBootstrap.d.ts +23 -1
  80. package/dist/src/mobile/shellExpoDevices.d.ts +3 -0
  81. package/dist/src/mobile/shellHttp.d.ts +2 -0
  82. package/dist/src/mobile/shellPush.d.ts +11 -0
  83. package/dist/src/mobile/shellSync.d.ts +47 -0
  84. package/dist/src/mobile/staticDocument.d.ts +5 -0
  85. package/dist/src/mobile/syncRemediation.d.ts +10 -0
  86. package/dist/src/mobile/syncSchema.d.ts +9 -0
  87. package/dist/src/mobile/transport.d.ts +16 -1
  88. package/dist/src/plugins/hmr.d.ts +3 -0
  89. package/dist/src/plugins/imageOptimizer.d.ts +1 -1
  90. package/dist/src/react/hooks/useMediaQuery.d.ts +1 -1
  91. package/dist/src/svelte/pageHandler.d.ts +3 -0
  92. package/dist/src/utils/imageProcessing.d.ts +3 -0
  93. package/dist/src/utils/loadConfig.d.ts +1 -0
  94. package/dist/src/utils/logger.d.ts +1 -0
  95. package/dist/src/utils/startupBanner.d.ts +1 -0
  96. package/dist/src/utils/userAgentFunctions.d.ts +1 -1
  97. package/dist/src/vue/pageHandler.d.ts +3 -0
  98. package/dist/svelte/index.js +316 -23
  99. package/dist/svelte/index.js.map +8 -5
  100. package/dist/svelte/server.js +311 -18
  101. package/dist/svelte/server.js.map +8 -5
  102. package/dist/types/build.d.ts +50 -3
  103. package/dist/types/cli.d.ts +1 -0
  104. package/dist/types/messages.d.ts +1 -1
  105. package/dist/vue/index.js +316 -23
  106. package/dist/vue/index.js.map +8 -5
  107. package/dist/vue/server.js +311 -18
  108. package/dist/vue/server.js.map +8 -5
  109. package/package.json +41 -11
@@ -151,7 +151,8 @@ const findManifestHref = (
151
151
 
152
152
  const replaceStylesheetLink = (
153
153
  existingLink: HTMLLinkElement,
154
- newHref: string
154
+ newHref: string,
155
+ attempt = 0
155
156
  ) => {
156
157
  const replacement = existingLink.cloneNode(true);
157
158
  if (!(replacement instanceof HTMLLinkElement)) {
@@ -167,7 +168,20 @@ const replaceStylesheetLink = (
167
168
  resolve(applied);
168
169
  };
169
170
  replacement.onload = () => finish(true);
170
- replacement.onerror = () => finish(false);
171
+ replacement.onerror = () => {
172
+ if (attempt >= 1) {
173
+ finish(false);
174
+
175
+ return;
176
+ }
177
+ replacement.remove();
178
+ settled = true;
179
+ void replaceStylesheetLink(
180
+ existingLink,
181
+ `${newHref}${newHref.includes('?') ? '&' : '?'}retry=${Date.now()}`,
182
+ attempt + 1
183
+ ).then(resolve);
184
+ };
171
185
  replacement.href = newHref;
172
186
  existingLink.after(replacement);
173
187
  setTimeout(() => {
@@ -7,12 +7,22 @@ import {
7
7
  isRuntimeErrorOverlay,
8
8
  showErrorOverlay
9
9
  } from '../errorOverlay';
10
+ import { detectCurrentFramework } from '../frameworkDetect';
10
11
  import { sendAbsoluteHmrTiming } from '../hmrTiming';
11
12
 
12
13
  export const handleFullReload = (message?: {
13
- data: { serverDuration?: number };
14
+ data: { affectedFrameworks?: string[]; serverDuration?: number };
14
15
  timestamp?: number;
15
16
  }) => {
17
+ const affectedFrameworks = message?.data.affectedFrameworks;
18
+ const currentFramework = detectCurrentFramework();
19
+ if (
20
+ affectedFrameworks?.length &&
21
+ currentFramework &&
22
+ !affectedFrameworks.includes(currentFramework)
23
+ ) {
24
+ return;
25
+ }
16
26
  const clientStart = performance.now();
17
27
  sendAbsoluteHmrTiming({
18
28
  clientStart,
@@ -18,6 +18,8 @@ import {
18
18
  sendAbsoluteHmrTiming
19
19
  } from './hmrTiming';
20
20
  import { hideErrorOverlay, showErrorOverlay } from './errorOverlay';
21
+ import { installAbsoluteNativeSyncDevtools } from './syncDevtools';
22
+ import { installAbsoluteMobilePreview } from '../../mobile/mobilePreviewClient';
21
23
  import {
22
24
  dispatchAngularComponentRemount,
23
25
  dispatchAngularComponentUpdate
@@ -45,6 +47,35 @@ const isStringRecord = (value: unknown): value is Record<string, string> =>
45
47
  Object.values(value).every((entry) => typeof entry === 'string');
46
48
 
47
49
  restoreAbsoluteHmrApply();
50
+ const nativeDeviceAdapterPath = '/__absolute/native-device-adapter.js';
51
+ const hmrClientTarget = absoluteHmrClientTarget();
52
+ if (hmrClientTarget === 'mobile-preview') installAbsoluteMobilePreview();
53
+ const nativeDeviceAdapterReady =
54
+ hmrClientTarget === 'web' || hmrClientTarget === 'mobile-preview'
55
+ ? Promise.resolve()
56
+ : import(nativeDeviceAdapterPath).then(() => undefined);
57
+ Reflect.set(
58
+ globalThis,
59
+ '__ABS_NATIVE_DEVICES_READY__',
60
+ nativeDeviceAdapterReady
61
+ );
62
+ Reflect.set(globalThis, '__ABS_NATIVE_DEVICES_READY_STATE__', 'loading');
63
+ void nativeDeviceAdapterReady.then(
64
+ () => {
65
+ Reflect.set(globalThis, '__ABS_NATIVE_DEVICES_READY_STATE__', 'ready');
66
+ },
67
+ (error) => {
68
+ Reflect.set(globalThis, '__ABS_NATIVE_DEVICES_READY_STATE__', 'failed');
69
+ console.error(
70
+ '[Absolute Mobile] Native device adapter failed to load:',
71
+ error
72
+ );
73
+ }
74
+ );
75
+ const removeNativeSyncDevtools =
76
+ hmrClientTarget === 'web'
77
+ ? () => undefined
78
+ : installAbsoluteNativeSyncDevtools();
48
79
 
49
80
  /* Lightweight "server disconnected" banner. When the dev server is
50
81
  * genuinely down (process restarting or crashed) the browser would
@@ -165,15 +196,15 @@ type HMRMessage = {
165
196
 
166
197
  const handleStylesheetUpdate = (message: HMRMessage) => {
167
198
  const clientStart = performance.now();
168
- void reloadCSSStylesheets(message.data.manifest ?? {}).then((applied) => {
199
+ void reloadCSSStylesheets(message.data.manifest ?? {}).then((applied) =>
169
200
  sendAbsoluteHmrTiming({
170
201
  clientStart,
171
202
  kind: 'css',
172
203
  outcome: applied ? 'applied' : 'failed',
173
204
  serverMs: message.data.serverDuration,
174
205
  updateId: message.timestamp
175
- });
176
- });
206
+ })
207
+ );
177
208
  };
178
209
 
179
210
  const handleHMRMessage = (message: HMRMessage) => {
@@ -413,6 +444,7 @@ if (!(window.__HMR_WS__ && window.__HMR_WS__.readyState === WebSocket.OPEN)) {
413
444
  };
414
445
 
415
446
  window.addEventListener('beforeunload', () => {
447
+ removeNativeSyncDevtools();
416
448
  if (hmrState.isHMRUpdating) {
417
449
  if (hmrState.pingInterval) clearInterval(hmrState.pingInterval);
418
450
  if (hmrState.reconnectTimeout)
@@ -15,6 +15,7 @@ const isHmrTarget = (value: unknown): value is HMRClientTarget =>
15
15
  value === 'capacitor-android' ||
16
16
  value === 'capacitor-ios' ||
17
17
  value === 'capacitor-native' ||
18
+ value === 'mobile-preview' ||
18
19
  value === 'web';
19
20
 
20
21
  const isHmrKind = (value: unknown): value is HMRApplyKind =>
@@ -47,14 +48,14 @@ const getSessionStorage = () => {
47
48
  return storage;
48
49
  };
49
50
 
50
- const persistHmrApply = (timing: HmrApply) => {
51
+ const persistHmrApplies = (timings: HmrApply[]) => {
51
52
  try {
52
53
  const storage = getSessionStorage();
53
54
  const setItem = storage && Reflect.get(storage, 'setItem');
54
55
  if (typeof setItem !== 'function') return;
55
56
  Reflect.apply(setItem, storage, [
56
57
  HMR_APPLY_STORAGE_KEY,
57
- JSON.stringify(timing)
58
+ JSON.stringify(timings)
58
59
  ]);
59
60
  } catch {
60
61
  // Storage may be unavailable in sandboxed or privacy-restricted documents.
@@ -69,6 +70,7 @@ export const absoluteHmrClientTarget = () => {
69
70
  const marker = new URLSearchParams(search).get('__absolute_target');
70
71
  if (marker === 'capacitor-android') return marker;
71
72
  if (marker === 'capacitor-ios') return marker;
73
+ if (marker === 'mobile-preview') return marker;
72
74
  }
73
75
  }
74
76
  const capacitor = Reflect.get(globalThis, 'Capacitor');
@@ -100,10 +102,17 @@ export const restoreAbsoluteHmrApply = () => {
100
102
  HMR_APPLY_STORAGE_KEY
101
103
  ]);
102
104
  if (typeof serialized !== 'string') return;
103
- const timing: unknown = JSON.parse(serialized);
104
- if (!isHmrApply(timing)) return;
105
- window.__ABS_HMR_LAST_APPLY__ = timing;
106
- window.__ABS_HMR_APPLIES__ = [timing];
105
+ const stored: unknown = JSON.parse(serialized);
106
+ let timings: HmrApply[] = [];
107
+ if (Array.isArray(stored)) {
108
+ timings = stored
109
+ .filter(isHmrApply)
110
+ .slice(-MAX_RETAINED_HMR_APPLIES);
111
+ } else if (isHmrApply(stored)) timings = [stored];
112
+ const last = timings.at(-1);
113
+ if (!last) return;
114
+ window.__ABS_HMR_LAST_APPLY__ = last;
115
+ window.__ABS_HMR_APPLIES__ = timings;
107
116
  } catch {
108
117
  // A malformed or inaccessible entry should never affect HMR startup.
109
118
  }
@@ -135,7 +144,7 @@ export const sendAbsoluteHmrTiming = (options: SendHmrTimingOptions) => {
135
144
  if (applies.length > MAX_RETAINED_HMR_APPLIES) {
136
145
  applies.splice(0, applies.length - MAX_RETAINED_HMR_APPLIES);
137
146
  }
138
- persistHmrApply(timing);
147
+ persistHmrApplies(applies);
139
148
  if (!window.__HMR_WS__) return;
140
149
  window.__HMR_WS__.send(JSON.stringify({ ...timing, type: 'hmr-timing' }));
141
150
  };
@@ -0,0 +1,237 @@
1
+ import type {} from '../../types/globals';
2
+ import {
3
+ discardSyncRuntimeDeadLetter,
4
+ inspectSyncRuntime,
5
+ rebaseSyncRuntimeDeadLetter,
6
+ retrySyncRuntimeDeadLetter,
7
+ type SyncRuntimeInspection
8
+ } from '@absolutejs/sync/client/runtime';
9
+
10
+ export type SyncDevtoolsBridge = {
11
+ discard: (operationId: string) => Promise<void>;
12
+ inspect: () => Promise<SyncRuntimeInspection>;
13
+ rebase: (operationId: string, args: unknown) => Promise<string>;
14
+ retry: (operationId: string) => Promise<void>;
15
+ };
16
+
17
+ const DEVTOOLS_ID = 'absolutejs-sync-devtools';
18
+ const REFRESH_INTERVAL_MS = 1_500;
19
+ const bridge: SyncDevtoolsBridge = {
20
+ discard: discardSyncRuntimeDeadLetter,
21
+ inspect: inspectSyncRuntime,
22
+ rebase: rebaseSyncRuntimeDeadLetter,
23
+ retry: retrySyncRuntimeDeadLetter
24
+ };
25
+
26
+ const time = (value: number | undefined) =>
27
+ value === undefined ? '—' : new Date(value).toLocaleTimeString();
28
+
29
+ const styles = `
30
+ :host { all: initial; color-scheme: light dark; }
31
+ button { font: inherit; }
32
+ .trigger { position:fixed;right:max(12px,env(safe-area-inset-right));bottom:max(12px,env(safe-area-inset-bottom));z-index:2147483645;border:0;border-radius:999px;padding:9px 13px;background:#111827;color:#fff;box-shadow:0 4px 18px #0006;font:600 12px/1.2 ui-monospace,SFMono-Regular,Menlo,monospace; }
33
+ .trigger[data-alert=true] { background:#b91c1c; }
34
+ .panel { position:fixed;inset:max(12px,env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) max(56px,env(safe-area-inset-bottom)) auto;z-index:2147483645;width:min(420px,calc(100vw - 24px));max-height:calc(100vh - 80px);overflow:auto;border:1px solid #64748b66;border-radius:14px;background:#fffffff2;color:#111827;box-shadow:0 16px 48px #0008;font:12px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace;backdrop-filter:blur(12px); }
35
+ [hidden] { display:none!important; }
36
+ header { position:sticky;top:0;display:flex;align-items:center;justify-content:space-between;padding:12px 14px;border-bottom:1px solid #64748b44;background:inherit; }
37
+ h2 { margin:0;font-size:14px; }
38
+ .close,.action { border:1px solid #64748b66;border-radius:7px;background:transparent;color:inherit;padding:5px 8px; }
39
+ .body { padding:12px 14px; }
40
+ .metrics { display:grid;grid-template-columns:repeat(2,1fr);gap:7px;margin-bottom:12px; }
41
+ .metric { padding:8px;border-radius:8px;background:#64748b18; }
42
+ .metric strong { display:block;font-size:16px; }
43
+ .empty { color:#64748b; }
44
+ .letter { margin-top:9px;padding:10px;border:1px solid #ef444466;border-radius:9px;overflow-wrap:anywhere; }
45
+ .letter strong { display:block; }
46
+ .meta { color:#64748b;margin:4px 0 8px; }
47
+ .actions { display:flex;flex-wrap:wrap;gap:6px; }
48
+ .danger { color:#b91c1c; }
49
+ .notice { margin-bottom:9px;padding:8px;border-radius:7px;background:#f59e0b22; }
50
+ @media (prefers-color-scheme:dark) { .panel { background:#111827f2;color:#f8fafc; } .empty,.meta { color:#94a3b8; } .danger { color:#fca5a5; } }
51
+ `;
52
+
53
+ const renderInspection = (
54
+ body: HTMLElement,
55
+ inspection: SyncRuntimeInspection,
56
+ notice?: string
57
+ ) => {
58
+ body.replaceChildren();
59
+ if (notice) {
60
+ const message = document.createElement('div');
61
+ message.className = 'notice';
62
+ message.textContent = notice;
63
+ body.appendChild(message);
64
+ }
65
+ const metrics = document.createElement('div');
66
+ metrics.className = 'metrics';
67
+ for (const [label, value] of [
68
+ ['Pending', inspection.pending],
69
+ ['Dead letters', inspection.deadLetters.length],
70
+ ['Conflicts', inspection.conflicts],
71
+ ['Auto-resolved', inspection.automaticResolutions]
72
+ ] as const) {
73
+ const metric = document.createElement('div');
74
+ metric.className = 'metric';
75
+ const strong = document.createElement('strong');
76
+ strong.textContent = String(value);
77
+ metric.append(strong, label);
78
+ metrics.appendChild(metric);
79
+ }
80
+ body.appendChild(metrics);
81
+ const activity = document.createElement('div');
82
+ activity.className = 'meta';
83
+ activity.textContent = `Clients ${inspection.clients} · last push ${time(inspection.lastSuccessfulPushAt)} · last pull ${time(inspection.lastSuccessfulPullAt)}`;
84
+ body.appendChild(activity);
85
+ if (inspection.deadLetters.length === 0) {
86
+ const empty = document.createElement('div');
87
+ empty.className = 'empty';
88
+ empty.textContent = 'No mutations need manual remediation.';
89
+ body.appendChild(empty);
90
+
91
+ return;
92
+ }
93
+ for (const deadLetter of inspection.deadLetters) {
94
+ const item = document.createElement('section');
95
+ item.className = 'letter';
96
+ const title = document.createElement('strong');
97
+ title.textContent = deadLetter.name;
98
+ const metadata = document.createElement('div');
99
+ metadata.className = 'meta';
100
+ metadata.textContent = `${deadLetter.kind ?? 'rejected'}${deadLetter.code ? ` · ${deadLetter.code}` : ''} · attempts ${deadLetter.attempts} · ${time(deadLetter.deadLetteredAt)}`;
101
+ const detail = document.createElement('div');
102
+ detail.textContent =
103
+ deadLetter.message ?? 'The server rejected this mutation.';
104
+ const actions = document.createElement('div');
105
+ actions.className = 'actions';
106
+ for (const [action, label] of [
107
+ ['retry', 'Retry unchanged'],
108
+ ['rebase', 'Rebase with new args'],
109
+ ['discard', 'Discard']
110
+ ] as const) {
111
+ const button = document.createElement('button');
112
+ button.className = `action${action === 'discard' ? ' danger' : ''}`;
113
+ button.dataset.action = action;
114
+ button.dataset.operationId = deadLetter.operationId;
115
+ button.textContent = label;
116
+ actions.appendChild(button);
117
+ }
118
+ item.append(title, metadata, detail, actions);
119
+ body.appendChild(item);
120
+ }
121
+ };
122
+
123
+ /** Install the development-only, framework-neutral native Sync panel. */
124
+ export const installAbsoluteNativeSyncDevtools = (
125
+ devtoolsBridge: SyncDevtoolsBridge = bridge
126
+ ) => {
127
+ if (typeof document === 'undefined' || !document.body)
128
+ return () => undefined;
129
+ if (document.getElementById(DEVTOOLS_ID)) return () => undefined;
130
+ const host = document.createElement('aside');
131
+ host.id = DEVTOOLS_ID;
132
+ host.dataset.hmrOverlay = 'true';
133
+ const root = host.attachShadow({ mode: 'open' });
134
+ const style = document.createElement('style');
135
+ style.textContent = styles;
136
+ const trigger = document.createElement('button');
137
+ trigger.className = 'trigger';
138
+ trigger.textContent = 'Sync';
139
+ trigger.type = 'button';
140
+ const panel = document.createElement('section');
141
+ panel.className = 'panel';
142
+ panel.hidden = true;
143
+ const header = document.createElement('header');
144
+ const title = document.createElement('h2');
145
+ title.textContent = 'AbsoluteJS Sync';
146
+ const close = document.createElement('button');
147
+ close.className = 'close';
148
+ close.textContent = 'Close';
149
+ close.type = 'button';
150
+ header.append(title, close);
151
+ const body = document.createElement('div');
152
+ body.className = 'body';
153
+ panel.append(header, body);
154
+ root.append(style, trigger, panel);
155
+ document.body.appendChild(host);
156
+ let active = true;
157
+ let notice: string | undefined;
158
+ const refresh = async () => {
159
+ try {
160
+ const inspection = await devtoolsBridge.inspect();
161
+ if (!active) return;
162
+ trigger.dataset.alert = String(inspection.deadLetters.length > 0);
163
+ trigger.textContent = inspection.deadLetters.length
164
+ ? `Sync · ${inspection.deadLetters.length}`
165
+ : 'Sync';
166
+ if (!panel.hidden) renderInspection(body, inspection, notice);
167
+ notice = undefined;
168
+ } catch {
169
+ if (!active || panel.hidden) return;
170
+ notice = 'Sync diagnostics are temporarily unavailable.';
171
+ }
172
+ };
173
+ trigger.addEventListener('click', () => {
174
+ panel.hidden = !panel.hidden;
175
+ if (!panel.hidden) void refresh();
176
+ });
177
+ close.addEventListener('click', () => {
178
+ panel.hidden = true;
179
+ });
180
+ const remediate = async (
181
+ action: string | undefined,
182
+ operationId: string
183
+ ) => {
184
+ try {
185
+ if (action === 'retry') await devtoolsBridge.retry(operationId);
186
+ else if (action === 'discard') {
187
+ if (
188
+ !globalThis.confirm(
189
+ 'Discard this local mutation permanently?'
190
+ )
191
+ )
192
+ return;
193
+ await devtoolsBridge.discard(operationId);
194
+ } else if (action === 'rebase') {
195
+ const serialized = globalThis.prompt(
196
+ 'New mutation arguments as JSON. This creates a new operation intent:'
197
+ );
198
+ if (serialized === null) return;
199
+ let args: unknown;
200
+ try {
201
+ args = JSON.parse(serialized);
202
+ } catch {
203
+ notice = 'Rebase cancelled: arguments were not valid JSON.';
204
+ await refresh();
205
+
206
+ return;
207
+ }
208
+ if (
209
+ !globalThis.confirm(
210
+ 'Create a new mutation with these arguments?'
211
+ )
212
+ )
213
+ return;
214
+ await devtoolsBridge.rebase(operationId, args);
215
+ }
216
+ notice = 'Sync remediation applied.';
217
+ } catch {
218
+ notice =
219
+ 'Sync remediation failed. The local mutation was retained.';
220
+ }
221
+ await refresh();
222
+ };
223
+ body.addEventListener('click', (event) => {
224
+ if (!(event.target instanceof HTMLButtonElement)) return;
225
+ const { action, operationId } = event.target.dataset;
226
+ if (!operationId) return;
227
+ void remediate(action, operationId);
228
+ });
229
+ const interval = setInterval(() => void refresh(), REFRESH_INTERVAL_MS);
230
+ void refresh();
231
+
232
+ return () => {
233
+ active = false;
234
+ clearInterval(interval);
235
+ host.remove();
236
+ };
237
+ };
@@ -2,6 +2,32 @@
2
2
  // src/dev/serverBootstrap.ts
3
3
  import { copyFileSync, existsSync, readdirSync, unlinkSync } from "fs";
4
4
  import { dirname, extname, join, resolve } from "path";
5
+
6
+ // src/dev/serverEntryCopies.ts
7
+ var ENTRY_COPY_OWNER_PATTERN = /^\.absolutejs-hmr-(\d+)-(?:bootstrap-)?\d+\.[^.]+$/;
8
+ var absoluteServerEntryCopyOwnerPid = (name) => {
9
+ const match = ENTRY_COPY_OWNER_PATTERN.exec(name);
10
+ if (!match)
11
+ return null;
12
+ const pid = Number(match[1]);
13
+ return Number.isSafeInteger(pid) && pid > 0 ? pid : null;
14
+ };
15
+ var isProcessAlive = (pid) => {
16
+ try {
17
+ process.kill(pid, 0);
18
+ return true;
19
+ } catch (error) {
20
+ return !(error instanceof Error && ("code" in error) && error.code === "ESRCH");
21
+ }
22
+ };
23
+ var isStaleAbsoluteServerEntryCopy = (name, currentPid = process.pid, ownerIsAlive = isProcessAlive) => {
24
+ const ownerPid = absoluteServerEntryCopyOwnerPid(name);
25
+ if (ownerPid === null)
26
+ return false;
27
+ return ownerPid === currentPid || !ownerIsAlive(ownerPid);
28
+ };
29
+
30
+ // src/dev/serverBootstrap.ts
5
31
  var originalEntry = process.env.ABSOLUTE_SERVER_ENTRY;
6
32
  if (!originalEntry) {
7
33
  throw new Error("ABSOLUTE_SERVER_ENTRY is required by the AbsoluteJS dev bootstrap");
@@ -24,6 +50,8 @@ if (!isHotReevaluation) {
24
50
  if (!name.startsWith(copyPrefix) || !name.endsWith(entryExtension)) {
25
51
  continue;
26
52
  }
53
+ if (!isStaleAbsoluteServerEntryCopy(name))
54
+ continue;
27
55
  removeEntryCopy(join(entryDir, name));
28
56
  }
29
57
  }