@ai-ecoverse/slicc-jsh 0.3.8 → 0.3.9

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/dist/jsh.mjs CHANGED
@@ -1536,10 +1536,191 @@ ${e3}`;
1536
1536
  }
1537
1537
  });
1538
1538
 
1539
+ // src/runtime/path.mjs
1540
+ function normalizeArray(parts, allowAboveRoot) {
1541
+ const res = [];
1542
+ for (const part of parts) {
1543
+ if (part === "" || part === ".") continue;
1544
+ if (part === "..") {
1545
+ if (res.length > 0 && res[res.length - 1] !== "..") res.pop();
1546
+ else if (allowAboveRoot) res.push("..");
1547
+ } else {
1548
+ res.push(part);
1549
+ }
1550
+ }
1551
+ return res;
1552
+ }
1553
+ function normalize(path) {
1554
+ if (path.length === 0) return ".";
1555
+ const isAbsolute = path.charCodeAt(0) === 47;
1556
+ const trailingSep = path.charCodeAt(path.length - 1) === 47;
1557
+ let out = normalizeArray(path.split("/"), !isAbsolute).join("/");
1558
+ if (out.length === 0 && !isAbsolute) out = ".";
1559
+ if (out.length > 0 && trailingSep) out += "/";
1560
+ return (isAbsolute ? "/" : "") + out;
1561
+ }
1562
+ function join(...parts) {
1563
+ const joined = parts.filter((p) => typeof p === "string" && p.length > 0).join("/");
1564
+ if (joined.length === 0) return ".";
1565
+ return normalize(joined);
1566
+ }
1567
+ function dirname(path) {
1568
+ if (path.length === 0) return ".";
1569
+ const hasRoot = path.charCodeAt(0) === 47;
1570
+ let end = -1;
1571
+ let matchedSlash = true;
1572
+ for (let i2 = path.length - 1; i2 >= 1; i2--) {
1573
+ if (path.charCodeAt(i2) === 47) {
1574
+ if (!matchedSlash) {
1575
+ end = i2;
1576
+ break;
1577
+ }
1578
+ } else {
1579
+ matchedSlash = false;
1580
+ }
1581
+ }
1582
+ if (end === -1) return hasRoot ? "/" : ".";
1583
+ return path.slice(0, end);
1584
+ }
1585
+ function basename(path, ext) {
1586
+ let start = 0;
1587
+ let end = -1;
1588
+ let matchedSlash = true;
1589
+ for (let i2 = path.length - 1; i2 >= 0; i2--) {
1590
+ if (path.charCodeAt(i2) === 47) {
1591
+ if (!matchedSlash) {
1592
+ start = i2 + 1;
1593
+ break;
1594
+ }
1595
+ } else if (end === -1) {
1596
+ matchedSlash = false;
1597
+ end = i2 + 1;
1598
+ }
1599
+ }
1600
+ const base = end === -1 ? "" : path.slice(start, end);
1601
+ if (ext && base.endsWith(ext) && base !== ext) return base.slice(0, base.length - ext.length);
1602
+ return base;
1603
+ }
1604
+ function extname(path) {
1605
+ const base = basename(path);
1606
+ const dot = base.lastIndexOf(".");
1607
+ if (dot <= 0) return "";
1608
+ return base.slice(dot);
1609
+ }
1610
+ function resolve(getCwd, parts) {
1611
+ let resolved = "";
1612
+ let isAbsolute = false;
1613
+ for (let i2 = parts.length - 1; i2 >= -1 && !isAbsolute; i2--) {
1614
+ const part = i2 >= 0 ? parts[i2] : getCwd();
1615
+ if (typeof part !== "string" || part.length === 0) continue;
1616
+ resolved = resolved.length > 0 ? `${part}/${resolved}` : part;
1617
+ isAbsolute = part.charCodeAt(0) === 47;
1618
+ }
1619
+ const normalized = normalizeArray(resolved.split("/"), !isAbsolute).join("/");
1620
+ if (isAbsolute) return normalized.length > 0 ? `/${normalized}` : "/";
1621
+ return normalized.length > 0 ? normalized : ".";
1622
+ }
1623
+ function parse(path) {
1624
+ const ret = { root: "", dir: "", base: "", ext: "", name: "" };
1625
+ if (path.length === 0) return ret;
1626
+ const isAbsolute = path.charCodeAt(0) === 47;
1627
+ if (isAbsolute) ret.root = "/";
1628
+ ret.dir = dirname(path);
1629
+ ret.base = basename(path);
1630
+ ret.ext = extname(path);
1631
+ ret.name = ret.ext ? ret.base.slice(0, ret.base.length - ret.ext.length) : ret.base;
1632
+ if (ret.dir === "." && !isAbsolute) ret.dir = "";
1633
+ return ret;
1634
+ }
1635
+ function format(pathObject) {
1636
+ if (typeof pathObject === "string") return pathObject;
1637
+ const dir = pathObject.dir || pathObject.root || "";
1638
+ const base = pathObject.base || `${pathObject.name || ""}${pathObject.ext || ""}`;
1639
+ if (!dir) return base;
1640
+ if (dir === "/") return `/${base}`;
1641
+ return `${dir}/${base}`;
1642
+ }
1643
+ function createPath(getCwd = () => "/") {
1644
+ const api = {
1645
+ sep: "/",
1646
+ delimiter: ":",
1647
+ basename,
1648
+ dirname,
1649
+ extname,
1650
+ parse,
1651
+ format,
1652
+ isAbsolute: (path) => path.length > 0 && path.charCodeAt(0) === 47,
1653
+ join,
1654
+ normalize,
1655
+ resolve: (...parts) => resolve(getCwd, parts),
1656
+ relative(from, to) {
1657
+ const fromAbs = resolve(getCwd, [from]);
1658
+ const toAbs = resolve(getCwd, [to]);
1659
+ if (fromAbs === toAbs) return "";
1660
+ const fromParts = fromAbs.split("/").filter(Boolean);
1661
+ const toParts = toAbs.split("/").filter(Boolean);
1662
+ let i2 = 0;
1663
+ while (i2 < fromParts.length && i2 < toParts.length && fromParts[i2] === toParts[i2]) i2++;
1664
+ return [...fromParts.slice(i2).map(() => ".."), ...toParts.slice(i2)].join("/");
1665
+ }
1666
+ };
1667
+ api.posix = api;
1668
+ return api;
1669
+ }
1670
+
1671
+ // src/runtime/realpath.mjs
1672
+ var MAX_LINKS = 40;
1673
+ function realpathWith(fs, path, p, fail) {
1674
+ let resolved = path.resolve(String(p));
1675
+ const knownHard = /* @__PURE__ */ new Set();
1676
+ let hops = 0;
1677
+ let current2 = "/";
1678
+ let pos = 1;
1679
+ const call = (fn, syscall, at2) => {
1680
+ try {
1681
+ return fn();
1682
+ } catch (err) {
1683
+ throw fail(err?.code || "ENOENT", syscall, at2, err);
1684
+ }
1685
+ };
1686
+ while (pos < resolved.length) {
1687
+ const next = resolved.indexOf("/", pos);
1688
+ const part = next === -1 ? resolved.slice(pos) : resolved.slice(pos, next);
1689
+ pos = next === -1 ? resolved.length : next + 1;
1690
+ if (!part) continue;
1691
+ const previous = current2;
1692
+ const base = current2 === "/" ? `/${part}` : `${current2}/${part}`;
1693
+ current2 = base;
1694
+ if (knownHard.has(base)) continue;
1695
+ const st = call(() => fs.lstat(base), "lstat", base);
1696
+ if (!st.isSymbolicLink) {
1697
+ knownHard.add(base);
1698
+ continue;
1699
+ }
1700
+ if (++hops > MAX_LINKS) throw fail("ELOOP", "stat", base);
1701
+ call(() => fs.stat(base), "stat", base);
1702
+ const target = call(() => fs.readlink(base), "readlink", base);
1703
+ resolved = path.resolve(previous, target, resolved.slice(pos));
1704
+ current2 = "/";
1705
+ pos = 1;
1706
+ }
1707
+ return resolved;
1708
+ }
1709
+ function realMainPath(ctx, filePath, execArgv = []) {
1710
+ if (execArgv.includes("--preserve-symlinks-main")) return filePath;
1711
+ const fs = ctx?.sync?.fs;
1712
+ if (typeof fs?.lstat !== "function" || typeof fs?.readlink !== "function") return filePath;
1713
+ try {
1714
+ return realpathWith(fs, createPath(() => ctx.cwd), filePath, (code) => Object.assign(new Error(code), { code }));
1715
+ } catch {
1716
+ return filePath;
1717
+ }
1718
+ }
1719
+
1539
1720
  // package.json
1540
1721
  var package_default = {
1541
1722
  name: "@ai-ecoverse/slicc-jsh",
1542
- version: "0.3.8",
1723
+ version: "0.3.9",
1543
1724
  description: "Node.js-compatible runtime for slicc-kernel: the node and jsh commands (abi: js)",
1544
1725
  type: "module",
1545
1726
  license: "Apache-2.0",
@@ -2377,8 +2558,9 @@ function compiler(rt) {
2377
2558
  return (...args) => fn(...args.slice(0, JSH_PARAMS.length), importFrom);
2378
2559
  };
2379
2560
  }
2380
- async function runKernelJsh(ctx, rt, filename) {
2561
+ async function runKernelJsh(ctx, rt, givenFilename) {
2381
2562
  const { process: process2, console: console2 } = rt;
2563
+ const filename = realMainPath(ctx, givenFilename);
2382
2564
  let stdoutIsTTY = false;
2383
2565
  try {
2384
2566
  stdoutIsTTY = !!await rt.track(Promise.resolve(ctx.isatty?.(1)));
@@ -3543,7 +3725,7 @@ var {
3543
3725
  // identicalSequenceRange,
3544
3726
  inspect,
3545
3727
  // inspectDefaultOptions,
3546
- format,
3728
+ format: format2,
3547
3729
  formatWithOptions,
3548
3730
  // getStringWidth,
3549
3731
  stripVTControlCharacters,
@@ -3634,7 +3816,7 @@ function createUtil() {
3634
3816
  inspect3.defaultOptions = inspect.defaultOptions ?? { depth: 2, colors: false };
3635
3817
  return {
3636
3818
  inspect: inspect3,
3637
- format,
3819
+ format: format2,
3638
3820
  formatWithOptions,
3639
3821
  promisify,
3640
3822
  types,
@@ -4157,7 +4339,7 @@ var Parser = function Parser2(options, input, startPos) {
4157
4339
  this.privateNameStack = [];
4158
4340
  };
4159
4341
  var prototypeAccessors = { inFunction: { configurable: true }, inGenerator: { configurable: true }, inAsync: { configurable: true }, canAwait: { configurable: true }, allowReturn: { configurable: true }, allowSuper: { configurable: true }, allowDirectSuper: { configurable: true }, treatFunctionsAsVar: { configurable: true }, allowNewDotTarget: { configurable: true }, allowUsing: { configurable: true }, inClassStaticBlock: { configurable: true } };
4160
- Parser.prototype.parse = function parse() {
4342
+ Parser.prototype.parse = function parse2() {
4161
4343
  var this$1$1 = this;
4162
4344
  var node = this.options.program || this.startNode();
4163
4345
  this.nextToken();
@@ -4240,7 +4422,7 @@ Parser.extend = function extend() {
4240
4422
  }
4241
4423
  return cls;
4242
4424
  };
4243
- Parser.parse = function parse2(input, options) {
4425
+ Parser.parse = function parse3(input, options) {
4244
4426
  return new this(options, input).parse();
4245
4427
  };
4246
4428
  Parser.parseExpressionAt = function parseExpressionAt(input, pos, options) {
@@ -9381,7 +9563,7 @@ Parser.acorn = {
9381
9563
  lineBreakG,
9382
9564
  nonASCIIwhitespace
9383
9565
  };
9384
- function parse3(input, options) {
9566
+ function parse4(input, options) {
9385
9567
  return Parser.parse(input, options);
9386
9568
  }
9387
9569
 
@@ -9423,7 +9605,7 @@ function transformEsm(source, filename) {
9423
9605
  const body = stripHashbang(source);
9424
9606
  let ast;
9425
9607
  try {
9426
- ast = parse3(body, {
9608
+ ast = parse4(body, {
9427
9609
  ecmaVersion: "latest",
9428
9610
  sourceType: "module",
9429
9611
  allowAwaitOutsideFunction: true
@@ -9884,7 +10066,7 @@ function rewriteDynamicImports(source) {
9884
10066
  const body = stripHashbang(source);
9885
10067
  let ast;
9886
10068
  try {
9887
- ast = parse3(body, {
10069
+ ast = parse4(body, {
9888
10070
  ecmaVersion: "latest",
9889
10071
  sourceType: "script",
9890
10072
  allowAwaitOutsideFunction: false
@@ -9914,7 +10096,7 @@ function rewriteDynamicImports(source) {
9914
10096
  function shouldRunAsEsm(source) {
9915
10097
  const body = stripHashbang(source);
9916
10098
  try {
9917
- parse3(body, {
10099
+ parse4(body, {
9918
10100
  ecmaVersion: "latest",
9919
10101
  sourceType: "script",
9920
10102
  allowAwaitOutsideFunction: false
@@ -9923,7 +10105,7 @@ function shouldRunAsEsm(source) {
9923
10105
  } catch {
9924
10106
  }
9925
10107
  try {
9926
- parse3(body, {
10108
+ parse4(body, {
9927
10109
  ecmaVersion: "latest",
9928
10110
  sourceType: "module",
9929
10111
  allowAwaitOutsideFunction: true
@@ -9934,138 +10116,6 @@ function shouldRunAsEsm(source) {
9934
10116
  }
9935
10117
  }
9936
10118
 
9937
- // src/runtime/path.mjs
9938
- function normalizeArray(parts, allowAboveRoot) {
9939
- const res = [];
9940
- for (const part of parts) {
9941
- if (part === "" || part === ".") continue;
9942
- if (part === "..") {
9943
- if (res.length > 0 && res[res.length - 1] !== "..") res.pop();
9944
- else if (allowAboveRoot) res.push("..");
9945
- } else {
9946
- res.push(part);
9947
- }
9948
- }
9949
- return res;
9950
- }
9951
- function normalize(path) {
9952
- if (path.length === 0) return ".";
9953
- const isAbsolute = path.charCodeAt(0) === 47;
9954
- const trailingSep = path.charCodeAt(path.length - 1) === 47;
9955
- let out = normalizeArray(path.split("/"), !isAbsolute).join("/");
9956
- if (out.length === 0 && !isAbsolute) out = ".";
9957
- if (out.length > 0 && trailingSep) out += "/";
9958
- return (isAbsolute ? "/" : "") + out;
9959
- }
9960
- function join(...parts) {
9961
- const joined = parts.filter((p) => typeof p === "string" && p.length > 0).join("/");
9962
- if (joined.length === 0) return ".";
9963
- return normalize(joined);
9964
- }
9965
- function dirname(path) {
9966
- if (path.length === 0) return ".";
9967
- const hasRoot = path.charCodeAt(0) === 47;
9968
- let end = -1;
9969
- let matchedSlash = true;
9970
- for (let i2 = path.length - 1; i2 >= 1; i2--) {
9971
- if (path.charCodeAt(i2) === 47) {
9972
- if (!matchedSlash) {
9973
- end = i2;
9974
- break;
9975
- }
9976
- } else {
9977
- matchedSlash = false;
9978
- }
9979
- }
9980
- if (end === -1) return hasRoot ? "/" : ".";
9981
- return path.slice(0, end);
9982
- }
9983
- function basename(path, ext) {
9984
- let start = 0;
9985
- let end = -1;
9986
- let matchedSlash = true;
9987
- for (let i2 = path.length - 1; i2 >= 0; i2--) {
9988
- if (path.charCodeAt(i2) === 47) {
9989
- if (!matchedSlash) {
9990
- start = i2 + 1;
9991
- break;
9992
- }
9993
- } else if (end === -1) {
9994
- matchedSlash = false;
9995
- end = i2 + 1;
9996
- }
9997
- }
9998
- const base = end === -1 ? "" : path.slice(start, end);
9999
- if (ext && base.endsWith(ext) && base !== ext) return base.slice(0, base.length - ext.length);
10000
- return base;
10001
- }
10002
- function extname(path) {
10003
- const base = basename(path);
10004
- const dot = base.lastIndexOf(".");
10005
- if (dot <= 0) return "";
10006
- return base.slice(dot);
10007
- }
10008
- function resolve(getCwd, parts) {
10009
- let resolved = "";
10010
- let isAbsolute = false;
10011
- for (let i2 = parts.length - 1; i2 >= -1 && !isAbsolute; i2--) {
10012
- const part = i2 >= 0 ? parts[i2] : getCwd();
10013
- if (typeof part !== "string" || part.length === 0) continue;
10014
- resolved = resolved.length > 0 ? `${part}/${resolved}` : part;
10015
- isAbsolute = part.charCodeAt(0) === 47;
10016
- }
10017
- const normalized = normalizeArray(resolved.split("/"), !isAbsolute).join("/");
10018
- if (isAbsolute) return normalized.length > 0 ? `/${normalized}` : "/";
10019
- return normalized.length > 0 ? normalized : ".";
10020
- }
10021
- function parse4(path) {
10022
- const ret = { root: "", dir: "", base: "", ext: "", name: "" };
10023
- if (path.length === 0) return ret;
10024
- const isAbsolute = path.charCodeAt(0) === 47;
10025
- if (isAbsolute) ret.root = "/";
10026
- ret.dir = dirname(path);
10027
- ret.base = basename(path);
10028
- ret.ext = extname(path);
10029
- ret.name = ret.ext ? ret.base.slice(0, ret.base.length - ret.ext.length) : ret.base;
10030
- if (ret.dir === "." && !isAbsolute) ret.dir = "";
10031
- return ret;
10032
- }
10033
- function format2(pathObject) {
10034
- if (typeof pathObject === "string") return pathObject;
10035
- const dir = pathObject.dir || pathObject.root || "";
10036
- const base = pathObject.base || `${pathObject.name || ""}${pathObject.ext || ""}`;
10037
- if (!dir) return base;
10038
- if (dir === "/") return `/${base}`;
10039
- return `${dir}/${base}`;
10040
- }
10041
- function createPath(getCwd = () => "/") {
10042
- const api = {
10043
- sep: "/",
10044
- delimiter: ":",
10045
- basename,
10046
- dirname,
10047
- extname,
10048
- parse: parse4,
10049
- format: format2,
10050
- isAbsolute: (path) => path.length > 0 && path.charCodeAt(0) === 47,
10051
- join,
10052
- normalize,
10053
- resolve: (...parts) => resolve(getCwd, parts),
10054
- relative(from, to) {
10055
- const fromAbs = resolve(getCwd, [from]);
10056
- const toAbs = resolve(getCwd, [to]);
10057
- if (fromAbs === toAbs) return "";
10058
- const fromParts = fromAbs.split("/").filter(Boolean);
10059
- const toParts = toAbs.split("/").filter(Boolean);
10060
- let i2 = 0;
10061
- while (i2 < fromParts.length && i2 < toParts.length && fromParts[i2] === toParts[i2]) i2++;
10062
- return [...fromParts.slice(i2).map(() => ".."), ...toParts.slice(i2)].join("/");
10063
- }
10064
- };
10065
- api.posix = api;
10066
- return api;
10067
- }
10068
-
10069
10119
  // src/runtime/builtins/assert.mjs
10070
10120
  var inspect2 = (v) => inspect(v, { compact: false, breakLength: 80, sorted: true });
10071
10121
  var AssertionError = class extends Error {
@@ -11371,36 +11421,7 @@ function createCp({ path, ops, abs, fsError, copyFileSync, mkdirpSync }) {
11371
11421
  const unlink = (p) => call(() => ops.unlink(abs(p)), "unlink", p);
11372
11422
  const readdir = (p) => call(() => ops.readdir(abs(p)), "scandir", p);
11373
11423
  const exists = (p) => !!tryCall(() => ops.stat(abs(p)));
11374
- const MAX_LINKS = 40;
11375
- function realpathSync(p) {
11376
- let resolved = path.resolve(String(p));
11377
- const knownHard = /* @__PURE__ */ new Set();
11378
- let hops = 0;
11379
- let current2 = "/";
11380
- let pos = 1;
11381
- while (pos < resolved.length) {
11382
- const next = resolved.indexOf("/", pos);
11383
- const part = next === -1 ? resolved.slice(pos) : resolved.slice(pos, next);
11384
- pos = next === -1 ? resolved.length : next + 1;
11385
- if (!part) continue;
11386
- const previous = current2;
11387
- const base = current2 === "/" ? `/${part}` : `${current2}/${part}`;
11388
- current2 = base;
11389
- if (knownHard.has(base)) continue;
11390
- const st = call(() => ops.lstat(base), "lstat", base);
11391
- if (!st.isSymbolicLink) {
11392
- knownHard.add(base);
11393
- continue;
11394
- }
11395
- if (++hops > MAX_LINKS) throw fsError("ELOOP", "stat", base);
11396
- call(() => ops.stat(base), "stat", base);
11397
- const target = call(() => ops.readlink(base), "readlink", base);
11398
- resolved = path.resolve(previous, target, resolved.slice(pos));
11399
- current2 = "/";
11400
- pos = 1;
11401
- }
11402
- return resolved;
11403
- }
11424
+ const realpathSync = (p) => realpathWith(ops, path, p, (code, syscall, at2, err) => fsError(code, syscall, at2, err));
11404
11425
  function weaklyCanonical(p) {
11405
11426
  const parts = path.resolve(p).split("/").filter(Boolean);
11406
11427
  for (let i2 = parts.length; i2 > 0; i2--) {
@@ -15211,9 +15232,17 @@ function fileURLToPath(url) {
15211
15232
  }
15212
15233
  return decodeURIComponent(parsed.pathname);
15213
15234
  }
15235
+ var FILE_URL_SAFE = /[A-Za-z0-9\-._/!$&'()*+,;=:@]/;
15236
+ function encodeFilePath(path) {
15237
+ let out = "";
15238
+ for (const ch of path) {
15239
+ if (FILE_URL_SAFE.test(ch)) out += ch;
15240
+ else for (const b of new TextEncoder().encode(ch)) out += `%${b.toString(16).toUpperCase().padStart(2, "0")}`;
15241
+ }
15242
+ return out;
15243
+ }
15214
15244
  function pathToFileURL(path) {
15215
- const encoded = path.split("/").map((seg) => encodeURIComponent(seg)).join("/");
15216
- return new URL(`file://${encoded}`);
15245
+ return new URL(`file://${encodeFilePath(path)}`);
15217
15246
  }
15218
15247
  function parse5(urlStr, parseQueryString = false, slashesDenoteHost = false) {
15219
15248
  void slashesDenoteHost;
@@ -15531,8 +15560,19 @@ function createResolver({
15531
15560
  path,
15532
15561
  readPackageJson,
15533
15562
  conditions = REQUIRE_CONDITIONS,
15534
- extensions = DEFAULT_EXTENSIONS
15563
+ extensions = DEFAULT_EXTENSIONS,
15564
+ preserveSymlinks: preserveSymlinks2 = false
15535
15565
  } = {}) {
15566
+ const real = (filename) => {
15567
+ if (preserveSymlinks2 || typeof fs.lstat !== "function" || typeof fs.readlink !== "function") {
15568
+ return filename;
15569
+ }
15570
+ try {
15571
+ return realpathWith(fs, path, filename, (code) => Object.assign(new Error(code), { code }));
15572
+ } catch {
15573
+ return filename;
15574
+ }
15575
+ };
15536
15576
  const tryStat = (p) => {
15537
15577
  try {
15538
15578
  if (!fs.exists(p)) return null;
@@ -15738,17 +15778,17 @@ function createResolver({
15738
15778
  const fromDir = parentFilename.endsWith("/") || tryStat(parentFilename)?.isDirectory ? parentFilename : path.dirname(parentFilename);
15739
15779
  if (request.startsWith("#")) {
15740
15780
  const hit = packageImportsResolve(request, parentFilename);
15741
- if (hit) return { type: "file", filename: hit };
15781
+ if (hit) return { type: "file", filename: real(hit) };
15742
15782
  throw moduleNotFound(request, stack);
15743
15783
  }
15744
15784
  if (request.startsWith("/") || request.startsWith("./") || request.startsWith("../")) {
15745
15785
  const abs = path.resolve(fromDir, request);
15746
15786
  const hit = loadAsFileOrDir(abs);
15747
- if (hit) return { type: "file", filename: hit };
15787
+ if (hit) return { type: "file", filename: real(hit) };
15748
15788
  throw moduleNotFound(request, stack);
15749
15789
  }
15750
15790
  const nm = loadNodeModules(request, fromDir);
15751
- if (nm) return { type: "file", filename: nm };
15791
+ if (nm) return { type: "file", filename: real(nm) };
15752
15792
  throw moduleNotFound(request, stack);
15753
15793
  }
15754
15794
  return { resolve: resolve2, tryFile, loadAsDirectory };
@@ -15798,6 +15838,18 @@ function isBuiltinName(name) {
15798
15838
 
15799
15839
  // src/runtime/cjs/loader.mjs
15800
15840
  var decoder5 = new TextDecoder();
15841
+ function nodeModulePaths(dir) {
15842
+ const parts = dir.split("/").filter(Boolean);
15843
+ const out = [];
15844
+ for (let i2 = parts.length; i2 >= 0; i2--) {
15845
+ if (parts[i2 - 1] === "node_modules") continue;
15846
+ out.push(`/${[...parts.slice(0, i2), "node_modules"].join("/")}`);
15847
+ }
15848
+ return out;
15849
+ }
15850
+ function preserveSymlinks(process2) {
15851
+ return (process2?.execArgv ?? []).includes("--preserve-symlinks") || process2?.env?.NODE_PRESERVE_SYMLINKS === "1";
15852
+ }
15801
15853
  function createCjs({
15802
15854
  ctx,
15803
15855
  process: process2,
@@ -15823,7 +15875,7 @@ function createCjs({
15823
15875
  return null;
15824
15876
  }
15825
15877
  };
15826
- const resolver = createResolver({ fs, path, readPackageJson });
15878
+ const resolver = createResolver({ fs, path, readPackageJson, preserveSymlinks: preserveSymlinks(process2) });
15827
15879
  const builtins = createBuiltins({ ctx, process: process2, Buffer: Buffer2, console: console2, path, handles, timers });
15828
15880
  const cache2 = /* @__PURE__ */ Object.create(null);
15829
15881
  function Module(id, parent) {
@@ -15834,9 +15886,10 @@ function createCjs({
15834
15886
  this.parent = parent ?? null;
15835
15887
  this.loaded = false;
15836
15888
  this.children = [];
15837
- this.paths = [];
15889
+ this.paths = id.startsWith("/") ? nodeModulePaths(path.dirname(id)) : [];
15838
15890
  }
15839
15891
  Module._cache = cache2;
15892
+ Module._nodeModulePaths = (from) => nodeModulePaths(path.resolve(process2.cwd(), String(from)));
15840
15893
  Module.builtinModules = [
15841
15894
  "assert",
15842
15895
  "assert/strict",
@@ -16139,6 +16192,7 @@ ${err.name}: ${err.message}`;
16139
16192
  mod.filename = filename;
16140
16193
  mod.id = filename === "[stdin]" || filename === "[eval]" ? filename : ".";
16141
16194
  mod.path = filename.startsWith("[") ? "." : path.dirname(filename);
16195
+ mod.paths = nodeModulePaths(filename.startsWith("[") ? process2.cwd() : path.dirname(filename));
16142
16196
  cache2[filename] = mod;
16143
16197
  mainModule = setMain ? mod : void 0;
16144
16198
  if (filename.startsWith("[")) {
@@ -16169,6 +16223,7 @@ function parseNodeArgv(argv) {
16169
16223
  let print = false;
16170
16224
  let script;
16171
16225
  const userArgs = [];
16226
+ const flags = [];
16172
16227
  let i2 = 0;
16173
16228
  while (i2 < args.length) {
16174
16229
  const arg = args[i2];
@@ -16216,6 +16271,11 @@ function parseNodeArgv(argv) {
16216
16271
  userArgs.push(...args.slice(i2));
16217
16272
  break;
16218
16273
  }
16274
+ if (arg === "--preserve-symlinks" || arg === "--preserve-symlinks-main") {
16275
+ flags.push(arg);
16276
+ i2 += 1;
16277
+ continue;
16278
+ }
16219
16279
  if (arg.startsWith("-")) {
16220
16280
  if (arg === "-c" || arg === "--check") {
16221
16281
  i2 += 1;
@@ -16234,7 +16294,7 @@ function parseNodeArgv(argv) {
16234
16294
  code: evalCode,
16235
16295
  print,
16236
16296
  processArgv: [argv0, ...userArgs],
16237
- execArgv: [flag, evalCode]
16297
+ execArgv: [...flags, flag, evalCode]
16238
16298
  };
16239
16299
  }
16240
16300
  if (script !== void 0) {
@@ -16242,13 +16302,13 @@ function parseNodeArgv(argv) {
16242
16302
  mode: "file",
16243
16303
  script,
16244
16304
  processArgv: [argv0, script, ...userArgs],
16245
- execArgv: []
16305
+ execArgv: [...flags]
16246
16306
  };
16247
16307
  }
16248
16308
  return {
16249
16309
  mode: "empty",
16250
16310
  processArgv: [argv0],
16251
- execArgv: []
16311
+ execArgv: [...flags]
16252
16312
  };
16253
16313
  }
16254
16314
 
@@ -16397,8 +16457,7 @@ var IMPORT_CONDITIONS = ["slicc", "import", "node", "default"];
16397
16457
  function pathToFileURL2(filename) {
16398
16458
  if (filename.startsWith("file:")) return filename;
16399
16459
  const p = filename.startsWith("/") ? filename : `/${filename}`;
16400
- const encoded = p.split("/").map((seg) => encodeURIComponent(seg)).join("/");
16401
- return `file://${encoded}`;
16460
+ return `file://${encodeFilePath(p)}`;
16402
16461
  }
16403
16462
  function cjsToNamespace(exports) {
16404
16463
  if (exports && typeof exports === "object" && exports.__esModule && "default" in exports) {
@@ -16449,7 +16508,8 @@ function createEsm({ ctx, process: process2, handles, builtins, cjs, trackPromis
16449
16508
  path,
16450
16509
  readPackageJson,
16451
16510
  conditions: IMPORT_CONDITIONS,
16452
- extensions: [".js", ".mjs", ".cjs", ".json"]
16511
+ extensions: [".js", ".mjs", ".cjs", ".json"],
16512
+ preserveSymlinks: preserveSymlinks(process2)
16453
16513
  });
16454
16514
  const cache2 = /* @__PURE__ */ new Map();
16455
16515
  const evaluatingStack = /* @__PURE__ */ new Set();
@@ -16475,12 +16535,20 @@ function createEsm({ ctx, process: process2, handles, builtins, cjs, trackPromis
16475
16535
  if (source != null && shouldRunAsEsm(source)) return true;
16476
16536
  return false;
16477
16537
  }
16538
+ function esmResolve(specifier, parentFilename) {
16539
+ try {
16540
+ return resolver.resolve(String(specifier), parentFilename, [parentFilename]);
16541
+ } catch (err) {
16542
+ if (err && err.code === "MODULE_NOT_FOUND") err.code = "ERR_MODULE_NOT_FOUND";
16543
+ throw err;
16544
+ }
16545
+ }
16478
16546
  function makeImportMeta(filename) {
16479
16547
  const url = filename.startsWith("[") ? filename : pathToFileURL2(filename);
16480
16548
  const meta = {
16481
16549
  url,
16482
16550
  resolve(specifier) {
16483
- const resolved = resolver.resolve(String(specifier), filename, [filename]);
16551
+ const resolved = esmResolve(specifier, filename);
16484
16552
  if (resolved.type === "builtin") return `node:${resolved.id}`;
16485
16553
  return pathToFileURL2(resolved.filename);
16486
16554
  }
@@ -16492,7 +16560,7 @@ function createEsm({ ctx, process: process2, handles, builtins, cjs, trackPromis
16492
16560
  return meta;
16493
16561
  }
16494
16562
  function resolveAndLoadSync(specifier, parentFilename) {
16495
- const resolved = resolver.resolve(specifier, parentFilename, [parentFilename]);
16563
+ const resolved = esmResolve(specifier, parentFilename);
16496
16564
  if (resolved.type === "builtin") {
16497
16565
  return cjsToNamespace(builtins.load(resolved.id));
16498
16566
  }
@@ -16563,7 +16631,7 @@ ${code}`
16563
16631
  };
16564
16632
  const __preload = async () => {
16565
16633
  for (const spec of staticSpecs) {
16566
- const resolved = resolver.resolve(spec, filename, [filename]);
16634
+ const resolved = esmResolve(spec, filename);
16567
16635
  if (resolved.type === "builtin") continue;
16568
16636
  const dep = cache2.get(resolved.filename);
16569
16637
  if (dep?.namespace) continue;
@@ -18785,13 +18853,14 @@ slicc-jsh ${NODE_SHIM_VERSION} (Node-compatible, abi: js)
18785
18853
  return 1;
18786
18854
  }
18787
18855
  process2.argv[1] = filePath;
18856
+ const mainPath = realMainPath(ctx, filePath, process2.execArgv);
18788
18857
  try {
18789
- const useEsm = esm.isEsmFilename(filePath, source);
18858
+ const useEsm = esm.isEsmFilename(mainPath, source);
18790
18859
  if (useEsm) {
18791
- const result = esm.runMain(filePath, source);
18860
+ const result = esm.runMain(mainPath, source);
18792
18861
  if (result != null && typeof result.then === "function") setEntry(result, "esm");
18793
18862
  } else {
18794
- cjs.runMain(filePath, source);
18863
+ cjs.runMain(mainPath, source);
18795
18864
  }
18796
18865
  nextTick.flushSync();
18797
18866
  } catch (err) {