epos 1.4.0 → 1.4.2
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/package.json +2 -2
- package/src/kit/kit-server.js +40 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epos",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"author": "imkost",
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "node ./src/kit/kit-bin.js",
|
|
11
11
|
"lint": "eslint ./src",
|
|
12
|
-
"
|
|
12
|
+
"release": "npm publish --loglevel=error"
|
|
13
13
|
},
|
|
14
14
|
"bin": {
|
|
15
15
|
"epos": "src/kit/kit-bin.js"
|
package/src/kit/kit-server.js
CHANGED
|
@@ -12,9 +12,9 @@ const $server = {
|
|
|
12
12
|
this._port = 4322
|
|
13
13
|
this._maxFiles = 10_000
|
|
14
14
|
|
|
15
|
-
this._pkgs = {} // { [path]: { name, dir, watcher } }
|
|
16
|
-
this._server = null
|
|
17
15
|
this._wss = null
|
|
16
|
+
this._server = null
|
|
17
|
+
this._pkgs = {} // { [path]: { name, dir, watcher } }
|
|
18
18
|
|
|
19
19
|
await this._initServer()
|
|
20
20
|
await this._initWebSocket()
|
|
@@ -82,43 +82,51 @@ const $server = {
|
|
|
82
82
|
ready.resolve()
|
|
83
83
|
})
|
|
84
84
|
|
|
85
|
-
// watch
|
|
85
|
+
// watch manifest files
|
|
86
86
|
const variants = new Set(['epos.json', 'epos.yaml', 'epos.yml'])
|
|
87
|
-
watcher.on('
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
watcher.on('all', async (event, path) => {
|
|
88
|
+
const isManifest = variants.has($path.basename(path))
|
|
89
|
+
if (!isManifest) return
|
|
90
|
+
|
|
91
|
+
// manifest removed? -> stop pkg watcher
|
|
92
|
+
if (event === 'unlink') {
|
|
93
|
+
if (!this._pkgs[path]) return
|
|
94
|
+
this._pkgs[path].watcher.close()
|
|
95
|
+
delete this._pkgs[path]
|
|
96
|
+
return
|
|
97
|
+
}
|
|
93
98
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
// read manifest
|
|
100
|
+
let name = null
|
|
101
|
+
let manifest = null
|
|
102
|
+
try {
|
|
103
|
+
const isJson = path.endsWith('.json')
|
|
104
|
+
const content = await $fs.readFile(path, 'utf-8')
|
|
105
|
+
manifest = isJson ? JSON.parse(content) : $yaml.load(content)
|
|
106
|
+
name = manifest.name
|
|
107
|
+
} catch {}
|
|
108
|
+
|
|
109
|
+
// invalid manifest? -> stop pkg watcher
|
|
110
|
+
if (!name) {
|
|
111
|
+
if (!this._pkgs[path]) return
|
|
112
|
+
this._pkgs[path].watcher.close()
|
|
113
|
+
delete this._pkgs[path]
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// create pkg watcher
|
|
118
|
+
const dir = $path.dirname(path)
|
|
119
|
+
const pkgWatcher = this._createPkgWatcher(name, dir)
|
|
120
|
+
this._pkgs[path] = { name, dir, watcher: pkgWatcher }
|
|
99
121
|
})
|
|
100
122
|
|
|
101
123
|
await ready.promise
|
|
102
124
|
},
|
|
103
125
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const isJson = manifestPath.endsWith('.json')
|
|
107
|
-
const content = await $fs.readFile(manifestPath, 'utf-8')
|
|
108
|
-
const manifest = isJson ? JSON.parse(content) : $yaml.load(content)
|
|
109
|
-
|
|
110
|
-
// no name? -> ignore
|
|
111
|
-
const name = manifest.name
|
|
112
|
-
if (!name) return null
|
|
113
|
-
|
|
114
|
-
// create pkg dir watcher
|
|
115
|
-
const dir = $path.dirname(manifestPath)
|
|
116
|
-
const watcher = $chokidar.watch(dir, {
|
|
117
|
-
ignored: this._ignored,
|
|
118
|
-
ignoreInitial: true,
|
|
119
|
-
})
|
|
126
|
+
_createPkgWatcher(name, dir) {
|
|
127
|
+
const watcher = $chokidar.watch(dir, { ignored: this._ignored })
|
|
120
128
|
|
|
121
|
-
// broadcast changes
|
|
129
|
+
// broadcast all changes
|
|
122
130
|
watcher.on('all', (event, path) => {
|
|
123
131
|
const data = JSON.stringify({ name, path: $path.relative(dir, path) })
|
|
124
132
|
for (const client of this._wss.clients) {
|
|
@@ -127,7 +135,7 @@ const $server = {
|
|
|
127
135
|
}
|
|
128
136
|
})
|
|
129
137
|
|
|
130
|
-
return
|
|
138
|
+
return watcher
|
|
131
139
|
},
|
|
132
140
|
|
|
133
141
|
async _handleRequest(req) {
|