socket-function 0.78.0 → 0.79.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.79.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];
@@ -165,7 +165,7 @@ export function requireMain() {
165
165
  source?: string;
166
166
  }
167
167
  }} */
168
- let serializedModules = Object.create(null);
168
+ let serializedModules: { [id: string]: SerializedModule | undefined } = Object.create(null);
169
169
 
170
170
  type ModuleType = {
171
171
  id: string;
@@ -468,7 +468,7 @@ export function requireMain() {
468
468
  return builtInModuleExports[request as keyof typeof builtInModuleExports];
469
469
  }
470
470
 
471
- let resolvedPath;
471
+ let resolvedPath: string | undefined;
472
472
  if (request in moduleCache) {
473
473
  resolvedPath = request;
474
474
  } else {
@@ -512,7 +512,7 @@ export function requireMain() {
512
512
  }
513
513
 
514
514
  let exportsOverride: unknown | undefined;
515
- if (resolvedPath === "NOTALLOWEDCLIENTSIDE" || !serializedModules[resolvedPath].allowclient) {
515
+ if (resolvedPath === "NOTALLOWEDCLIENTSIDE" || !serializedModules[resolvedPath]?.allowclient) {
516
516
  let childId = resolvedPath === "NOTALLOWEDCLIENTSIDE" ? request : resolvedPath;
517
517
  if (serializedModules[resolvedPath]?.serveronly) {
518
518
  exportsOverride = new Proxy(
@@ -540,8 +540,13 @@ export function requireMain() {
540
540
  if (property === unloadedModule) return true;
541
541
  if (property === "default") return exportsOverride;
542
542
 
543
+ let type = "non-whitelisted";
544
+ if (!serializedModules[resolvedPath!]) {
545
+ type = "missing module";
546
+ }
547
+
543
548
  console.warn(
544
- `Accessed non-whitelisted module %c${childId}%c, specifically property %c${String(
549
+ `Accessed ${type} module %c${childId}%c, specifically property %c${String(
545
550
  property
546
551
  )}%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
552
  }`,
@@ -623,6 +628,16 @@ export function requireMain() {
623
628
  }
624
629
 
625
630
  let serializedModule = serializedModules[resolvedId];
631
+ if (!serializedModule) {
632
+ // I can't figure out why this happens as it seems to happen very rarely and only when I'm debugging other code.
633
+ // - I have had it happen immediately after starting the app. Although in theory a hot reload could have
634
+ // triggered due to VS code writing to a file.
635
+ // - I've had times when it happens once after startup and then it goes away and other times where it
636
+ // happens every single time and never goes away until I restart aipaint.
637
+ // - Maybe it happens if we switch servers and so the root paths are different in some way?
638
+ debugger;
639
+ console.warn(`Failed to find module ${resolvedId}. The server should have given an error about this.`, serializedModules);
640
+ }
626
641
 
627
642
  let module = Object.create(null);
628
643
  moduleCache[resolvedId] = module;
@@ -631,14 +646,14 @@ export function requireMain() {
631
646
  module.exports = {};
632
647
  module.exports.default = module.exports;
633
648
  module.children = [];
634
- for (let key in serializedModule.flags || {}) {
649
+ for (let key in serializedModule?.flags || {}) {
635
650
  if (key === "loaded") continue;
636
651
  module[key] = true;
637
652
  }
638
653
 
639
654
  module.load = load;
640
655
 
641
- let originalSource = serializedModule.source;
656
+ let originalSource = serializedModule?.source || "";
642
657
  let moduleFnc = wrapSafe(module.id, originalSource);
643
658
 
644
659
  globalThis.onProgressHandler?.({
@@ -653,7 +668,8 @@ export function requireMain() {
653
668
  }
654
669
 
655
670
  function load() {
656
- let serializedModule = serializedModules[resolvedId];
671
+ const serializedModule = serializedModules[resolvedId];
672
+ if (!serializedModule) return;
657
673
  if (!module.loaded) {
658
674
  if (alreadyHave) {
659
675
  delete alreadyHave.seqNums[serializedModule.seqNum];