pinokiod 3.9.14 → 3.9.16
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/api/index.js +2 -0
- package/kernel/loader.js +16 -2
- package/package.json +1 -1
package/kernel/api/index.js
CHANGED
|
@@ -550,9 +550,11 @@ class Api {
|
|
|
550
550
|
}
|
|
551
551
|
method = mod[methodName].bind(mod)
|
|
552
552
|
} else {
|
|
553
|
+
console.log(">> 3")
|
|
553
554
|
if (chunks.length === 1) {
|
|
554
555
|
let methodName = chunks[0]
|
|
555
556
|
modpath = path.resolve(__dirname, methodName)
|
|
557
|
+
console.log({ modpath })
|
|
556
558
|
mod = (await this.loader.load(modpath))
|
|
557
559
|
method = mod.resolved
|
|
558
560
|
dirname = mod.dirname
|
package/kernel/loader.js
CHANGED
|
@@ -12,6 +12,7 @@ class Loader {
|
|
|
12
12
|
clearModule(_path)
|
|
13
13
|
|
|
14
14
|
let exists = await this.exists(_path)
|
|
15
|
+
console.log({ exists, _path })
|
|
15
16
|
if (!exists) {
|
|
16
17
|
return { resolved: null, dirname: path.dirname(_path), }
|
|
17
18
|
}
|
|
@@ -19,24 +20,31 @@ class Loader {
|
|
|
19
20
|
if (/\.json$/i.test(_path)) {
|
|
20
21
|
resolved = await this.requireJSON(_path)
|
|
21
22
|
dirname = path.dirname(_path)
|
|
23
|
+
console.log("#1", { resolved, dirname })
|
|
22
24
|
} else if (/\.js$/i.test(_path)) {
|
|
23
25
|
resolved = await this.requireJS(_path)
|
|
24
26
|
dirname = path.dirname(_path)
|
|
27
|
+
console.log("#2", { resolved, dirname })
|
|
25
28
|
// } else if (/\.(csv|txt)$/i.test(_path)) {
|
|
26
29
|
// resolved = await this.requireCSV(_path)
|
|
27
30
|
// } else if (/\.(yaml|yml)$/.test(_path)) {
|
|
28
31
|
// resolved = await this.requireYAML(_path)
|
|
29
32
|
} else {
|
|
33
|
+
console.log("#3", { resolved, dirname })
|
|
30
34
|
// load JS if directory
|
|
31
35
|
try {
|
|
32
36
|
let stat = await fs.promises.stat(_path)
|
|
37
|
+
console.log({ stat, _path })
|
|
33
38
|
if (stat.isDirectory()) {
|
|
39
|
+
console.log("isDirectory")
|
|
34
40
|
resolved = await this.requireJS(_path)
|
|
35
41
|
dirname = _path
|
|
36
42
|
} else {
|
|
43
|
+
console.log("isNotDirectory")
|
|
37
44
|
resolved = null
|
|
38
45
|
}
|
|
39
46
|
} catch (e) {
|
|
47
|
+
console.log("3Error", e)
|
|
40
48
|
resolved = null
|
|
41
49
|
}
|
|
42
50
|
}
|
|
@@ -86,8 +94,14 @@ class Loader {
|
|
|
86
94
|
})
|
|
87
95
|
return result
|
|
88
96
|
}
|
|
89
|
-
exists(abspath) {
|
|
90
|
-
|
|
97
|
+
async exists(abspath) {
|
|
98
|
+
try {
|
|
99
|
+
await fs.promises.stat(abspath);
|
|
100
|
+
return true;
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
//return new Promise(r=>fs.access(abspath, fs.constants.F_OK, e => r(!e)))
|
|
91
105
|
}
|
|
92
106
|
}
|
|
93
107
|
module.exports = Loader
|