pinokiod 5.0.13 → 5.1.1

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/kernel/bin/git.js CHANGED
@@ -52,8 +52,8 @@ class Git {
52
52
  async uninstall(req, ondata) {
53
53
  await this.kernel.bin.exec({ message: "conda remove git gh" }, ondata)
54
54
  }
55
- env(cwd) {
56
- const gitconfig_path = path.resolve(this.kernel.homedir, "gitconfig")
55
+ env() {
56
+ let gitconfig_path = path.resolve(this.kernel.homedir, "gitconfig")
57
57
  return {
58
58
  GIT_CONFIG_GLOBAL: gitconfig_path,
59
59
  GH_CONFIG_DIR: this.kernel.path("config/gh")
package/kernel/git.js CHANGED
@@ -131,9 +131,25 @@ class Git {
131
131
  }
132
132
  }
133
133
  async findGitDirs(dir, results = []) {
134
- const entries = await fs.promises.readdir(dir, { withFileTypes: true });
134
+ let entries
135
+ try {
136
+ entries = await fs.promises.readdir(dir, { withFileTypes: true });
137
+ } catch (err) {
138
+ if (err && (err.code === "ENOENT" || err.code === "EACCES")) {
139
+ return results
140
+ }
141
+ throw err
142
+ }
135
143
  for (const entry of entries) {
136
- let type = await Util.file_type(dir, entry)
144
+ let type
145
+ try {
146
+ type = await Util.file_type(dir, entry)
147
+ } catch (err) {
148
+ if (err && (err.code === "ENOENT" || err.code === "EACCES")) {
149
+ continue
150
+ }
151
+ throw err
152
+ }
137
153
  if (type.directory) {
138
154
  if (entry.name === '.git') {
139
155
  results.push(path.join(dir, entry.name));
@@ -142,7 +158,14 @@ class Git {
142
158
  if (entry.name === 'node_modules' || entry.name === 'venv' || entry.name.startsWith(".")) {
143
159
  continue; // skip these heavy folders
144
160
  }
145
- await this.findGitDirs(path.join(dir, entry.name), results);
161
+ try {
162
+ await this.findGitDirs(path.join(dir, entry.name), results);
163
+ } catch (err) {
164
+ if (err && (err.code === "ENOENT" || err.code === "EACCES")) {
165
+ continue
166
+ }
167
+ throw err
168
+ }
146
169
  }
147
170
  }
148
171
  return results;
package/kernel/index.js CHANGED
@@ -1007,7 +1007,11 @@ class Kernel {
1007
1007
  this.git.init().then(() => {
1008
1008
  this.git.index(this).then(() => {
1009
1009
  //console.log(this.git.mapping)
1010
+ }).catch((err) => {
1011
+ console.warn("Git index error:", err && err.message ? err.message : err)
1010
1012
  })
1013
+ }).catch((err) => {
1014
+ console.warn("Git init error:", err && err.message ? err.message : err)
1011
1015
  })
1012
1016
  this.shell.init().then(async () => {
1013
1017
  this.bin.check({
@@ -0,0 +1,111 @@
1
+ const ParcelWatcher = require('@parcel/watcher')
2
+
3
+ class WorkspaceStatusManager {
4
+ constructor(options = {}) {
5
+ this.enableWatchers = options.enableWatchers !== false
6
+ this.fallbackIntervalMs = typeof options.fallbackIntervalMs === 'number' ? options.fallbackIntervalMs : 60000
7
+ this.cache = new Map()
8
+ this.watchers = new Map()
9
+ this.defaultIgnores = options.ignores && Array.isArray(options.ignores) ? options.ignores : [
10
+ '**/.git/**',
11
+ '**/node_modules/**',
12
+ '**/.venv/**',
13
+ '**/venv/**',
14
+ '**/env/**',
15
+ '**/__pycache__/**',
16
+ '**/site-packages/**',
17
+ '**/dist/**',
18
+ '**/build/**',
19
+ '**/.cache/**',
20
+ '**/logs/**',
21
+ '**/*.log',
22
+ '**/tmp/**',
23
+ '**/temp/**',
24
+ '**/.parcel-cache/**',
25
+ '**/.webpack/**',
26
+ ]
27
+ }
28
+
29
+ markDirty(workspaceName) {
30
+ let entry = this.cache.get(workspaceName)
31
+ if (!entry) {
32
+ entry = { dirty: true, inflight: null, data: null, updatedAt: 0 }
33
+ } else {
34
+ entry.dirty = true
35
+ }
36
+ this.cache.set(workspaceName, entry)
37
+ }
38
+
39
+ async ensureWatcher(workspaceName, workspaceRoot) {
40
+ if (!this.enableWatchers) {
41
+ return
42
+ }
43
+ if (this.watchers.has(workspaceName)) {
44
+ return
45
+ }
46
+ try {
47
+ const subscription = await ParcelWatcher.subscribe(
48
+ workspaceRoot,
49
+ (error, events) => {
50
+ if (error) {
51
+ console.warn('workspace watcher error', workspaceName, error)
52
+ return
53
+ }
54
+ if (events && events.length > 0) {
55
+ console.log("Events", events)
56
+ this.markDirty(workspaceName)
57
+ }
58
+ },
59
+ { ignore: this.defaultIgnores }
60
+ )
61
+ this.watchers.set(workspaceName, subscription)
62
+ this.markDirty(workspaceName)
63
+ } catch (error) {
64
+ console.warn('workspace watcher unavailable, falling back to polling', workspaceName, error)
65
+ this.enableWatchers = false
66
+ this.watchers.clear()
67
+ }
68
+ }
69
+
70
+ async getStatus(workspaceName, computeStatusFn, workspaceRoot) {
71
+ let entry = this.cache.get(workspaceName)
72
+ if (!entry) {
73
+ entry = { dirty: true, inflight: null, data: null, updatedAt: 0 }
74
+ this.cache.set(workspaceName, entry)
75
+ }
76
+ const now = Date.now()
77
+ if (entry.updatedAt && (now - entry.updatedAt) > this.fallbackIntervalMs) {
78
+ entry.dirty = true
79
+ }
80
+ if (!this.enableWatchers) {
81
+ entry.dirty = true
82
+ }
83
+
84
+ if (!entry.dirty && entry.data) {
85
+ return entry.data
86
+ }
87
+ if (entry.inflight) {
88
+ return entry.inflight
89
+ }
90
+
91
+ if (this.enableWatchers && workspaceRoot) {
92
+ await this.ensureWatcher(workspaceName, workspaceRoot)
93
+ }
94
+
95
+ entry.inflight = (async () => {
96
+ const data = await computeStatusFn()
97
+ entry.data = data
98
+ entry.dirty = false
99
+ entry.updatedAt = Date.now()
100
+ entry.inflight = null
101
+ return data
102
+ })().catch((error) => {
103
+ entry.inflight = null
104
+ throw error
105
+ })
106
+
107
+ return entry.inflight
108
+ }
109
+ }
110
+
111
+ module.exports = WorkspaceStatusManager
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "5.0.13",
3
+ "version": "5.1.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -86,6 +86,7 @@
86
86
  "xterm-addon-serialize": "^0.9.0",
87
87
  "xterm-headless": "^5.1.0",
88
88
  "yaml": "^2.3.4",
89
- "yargs-unparser-custom-flag": "^2.0.0"
89
+ "yargs-unparser-custom-flag": "^2.0.0",
90
+ "@parcel/watcher": "^2.4.1"
90
91
  }
91
92
  }
package/server/index.js CHANGED
@@ -59,6 +59,7 @@ const Environment = require("../kernel/environment")
59
59
  const Cloudflare = require("../kernel/api/cloudflare")
60
60
  const Util = require("../kernel/util")
61
61
  const Info = require("../kernel/info")
62
+ const WorkspaceStatusManager = require("../kernel/workspace_status")
62
63
 
63
64
  const Setup = require("../kernel/bin/setup")
64
65
 
@@ -120,6 +121,10 @@ class Server {
120
121
  /(^|\/)\.pytest_cache\//,
121
122
  /(^|\/)\.git\//
122
123
  ]
124
+ this.workspaceStatus = new WorkspaceStatusManager({
125
+ enableWatchers: process.env.PINOKIO_DISABLE_WATCH === '1' ? false : true,
126
+ fallbackIntervalMs: 60000,
127
+ })
123
128
 
124
129
  // sometimes the C:\Windows\System32 is not in PATH, need to add
125
130
  let platform = os.platform()
@@ -854,9 +859,11 @@ class Server {
854
859
  async chrome(req, res, type, options) {
855
860
 
856
861
  let d = Date.now()
862
+ console.time("bin check")
857
863
  let { requirements, install_required, requirements_pending, error } = await this.kernel.bin.check({
858
864
  bin: this.kernel.bin.preset("dev"),
859
865
  })
866
+ console.timeEnd("bin check")
860
867
  if (!requirements_pending && install_required) {
861
868
  res.redirect(`/setup/dev?callback=${req.originalUrl}`)
862
869
  return
@@ -7404,7 +7411,12 @@ class Server {
7404
7411
  }))
7405
7412
  this.app.get("/info/gitstatus/:name", ex(async (req, res) => {
7406
7413
  try {
7407
- const data = await this.computeWorkspaceGitStatus(req.params.name)
7414
+ const workspaceRoot = this.kernel.path("api", req.params.name)
7415
+ const data = await this.workspaceStatus.getStatus(
7416
+ req.params.name,
7417
+ () => this.computeWorkspaceGitStatus(req.params.name),
7418
+ workspaceRoot
7419
+ )
7408
7420
  res.json(data)
7409
7421
  } catch (error) {
7410
7422
  console.error('[git-status] compute error', req.params.name, error)
package/aside DELETED
File without changes