socket-function 0.79.0 → 0.80.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/package.json +1 -1
- package/require/require.ts +38 -13
package/package.json
CHANGED
package/require/require.ts
CHANGED
|
@@ -82,6 +82,10 @@ export function requireMain() {
|
|
|
82
82
|
let startTime = Date.now();
|
|
83
83
|
globalThis.BOOT_TIME = startTime;
|
|
84
84
|
|
|
85
|
+
// Set to the first rootDomain, unless the first import does not have a domain
|
|
86
|
+
let mainRootOrigin = location.origin + location.pathname;
|
|
87
|
+
let isFirstImport = true;
|
|
88
|
+
|
|
85
89
|
(Symbol as any).dispose = Symbol.dispose || Symbol("dispose");
|
|
86
90
|
(Symbol as any).asyncDispose = Symbol.asyncDispose || Symbol("asyncDispose");
|
|
87
91
|
|
|
@@ -203,6 +207,16 @@ export function requireMain() {
|
|
|
203
207
|
|
|
204
208
|
let requireBatch: { [request: string]: (() => void)[] } | undefined;
|
|
205
209
|
function rootRequire(request: string, batch?: boolean): unknown {
|
|
210
|
+
if (isFirstImport) {
|
|
211
|
+
isFirstImport = false;
|
|
212
|
+
if (request.startsWith("https://")) {
|
|
213
|
+
mainRootOrigin = getRootDomain(request);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (!request.startsWith("https://")) {
|
|
217
|
+
request = mainRootOrigin + request;
|
|
218
|
+
}
|
|
219
|
+
|
|
206
220
|
if (!batch) {
|
|
207
221
|
if (request in rootResolveCache) {
|
|
208
222
|
let resolvedRequest = rootResolveCache[request];
|
|
@@ -247,6 +261,21 @@ export function requireMain() {
|
|
|
247
261
|
return rootRequireMultiple([request]).then((x) => x[0].exports);
|
|
248
262
|
}
|
|
249
263
|
}
|
|
264
|
+
|
|
265
|
+
function getRootDomain(request: string) {
|
|
266
|
+
let url = new URL(request);
|
|
267
|
+
let origin = url.origin;
|
|
268
|
+
// Fix stupid :443 erasure (other ports aren't erased, except 80, but we'll never use HTTP,
|
|
269
|
+
// so that's fine).
|
|
270
|
+
{
|
|
271
|
+
let remaining = request.slice(origin.length);
|
|
272
|
+
if (remaining.startsWith(":443/")) {
|
|
273
|
+
origin += ":443";
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return origin + "/";
|
|
277
|
+
}
|
|
278
|
+
|
|
250
279
|
async function rootRequireMultiple(requests: string[]) {
|
|
251
280
|
console.log(`%cimport(${requests.join(", ")}) at ${Date.now() - startTime}ms`, "color: orange");
|
|
252
281
|
|
|
@@ -280,21 +309,12 @@ export function requireMain() {
|
|
|
280
309
|
if (!request.startsWith("https://")) {
|
|
281
310
|
throw new Error(`Mixed domains with non-domain requests is not supported presently. Requests: ${requests.join(" | ")}`);
|
|
282
311
|
}
|
|
283
|
-
let
|
|
284
|
-
let origin = url.origin;
|
|
285
|
-
// Fix stupid :443 erasure (other ports aren't erased, except 80, but we'll never use HTTP,
|
|
286
|
-
// so that's fine).
|
|
287
|
-
{
|
|
288
|
-
let remaining = request.slice(origin.length);
|
|
289
|
-
if (remaining.startsWith(":443/")) {
|
|
290
|
-
origin += ":443";
|
|
291
|
-
}
|
|
292
|
-
}
|
|
312
|
+
let origin = getRootDomain(request);
|
|
293
313
|
if (domainOrigin && domainOrigin !== origin) {
|
|
294
314
|
// TODO: If this happens, we can probably just split the call up into multiple calls?
|
|
295
315
|
throw new Error(`Mixed domains in require call is not supported presently. Requests: ${requests.join(" | ")}`);
|
|
296
316
|
}
|
|
297
|
-
domainOrigin = origin
|
|
317
|
+
domainOrigin = origin;
|
|
298
318
|
// By stripping by length, we can turn https://example.com/./test => "./test"
|
|
299
319
|
// (where as if we used pathname, it would turn into "/test"
|
|
300
320
|
return request.slice(domainOrigin.length);
|
|
@@ -475,7 +495,7 @@ export function requireMain() {
|
|
|
475
495
|
if (!(request in serializedModule.requests)) {
|
|
476
496
|
if (!asyncIsFine && !globalThis.suppressUnexpectedModuleWarning) {
|
|
477
497
|
console.warn(
|
|
478
|
-
`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
|
|
498
|
+
`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. Expected imports: ${Object.keys(serializedModule.requests).join(" | ")}`,
|
|
479
499
|
"color: red",
|
|
480
500
|
"color: unset",
|
|
481
501
|
"color: red",
|
|
@@ -487,6 +507,11 @@ export function requireMain() {
|
|
|
487
507
|
// (This path isn't hit often, as we usually preload, but... sometimes we won't).
|
|
488
508
|
if (request.startsWith(".")) {
|
|
489
509
|
request = moduleFolder + request;
|
|
510
|
+
} else {
|
|
511
|
+
// Still use the same domain
|
|
512
|
+
if (!request.startsWith("https://")) {
|
|
513
|
+
request = getRootDomain(request) + request;
|
|
514
|
+
}
|
|
490
515
|
}
|
|
491
516
|
return rootRequire(request);
|
|
492
517
|
}
|
|
@@ -501,7 +526,7 @@ export function requireMain() {
|
|
|
501
526
|
if (resolvedPath !== "NOTALLOWEDCLIENTSIDE" && !serializedModules[resolvedPath]) {
|
|
502
527
|
if (!asyncIsFine) {
|
|
503
528
|
console.warn(
|
|
504
|
-
`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
|
|
529
|
+
`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. Expected imports: ${Object.keys(serializedModule.requests).join(" | ")}`,
|
|
505
530
|
"color: red",
|
|
506
531
|
"color: unset",
|
|
507
532
|
"color: red",
|