socket-function 0.12.5 → 0.12.7
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/package.json +2 -2
- package/require/RequireController.ts +8 -0
- package/require/require.js +22 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "socket-function",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.7",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"node-forge": "https://github.com/sliftist/forge#name",
|
|
14
14
|
"pako": "^2.1.0",
|
|
15
15
|
"preact": "^10.10.6",
|
|
16
|
-
"typenode": "^5.3.
|
|
16
|
+
"typenode": "^5.3.12",
|
|
17
17
|
"ws": "^8.8.0"
|
|
18
18
|
},
|
|
19
19
|
"optionalDependencies": {
|
|
@@ -31,11 +31,16 @@ declare global {
|
|
|
31
31
|
// And... maybe it is useful in other cases?
|
|
32
32
|
/** Used internally by RequireController */
|
|
33
33
|
requireControllerSeqNum?: number;
|
|
34
|
+
|
|
35
|
+
// Times are both unique (two modules evaluated at the same Date.now() will have different values).
|
|
36
|
+
evalStartTime?: number;
|
|
37
|
+
evalEndTime?: number;
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
interface Window {
|
|
37
41
|
clientsideBootTime: number;
|
|
38
42
|
}
|
|
43
|
+
var suppressUnexpectedModuleWarning: boolean;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
export interface SerializedModule {
|
|
@@ -108,6 +113,9 @@ class RequireControllerBase {
|
|
|
108
113
|
}
|
|
109
114
|
if (requireCalls) {
|
|
110
115
|
async function requireAll(calls: string[]) {
|
|
116
|
+
// NOTE: awaiting isn't just for better and consistent load order, it also greatly improves load efficiency,
|
|
117
|
+
// as parallel calls can't know what files will be loaded, so there is a lot of duplicate loading. Loading
|
|
118
|
+
// 1 at a time allows require to efficiently require only files that previous imports haven't loaded.
|
|
111
119
|
for (let call of calls) {
|
|
112
120
|
try {
|
|
113
121
|
await require(call);
|
package/require/require.js
CHANGED
|
@@ -49,6 +49,17 @@
|
|
|
49
49
|
};
|
|
50
50
|
global.builtInModuleExports = builtInModuleExports;
|
|
51
51
|
|
|
52
|
+
let lastTime = 0;
|
|
53
|
+
function nextTime() {
|
|
54
|
+
let time = Date.now();
|
|
55
|
+
if (time <= lastTime) {
|
|
56
|
+
// NOTE: We SHOULD really add epsilon, but... this is a lot easier, and is close enough,
|
|
57
|
+
// as times will never have too large of a magnitude.
|
|
58
|
+
time = lastTime + 0.01;
|
|
59
|
+
}
|
|
60
|
+
lastTime = time;
|
|
61
|
+
return time;
|
|
62
|
+
}
|
|
52
63
|
|
|
53
64
|
/** @type {{
|
|
54
65
|
[resolvePath: string]: {
|
|
@@ -233,6 +244,7 @@
|
|
|
233
244
|
// TODO: Maybe do a request, making this async, if it isn't found?
|
|
234
245
|
return serializedModule.requests[request];
|
|
235
246
|
};
|
|
247
|
+
let moduleFolder = module.filename.replace(/\\/g, "/").split("/").slice(0, -1).join("/") + "/";
|
|
236
248
|
return require;
|
|
237
249
|
function require(request, asyncIsFine) {
|
|
238
250
|
if (asyncIsFineOuter) {
|
|
@@ -250,12 +262,18 @@
|
|
|
250
262
|
resolvedPath = request;
|
|
251
263
|
} else {
|
|
252
264
|
if (!(request in serializedModule.requests)) {
|
|
253
|
-
if (!asyncIsFine) {
|
|
265
|
+
if (!asyncIsFine && !globalThis.suppressUnexpectedModuleWarning) {
|
|
254
266
|
console.warn(`Accessed unexpected module %c${request}%c in %c${module.id}%c\n\tTreating it as an async require.\n\tAll modules require synchronously clientside must be required serverside at a module level.`,
|
|
255
267
|
"color: red", "color: unset",
|
|
256
268
|
"color: red", "color: unset",
|
|
257
269
|
);
|
|
258
270
|
}
|
|
271
|
+
// NOTE: We should still namespace it to the current folder (if it is a relative path),
|
|
272
|
+
// otherwise relative async imports won't work!
|
|
273
|
+
// (This path isn't hit often, as we usually preload, but... sometimes we won't).
|
|
274
|
+
if (request.startsWith(".")) {
|
|
275
|
+
request = moduleFolder + request;
|
|
276
|
+
}
|
|
259
277
|
return rootRequire(request);
|
|
260
278
|
}
|
|
261
279
|
|
|
@@ -421,6 +439,8 @@
|
|
|
421
439
|
currentModuleEvaluationStack.push(module.filename);
|
|
422
440
|
try {
|
|
423
441
|
module.isPreloading = true;
|
|
442
|
+
module.evalStartTime = nextTime();
|
|
443
|
+
module.evalEndTime = undefined;
|
|
424
444
|
moduleFnc.call(
|
|
425
445
|
{
|
|
426
446
|
// NOTE: Adding __importStar to the module causes typescript to use our implementation,
|
|
@@ -440,6 +460,7 @@
|
|
|
440
460
|
dirname,
|
|
441
461
|
importDynamic
|
|
442
462
|
);
|
|
463
|
+
module.evalEndTime = nextTime();
|
|
443
464
|
time = Date.now() - time;
|
|
444
465
|
// NOTE: This log statment is disabled as I believe it causes lag (when devtools is open).
|
|
445
466
|
// As in, adding about 500ms to our load time, which is annoying when debugging.
|