socket-function 0.96.0 → 0.98.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.96.0",
3
+ "version": "0.98.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -8,6 +8,7 @@ import zlib from "zlib";
8
8
  import { cacheLimited, lazy } from "../src/caching";
9
9
  import { formatNumber } from "../src/formatting/format";
10
10
  import { requireMain } from "./require";
11
+ import path from "path";
11
12
 
12
13
  const COMPRESS_CACHE_SIZE = 1024 * 1024 * 128;
13
14
 
@@ -136,6 +137,11 @@ class RequireControllerBase {
136
137
  requireCalls?: string[];
137
138
  cacheTime?: number;
138
139
  }) {
140
+ if (!this.rootResolvePath) {
141
+ let dir = path.resolve(".");
142
+ dir = dir.replaceAll("\\", "/");
143
+ this.rootResolvePath = dir;
144
+ }
139
145
  let { requireCalls, cacheTime } = config || {};
140
146
  let result = resolvedHTMLFile();
141
147
  if (beforeEntryText.length > 0) {
@@ -405,8 +411,14 @@ declare global {
405
411
  }
406
412
 
407
413
  let baseController = new RequireControllerBase();
408
- export function setRequireBootRequire(path: string) {
409
- baseController.rootResolvePath = path;
414
+ /** Sets the root directory that imports should be resolved from. Defaults to "." */
415
+ export function setRequireBootRequire(dir: string) {
416
+ dir = path.resolve(dir);
417
+ dir = dir.replaceAll("\\", "/");
418
+ if (!dir.endsWith("/")) {
419
+ dir += "/";
420
+ }
421
+ baseController.rootResolvePath = dir;
410
422
  }
411
423
 
412
424
  export const RequireController = SocketFunction.register(
@@ -84,6 +84,8 @@ export class JSONLACKS {
84
84
  // then it is about 2X slower (although it depends on the size and complexity of the objects!)
85
85
  @measureFnc
86
86
  public static parse<T>(text: string, config?: JSONLACKS_ParseConfig, hydrateState?: HydrateState): T {
87
+ // Empty string should parse to SOMETHING
88
+ if (text.trim() === "") return undefined as T;
87
89
  let obj: unknown;
88
90
 
89
91
  let extendedParsing = config?.extended ?? JSONLACKS.EXTENDED_PARSER;