socket-function 0.79.0 → 0.81.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 +43 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.79.0",
3
+ "version": "0.81.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -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,21 @@ export function requireMain() {
203
207
 
204
208
  let requireBatch: { [request: string]: (() => void)[] } | undefined;
205
209
  function rootRequire(request: string, batch?: boolean): unknown {
210
+ if (request.includes("file://")) {
211
+ // How does this happen? It definitely breaks things, and we could remove the file://, but... how
212
+ // does it even happen?
213
+ debugger;
214
+ }
215
+ if (isFirstImport) {
216
+ isFirstImport = false;
217
+ if (request.startsWith("https://")) {
218
+ mainRootOrigin = getRootDomain(request);
219
+ }
220
+ }
221
+ if (!request.startsWith("https://")) {
222
+ request = mainRootOrigin + request;
223
+ }
224
+
206
225
  if (!batch) {
207
226
  if (request in rootResolveCache) {
208
227
  let resolvedRequest = rootResolveCache[request];
@@ -247,6 +266,21 @@ export function requireMain() {
247
266
  return rootRequireMultiple([request]).then((x) => x[0].exports);
248
267
  }
249
268
  }
269
+
270
+ function getRootDomain(request: string) {
271
+ let url = new URL(request);
272
+ let origin = url.origin;
273
+ // Fix stupid :443 erasure (other ports aren't erased, except 80, but we'll never use HTTP,
274
+ // so that's fine).
275
+ {
276
+ let remaining = request.slice(origin.length);
277
+ if (remaining.startsWith(":443/")) {
278
+ origin += ":443";
279
+ }
280
+ }
281
+ return origin + "/";
282
+ }
283
+
250
284
  async function rootRequireMultiple(requests: string[]) {
251
285
  console.log(`%cimport(${requests.join(", ")}) at ${Date.now() - startTime}ms`, "color: orange");
252
286
 
@@ -280,21 +314,12 @@ export function requireMain() {
280
314
  if (!request.startsWith("https://")) {
281
315
  throw new Error(`Mixed domains with non-domain requests is not supported presently. Requests: ${requests.join(" | ")}`);
282
316
  }
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
- }
317
+ let origin = getRootDomain(request);
293
318
  if (domainOrigin && domainOrigin !== origin) {
294
319
  // TODO: If this happens, we can probably just split the call up into multiple calls?
295
320
  throw new Error(`Mixed domains in require call is not supported presently. Requests: ${requests.join(" | ")}`);
296
321
  }
297
- domainOrigin = origin + "/";
322
+ domainOrigin = origin;
298
323
  // By stripping by length, we can turn https://example.com/./test => "./test"
299
324
  // (where as if we used pathname, it would turn into "/test"
300
325
  return request.slice(domainOrigin.length);
@@ -475,7 +500,7 @@ export function requireMain() {
475
500
  if (!(request in serializedModule.requests)) {
476
501
  if (!asyncIsFine && !globalThis.suppressUnexpectedModuleWarning) {
477
502
  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.`,
503
+ `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
504
  "color: red",
480
505
  "color: unset",
481
506
  "color: red",
@@ -487,6 +512,11 @@ export function requireMain() {
487
512
  // (This path isn't hit often, as we usually preload, but... sometimes we won't).
488
513
  if (request.startsWith(".")) {
489
514
  request = moduleFolder + request;
515
+ } else {
516
+ // Still use the same domain
517
+ if (!request.startsWith("https://")) {
518
+ request = getRootDomain(request) + request;
519
+ }
490
520
  }
491
521
  return rootRequire(request);
492
522
  }
@@ -501,7 +531,7 @@ export function requireMain() {
501
531
  if (resolvedPath !== "NOTALLOWEDCLIENTSIDE" && !serializedModules[resolvedPath]) {
502
532
  if (!asyncIsFine) {
503
533
  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.`,
534
+ `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
535
  "color: red",
506
536
  "color: unset",
507
537
  "color: red",