functionalscript 0.0.479 → 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.
- package/commonjs/build/module.f.cjs +3 -3
- package/commonjs/build/test.f.cjs +33 -23
- package/commonjs/package/module.f.cjs +3 -3
- package/commonjs/path/module.f.cjs +34 -33
- package/commonjs/path/test.f.cjs +54 -52
- package/package.json +1 -1
- package/types/object/module.f.cjs +6 -3
- package/types/object/test.f.cjs +1 -1
|
@@ -58,7 +58,7 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
|
58
58
|
const error = e => [['error', e], [requireMap, m]]
|
|
59
59
|
if (moduleDir === null) { return error('file not found') }
|
|
60
60
|
const r = parseAndFind(packageGet)(moduleDir)(p)
|
|
61
|
-
if (r ===
|
|
61
|
+
if (r === null) { return error('file not found') }
|
|
62
62
|
const rIdStr = idToString(r.id)
|
|
63
63
|
if (setContains(rIdStr)(buildSet1)) { return error('circular reference') }
|
|
64
64
|
const [state, m1] = build(buildSet1)(r.id)(r.source)(m)
|
|
@@ -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 = {
|
|
@@ -11,11 +12,11 @@ const compileMap = {
|
|
|
11
12
|
'ok',
|
|
12
13
|
require_ => m0 => {
|
|
13
14
|
let [r, m] = require_('./b')(m0);
|
|
14
|
-
if (r[0] === 'error') { throw r }
|
|
15
|
+
if (r[0] === 'error') { throw JSON.stringify(r) }
|
|
15
16
|
[r, m] = require_('./a/')(m);
|
|
16
|
-
if (r[0] === 'error') { throw r }
|
|
17
|
+
if (r[0] === 'error') { throw JSON.stringify(r) }
|
|
17
18
|
[r, m] = require_('x/r')(m);
|
|
18
|
-
if (r[0] === 'error') { throw r }
|
|
19
|
+
if (r[0] === 'error') { throw JSON.stringify(r) }
|
|
19
20
|
return [['ok', ':index.js'], m]
|
|
20
21
|
}],
|
|
21
22
|
':b.js': [
|
|
@@ -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
|
|
|
@@ -71,21 +72,30 @@ const getOrBuild = _.getOrBuild
|
|
|
71
72
|
|
|
72
73
|
module.exports = () => {
|
|
73
74
|
let [r, m] = getOrBuild({ package: '', path: ['index.js'] })(undefined)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
{
|
|
76
|
+
const x = JSON.stringify(r)
|
|
77
|
+
if (x !==
|
|
78
|
+
'["ok",{"exports":":index.js","requireMap":{"./a/":"/a/index.js","./b":"/b.js","x/r":"/node_modules/x/r.js"}}]'
|
|
79
|
+
) {
|
|
80
|
+
throw x
|
|
81
|
+
}
|
|
78
82
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
{
|
|
84
|
+
[r, m] = getOrBuild({ package: '', path: ['b.js'] })(m)
|
|
85
|
+
const x = JSON.stringify(r)
|
|
86
|
+
if (x !==
|
|
87
|
+
'["ok",{"exports":":b.js","requireMap":{}}]'
|
|
88
|
+
) {
|
|
89
|
+
throw x
|
|
90
|
+
}
|
|
84
91
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
{
|
|
93
|
+
[r, m] = getOrBuild({ package: '', path: ['c.js'] })(m)
|
|
94
|
+
const x = JSON.stringify(r)
|
|
95
|
+
if (x !==
|
|
96
|
+
'["error",["file not found"]]'
|
|
97
|
+
) {
|
|
98
|
+
throw x
|
|
99
|
+
}
|
|
90
100
|
}
|
|
91
101
|
}
|
|
@@ -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 = {
|
|
@@ -17,17 +17,17 @@ const module_ = require("../module/module.f.cjs")
|
|
|
17
17
|
/** @type {(path: string) => readonly string[]} */
|
|
18
18
|
const split = path => path.split('/')
|
|
19
19
|
|
|
20
|
-
/** @typedef {readonly[list.List<string>] |
|
|
20
|
+
/** @typedef {readonly[list.List<string>] | null} OptionList */
|
|
21
21
|
|
|
22
22
|
/** @type {(items: string) => (prior: OptionList) => OptionList} */
|
|
23
23
|
const normItemsOp = first => prior => {
|
|
24
|
-
if (prior ===
|
|
24
|
+
if (prior === null) { return null }
|
|
25
25
|
const tail = prior[0]
|
|
26
26
|
switch (first) {
|
|
27
27
|
case '': case '.': { return prior }
|
|
28
28
|
case '..': {
|
|
29
29
|
const result = next(tail)
|
|
30
|
-
if (result ===
|
|
30
|
+
if (result === list.empty) { return null }
|
|
31
31
|
return [result.tail]
|
|
32
32
|
}
|
|
33
33
|
default: {
|
|
@@ -38,53 +38,52 @@ const normItemsOp = first => prior => {
|
|
|
38
38
|
|
|
39
39
|
/** @type {(items: list.List<string>) => OptionList} */
|
|
40
40
|
const normItems = items => {
|
|
41
|
-
const result = fold(normItemsOp)([
|
|
42
|
-
return result ===
|
|
41
|
+
const result = fold(normItemsOp)([list.empty])(items)
|
|
42
|
+
return result === null ? result : [reverse(result[0])]
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const firstNull = first(null)
|
|
46
46
|
|
|
47
|
-
/** @type {(local: string) => (path: string) => LocalPath|
|
|
47
|
+
/** @type {(local: string) => (path: string) => LocalPath|null} */
|
|
48
48
|
const parseLocal = local => {
|
|
49
49
|
/** @type {(path: string) => readonly[boolean, boolean, list.List<string>]} */
|
|
50
50
|
const fSeq = path => {
|
|
51
51
|
const pathSeq = split(path)
|
|
52
|
-
const dir = [
|
|
53
|
-
return /** @type {readonly (string|
|
|
52
|
+
const dir = [null, '', '.', '..'].includes(pathSeq[pathSeq.length - 1])
|
|
53
|
+
return /** @type {readonly (string|null)[]} */(['.', '..']).includes(firstNull(pathSeq)) ?
|
|
54
54
|
[false, dir, flat([split(local), pathSeq])] :
|
|
55
55
|
[true, dir, pathSeq]
|
|
56
56
|
}
|
|
57
|
-
/** @type {(path: string) => LocalPath|
|
|
58
|
-
|
|
57
|
+
// /** @type {(path: string) => LocalPath|null} */
|
|
58
|
+
return path => {
|
|
59
59
|
const [external, dir, items] = fSeq(path)
|
|
60
60
|
const n = normItems(items)
|
|
61
|
-
if (n ===
|
|
61
|
+
if (n === null) { return null }
|
|
62
62
|
return {
|
|
63
63
|
external,
|
|
64
64
|
dir,
|
|
65
65
|
items: toArray(n[0])
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
return f
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
/** @typedef {readonly[string, list.List<string>]} IdPath */
|
|
72
71
|
|
|
73
|
-
/** @type {(prior: readonly[string|
|
|
72
|
+
/** @type {(prior: readonly[string|null, list.List<string>]) => list.Thunk<IdPath>} */
|
|
74
73
|
const variants = prior => () => {
|
|
75
74
|
const [a, b] = prior
|
|
76
75
|
const r = next(b)
|
|
77
|
-
if (r ===
|
|
76
|
+
if (r === list.empty) { return list.empty }
|
|
78
77
|
const { first, tail } = r
|
|
79
78
|
/** @type {IdPath} */
|
|
80
|
-
const n = [a ===
|
|
79
|
+
const n = [a === null ? first : `${a}/${first}`, tail]
|
|
81
80
|
return { first: n, tail: variants(n) }
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
/** @type {(d: (local: string) => string|
|
|
83
|
+
/** @type {(d: (local: string) => string|null) => (p: IdPath) => IdPath|undefined} */
|
|
85
84
|
const mapDependency = d => ([external, internal]) => {
|
|
86
85
|
const id = d(external)
|
|
87
|
-
return id ===
|
|
86
|
+
return id === null ? undefined : [id, internal]
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
/**
|
|
@@ -96,34 +95,34 @@ const mapDependency = d => ([external, internal]) => {
|
|
|
96
95
|
*/
|
|
97
96
|
|
|
98
97
|
/**
|
|
99
|
-
* @type {(d: (local: string) => string|
|
|
98
|
+
* @type {(d: (local: string) => string|null) =>
|
|
100
99
|
* (dir: boolean) =>
|
|
101
100
|
* (items: list.List<string>) =>
|
|
102
|
-
* Path|
|
|
101
|
+
* Path|null}
|
|
103
102
|
*/
|
|
104
103
|
const parseGlobal = dependencies =>
|
|
105
104
|
{
|
|
106
105
|
const fMap = filterMap(mapDependency(dependencies))
|
|
107
106
|
return dir => items => {
|
|
108
|
-
const v = variants([
|
|
109
|
-
const r =
|
|
110
|
-
if (r ===
|
|
107
|
+
const v = variants([null, items])
|
|
108
|
+
const r = firstNull(fMap(v))
|
|
109
|
+
if (r === null) { return null }
|
|
111
110
|
return { package: r[0], items: toArray(r[1]), dir }
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
|
|
115
114
|
/**
|
|
116
115
|
* @type {(packageId: string) =>
|
|
117
|
-
* (dependencies: (local: string) => string|
|
|
116
|
+
* (dependencies: (local: string) => string|null) =>
|
|
118
117
|
* (local: string) =>
|
|
119
118
|
* (path: string) =>
|
|
120
|
-
* Path|
|
|
119
|
+
* Path|null }
|
|
121
120
|
*/
|
|
122
121
|
const parse = packageId => dependencies => {
|
|
123
122
|
const pg = parseGlobal(dependencies)
|
|
124
123
|
return local => path => {
|
|
125
124
|
const parsed = parseLocal(local)(path)
|
|
126
|
-
if (parsed ===
|
|
125
|
+
if (parsed === null) { return null }
|
|
127
126
|
const {external, dir, items } = parsed
|
|
128
127
|
if (!external) { return { package: packageId, items, dir } }
|
|
129
128
|
return pg(dir)(items)
|
|
@@ -134,9 +133,11 @@ const parse = packageId => dependencies => {
|
|
|
134
133
|
* @typedef {{
|
|
135
134
|
* readonly id: module_.Id
|
|
136
135
|
* readonly source: string
|
|
137
|
-
* }
|
|
136
|
+
* }} FoundResult
|
|
138
137
|
*/
|
|
139
138
|
|
|
139
|
+
/** @typedef {FoundResult| null} Result */
|
|
140
|
+
|
|
140
141
|
/**
|
|
141
142
|
* @type {(packageGet: package_.Get) =>
|
|
142
143
|
* (moduleId: module_.Id) =>
|
|
@@ -146,20 +147,20 @@ const parse = packageId => dependencies => {
|
|
|
146
147
|
*/
|
|
147
148
|
const parseAndFind = packageGet => moduleId => path => {
|
|
148
149
|
const currentPack = packageGet(moduleId.package)
|
|
149
|
-
if (currentPack ===
|
|
150
|
+
if (currentPack === null) { return null }
|
|
150
151
|
const p = parse(moduleId.package)(currentPack.dependency)(moduleId.path.join('/'))(path)
|
|
151
|
-
if (p ===
|
|
152
|
+
if (p === null) { return null }
|
|
152
153
|
const pack = packageGet(p.package)
|
|
153
|
-
if (pack ===
|
|
154
|
-
/** @type {(file: string) =>
|
|
154
|
+
if (pack === null) { return null }
|
|
155
|
+
/** @type {(file: string) => FoundResult | undefined } */
|
|
155
156
|
const tryFile = file => {
|
|
156
157
|
const source = pack.file(file)
|
|
157
|
-
return source ===
|
|
158
|
+
return source === null ? undefined : { id: { package: p.package, path: file.split('/') }, source }
|
|
158
159
|
}
|
|
159
160
|
const file = p.items.join('/')
|
|
160
161
|
const indexJs = join('/')(concat(p.items)(['index.js']))
|
|
161
162
|
const fileList = p.dir || isEmpty(p.items) ? [indexJs] : [file, `${file}.js`, indexJs]
|
|
162
|
-
return
|
|
163
|
+
return firstNull(filterMap(tryFile)(fileList))
|
|
163
164
|
}
|
|
164
165
|
|
|
165
166
|
module.exports = {
|
package/commonjs/path/test.f.cjs
CHANGED
|
@@ -6,88 +6,90 @@ 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|null} */
|
|
10
|
+
const i = o => s => at(s)(o)
|
|
11
|
+
|
|
9
12
|
/** @type {(g: json.Unknown|undefined) => string} */
|
|
10
13
|
const stringify = g => {
|
|
11
14
|
if (g === undefined) { throw g }
|
|
12
15
|
return json.stringify(identity)(g)
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
module.exports =
|
|
16
|
-
() => {
|
|
17
|
-
const p = { name: '', version: '' }
|
|
18
|
+
module.exports = {
|
|
19
|
+
0: () => {
|
|
18
20
|
const result = _.parseLocal('')('./a')
|
|
19
21
|
if (stringify(result) !== '{"external":false,"dir":false,"items":["a"]}') { throw result }
|
|
20
22
|
},
|
|
21
|
-
() => {
|
|
23
|
+
1: () => {
|
|
22
24
|
const result = _.parseLocal('')('./a/')
|
|
23
25
|
if (stringify(result) !== '{"external":false,"dir":true,"items":["a"]}') { throw result }
|
|
24
26
|
},
|
|
25
|
-
() => {
|
|
27
|
+
2: () => {
|
|
26
28
|
const result = _.parseLocal('')('..')
|
|
27
|
-
if (result !==
|
|
29
|
+
if (result !== null) { throw result }
|
|
28
30
|
},
|
|
29
|
-
() => {
|
|
31
|
+
3: () => {
|
|
30
32
|
const result = _.parseLocal('a')('')
|
|
31
33
|
if (stringify(result) !== '{"external":true,"dir":true,"items":[]}') { throw result }
|
|
32
34
|
},
|
|
33
|
-
() => {
|
|
35
|
+
4: () => {
|
|
34
36
|
const result = _.parseLocal('')('./a/b/.././c')
|
|
35
37
|
if (stringify(result) !== '{"external":false,"dir":false,"items":["a","c"]}') { throw result }
|
|
36
38
|
},
|
|
37
|
-
() => {
|
|
39
|
+
5: () => {
|
|
38
40
|
const result = _.parseLocal('x/r')('./a/b/.././c')
|
|
39
41
|
if (stringify(result) !== '{"external":false,"dir":false,"items":["x","r","a","c"]}') { throw result }
|
|
40
42
|
},
|
|
41
|
-
() => {
|
|
43
|
+
6: () => {
|
|
42
44
|
const result = _.parseLocal('a')('a/b/.././c')
|
|
43
45
|
if (stringify(result) !== '{"external":true,"dir":false,"items":["a","c"]}') { throw result }
|
|
44
46
|
},
|
|
45
|
-
() => {
|
|
47
|
+
7: () => {
|
|
46
48
|
const result = _.parseLocal('')('./x/..')
|
|
47
49
|
if (stringify(result) !== '{"external":false,"dir":true,"items":[]}') { throw result }
|
|
48
50
|
},
|
|
49
|
-
|
|
50
|
-
if (_.parseGlobal(() =>
|
|
51
|
-
if (_.parseGlobal(() =>
|
|
52
|
-
if (_.parseGlobal(
|
|
53
|
-
{
|
|
54
|
-
const result = stringify(_.parseGlobal(
|
|
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: () => {
|
|
56
|
+
const result = stringify(_.parseGlobal(i({ b: 'x' }))(false)(['b']))
|
|
55
57
|
if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
|
|
56
|
-
}
|
|
57
|
-
if (_.parseGlobal(
|
|
58
|
-
{
|
|
59
|
-
const result = stringify(_.parseGlobal(
|
|
58
|
+
},
|
|
59
|
+
4: () => { if (_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b']) !== null) { throw 'error' } },
|
|
60
|
+
5: () => {
|
|
61
|
+
const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r']))
|
|
60
62
|
if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
|
|
61
|
-
}
|
|
62
|
-
{
|
|
63
|
-
const result = stringify(_.parseGlobal(
|
|
63
|
+
},
|
|
64
|
+
6: () => {
|
|
65
|
+
const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r', 'd', 't']))
|
|
64
66
|
if (result !== '{"package":"x","items":["d","t"],"dir":false}') { throw result }
|
|
65
|
-
}
|
|
66
|
-
{
|
|
67
|
-
const result = stringify(_.parseGlobal(
|
|
67
|
+
},
|
|
68
|
+
7: () => {
|
|
69
|
+
const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(true)(['b', 'r', 'd', 't']))
|
|
68
70
|
if (result !== '{"package":"x","items":["d","t"],"dir":true}') { throw result }
|
|
69
|
-
}
|
|
71
|
+
},
|
|
70
72
|
},
|
|
71
|
-
() => {
|
|
73
|
+
9: () => {
|
|
72
74
|
/** @type {object.Map<package_.Package>} */
|
|
73
75
|
const packages = {
|
|
74
76
|
'': {
|
|
75
77
|
dependency: () => todo(),
|
|
76
|
-
file:
|
|
78
|
+
file: i({ 'a/c': 'return "a/c"' }),
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
const result = stringify(_.parseAndFind(
|
|
81
|
+
const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('../c'))
|
|
80
82
|
if (result !== '{"id":{"package":"","path":["a","c"]},"source":"return \\"a/c\\""}') { throw result }
|
|
81
83
|
},
|
|
82
|
-
() => {
|
|
84
|
+
10: () => {
|
|
83
85
|
/** @type {object.Map<package_.Package>} */
|
|
84
86
|
const packages = {
|
|
85
87
|
'': {
|
|
86
88
|
dependency: x => {
|
|
87
89
|
const path = `node_modules/${x}`
|
|
88
|
-
return at(path)(packages) !==
|
|
90
|
+
return at(path)(packages) !== null ? path : null
|
|
89
91
|
},
|
|
90
|
-
file:
|
|
92
|
+
file: i({
|
|
91
93
|
'index.js': 'return "index.js"',
|
|
92
94
|
'x/index.js': 'return "x/index.js"',
|
|
93
95
|
'x.js': 'return "x.js"',
|
|
@@ -95,87 +97,87 @@ module.exports = [
|
|
|
95
97
|
},
|
|
96
98
|
'node_modules/z': {
|
|
97
99
|
dependency: () => todo(),
|
|
98
|
-
file:
|
|
100
|
+
file: i({ 'a/c/index.js': 'return "a/c"' }),
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
{
|
|
102
|
-
const result = stringify(_.parseAndFind(
|
|
104
|
+
const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('z/a/c'))
|
|
103
105
|
if (result !== '{"id":{"package":"node_modules/z","path":["a","c","index.js"]},"source":"return \\"a/c\\""}') {
|
|
104
106
|
throw result
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
{
|
|
108
|
-
const result = stringify(_.parseAndFind(
|
|
110
|
+
const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('../..'))
|
|
109
111
|
if (result !== '{"id":{"package":"","path":["index.js"]},"source":"return \\"index.js\\""}') { throw result }
|
|
110
112
|
}
|
|
111
113
|
{
|
|
112
|
-
const result = stringify(_.parseAndFind(
|
|
114
|
+
const result = stringify(_.parseAndFind(i(packages))({ package: '', path: [] })('./x'))
|
|
113
115
|
if (result !== '{"id":{"package":"","path":["x.js"]},"source":"return \\"x.js\\""}') { throw result }
|
|
114
116
|
}
|
|
115
117
|
{
|
|
116
|
-
const result = stringify(_.parseAndFind(
|
|
118
|
+
const result = stringify(_.parseAndFind(i(packages))({ package: '', path: [] })('./x.js'))
|
|
117
119
|
if (result !== '{"id":{"package":"","path":["x.js"]},"source":"return \\"x.js\\""}') { throw result }
|
|
118
120
|
}
|
|
119
121
|
{
|
|
120
|
-
const result = stringify(_.parseAndFind(
|
|
122
|
+
const result = stringify(_.parseAndFind(i(packages))({ package: '', path: [] })('./x/'))
|
|
121
123
|
if (result !== '{"id":{"package":"","path":["x","index.js"]},"source":"return \\"x/index.js\\""}') { throw result }
|
|
122
124
|
}
|
|
123
125
|
{
|
|
124
|
-
const result = stringify(_.parseAndFind(
|
|
126
|
+
const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['x', 'a'] })('../'))
|
|
125
127
|
if (result !== '{"id":{"package":"","path":["x","index.js"]},"source":"return \\"x/index.js\\""}') { throw result }
|
|
126
128
|
}
|
|
127
129
|
{
|
|
128
|
-
const result = stringify(_.parseAndFind(
|
|
130
|
+
const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['x', 'a'] })('..'))
|
|
129
131
|
if (result !== '{"id":{"package":"","path":["x","index.js"]},"source":"return \\"x/index.js\\""}') { throw result }
|
|
130
132
|
}
|
|
131
133
|
},
|
|
132
|
-
() => {
|
|
134
|
+
11: () => {
|
|
133
135
|
/** @type {object.Map<package_.Package>} */
|
|
134
136
|
const packages = {
|
|
135
137
|
'': {
|
|
136
138
|
dependency: x => {
|
|
137
139
|
const path = `node_modules/${x}`
|
|
138
|
-
return at(path)(packages) !==
|
|
140
|
+
return at(path)(packages) !== null ? path : null
|
|
139
141
|
},
|
|
140
142
|
file: todo
|
|
141
143
|
},
|
|
142
144
|
'node_modules/z/a': {
|
|
143
145
|
dependency: () => todo(),
|
|
144
|
-
file:
|
|
146
|
+
file: i({
|
|
145
147
|
'c/index.js': 'return "c/index.js"',
|
|
146
148
|
'c.js': 'return "c.js"'
|
|
147
149
|
}),
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
{
|
|
151
|
-
const result = stringify(_.parseAndFind(
|
|
153
|
+
const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('z/a/c'))
|
|
152
154
|
if (result !== '{"id":{"package":"node_modules/z/a","path":["c.js"]},"source":"return \\"c.js\\""}') { throw result }
|
|
153
155
|
}
|
|
154
156
|
{
|
|
155
|
-
const result = stringify(_.parseAndFind(
|
|
157
|
+
const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('z/a/c/'))
|
|
156
158
|
if (result !== '{"id":{"package":"node_modules/z/a","path":["c","index.js"]},"source":"return \\"c/index.js\\""}') { throw result }
|
|
157
159
|
}
|
|
158
160
|
},
|
|
159
|
-
() => {
|
|
161
|
+
12: () => {
|
|
160
162
|
/** @type {object.Map<package_.Package>} */
|
|
161
163
|
const packages = {
|
|
162
164
|
'': {
|
|
163
165
|
dependency: x => {
|
|
164
166
|
const path = `node_modules/${x}`
|
|
165
|
-
return at(path)(packages) !==
|
|
167
|
+
return at(path)(packages) !== null ? path : null
|
|
166
168
|
},
|
|
167
169
|
file: todo
|
|
168
170
|
},
|
|
169
171
|
'node_modules/z/a/c': {
|
|
170
172
|
dependency: () => todo(),
|
|
171
|
-
file:
|
|
173
|
+
file: i({
|
|
172
174
|
'': 'throw',
|
|
173
175
|
'.js': 'throw',
|
|
174
176
|
'index.js': 'return "a/c"'
|
|
175
177
|
}),
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
|
-
const result = stringify(_.parseAndFind(
|
|
180
|
+
const result = stringify(_.parseAndFind(i(packages))({ package: '', path: ['a', 'b'] })('z/a/c'))
|
|
179
181
|
if (result !== '{"id":{"package":"node_modules/z/a/c","path":["index.js"]},"source":"return \\"a/c\\""}') { throw result }
|
|
180
182
|
}
|
|
181
|
-
|
|
183
|
+
}
|
package/package.json
CHANGED
|
@@ -16,8 +16,11 @@ const { getOwnPropertyDescriptor, fromEntries: objectFromEntries } = Object
|
|
|
16
16
|
* @typedef {readonly[string, T]} Entry
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
/** @type {(name: string) => <T>(object: Map<T>) => T|
|
|
20
|
-
const at = name => object =>
|
|
19
|
+
/** @type {(name: string) => <T>(object: Map<T>) => T|null} */
|
|
20
|
+
const at = name => object => {
|
|
21
|
+
const r = getOwnPropertyDescriptor(object, name)
|
|
22
|
+
return r === void 0 ? null : r.value
|
|
23
|
+
}
|
|
21
24
|
|
|
22
25
|
/** @type {<T>(e: list.List<Entry<T>>) => list.List<Entry<T>>} */
|
|
23
26
|
const sort = e => mapEntries(mapFromEntries(e))
|
|
@@ -26,7 +29,7 @@ const sort = e => mapEntries(mapFromEntries(e))
|
|
|
26
29
|
const fromEntries = e => objectFromEntries(iterable(e))
|
|
27
30
|
|
|
28
31
|
/** @type {<T>(m: map.Map<T>) => Map<T>} */
|
|
29
|
-
const fromMap =
|
|
32
|
+
const fromMap = m => fromEntries(mapEntries(m))
|
|
30
33
|
|
|
31
34
|
module.exports = {
|
|
32
35
|
/** @readonly */
|
package/types/object/test.f.cjs
CHANGED