socket-function 0.88.0 → 0.90.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 +49 -37
- 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
|
}
|
|
@@ -99,11 +104,13 @@ const hotReloadModule = cache((module: NodeJS.Module) => {
|
|
|
99
104
|
callback([module]);
|
|
100
105
|
}
|
|
101
106
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
if (module.allowclient) {
|
|
108
|
+
triggerClientSideReload({
|
|
109
|
+
files: [module.filename],
|
|
110
|
+
changeTime: curr.mtimeMs,
|
|
111
|
+
fast,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
107
114
|
});
|
|
108
115
|
});
|
|
109
116
|
let reloadTriggering = false;
|
|
@@ -135,42 +142,47 @@ class HotReloadControllerBase {
|
|
|
135
142
|
clientWatcherNodes.add(callerId);
|
|
136
143
|
}
|
|
137
144
|
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;
|
|
145
|
+
try {
|
|
146
|
+
console.groupCollapsed(magenta(`Trigger hotreload for files ${formatTime(Date.now() - changeTime)} after file change`));
|
|
147
|
+
for (let file of files) {
|
|
148
|
+
console.log(file);
|
|
150
149
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
console.groupEnd();
|
|
151
|
+
let modules: NodeJS.Module[] = [];
|
|
152
|
+
for (let file of files) {
|
|
153
|
+
file = location.origin + "/" + file;
|
|
154
|
+
let module = require.cache[file];
|
|
155
|
+
if (!module) {
|
|
156
|
+
console.log(`Module not found: ${file}, reloading page to ensure new version is loaded`);
|
|
157
|
+
document.location.reload();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!module.hotreload) {
|
|
161
|
+
console.log(`Module not hotreloadable: ${file}, reloading page to ensure new version is loaded`);
|
|
162
|
+
document.location.reload();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
modules.push(module);
|
|
166
|
+
}
|
|
167
|
+
for (let module of modules) {
|
|
168
|
+
module.loaded = false;
|
|
169
|
+
}
|
|
170
|
+
isHotReloadingValue = true;
|
|
171
|
+
try {
|
|
172
|
+
await Promise.all(modules.map(module => module.load(module.filename)));
|
|
173
|
+
} finally {
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
isHotReloadingValue = false;
|
|
176
|
+
}, 1000);
|
|
155
177
|
}
|
|
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
178
|
|
|
170
|
-
|
|
171
|
-
|
|
179
|
+
for (let callback of hotReloadCallbacks) {
|
|
180
|
+
callback(modules);
|
|
181
|
+
}
|
|
182
|
+
console.log(magenta(`Hot reload complete ${formatTime(Date.now() - changeTime)} after file change`));
|
|
183
|
+
} catch (e: any) {
|
|
184
|
+
console.error(`Hot reload failed ${e.stack}`);
|
|
172
185
|
}
|
|
173
|
-
console.log(magenta(`Hot reload complete ${formatTime(Date.now() - changeTime)} after file change`));
|
|
174
186
|
}
|
|
175
187
|
}
|
|
176
188
|
|
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;
|