pinokiod 3.2.222 → 3.2.224

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.
@@ -25,6 +25,7 @@ class Api {
25
25
  this.waiter = {}
26
26
  this.proxies = {}
27
27
  this.mods = {}
28
+ this.child_procs = {}
28
29
  this.lproxy = new Lproxy()
29
30
  }
30
31
  get_proxy_url(root, port) {
@@ -126,12 +127,26 @@ class Api {
126
127
 
127
128
 
128
129
  let { cwd, script } = await this.resolveScript(requestPath)
130
+ console.log("STOP", { script })
129
131
  if (script.on) {
130
132
  if (script.on.stop) {
131
133
  await this.process(script.on.stop)
132
134
  }
133
135
  }
134
136
 
137
+ // reset modules
138
+ let modpath = this.resolvePath(cwd, req.params.uri)
139
+ console.log("STOP modpath", modpath)
140
+ console.log("this.mods before", this.mods)
141
+ console.log("this.child_procs before", this.child_procs)
142
+ let child_procs = Array.from(this.child_procs[modpath])
143
+ for(let proc of child_procs) {
144
+ console.log("reset child proc", proc)
145
+ delete this.mods[proc]
146
+ }
147
+ delete this.child_procs[modpath]
148
+ console.log("this.mods after", this.mods)
149
+ console.log("this.child_procs after", this.child_procs)
135
150
 
136
151
 
137
152
  // stop all shell processes connected to the uri
@@ -412,15 +427,33 @@ class Api {
412
427
  if (req.uri) {
413
428
  modpath = this.resolvePath(cwd, req.uri)
414
429
  let m = (await this.loader.load(modpath))
430
+ const stats = await fs.promises.stat(modpath)
431
+ if (!this.child_procs[req.parent.path]) {
432
+ this.child_procs[req.parent.path] = new Set()
433
+ }
434
+ console.log("SCRIPT RESOLVE METHOD", req)
415
435
  if (this.mods[modpath]) {
416
- console.log("Same, used the cached object")
417
436
  // use the cached module if unchanged
418
- m = this.mods[modpath]
437
+ if (String(stats.mtime) === String(this.mods[modpath].updated)) {
438
+ console.log("NOT UPDATED. Use the cached version")
439
+ m = this.mods[modpath].mod
440
+ } else {
441
+ console.log("UPDATED. Use the Reloaded version")
442
+ this.child_procs[req.parent.path].add(modpath)
443
+ this.mods[modpath] = {
444
+ mod: m,
445
+ updated: String(stats.mtime),
446
+ }
447
+ }
419
448
  } else {
420
- m = (await this.loader.load(modpath))
449
+ console.log("NEW. Load for the first time")
421
450
  // cache the mods so the module can be stateful
422
451
  // the modules can set attributes on itself
423
- this.mods[modpath] = m
452
+ this.child_procs[req.parent.path].add(modpath)
453
+ this.mods[modpath] = {
454
+ mod: m,
455
+ updated: String(stats.mtime),
456
+ }
424
457
  }
425
458
  mod = m.resolved
426
459
  dirname = m.dirname
@@ -600,6 +633,12 @@ class Api {
600
633
  // 6. rpc must have method names
601
634
  if (rpc.method) {
602
635
 
636
+ rpc.parent = {
637
+ uri: request.uri,
638
+ path: request.path,
639
+ git: this.parentGitURI(request.path),
640
+ body: script
641
+ }
603
642
  // 7. resolve the rpc
604
643
  let resolved = await this.resolveMethod(rpc, cwd)
605
644
 
@@ -622,12 +661,12 @@ class Api {
622
661
 
623
662
  rpc.root = request.uri
624
663
 
625
- rpc.parent = {
626
- uri: request.uri,
627
- path: request.path,
628
- git: this.parentGitURI(request.path),
629
- body: script
630
- }
664
+ // rpc.parent = {
665
+ // uri: request.uri,
666
+ // path: request.path,
667
+ // git: this.parentGitURI(request.path),
668
+ // body: script
669
+ // }
631
670
 
632
671
  if (request.client) rpc.client = request.client
633
672
 
@@ -393,7 +393,7 @@ class Bin {
393
393
  let brew = []
394
394
  if (brew_exists) {
395
395
  start = false
396
- res = await this.exec({ message: `brew list -1` }, (stream) => {
396
+ res = await this.exec({ message: `brew list -1`, conda: { skip: true } }, (stream) => {
397
397
  // console.log("brew list check", { stream })
398
398
  })
399
399
  console.log("BREW", res.response)
@@ -422,7 +422,7 @@ class Bin {
422
422
  // check brew_installed
423
423
  console.log("checking brew installed")
424
424
  let e = await this.kernel.bin.exists("homebrew")
425
- let { stdout }= await this.exec({ message: "xcode-select -p" }, (stream) => { })
425
+ let { stdout }= await this.exec({ message: "xcode-select -p", conda: { skip: true } }, (stream) => { })
426
426
  let e2 = /(.*Library.*Developer.*CommandLineTools.*|.*Xcode.*Developer.*)/gi.test(stdout)
427
427
  let e3 = await this.kernel.exists("/Library/Developer/CommandLineTools")
428
428
 
@@ -433,7 +433,7 @@ class Bin {
433
433
  // - no
434
434
 
435
435
  let e4;
436
- let result = await this.exec({ message: "xcode-select --version" }, (stream) => { })
436
+ let result = await this.exec({ message: "xcode-select --version", conda: { skip: true } }, (stream) => { })
437
437
  if (result && result.stdout) {
438
438
  e4 = /xcode-select version ([0-9]+)/gi.exec(result.stdout)
439
439
  if (e4 && e4.length > 1) {
@@ -103,6 +103,19 @@ const ENVS = async () => {
103
103
  "#",
104
104
  "##########################################################################",
105
105
  ],
106
+ }, {
107
+ type: ["app"],
108
+ key: "PINOKIO_SCRIPT_AUTOLAUNCH",
109
+ val: "true",
110
+ comment: [
111
+ "##########################################################################",
112
+ "#",
113
+ "# PINOKIO_SCRIPT_AUTOLAUNCH",
114
+ "# the relative file path for auto launching any script",
115
+ "# the specified script will automatically run when pinokio first launches",
116
+ "#",
117
+ "##########################################################################",
118
+ ]
106
119
  }, {
107
120
  type: ["system"],
108
121
  key: "PINOKIO_SHARE_VAR",
package/kernel/index.js CHANGED
@@ -323,14 +323,6 @@ class Kernel {
323
323
  path: folder,
324
324
  })
325
325
  }
326
-
327
-
328
- // get env
329
- let env_path = path.resolve(this.api.userdir, folder)
330
- let e = await Util.get(env_path)
331
- if (e.PINOKIO_SCRIPT_AUTOLAUNCH) {
332
-
333
- }
334
326
  }
335
327
  for(let key in this.bin.installed) {
336
328
  let s = this.bin.installed[key]
@@ -497,6 +489,27 @@ class Kernel {
497
489
  }
498
490
  }
499
491
  })
492
+
493
+ // get env
494
+ for(let api of this.i.api) {
495
+ let env_path = path.resolve(this.api.userdir, api.path)
496
+ let e = await Environment.get(env_path)
497
+ console.log(e)
498
+ if (e.PINOKIO_SCRIPT_AUTOLAUNCH) {
499
+ let autolaunch_path = path.resolve(env_path, e.PINOKIO_SCRIPT_AUTOLAUNCH)
500
+ console.log("AUTOLAUNCHING", autolaunch_path)
501
+ let res = await new Promise((resolve, reject) => {
502
+ this.api.process({
503
+ uri: autolaunch_path,
504
+ input: {}
505
+ // client: req.client,
506
+ // caller: req.parent.path,
507
+ }, (r) => {
508
+ resolve(r.input)
509
+ })
510
+ })
511
+ }
512
+ }
500
513
  }
501
514
  // console.log({ grant_permission })
502
515
  // if (grant_permission) {
@@ -539,6 +552,7 @@ class Kernel {
539
552
 
540
553
  await fs.promises.mkdir(this.path("logs"), { recursive: true }).catch((e) => { })
541
554
  await fs.promises.writeFile(this.path("logs/system.json"), JSON.stringify(this.i, null, 2))
555
+
542
556
  /*
543
557
  this.sys = new Sysinfo()
544
558
  await this.sys.init(this)
package/kernel/shell.js CHANGED
@@ -788,6 +788,7 @@ class Shell {
788
788
  async exec(params) {
789
789
  params = await this.activate(params)
790
790
  this.cmd = this.build(params)
791
+ console.log("this.cmd", this.cmd)
791
792
  let res = await new Promise((resolve, reject) => {
792
793
  this.resolve = resolve
793
794
  this.reject = reject
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.2.222",
3
+ "version": "3.2.224",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {