sliftutils 1.2.13 → 1.2.14
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 +5 -15
- 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
|
+
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,9 @@ function chromeExtensionContentScriptHotReload() {
|
|
|
107
100
|
|
|
108
101
|
setInterval(() => {
|
|
109
102
|
try {
|
|
110
|
-
chrome.
|
|
111
|
-
if (chrome.runtime.lastError)
|
|
112
|
-
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
let hash: string | undefined = response?.hash;
|
|
103
|
+
chrome.storage.local.get(HOT_RELOAD_HASH_STORAGE_KEY, (result) => {
|
|
104
|
+
if (chrome.runtime.lastError) return;
|
|
105
|
+
let hash: string | undefined = result?.[HOT_RELOAD_HASH_STORAGE_KEY];
|
|
116
106
|
if (!hash) return;
|
|
117
107
|
if (lastHash === undefined) {
|
|
118
108
|
lastHash = hash;
|