functionalscript 0.0.425 → 0.0.426
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 +1 -1
- package/test.mjs +47 -17
package/package.json
CHANGED
package/test.mjs
CHANGED
|
@@ -21,7 +21,18 @@
|
|
|
21
21
|
/** @type {FsPromises} */
|
|
22
22
|
const { readdir, readFile } = await import(globalThis.Deno ? 'https://deno.land/std/node/fs/promises.ts' : 'node:fs/promises')
|
|
23
23
|
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {{
|
|
26
|
+
* [k: in string]?: Module
|
|
27
|
+
* }} Dependencies
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {{
|
|
32
|
+
* dependencies: Dependencies
|
|
33
|
+
* exports?: unknown
|
|
34
|
+
* }} Module
|
|
35
|
+
*/
|
|
25
36
|
|
|
26
37
|
/** @typedef {(name: string) => unknown} Require */
|
|
27
38
|
|
|
@@ -70,32 +81,42 @@ const map = await load()
|
|
|
70
81
|
|
|
71
82
|
/**
|
|
72
83
|
* @typedef {{
|
|
73
|
-
* [k in string]:
|
|
84
|
+
* [k in string]: Module
|
|
74
85
|
* }} ModuleMap
|
|
75
86
|
*/
|
|
76
87
|
|
|
77
88
|
const build = async () => {
|
|
78
89
|
/** @type {ModuleMap} */
|
|
79
90
|
const d = {}
|
|
80
|
-
/** @type {(base: readonly string[]) => (i: string) => (k: string) =>
|
|
81
|
-
const req =
|
|
91
|
+
/** @type {(base: readonly string[]) => (i: string) => (k: string) => readonly[string, Module]} */
|
|
92
|
+
const req = base => i => k => {
|
|
82
93
|
const relativePath = k.split('/')
|
|
83
94
|
const dif = relativePath.filter(v => v === '..').length
|
|
84
|
-
const path = [
|
|
95
|
+
const path = [base.slice(0, base.length - dif), relativePath.filter(v => !['..', '.'].includes(v))]
|
|
85
96
|
.flat()
|
|
86
97
|
const pathStr = path.join('/')
|
|
87
98
|
const newBase = path.slice(0, path.length - 1)
|
|
88
|
-
|
|
89
|
-
|
|
99
|
+
{
|
|
100
|
+
const module = d[pathStr]
|
|
101
|
+
if (module !== undefined) {
|
|
102
|
+
return [pathStr, module]
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
{
|
|
90
106
|
/** @type {Module} */
|
|
91
|
-
const
|
|
107
|
+
const module = {
|
|
108
|
+
dependencies: {}
|
|
109
|
+
}
|
|
92
110
|
console.log(`${i}building ${pathStr}`)
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
const getModule = req(newBase)(`${i}| `)
|
|
112
|
+
const newReq = s => {
|
|
113
|
+
const [p, result] = getModule(s)
|
|
114
|
+
module.dependencies[p] = result
|
|
115
|
+
return result.exports
|
|
116
|
+
}
|
|
117
|
+
map[pathStr](module, newReq)
|
|
118
|
+
d[pathStr] = module
|
|
119
|
+
return [pathStr, module]
|
|
99
120
|
}
|
|
100
121
|
}
|
|
101
122
|
const r = req(['.'])('')
|
|
@@ -107,6 +128,16 @@ const build = async () => {
|
|
|
107
128
|
|
|
108
129
|
const modules = await build()
|
|
109
130
|
|
|
131
|
+
// graph
|
|
132
|
+
|
|
133
|
+
for (const [k, v] of Object.entries(modules)) {
|
|
134
|
+
console.log(`: ${k}`)
|
|
135
|
+
console.log(Object.keys(v.dependencies))
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// test runner.
|
|
139
|
+
|
|
140
|
+
/** @type {(i: string) => (v: unknown) => void} */
|
|
110
141
|
const test = i => v => {
|
|
111
142
|
switch (typeof v) {
|
|
112
143
|
case 'function': {
|
|
@@ -124,9 +155,8 @@ const test = i => v => {
|
|
|
124
155
|
}
|
|
125
156
|
} else {
|
|
126
157
|
for (const [k, v2] of Object.entries(v)) {
|
|
127
|
-
const i2 = `${i}| `
|
|
128
158
|
console.log(`${i}${k}:`)
|
|
129
|
-
test(
|
|
159
|
+
test(`${i}| `)(v2)
|
|
130
160
|
}
|
|
131
161
|
}
|
|
132
162
|
return;
|
|
@@ -137,6 +167,6 @@ const test = i => v => {
|
|
|
137
167
|
for (const [k, v] of Object.entries(modules)) {
|
|
138
168
|
if (k.endsWith('test.f.cjs')) {
|
|
139
169
|
console.log(`testing ${k}`)
|
|
140
|
-
test('| ')(v)
|
|
170
|
+
test('| ')(v.exports)
|
|
141
171
|
}
|
|
142
172
|
}
|