socket-function 0.78.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.78.0",
3
+ "version": "0.80.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -243,9 +243,10 @@ class RequireControllerBase {
243
243
  asyncRequests: module.asyncRequires || {},
244
244
  flags: {},
245
245
  };
246
+ let flags = modules[module.filename].flags!;
246
247
  for (let [flag, value] of Object.entries(module)) {
247
248
  if (value === true) {
248
- modules[module.filename].flags![flag] = value;
249
+ flags[flag] = value;
249
250
  }
250
251
  }
251
252
  let moduleObj = modules[module.filename];
@@ -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
 
@@ -165,7 +169,7 @@ export function requireMain() {
165
169
  source?: string;
166
170
  }
167
171
  }} */
168
- let serializedModules = Object.create(null);
172
+ let serializedModules: { [id: string]: SerializedModule | undefined } = Object.create(null);
169
173
 
170
174
  type ModuleType = {
171
175
  id: string;
@@ -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 url = new URL(request);
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);
@@ -468,14 +488,14 @@ export function requireMain() {
468
488
  return builtInModuleExports[request as keyof typeof builtInModuleExports];
469
489
  }
470
490
 
471
- let resolvedPath;
491
+ let resolvedPath: string | undefined;
472
492
  if (request in moduleCache) {
473
493
  resolvedPath = request;
474
494
  } else {
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",
@@ -512,7 +537,7 @@ export function requireMain() {
512
537
  }
513
538
 
514
539
  let exportsOverride: unknown | undefined;
515
- if (resolvedPath === "NOTALLOWEDCLIENTSIDE" || !serializedModules[resolvedPath].allowclient) {
540
+ if (resolvedPath === "NOTALLOWEDCLIENTSIDE" || !serializedModules[resolvedPath]?.allowclient) {
516
541
  let childId = resolvedPath === "NOTALLOWEDCLIENTSIDE" ? request : resolvedPath;
517
542
  if (serializedModules[resolvedPath]?.serveronly) {
518
543
  exportsOverride = new Proxy(
@@ -540,8 +565,13 @@ export function requireMain() {
540
565
  if (property === unloadedModule) return true;
541
566
  if (property === "default") return exportsOverride;
542
567
 
568
+ let type = "non-whitelisted";
569
+ if (!serializedModules[resolvedPath!]) {
570
+ type = "missing module";
571
+ }
572
+
543
573
  console.warn(
544
- `Accessed non-whitelisted module %c${childId}%c, specifically property %c${String(
574
+ `Accessed ${type} module %c${childId}%c, specifically property %c${String(
545
575
  property
546
576
  )}%c.\n\tAdd %cmodule.allowclient = true%c to the file to allow access.\n\t(IF it is a 3rd party library, use the global "setFlag" helper (in the file you imported the module) to set properties on other modules (it can even recursively set properties)).\n\n\tFrom ${module.id
547
577
  }`,
@@ -623,6 +653,16 @@ export function requireMain() {
623
653
  }
624
654
 
625
655
  let serializedModule = serializedModules[resolvedId];
656
+ if (!serializedModule) {
657
+ // I can't figure out why this happens as it seems to happen very rarely and only when I'm debugging other code.
658
+ // - I have had it happen immediately after starting the app. Although in theory a hot reload could have
659
+ // triggered due to VS code writing to a file.
660
+ // - I've had times when it happens once after startup and then it goes away and other times where it
661
+ // happens every single time and never goes away until I restart aipaint.
662
+ // - Maybe it happens if we switch servers and so the root paths are different in some way?
663
+ debugger;
664
+ console.warn(`Failed to find module ${resolvedId}. The server should have given an error about this.`, serializedModules);
665
+ }
626
666
 
627
667
  let module = Object.create(null);
628
668
  moduleCache[resolvedId] = module;
@@ -631,14 +671,14 @@ export function requireMain() {
631
671
  module.exports = {};
632
672
  module.exports.default = module.exports;
633
673
  module.children = [];
634
- for (let key in serializedModule.flags || {}) {
674
+ for (let key in serializedModule?.flags || {}) {
635
675
  if (key === "loaded") continue;
636
676
  module[key] = true;
637
677
  }
638
678
 
639
679
  module.load = load;
640
680
 
641
- let originalSource = serializedModule.source;
681
+ let originalSource = serializedModule?.source || "";
642
682
  let moduleFnc = wrapSafe(module.id, originalSource);
643
683
 
644
684
  globalThis.onProgressHandler?.({
@@ -653,7 +693,8 @@ export function requireMain() {
653
693
  }
654
694
 
655
695
  function load() {
656
- let serializedModule = serializedModules[resolvedId];
696
+ const serializedModule = serializedModules[resolvedId];
697
+ if (!serializedModule) return;
657
698
  if (!module.loaded) {
658
699
  if (alreadyHave) {
659
700
  delete alreadyHave.seqNums[serializedModule.seqNum];