@ai-ecoverse/slicc-kernel 1.160.1 → 1.160.3

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/node.js CHANGED
@@ -1,5 +1,8 @@
1
1
  // src/node.ts
2
- import { isAbsolute } from "node:path";
2
+ import { createHash } from "node:crypto";
3
+ import { lstatSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { isAbsolute, join } from "node:path";
3
6
  import { MessageChannel as MessageChannel2, Worker } from "node:worker_threads";
4
7
 
5
8
  // src/bytes.ts
@@ -3672,7 +3675,7 @@ function satisfies(version, range2) {
3672
3675
  }
3673
3676
 
3674
3677
  // src/version.ts
3675
- var KERNEL_VERSION = true ? "1.160.1" : "0.0.0-dev";
3678
+ var KERNEL_VERSION = true ? "1.160.3" : "0.0.0-dev";
3676
3679
  var OS_RELEASE = "6.0.0-slicc";
3677
3680
  function procVersion() {
3678
3681
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -30926,7 +30929,7 @@ var Launcher = class {
30926
30929
  this.moduleUrls.delete(source);
30927
30930
  this.moduleUrls.set(source, known);
30928
30931
  known.users++;
30929
- return known.made.url;
30932
+ return known.made;
30930
30933
  }
30931
30934
  const held = {
30932
30935
  made: (this.moduleUrl ?? dataModuleUrl)(source),
@@ -30941,7 +30944,7 @@ var Launcher = class {
30941
30944
  entry.evicted = true;
30942
30945
  this.releaseUrl(entry);
30943
30946
  }
30944
- return held.made.url;
30947
+ return held.made;
30945
30948
  }
30946
30949
  heldUrl(program) {
30947
30950
  const held = program.abi === "js" && program.url ? this.urlsInUse.get(program.url) : void 0;
@@ -31022,8 +31025,8 @@ var Launcher = class {
31022
31025
  }
31023
31026
  const { asked } = target;
31024
31027
  if (target.abi === "js") {
31025
- const url = this.urlFor(await this.text(target.wasm, caller, asked));
31026
- return { abi: "js", glue: "", url, path: target.wasm };
31028
+ const { url, source } = this.urlFor(await this.text(target.wasm, caller, asked));
31029
+ return { abi: "js", glue: "", url, path: target.wasm, ...source ? { source } : {} };
31027
31030
  }
31028
31031
  if (target.abi !== "wasi") {
31029
31032
  const [glue, { module: module2 }] = await Promise.all([
@@ -34801,6 +34804,11 @@ function sparesOf(options) {
34801
34804
  function processWorker(file, workerData) {
34802
34805
  return new Worker(file, { env: workerEnv(), ...workerData ? { workerData } : {} });
34803
34806
  }
34807
+ function sourceModule(source) {
34808
+ const url = `slicc-module:${createHash("sha256").update(source).digest("hex")}`;
34809
+ return { url, source, revoke: () => {
34810
+ } };
34811
+ }
34804
34812
  function warmPoolOf(options, file, workerData, live) {
34805
34813
  const size = sparesOf(options);
34806
34814
  if (size === 0) return void 0;
@@ -34871,12 +34879,72 @@ function workerEnv() {
34871
34879
  const { NODE_COMPILE_CACHE: _inherited, ...env } = process.env;
34872
34880
  return env;
34873
34881
  }
34882
+ var CACHE_PREFIX = "slicc-kernel-cc-";
34874
34883
  function cacheDirOf(dir) {
34875
- if (dir === void 0) return void 0;
34884
+ if (dir === false) return void 0;
34885
+ if (dir === void 0) return ownCacheDir();
34876
34886
  if (typeof dir !== "string" || !isAbsolute(dir)) {
34877
- throw new TypeError("createNodeKernel: compileCache must be an absolute directory path");
34887
+ throw new TypeError(
34888
+ "createNodeKernel: compileCache must be an absolute directory path or false"
34889
+ );
34890
+ }
34891
+ return { dir, own: false };
34892
+ }
34893
+ function cacheData(cache) {
34894
+ if (!cache) return void 0;
34895
+ return { compileCache: cache.dir, ...cache.own ? { ownedCache: true } : {} };
34896
+ }
34897
+ function dropCache(cache) {
34898
+ if (!cache?.own) return;
34899
+ try {
34900
+ rmSync(cache.dir, { recursive: true, force: true });
34901
+ } catch {
34902
+ }
34903
+ }
34904
+ function ownCacheDir(make = privateCacheDir) {
34905
+ try {
34906
+ return { dir: make(), own: true };
34907
+ } catch {
34908
+ return void 0;
34909
+ }
34910
+ }
34911
+ var swept = false;
34912
+ function privateCacheDir(base = tmpdir(), alive = pidAlive) {
34913
+ if (!swept) {
34914
+ swept = true;
34915
+ sweepCacheDirs(base, alive);
34916
+ }
34917
+ return mkdtempSync(join(base, `${CACHE_PREFIX}${process.pid}-`));
34918
+ }
34919
+ function sweepCacheDirs(base, alive = pidAlive, uid = process.getuid?.()) {
34920
+ let names2;
34921
+ try {
34922
+ names2 = readdirSync(base);
34923
+ } catch {
34924
+ return;
34925
+ }
34926
+ for (const name2 of names2) {
34927
+ if (!name2.startsWith(CACHE_PREFIX)) continue;
34928
+ const pid = Number(name2.slice(CACHE_PREFIX.length).split("-")[0]);
34929
+ if (!Number.isInteger(pid) || pid <= 0 || alive(pid)) continue;
34930
+ removeOurs(join(base, name2), uid);
34931
+ }
34932
+ }
34933
+ function removeOurs(path, uid) {
34934
+ try {
34935
+ const st = lstatSync(path);
34936
+ if (!st.isDirectory() || uid !== void 0 && st.uid !== uid) return;
34937
+ rmSync(path, { recursive: true, force: true });
34938
+ } catch {
34939
+ }
34940
+ }
34941
+ function pidAlive(pid) {
34942
+ try {
34943
+ process.kill(pid, 0);
34944
+ return true;
34945
+ } catch (err) {
34946
+ return err.code === "EPERM";
34878
34947
  }
34879
- return dir;
34880
34948
  }
34881
34949
  var nodeSessions = 0;
34882
34950
  function nodeClient(launcher, clients, { user, tag, requests }) {
@@ -34912,12 +34980,13 @@ async function createNodeKernel(options = {}) {
34912
34980
  const clients = /* @__PURE__ */ new Set();
34913
34981
  let terminated = false;
34914
34982
  const file = options.worker ?? new URL("./node-process-worker.js", import.meta.url);
34915
- const compileCache = cacheDirOf(options.compileCache);
34916
- const workerData = compileCache ? { compileCache } : void 0;
34983
+ const cache = cacheDirOf(options.compileCache);
34984
+ const workerData = cacheData(cache);
34917
34985
  const warm = warmPoolOf(options, file, workerData, live);
34918
34986
  const transport = options.network?.transport;
34919
34987
  const launcher = new Launcher({
34920
34988
  fs,
34989
+ moduleUrl: sourceModule,
34921
34990
  unlinkOwner: pidOwner(process),
34922
34991
  createWorker: () => nodeWorker(file, live, terminated, workerData, warm ? () => warm.take() : void 0),
34923
34992
  createDriverWorker: () => nodeWorker(
@@ -35050,6 +35119,7 @@ async function createNodeKernel(options = {}) {
35050
35119
  for (const kill of [...live]) kill();
35051
35120
  launcher.cdp.close();
35052
35121
  launcher.unmountAll();
35122
+ dropCache(cache);
35053
35123
  }
35054
35124
  };
35055
35125
  }
@@ -35063,8 +35133,12 @@ export {
35063
35133
  fetchTransport,
35064
35134
  memoryRoot,
35065
35135
  nodeTransport,
35136
+ ownCacheDir,
35137
+ privateCacheDir,
35066
35138
  serveHostfsPort,
35139
+ sourceModule,
35067
35140
  sparesOf,
35141
+ sweepCacheDirs,
35068
35142
  warmPool
35069
35143
  };
35070
35144
  //# sourceMappingURL=node.js.map