socket-function 0.81.0 → 0.82.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/require/require.ts +31 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.81.0",
3
+ "version": "0.82.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -370,6 +370,7 @@ export function requireMain() {
370
370
 
371
371
 
372
372
  if (Object.keys(modules).length === 1 && "" in modules) {
373
+ debugger;
373
374
  eval(modules[""].source || "");
374
375
  throw new Error(`Failed to find modules for ${originalRequests.join(", ")} (mapped to ${requests.join(", ")})`);
375
376
  }
@@ -473,10 +474,31 @@ export function requireMain() {
473
474
 
474
475
  function createRequire(module: ModuleType, serializedModule: SerializedModule, asyncIsFineOuter?: boolean) {
475
476
  require.cache = moduleCache;
476
- require.resolve = function (request: string) {
477
- // TODO: Maybe do a request, making this async, if it isn't found?
478
- return serializedModule.requests[request];
479
- };
477
+ function resolve(request: string) {
478
+ let requests = serializedModule.requests;
479
+ if (request in requests) {
480
+ return requests[request];
481
+ }
482
+ let absolutePath = request;
483
+ if (absolutePath.startsWith("./") || absolutePath.startsWith("../")) {
484
+ let folderParts = moduleFolder.split("/");
485
+ while (absolutePath.startsWith("./") || absolutePath.startsWith("../")) {
486
+ if (absolutePath.startsWith("./")) {
487
+ absolutePath = absolutePath.slice("./".length);
488
+ } else {
489
+ folderParts.pop();
490
+ absolutePath = absolutePath.slice("../".length);
491
+ }
492
+ }
493
+ absolutePath = folderParts.join("/") + "/" + absolutePath;
494
+ }
495
+ // Still use the same domain
496
+ if (!absolutePath.startsWith("https://")) {
497
+ absolutePath = mainRootOrigin + absolutePath;
498
+ }
499
+ return absolutePath;
500
+ }
501
+ require.resolve = resolve;
480
502
  let moduleFolder = module.filename.replace(/\\/g, "/").split("/").slice(0, -1).join("/") + "/";
481
503
  return require;
482
504
  function require(request: string, asyncIsFine?: boolean) {
@@ -493,9 +515,13 @@ export function requireMain() {
493
515
  return builtInModuleExports[request as keyof typeof builtInModuleExports];
494
516
  }
495
517
 
518
+ let absolutePath = resolve(request);
519
+
496
520
  let resolvedPath: string | undefined;
497
521
  if (request in moduleCache) {
498
522
  resolvedPath = request;
523
+ } else if (absolutePath in moduleCache) {
524
+ resolvedPath = absolutePath;
499
525
  } else {
500
526
  if (!(request in serializedModule.requests)) {
501
527
  if (!asyncIsFine && !globalThis.suppressUnexpectedModuleWarning) {
@@ -507,18 +533,7 @@ export function requireMain() {
507
533
  "color: unset"
508
534
  );
509
535
  }
510
- // NOTE: We should still namespace it to the current folder (if it is a relative path),
511
- // otherwise relative async imports won't work!
512
- // (This path isn't hit often, as we usually preload, but... sometimes we won't).
513
- if (request.startsWith(".")) {
514
- request = moduleFolder + request;
515
- } else {
516
- // Still use the same domain
517
- if (!request.startsWith("https://")) {
518
- request = getRootDomain(request) + request;
519
- }
520
- }
521
- return rootRequire(request);
536
+ return rootRequire(absolutePath);
522
537
  }
523
538
 
524
539
  // Built in modules that we haven't been implemented