socket-function 0.88.0 → 0.89.0
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/hot/HotReloadController.ts +42 -32
- package/package.json +1 -1
- package/require/require.ts +2 -1
|
@@ -40,6 +40,11 @@ declare global {
|
|
|
40
40
|
* - If not set for any files serverside, we will do nothing (and just leave old code running).
|
|
41
41
|
*/
|
|
42
42
|
hotreload?: boolean;
|
|
43
|
+
/** Overrides hotreload to disable hot reloading. Useful if you add "hotreload.flag" to a directory
|
|
44
|
+
* (which sets hotreload on all files in and under that directory), but want a specific file
|
|
45
|
+
* to not hotreload.
|
|
46
|
+
* - Also useful if you want files to hotreload clientside, but not serverside.
|
|
47
|
+
*/
|
|
43
48
|
noserverhotreload?: boolean;
|
|
44
49
|
}
|
|
45
50
|
}
|
|
@@ -135,42 +140,47 @@ class HotReloadControllerBase {
|
|
|
135
140
|
clientWatcherNodes.add(callerId);
|
|
136
141
|
}
|
|
137
142
|
async fileUpdated(files: string[], changeTime: number) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
console.groupEnd();
|
|
143
|
-
let modules: NodeJS.Module[] = [];
|
|
144
|
-
for (let file of files) {
|
|
145
|
-
let module = require.cache[file];
|
|
146
|
-
if (!module) {
|
|
147
|
-
console.log(`Module not found: ${file}, reloading page to ensure new version is loaded`);
|
|
148
|
-
document.location.reload();
|
|
149
|
-
return;
|
|
143
|
+
try {
|
|
144
|
+
console.groupCollapsed(magenta(`Trigger hotreload for files ${formatTime(Date.now() - changeTime)} after file change`));
|
|
145
|
+
for (let file of files) {
|
|
146
|
+
console.log(file);
|
|
150
147
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
148
|
+
console.groupEnd();
|
|
149
|
+
let modules: NodeJS.Module[] = [];
|
|
150
|
+
for (let file of files) {
|
|
151
|
+
file = location.origin + "/" + file;
|
|
152
|
+
let module = require.cache[file];
|
|
153
|
+
if (!module) {
|
|
154
|
+
console.log(`Module not found: ${file}, reloading page to ensure new version is loaded`);
|
|
155
|
+
document.location.reload();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (!module.hotreload) {
|
|
159
|
+
console.log(`Module not hotreloadable: ${file}, reloading page to ensure new version is loaded`);
|
|
160
|
+
document.location.reload();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
modules.push(module);
|
|
164
|
+
}
|
|
165
|
+
for (let module of modules) {
|
|
166
|
+
module.loaded = false;
|
|
167
|
+
}
|
|
168
|
+
isHotReloadingValue = true;
|
|
169
|
+
try {
|
|
170
|
+
await Promise.all(modules.map(module => module.load(module.filename)));
|
|
171
|
+
} finally {
|
|
172
|
+
setTimeout(() => {
|
|
173
|
+
isHotReloadingValue = false;
|
|
174
|
+
}, 1000);
|
|
155
175
|
}
|
|
156
|
-
modules.push(module);
|
|
157
|
-
}
|
|
158
|
-
for (let module of modules) {
|
|
159
|
-
module.loaded = false;
|
|
160
|
-
}
|
|
161
|
-
isHotReloadingValue = true;
|
|
162
|
-
try {
|
|
163
|
-
await Promise.all(modules.map(module => module.load(module.filename)));
|
|
164
|
-
} finally {
|
|
165
|
-
setTimeout(() => {
|
|
166
|
-
isHotReloadingValue = false;
|
|
167
|
-
}, 1000);
|
|
168
|
-
}
|
|
169
176
|
|
|
170
|
-
|
|
171
|
-
|
|
177
|
+
for (let callback of hotReloadCallbacks) {
|
|
178
|
+
callback(modules);
|
|
179
|
+
}
|
|
180
|
+
console.log(magenta(`Hot reload complete ${formatTime(Date.now() - changeTime)} after file change`));
|
|
181
|
+
} catch (e: any) {
|
|
182
|
+
console.error(`Hot reload failed ${e.stack}`);
|
|
172
183
|
}
|
|
173
|
-
console.log(magenta(`Hot reload complete ${formatTime(Date.now() - changeTime)} after file change`));
|
|
174
184
|
}
|
|
175
185
|
}
|
|
176
186
|
|
package/package.json
CHANGED
package/require/require.ts
CHANGED
|
@@ -240,8 +240,9 @@ export function requireMain() {
|
|
|
240
240
|
}
|
|
241
241
|
if (batch) {
|
|
242
242
|
if (!requireBatch) {
|
|
243
|
+
requireBatch = requireBatch || {};
|
|
243
244
|
setTimeout(() => {
|
|
244
|
-
requireBatch
|
|
245
|
+
if (!requireBatch) throw new Error("Impossible");
|
|
245
246
|
let requests = Object.keys(requireBatch);
|
|
246
247
|
let callbacks = Object.values(requireBatch).reduce((a, b) => a.concat(b), []);
|
|
247
248
|
requireBatch = undefined;
|