@ai-ecoverse/slicc-kernel 1.160.2 → 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,6 +1,8 @@
1
1
  // src/node.ts
2
2
  import { createHash } from "node:crypto";
3
- import { isAbsolute } from "node:path";
3
+ import { lstatSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { isAbsolute, join } from "node:path";
4
6
  import { MessageChannel as MessageChannel2, Worker } from "node:worker_threads";
5
7
 
6
8
  // src/bytes.ts
@@ -3673,7 +3675,7 @@ function satisfies(version, range2) {
3673
3675
  }
3674
3676
 
3675
3677
  // src/version.ts
3676
- var KERNEL_VERSION = true ? "1.160.2" : "0.0.0-dev";
3678
+ var KERNEL_VERSION = true ? "1.160.3" : "0.0.0-dev";
3677
3679
  var OS_RELEASE = "6.0.0-slicc";
3678
3680
  function procVersion() {
3679
3681
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -34877,12 +34879,72 @@ function workerEnv() {
34877
34879
  const { NODE_COMPILE_CACHE: _inherited, ...env } = process.env;
34878
34880
  return env;
34879
34881
  }
34882
+ var CACHE_PREFIX = "slicc-kernel-cc-";
34880
34883
  function cacheDirOf(dir) {
34881
- if (dir === void 0) return void 0;
34884
+ if (dir === false) return void 0;
34885
+ if (dir === void 0) return ownCacheDir();
34882
34886
  if (typeof dir !== "string" || !isAbsolute(dir)) {
34883
- 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";
34884
34947
  }
34885
- return dir;
34886
34948
  }
34887
34949
  var nodeSessions = 0;
34888
34950
  function nodeClient(launcher, clients, { user, tag, requests }) {
@@ -34918,8 +34980,8 @@ async function createNodeKernel(options = {}) {
34918
34980
  const clients = /* @__PURE__ */ new Set();
34919
34981
  let terminated = false;
34920
34982
  const file = options.worker ?? new URL("./node-process-worker.js", import.meta.url);
34921
- const compileCache = cacheDirOf(options.compileCache);
34922
- const workerData = compileCache ? { compileCache } : void 0;
34983
+ const cache = cacheDirOf(options.compileCache);
34984
+ const workerData = cacheData(cache);
34923
34985
  const warm = warmPoolOf(options, file, workerData, live);
34924
34986
  const transport = options.network?.transport;
34925
34987
  const launcher = new Launcher({
@@ -35057,6 +35119,7 @@ async function createNodeKernel(options = {}) {
35057
35119
  for (const kill of [...live]) kill();
35058
35120
  launcher.cdp.close();
35059
35121
  launcher.unmountAll();
35122
+ dropCache(cache);
35060
35123
  }
35061
35124
  };
35062
35125
  }
@@ -35070,9 +35133,12 @@ export {
35070
35133
  fetchTransport,
35071
35134
  memoryRoot,
35072
35135
  nodeTransport,
35136
+ ownCacheDir,
35137
+ privateCacheDir,
35073
35138
  serveHostfsPort,
35074
35139
  sourceModule,
35075
35140
  sparesOf,
35141
+ sweepCacheDirs,
35076
35142
  warmPool
35077
35143
  };
35078
35144
  //# sourceMappingURL=node.js.map