pinokiod 3.2.221 → 3.2.223

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.
@@ -24,6 +24,8 @@ class Api {
24
24
  this.done = {}
25
25
  this.waiter = {}
26
26
  this.proxies = {}
27
+ this.mods = {}
28
+ this.child_procs = {}
27
29
  this.lproxy = new Lproxy()
28
30
  }
29
31
  get_proxy_url(root, port) {
@@ -125,12 +127,26 @@ class Api {
125
127
 
126
128
 
127
129
  let { cwd, script } = await this.resolveScript(requestPath)
130
+ console.log("STOP", { script })
128
131
  if (script.on) {
129
132
  if (script.on.stop) {
130
133
  await this.process(script.on.stop)
131
134
  }
132
135
  }
133
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)
134
150
 
135
151
 
136
152
  // stop all shell processes connected to the uri
@@ -411,6 +427,34 @@ class Api {
411
427
  if (req.uri) {
412
428
  modpath = this.resolvePath(cwd, req.uri)
413
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)
435
+ if (this.mods[modpath]) {
436
+ // use the cached module if unchanged
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
+ }
448
+ } else {
449
+ console.log("NEW. Load for the first time")
450
+ // cache the mods so the module can be stateful
451
+ // the modules can set attributes on itself
452
+ this.child_procs[req.parent.path].add(modpath)
453
+ this.mods[modpath] = {
454
+ mod: m,
455
+ updated: String(stats.mtime),
456
+ }
457
+ }
414
458
  mod = m.resolved
415
459
  dirname = m.dirname
416
460
  method = mod[req.method].bind(mod)
@@ -589,6 +633,12 @@ class Api {
589
633
  // 6. rpc must have method names
590
634
  if (rpc.method) {
591
635
 
636
+ rpc.parent = {
637
+ uri: request.uri,
638
+ path: request.path,
639
+ git: this.parentGitURI(request.path),
640
+ body: script
641
+ }
592
642
  // 7. resolve the rpc
593
643
  let resolved = await this.resolveMethod(rpc, cwd)
594
644
 
@@ -611,12 +661,12 @@ class Api {
611
661
 
612
662
  rpc.root = request.uri
613
663
 
614
- rpc.parent = {
615
- uri: request.uri,
616
- path: request.path,
617
- git: this.parentGitURI(request.path),
618
- body: script
619
- }
664
+ // rpc.parent = {
665
+ // uri: request.uri,
666
+ // path: request.path,
667
+ // git: this.parentGitURI(request.path),
668
+ // body: script
669
+ // }
620
670
 
621
671
  if (request.client) rpc.client = request.client
622
672
 
@@ -670,7 +720,16 @@ class Api {
670
720
  } else {
671
721
  should_run = false
672
722
  }
723
+
673
724
  if (!should_run) {
725
+ // the current step is skipped, therefore the next value should be ignored as well
726
+ if (i < script.run.length-1) {
727
+ rpc.next = i+1
728
+ } else {
729
+ rpc.next = null
730
+ }
731
+
732
+
674
733
  //if (!rpc.when) {
675
734
  if (typeof rpc.next === "undefined" || rpc.next === null) {
676
735
  // last call
@@ -41,19 +41,28 @@ class Script {
41
41
  - absolute path
42
42
  - http path
43
43
  */
44
- let uri = await this.download(req, ondata, kernel)
45
- let res = await new Promise((resolve, reject) => {
46
- kernel.api.process({
47
- uri,
48
- input: req.params.params,
49
- client: req.client,
50
- caller: req.parent.path,
51
- }, (r) => {
52
- resolve(r.input)
44
+ // if already running, print that it's already running
45
+ let id = kernel.api.filePath(req.params.uri, req.cwd)
46
+ if (kernel.api.running[id]) {
47
+ let msg = `${req.params.uri} already running. Continuing...\r\n`
48
+ ondata({ raw: msg })
49
+ } else {
50
+ // if not already running, start.
51
+ let uri = await this.download(req, ondata, kernel)
52
+ let res = await new Promise((resolve, reject) => {
53
+ kernel.api.process({
54
+ uri,
55
+ input: req.params.params,
56
+ client: req.client,
57
+ caller: req.parent.path,
58
+ }, (r) => {
59
+ resolve(r.input)
60
+ })
53
61
  })
54
- })
55
- // need to call api.linkGit() so the git repositories list is up to date
56
- return res
62
+ // need to call api.linkGit() so the git repositories list is up to date
63
+ return res
64
+ }
65
+
57
66
  }
58
67
  async return(req, ondata, kernel) {
59
68
  /*
@@ -391,9 +391,10 @@ class Bin {
391
391
  console.log({ brew_path, brew_exists })
392
392
 
393
393
  let brew = []
394
+ console.time(">0")
394
395
  if (brew_exists) {
395
396
  start = false
396
- res = await this.exec({ message: `brew list -1` }, (stream) => {
397
+ res = await this.exec({ message: `brew list -1`, conda: { skip: true } }, (stream) => {
397
398
  // console.log("brew list check", { stream })
398
399
  })
399
400
  console.log("BREW", res.response)
@@ -416,15 +417,18 @@ class Bin {
416
417
  }
417
418
  }
418
419
  }
420
+ console.timeEnd(">0")
419
421
  this.installed.brew = new Set(brew)
420
422
 
421
423
 
422
424
  // check brew_installed
423
425
  console.log("checking brew installed")
426
+ console.time(">1")
424
427
  let e = await this.kernel.bin.exists("homebrew")
425
- let { stdout }= await this.exec({ message: "xcode-select -p" }, (stream) => { })
428
+ let { stdout }= await this.exec({ message: "xcode-select -p", conda: { skip: true } }, (stream) => { })
426
429
  let e2 = /(.*Library.*Developer.*CommandLineTools.*|.*Xcode.*Developer.*)/gi.test(stdout)
427
430
  let e3 = await this.kernel.exists("/Library/Developer/CommandLineTools")
431
+ console.timeEnd(">1")
428
432
 
429
433
  // if xcode-select version exists
430
434
  // - if version is greater thatn 2349 => yes
@@ -433,7 +437,8 @@ class Bin {
433
437
  // - no
434
438
 
435
439
  let e4;
436
- let result = await this.exec({ message: "xcode-select --version" }, (stream) => { })
440
+ console.time(">2")
441
+ let result = await this.exec({ message: "xcode-select --version", conda: { skip: true } }, (stream) => { })
437
442
  if (result && result.stdout) {
438
443
  e4 = /xcode-select version ([0-9]+)/gi.exec(result.stdout)
439
444
  if (e4 && e4.length > 1) {
@@ -450,6 +455,7 @@ class Bin {
450
455
  } else {
451
456
  e4 = false
452
457
  }
458
+ console.timeEnd(">2")
453
459
  console.log("BREW CHECK", { e, e2, e3, e4 })
454
460
  this.brew_installed = e && e2 && e3 && e4
455
461
 
@@ -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
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs')
2
2
  const os = require("os")
3
3
  const jsdom = require("jsdom");
4
+ const randomUseragent = require('random-useragent');
4
5
  const path = require('path')
5
6
  const fastq = require('fastq')
6
7
  const fetch = require('cross-fetch');
@@ -88,6 +89,15 @@ class Kernel {
88
89
  }
89
90
  return Environment.get2(folderpath, this)
90
91
  }
92
+ async userAgent(browser) {
93
+ if (browser) {
94
+ return randomUseragent.getRandom((ua) => {
95
+ return ua.browserName === browser;
96
+ });
97
+ } else {
98
+ return randomUseragent.getRandom()
99
+ }
100
+ }
91
101
  resumeprocess(uri) {
92
102
  let proc = this.procs[uri]
93
103
  if (proc && proc.resolve) {
@@ -100,6 +110,7 @@ class Kernel {
100
110
  type := "local" | "global"
101
111
  */
102
112
  let o = {}
113
+ console.log("IMPORT", params)
103
114
  for(let key in params) {
104
115
  // get memory for each uri
105
116
  let uri = params[key]
@@ -478,6 +489,27 @@ class Kernel {
478
489
  }
479
490
  }
480
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
+ }
481
513
  }
482
514
  // console.log({ grant_permission })
483
515
  // if (grant_permission) {
@@ -520,6 +552,7 @@ class Kernel {
520
552
 
521
553
  await fs.promises.mkdir(this.path("logs"), { recursive: true }).catch((e) => { })
522
554
  await fs.promises.writeFile(this.path("logs/system.json"), JSON.stringify(this.i, null, 2))
555
+
523
556
  /*
524
557
  this.sys = new Sysinfo()
525
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.221",
3
+ "version": "3.2.223",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {