functionalscript 0.0.480 → 0.0.481
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.
|
@@ -90,10 +90,10 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
|
90
90
|
}
|
|
91
91
|
// check package
|
|
92
92
|
const p = packageGet(moduleId.package)
|
|
93
|
-
if (p ===
|
|
93
|
+
if (p === null) { return notFound(moduleMap) }
|
|
94
94
|
// check file
|
|
95
95
|
const source = p.file(moduleId.path.join('/'))
|
|
96
|
-
return (source ===
|
|
96
|
+
return (source === null ? notFound : build(undefined)(moduleId)(source))(moduleMap)
|
|
97
97
|
}
|
|
98
98
|
return f
|
|
99
99
|
}
|
|
@@ -4,6 +4,7 @@ const module_ = require('../module/module.f.cjs')
|
|
|
4
4
|
const function_ = require('../module/function/module.f.cjs')
|
|
5
5
|
const result = require('../../types/result/module.f.cjs')
|
|
6
6
|
const package_ = require('../package/module.f.cjs')
|
|
7
|
+
const { at } = require('../../types/object/module.f.cjs')
|
|
7
8
|
|
|
8
9
|
/** @type {{ readonly [k in string]?: result.Result<function_.Function_, unknown> }} */
|
|
9
10
|
const compileMap = {
|
|
@@ -32,9 +33,9 @@ const compileMap = {
|
|
|
32
33
|
/** @type {function_.Compile} */
|
|
33
34
|
const compile = source => compileMap[source] ?? ['error', 'invalid source']
|
|
34
35
|
|
|
35
|
-
/** @typedef {{ readonly [k in string]
|
|
36
|
+
/** @typedef {{ readonly [k in string]: string }} StringMap */
|
|
36
37
|
|
|
37
|
-
/** @type {{ readonly [k in string]
|
|
38
|
+
/** @type {{ readonly [k in string]: { readonly dependencies: StringMap, readonly files: StringMap }}} */
|
|
38
39
|
const packageMap = {
|
|
39
40
|
'': {
|
|
40
41
|
dependencies: {
|
|
@@ -56,11 +57,11 @@ const packageMap = {
|
|
|
56
57
|
|
|
57
58
|
/** @type {package_.Get} */
|
|
58
59
|
const packageGet = packageId => {
|
|
59
|
-
const p = packageMap
|
|
60
|
-
return p ===
|
|
60
|
+
const p = at(packageId)(packageMap)
|
|
61
|
+
return p === null ? null :
|
|
61
62
|
{
|
|
62
|
-
dependency: dependency => p.dependencies
|
|
63
|
-
file: file => p.files
|
|
63
|
+
dependency: dependency => at(dependency)(p.dependencies),
|
|
64
|
+
file: file => at(file)(p.files),
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
|
|
@@ -22,14 +22,14 @@ const isPackageJson = j => {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* @typedef {{
|
|
25
|
-
* readonly dependency: (localPackageId: string) => string |
|
|
26
|
-
* readonly file: (localFileId: string) => string |
|
|
25
|
+
* readonly dependency: (localPackageId: string) => string | null
|
|
26
|
+
* readonly file: (localFileId: string) => string | null
|
|
27
27
|
* }} Package
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* @note Current package has an empty string '' as a packageId.
|
|
32
|
-
* @typedef {(packageId: string) => Package |
|
|
32
|
+
* @typedef {(packageId: string) => Package | null} Get
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
module.exports = {
|
|
@@ -80,10 +80,10 @@ const variants = prior => () => {
|
|
|
80
80
|
return { first: n, tail: variants(n) }
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/** @type {(d: (local: string) => string|
|
|
83
|
+
/** @type {(d: (local: string) => string|null) => (p: IdPath) => IdPath|undefined} */
|
|
84
84
|
const mapDependency = d => ([external, internal]) => {
|
|
85
85
|
const id = d(external)
|
|
86
|
-
return id ===
|
|
86
|
+
return id === null ? undefined : [id, internal]
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -95,10 +95,10 @@ const mapDependency = d => ([external, internal]) => {
|
|
|
95
95
|
*/
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
* @type {(d: (local: string) => string|
|
|
98
|
+
* @type {(d: (local: string) => string|null) =>
|
|
99
99
|
* (dir: boolean) =>
|
|
100
100
|
* (items: list.List<string>) =>
|
|
101
|
-
* Path|
|
|
101
|
+
* Path|null}
|
|
102
102
|
*/
|
|
103
103
|
const parseGlobal = dependencies =>
|
|
104
104
|
{
|
|
@@ -106,23 +106,23 @@ const parseGlobal = dependencies =>
|
|
|
106
106
|
return dir => items => {
|
|
107
107
|
const v = variants([null, items])
|
|
108
108
|
const r = firstNull(fMap(v))
|
|
109
|
-
if (r === null) { return
|
|
109
|
+
if (r === null) { return null }
|
|
110
110
|
return { package: r[0], items: toArray(r[1]), dir }
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* @type {(packageId: string) =>
|
|
116
|
-
* (dependencies: (local: string) => string|
|
|
116
|
+
* (dependencies: (local: string) => string|null) =>
|
|
117
117
|
* (local: string) =>
|
|
118
118
|
* (path: string) =>
|
|
119
|
-
* Path|
|
|
119
|
+
* Path|null }
|
|
120
120
|
*/
|
|
121
121
|
const parse = packageId => dependencies => {
|
|
122
122
|
const pg = parseGlobal(dependencies)
|
|
123
123
|
return local => path => {
|
|
124
124
|
const parsed = parseLocal(local)(path)
|
|
125
|
-
if (parsed === null) { return
|
|
125
|
+
if (parsed === null) { return null }
|
|
126
126
|
const {external, dir, items } = parsed
|
|
127
127
|
if (!external) { return { package: packageId, items, dir } }
|
|
128
128
|
return pg(dir)(items)
|
|
@@ -147,15 +147,15 @@ const parse = packageId => dependencies => {
|
|
|
147
147
|
*/
|
|
148
148
|
const parseAndFind = packageGet => moduleId => path => {
|
|
149
149
|
const currentPack = packageGet(moduleId.package)
|
|
150
|
-
if (currentPack ===
|
|
150
|
+
if (currentPack === null) { return null }
|
|
151
151
|
const p = parse(moduleId.package)(currentPack.dependency)(moduleId.path.join('/'))(path)
|
|
152
|
-
if (p ===
|
|
152
|
+
if (p === null) { return null }
|
|
153
153
|
const pack = packageGet(p.package)
|
|
154
|
-
if (pack ===
|
|
154
|
+
if (pack === null) { return null }
|
|
155
155
|
/** @type {(file: string) => FoundResult | undefined } */
|
|
156
156
|
const tryFile = file => {
|
|
157
157
|
const source = pack.file(file)
|
|
158
|
-
return source ===
|
|
158
|
+
return source === null ? undefined : { id: { package: p.package, path: file.split('/') }, source }
|
|
159
159
|
}
|
|
160
160
|
const file = p.items.join('/')
|
|
161
161
|
const indexJs = join('/')(concat(p.items)(['index.js']))
|
package/commonjs/path/test.f.cjs
CHANGED
|
@@ -6,11 +6,8 @@ const object = require('../../types/object/module.f.cjs')
|
|
|
6
6
|
const { at } = require('../../types/object/module.f.cjs')
|
|
7
7
|
const package_ = require('../package/module.f.cjs')
|
|
8
8
|
|
|
9
|
-
/** @type {<T>(o: object.Map<T>) => (s: string) => T|
|
|
10
|
-
const i = o => s =>
|
|
11
|
-
const r = at(s)(o)
|
|
12
|
-
return r === null ? undefined : r
|
|
13
|
-
}
|
|
9
|
+
/** @type {<T>(o: object.Map<T>) => (s: string) => T|null} */
|
|
10
|
+
const i = o => s => at(s)(o)
|
|
14
11
|
|
|
15
12
|
/** @type {(g: json.Unknown|undefined) => string} */
|
|
16
13
|
const stringify = g => {
|
|
@@ -51,27 +48,27 @@ module.exports = {
|
|
|
51
48
|
const result = _.parseLocal('')('./x/..')
|
|
52
49
|
if (stringify(result) !== '{"external":false,"dir":true,"items":[]}') { throw result }
|
|
53
50
|
},
|
|
54
|
-
8:
|
|
55
|
-
if (_.parseGlobal(() =>
|
|
56
|
-
if (_.parseGlobal(() =>
|
|
57
|
-
if (_.parseGlobal(i({ b: 'x' }))(false)(['d']) !==
|
|
58
|
-
{
|
|
51
|
+
8: {
|
|
52
|
+
0: () => { if (_.parseGlobal(() => null)(false)(['a', 'b']) !== null) { throw 'error' } },
|
|
53
|
+
1: () => { if (_.parseGlobal(() => null)(false)(['b']) !== null) { throw 'error' } },
|
|
54
|
+
2: () => { if (_.parseGlobal(i({ b: 'x' }))(false)(['d']) !== null) { throw 'error' } },
|
|
55
|
+
3: () => {
|
|
59
56
|
const result = stringify(_.parseGlobal(i({ b: 'x' }))(false)(['b']))
|
|
60
57
|
if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
|
|
61
|
-
}
|
|
62
|
-
if (_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b']) !==
|
|
63
|
-
{
|
|
58
|
+
},
|
|
59
|
+
4: () => { if (_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b']) !== null) { throw 'error' } },
|
|
60
|
+
5: () => {
|
|
64
61
|
const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r']))
|
|
65
62
|
if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
|
|
66
|
-
}
|
|
67
|
-
{
|
|
63
|
+
},
|
|
64
|
+
6: () => {
|
|
68
65
|
const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r', 'd', 't']))
|
|
69
66
|
if (result !== '{"package":"x","items":["d","t"],"dir":false}') { throw result }
|
|
70
|
-
}
|
|
71
|
-
{
|
|
67
|
+
},
|
|
68
|
+
7: () => {
|
|
72
69
|
const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(true)(['b', 'r', 'd', 't']))
|
|
73
70
|
if (result !== '{"package":"x","items":["d","t"],"dir":true}') { throw result }
|
|
74
|
-
}
|
|
71
|
+
},
|
|
75
72
|
},
|
|
76
73
|
9: () => {
|
|
77
74
|
/** @type {object.Map<package_.Package>} */
|
|
@@ -90,7 +87,7 @@ module.exports = {
|
|
|
90
87
|
'': {
|
|
91
88
|
dependency: x => {
|
|
92
89
|
const path = `node_modules/${x}`
|
|
93
|
-
return at(path)(packages) !==
|
|
90
|
+
return at(path)(packages) !== null ? path : null
|
|
94
91
|
},
|
|
95
92
|
file: i({
|
|
96
93
|
'index.js': 'return "index.js"',
|
|
@@ -140,7 +137,7 @@ module.exports = {
|
|
|
140
137
|
'': {
|
|
141
138
|
dependency: x => {
|
|
142
139
|
const path = `node_modules/${x}`
|
|
143
|
-
return at(path)(packages) !== null ? path :
|
|
140
|
+
return at(path)(packages) !== null ? path : null
|
|
144
141
|
},
|
|
145
142
|
file: todo
|
|
146
143
|
},
|
|
@@ -167,7 +164,7 @@ module.exports = {
|
|
|
167
164
|
'': {
|
|
168
165
|
dependency: x => {
|
|
169
166
|
const path = `node_modules/${x}`
|
|
170
|
-
return at(path)(packages) !== null ? path :
|
|
167
|
+
return at(path)(packages) !== null ? path : null
|
|
171
168
|
},
|
|
172
169
|
file: todo
|
|
173
170
|
},
|