sliftutils 1.2.13 → 1.2.15
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/builders/hotReload.ts +6 -13
- package/package.json +1 -1
package/builders/hotReload.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { isInBrowser, isInChromeExtension, isInChromeExtensionBackground, isInCh
|
|
|
3
3
|
|
|
4
4
|
const DEFAULT_WATCH_PORT = 9876;
|
|
5
5
|
const CONTENT_SCRIPT_POLL_INTERVAL_MS = 1000;
|
|
6
|
-
const
|
|
6
|
+
const HOT_RELOAD_HASH_STORAGE_KEY = "sliftHotReloadBuildHash";
|
|
7
7
|
|
|
8
8
|
export async function enableHotReloading(config?: {
|
|
9
9
|
port?: number;
|
|
@@ -79,16 +79,9 @@ function watchPortHotReload(port = DEFAULT_WATCH_PORT, onReload: () => void, onH
|
|
|
79
79
|
function chromeExtensionBackgroundHotReload(port = DEFAULT_WATCH_PORT) {
|
|
80
80
|
let currentHash: string | undefined;
|
|
81
81
|
|
|
82
|
-
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
83
|
-
if (message && message.type === HOT_RELOAD_HASH_MESSAGE) {
|
|
84
|
-
sendResponse({ hash: currentHash });
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
return undefined;
|
|
88
|
-
});
|
|
89
|
-
|
|
90
82
|
watchPortHotReload(port, () => { /* unused — hash callback drives reloads */ }, (hash) => {
|
|
91
83
|
if (!hash) return;
|
|
84
|
+
void chrome.storage.local.set({ [HOT_RELOAD_HASH_STORAGE_KEY]: hash });
|
|
92
85
|
if (currentHash === undefined) {
|
|
93
86
|
currentHash = hash;
|
|
94
87
|
console.log(`[Hot Reload] Initial build hash: ${hash}`);
|
|
@@ -107,12 +100,12 @@ function chromeExtensionContentScriptHotReload() {
|
|
|
107
100
|
|
|
108
101
|
setInterval(() => {
|
|
109
102
|
try {
|
|
110
|
-
chrome.
|
|
103
|
+
chrome.storage.local.get(HOT_RELOAD_HASH_STORAGE_KEY, (result) => {
|
|
111
104
|
if (chrome.runtime.lastError) {
|
|
112
|
-
console.
|
|
105
|
+
console.error("[Hot Reload] storage.get error:", chrome.runtime.lastError.message);
|
|
113
106
|
return;
|
|
114
107
|
}
|
|
115
|
-
let hash: string | undefined =
|
|
108
|
+
let hash: string | undefined = result?.[HOT_RELOAD_HASH_STORAGE_KEY];
|
|
116
109
|
if (!hash) return;
|
|
117
110
|
if (lastHash === undefined) {
|
|
118
111
|
lastHash = hash;
|
|
@@ -125,7 +118,7 @@ function chromeExtensionContentScriptHotReload() {
|
|
|
125
118
|
}
|
|
126
119
|
});
|
|
127
120
|
} catch (error) {
|
|
128
|
-
|
|
121
|
+
console.error("[Hot Reload] poll error:", (error as Error).stack ?? error);
|
|
129
122
|
}
|
|
130
123
|
}, CONTENT_SCRIPT_POLL_INTERVAL_MS);
|
|
131
124
|
}
|