pinokiod 3.9.13 → 3.9.15
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 +6 -0
- package/kernel/loader.js +8 -0
- package/package.json +1 -1
package/kernel/api/index.js
CHANGED
|
@@ -495,12 +495,15 @@ class Api {
|
|
|
495
495
|
let method
|
|
496
496
|
let dirname
|
|
497
497
|
let mod
|
|
498
|
+
console.log(">> resolveMethod", { req, cwd })
|
|
498
499
|
if (req.method && typeof req.method === "function") {
|
|
500
|
+
console.log(">> 1")
|
|
499
501
|
modpath = null
|
|
500
502
|
method = req.method
|
|
501
503
|
dirname = __dirname
|
|
502
504
|
mod = null
|
|
503
505
|
} else if (req.uri) {
|
|
506
|
+
console.log(">> 2")
|
|
504
507
|
modpath = this.resolvePath(cwd, req.uri)
|
|
505
508
|
let m = (await this.loader.load(modpath))
|
|
506
509
|
const stats = await fs.promises.stat(modpath)
|
|
@@ -532,6 +535,7 @@ class Api {
|
|
|
532
535
|
}
|
|
533
536
|
mod = m.resolved
|
|
534
537
|
dirname = m.dirname
|
|
538
|
+
console.log({ m })
|
|
535
539
|
method = mod[req.method].bind(mod)
|
|
536
540
|
} else {
|
|
537
541
|
// KERNEL
|
|
@@ -546,9 +550,11 @@ class Api {
|
|
|
546
550
|
}
|
|
547
551
|
method = mod[methodName].bind(mod)
|
|
548
552
|
} else {
|
|
553
|
+
console.log(">> 3")
|
|
549
554
|
if (chunks.length === 1) {
|
|
550
555
|
let methodName = chunks[0]
|
|
551
556
|
modpath = path.resolve(__dirname, methodName)
|
|
557
|
+
console.log({ modpath })
|
|
552
558
|
mod = (await this.loader.load(modpath))
|
|
553
559
|
method = mod.resolved
|
|
554
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
|
}
|