functionalscript 0.0.317 → 0.0.321
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/README.md +34 -5
- package/commonjs/build/index.js +46 -75
- package/commonjs/build/test.js +77 -0
- package/commonjs/module/index.js +16 -5
- package/commonjs/path/index.js +10 -12
- package/commonjs/path/test.js +28 -26
- package/package.json +1 -1
- package/test.js +1 -0
package/commonjs/README.md
CHANGED
|
@@ -3,7 +3,22 @@
|
|
|
3
3
|
```ts
|
|
4
4
|
// package/index.js
|
|
5
5
|
|
|
6
|
+
// A dictionary of packages.
|
|
7
|
+
//
|
|
8
|
+
// A package contains a dictionary of dependencies and a dictionary of files.
|
|
9
|
+
//
|
|
10
|
+
// `packageId` examples:
|
|
11
|
+
// - Node.js:
|
|
12
|
+
// - normalized: `./node_modules/functionalscript`
|
|
13
|
+
// - fs modules:
|
|
14
|
+
// - normalized: `github:functionalscript/functionalscript:bf4f3ed9ad1d3c19ee7bea3e76000dec77d01b4f`
|
|
15
|
+
// - `localPackageId` examples:
|
|
16
|
+
// - `functionalscript`
|
|
17
|
+
|
|
6
18
|
type PackageGet = (packageId: string) => Package | undefined
|
|
19
|
+
|
|
20
|
+
// A local file id is
|
|
21
|
+
|
|
7
22
|
type Package = {
|
|
8
23
|
// returns a global package id.
|
|
9
24
|
readonly dependency: (localPackageId: string) => string | undefined
|
|
@@ -13,21 +28,35 @@ type Package = {
|
|
|
13
28
|
|
|
14
29
|
// module/index.js
|
|
15
30
|
|
|
31
|
+
// A module map is a dictionary of modules.
|
|
32
|
+
//
|
|
33
|
+
// A module is a compiled and initialized source file.
|
|
34
|
+
|
|
35
|
+
type ModuleGet = (moduleId: string) => ModuleState | undefined
|
|
36
|
+
|
|
16
37
|
type ModuleMapInterface<M> = {
|
|
17
|
-
readonly
|
|
18
|
-
readonly insert: (
|
|
38
|
+
readonly get: (moduleMap: M) => ModuleGet
|
|
39
|
+
readonly insert: (moduleMap: M) => (moduleId: string) => (moduleState: ModuleState) => M
|
|
19
40
|
}
|
|
20
41
|
|
|
21
|
-
type ModuleState = readonly['ok', Module] | readonly['error', ModuleError]
|
|
42
|
+
type ModuleState = readonly['ok', Module] | readonly['error', ModuleError]
|
|
22
43
|
|
|
23
44
|
type Module = {
|
|
45
|
+
// Exports is a result of module initialization.
|
|
24
46
|
readonly exports: unknown
|
|
47
|
+
// A dictionary of required modules.
|
|
48
|
+
// For example, `require('functionalscript/types/list')` may produce the dictionary entry
|
|
49
|
+
// `['functionalscript/types/list', './node_modules/functionalscript/types/list/index.js']`
|
|
25
50
|
readonly requireMap: object.Map<string>
|
|
26
51
|
}
|
|
27
52
|
|
|
28
53
|
type ModuleError = 'file not found' | 'compile error' | 'runtime error' | 'circular reference'
|
|
29
54
|
|
|
30
|
-
|
|
55
|
+
// A module id is a global module id. It contains a package id and file id. For example
|
|
56
|
+
// - `./node_modules/functionalscript/types/list/index.js`
|
|
57
|
+
// - `github:functionalscript/functionalscript:bf4f3ed9ad1d3c19ee7bea3e76000dec77d01b4f/types/list/index.js`
|
|
58
|
+
|
|
59
|
+
type ModuleId = {
|
|
31
60
|
readonly packageId: string,
|
|
32
61
|
readonly path: readonly string[],
|
|
33
62
|
}
|
|
@@ -38,7 +67,7 @@ const moduleIdToString: (moduleId: ModuleId) => string;
|
|
|
38
67
|
|
|
39
68
|
type BuildConfig<M> = {
|
|
40
69
|
readonly packageGet: PackageGet
|
|
41
|
-
readonly moduleMapInterface: ModuleMapInterface<M>
|
|
70
|
+
readonly moduleMapInterface: ModuleMapInterface<M>
|
|
42
71
|
readonly moduleId: ModuleId
|
|
43
72
|
readonly moduleMap: M // mutable
|
|
44
73
|
}
|
package/commonjs/build/index.js
CHANGED
|
@@ -5,11 +5,12 @@ const { todo } = require('../../dev')
|
|
|
5
5
|
const map = require('../../types/map')
|
|
6
6
|
const object = require('../../types/object')
|
|
7
7
|
const path = require('../path')
|
|
8
|
+
const stringSet = require('../../types/stringSet')
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @template M
|
|
11
12
|
* @typedef {{
|
|
12
|
-
* readonly
|
|
13
|
+
* readonly packageGet: package_.Get
|
|
13
14
|
* readonly moduleMapInterface: module_.MapInterface<M>
|
|
14
15
|
* readonly moduleId: module_.Id
|
|
15
16
|
* readonly moduleMap: M
|
|
@@ -25,96 +26,66 @@ const path = require('../path')
|
|
|
25
26
|
const notFound = moduleMap => [['error', ['file not found']], moduleMap]
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
|
-
* @type {(
|
|
29
|
+
* @type {(compile: function_.Compile) =>
|
|
30
|
+
* (packageGet: package_.Get) =>
|
|
29
31
|
* <M>(moduleMapInterface: module_.MapInterface<M>) =>
|
|
30
|
-
* (compile: function_.Compile) =>
|
|
31
32
|
* (moduleId: module_.Id) =>
|
|
32
|
-
* (
|
|
33
|
+
* (moduleMap: M) =>
|
|
33
34
|
* Result<M>
|
|
34
35
|
* }
|
|
35
36
|
*/
|
|
36
|
-
const getOrBuild =
|
|
37
|
-
|
|
37
|
+
const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
38
38
|
/** @typedef {typeof moduleMapInterface extends module_.MapInterface<infer M> ? M : never} M */
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
(
|
|
59
|
-
(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// 'ok'
|
|
72
|
-
default: {
|
|
73
|
-
return todo()
|
|
74
|
-
}
|
|
40
|
+
/** @type {(buildSet: stringSet.StringSet) => (moduleId: module_.Id) => (source: string) => (moduleMap: M) => Result<M>} */
|
|
41
|
+
const build = buildSet => moduleId => {
|
|
42
|
+
const moduleIdStr = module_.idToString(moduleId)
|
|
43
|
+
const buildSet1 = stringSet.set(moduleIdStr)(buildSet)
|
|
44
|
+
const dir = module_.dir(moduleId)
|
|
45
|
+
/** @type {function_.Require<readonly[map.Map<string>, M]>} */
|
|
46
|
+
const require_ = p => ([requireMap, m]) => {
|
|
47
|
+
/** @type {(e: unknown) => function_.Result<readonly[map.Map<string>, M]>} */
|
|
48
|
+
const error = e => [['error', 'file not found'], [requireMap, m]]
|
|
49
|
+
if (dir === undefined) { return error('file not found') }
|
|
50
|
+
const r = path.parseAndFind(packageGet)(dir)(p)
|
|
51
|
+
if (r === undefined) { return error('file not found') }
|
|
52
|
+
const rIdStr = module_.idToString(r.id)
|
|
53
|
+
if (stringSet.contains(rIdStr)(buildSet1)) { return error('circular reference') }
|
|
54
|
+
const [state, m1] = build(buildSet1)(r.id)(r.source)(m)
|
|
55
|
+
return [state[0] === 'error' ? state : ['ok', state[1].exports], [map.set(p)(rIdStr)(requireMap), m1]]
|
|
56
|
+
}
|
|
57
|
+
return source => moduleMap => {
|
|
58
|
+
/** @type {(s: module_.State) => (m: M) => Result<M>} */
|
|
59
|
+
const set = s => m => [s, moduleMapInterface.set(moduleIdStr)(s)(m)]
|
|
60
|
+
/** @type {(e: module_.Error) => (m: M) => Result<M>} */
|
|
61
|
+
const error = e => set(['error', e])
|
|
62
|
+
// check compilation
|
|
63
|
+
const j = compile(source)
|
|
64
|
+
if (j[0] === 'error') { return error(['compilation error', j[1]])(moduleMap) }
|
|
65
|
+
// build
|
|
66
|
+
const [r, [requireMap, moduleMap2]] = j[1](require_)([undefined, moduleMap])
|
|
67
|
+
const x = r[0] === 'error' ?
|
|
68
|
+
error(['runtime error', r[1]]) :
|
|
69
|
+
set(['ok', { exports: r[1], requireMap: object.fromMap(requireMap) }])
|
|
70
|
+
return x(moduleMap2)
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
/** @type {(moduleId: module_.Id) => (moduleMap: M) => Result<M>} */
|
|
74
|
+
const f = moduleId => moduleMap => {
|
|
75
|
+
const moduleIdStr = module_.idToString(moduleId)
|
|
76
|
+
// check moduleMap
|
|
81
77
|
{
|
|
82
78
|
const m = moduleMapInterface.at(moduleIdStr)(moduleMap)
|
|
83
79
|
if (m !== undefined) { return [m, moduleMap] }
|
|
84
80
|
}
|
|
85
|
-
|
|
86
|
-
const p = packageGet(moduleId.
|
|
81
|
+
// check package
|
|
82
|
+
const p = packageGet(moduleId.package)
|
|
87
83
|
if (p === undefined) { return notFound(moduleMap) }
|
|
88
|
-
|
|
84
|
+
// check file
|
|
89
85
|
const source = p.file(moduleId.path.join('/'))
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const compileResult = compile(source)
|
|
93
|
-
if (compileResult[0] === 'error') { return error(['compilation error', compileResult[1]])(moduleMap) }
|
|
94
|
-
|
|
95
|
-
const moduleFunction = compileResult[1]
|
|
96
|
-
|
|
97
|
-
moduleMap = moduleMapInterface.insert(moduleIdStr)(['building'])(moduleMap)
|
|
98
|
-
|
|
99
|
-
const [[type, exportsOrError], [newModuleMap, requireMap]] = moduleFunction(require_)([moduleMap, map.empty])
|
|
100
|
-
moduleMap = newModuleMap
|
|
101
|
-
|
|
102
|
-
{
|
|
103
|
-
const m = moduleMapInterface.at(moduleIdStr)(moduleMap)
|
|
104
|
-
if (m === undefined ) { throw 'm === undefined' }
|
|
105
|
-
if (m[0] !== 'building') { return [m, moduleMap] }
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** @type {module_.State} */
|
|
109
|
-
const result = type === 'error' ?
|
|
110
|
-
['error', ['runtime error', exportsOrError]] :
|
|
111
|
-
['ok', {
|
|
112
|
-
exports: exportsOrError,
|
|
113
|
-
requireMap: object.fromMap(requireMap)
|
|
114
|
-
}]
|
|
115
|
-
|
|
116
|
-
return [result, moduleMapInterface.insert(moduleIdStr)(result)(moduleMap)]
|
|
86
|
+
return (source === undefined ? notFound : build(undefined)(moduleId)(source))(moduleMap)
|
|
117
87
|
}
|
|
88
|
+
return f
|
|
118
89
|
}
|
|
119
90
|
|
|
120
91
|
module.exports = {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const _ = require('.')
|
|
2
|
+
const map = require('../../types/map')
|
|
3
|
+
const module_ = require('../module')
|
|
4
|
+
const function_ = require('../module/function')
|
|
5
|
+
const result = require('../../types/result')
|
|
6
|
+
const package_ = require('../package')
|
|
7
|
+
|
|
8
|
+
/** @type {{ readonly [k in string]?: result.Result<function_.Function_, unknown> }} */
|
|
9
|
+
const compileMap = {
|
|
10
|
+
':index.js': [
|
|
11
|
+
'ok',
|
|
12
|
+
require_ => m0 => {
|
|
13
|
+
const [r1, m1] = require_('./b')(m0);
|
|
14
|
+
if (r1[0] === 'error') { throw r1 }
|
|
15
|
+
const [r2, m2] = require_('./a/')(m1);
|
|
16
|
+
if (r2[0] === 'error') { throw r2 }
|
|
17
|
+
const [r3, m3] = require_('x/r')(m2);
|
|
18
|
+
if (r3[0] === 'error') { throw r3 }
|
|
19
|
+
return [['ok', ':index.js'], m3]
|
|
20
|
+
}],
|
|
21
|
+
':b.js': [
|
|
22
|
+
'ok',
|
|
23
|
+
() => m0 => [['ok', ':b.js'], m0]],
|
|
24
|
+
':a/index.js': [
|
|
25
|
+
'ok',
|
|
26
|
+
() => m0 => [['ok', ':a/index.js'], m0]],
|
|
27
|
+
'x:r.js': [
|
|
28
|
+
'ok',
|
|
29
|
+
() => m0 => [['ok', 'x:r.js'], m0]],
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @type {function_.Compile} */
|
|
33
|
+
const compile = source => compileMap[source] ?? ['error', 'invalid source']
|
|
34
|
+
|
|
35
|
+
/** @type {{ readonly [k in string]?: { readonly dependencies: { readonly [k in string]?: string }, files:{ readonly [k in string]?: string } }}} */
|
|
36
|
+
const packageMap = {
|
|
37
|
+
'': {
|
|
38
|
+
dependencies: {
|
|
39
|
+
'x': 'x'
|
|
40
|
+
},
|
|
41
|
+
files: {
|
|
42
|
+
'index.js': ':index.js',
|
|
43
|
+
'b.js': ':b.js',
|
|
44
|
+
'a/index.js': ':a/index.js',
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
'x': {
|
|
48
|
+
dependencies: {},
|
|
49
|
+
files: {
|
|
50
|
+
'r.js': 'x:r.js'
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** @type {package_.Get} */
|
|
56
|
+
const packageGet = packageId => {
|
|
57
|
+
const p = packageMap[packageId]
|
|
58
|
+
if (p === undefined) { return undefined }
|
|
59
|
+
return {
|
|
60
|
+
dependency: dependency => p.dependencies[dependency],
|
|
61
|
+
file: file => p.files[file]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const getOrBuild = _.getOrBuild
|
|
66
|
+
(compile)
|
|
67
|
+
(packageGet)
|
|
68
|
+
(/** @type {module_.MapInterface<map.Map<module_.State>>} */(map))
|
|
69
|
+
|
|
70
|
+
{
|
|
71
|
+
const [r] = getOrBuild({ package: '', path: ['index.js'] })(undefined)
|
|
72
|
+
if (JSON.stringify(r) !==
|
|
73
|
+
'["ok",{"exports":":index.js","requireMap":{"./a/":"/a/index.js","./b":"/b.js","x/r":"x/r.js"}}]'
|
|
74
|
+
) {
|
|
75
|
+
throw r
|
|
76
|
+
}
|
|
77
|
+
}
|
package/commonjs/module/index.js
CHANGED
|
@@ -4,15 +4,14 @@ const object = require('../../types/object')
|
|
|
4
4
|
* @template M
|
|
5
5
|
* @typedef {{
|
|
6
6
|
* readonly at: (moduleId: string) => (moduleMap: M) => State | undefined
|
|
7
|
-
* readonly
|
|
7
|
+
* readonly set: (moduleId: string) => (moduleState: State) => (moduleMap: M) => M
|
|
8
8
|
* }} MapInterface
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @typedef {|
|
|
13
13
|
* readonly['ok', Module] |
|
|
14
|
-
* readonly['error', Error]
|
|
15
|
-
* readonly['building']
|
|
14
|
+
* readonly['error', Error]
|
|
16
15
|
* } State
|
|
17
16
|
*/
|
|
18
17
|
|
|
@@ -34,15 +33,27 @@ const object = require('../../types/object')
|
|
|
34
33
|
|
|
35
34
|
/**
|
|
36
35
|
* @typedef {{
|
|
37
|
-
* readonly
|
|
36
|
+
* readonly package: string
|
|
38
37
|
* readonly path: readonly string[]
|
|
39
38
|
* }} Id
|
|
40
39
|
*/
|
|
41
40
|
|
|
41
|
+
/** @type {(id: Id) => Id | undefined} */
|
|
42
|
+
const dir = id => {
|
|
43
|
+
const len = id.path.length
|
|
44
|
+
if (len < 1) { return undefined }
|
|
45
|
+
return {
|
|
46
|
+
package: id.package,
|
|
47
|
+
path: id.path.slice(0, len - 1)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
42
51
|
/** @type {(id: Id) => string} */
|
|
43
|
-
const idToString =
|
|
52
|
+
const idToString = id => `${id.package}/${id.path.join('/')}`
|
|
44
53
|
|
|
45
54
|
module.exports = {
|
|
55
|
+
/** @readonly */
|
|
56
|
+
dir,
|
|
46
57
|
/** @readonly */
|
|
47
58
|
idToString,
|
|
48
59
|
}
|
package/commonjs/path/index.js
CHANGED
|
@@ -89,7 +89,7 @@ const mapDependency = d => ([external, internal]) => {
|
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* @typedef {{
|
|
92
|
-
* readonly
|
|
92
|
+
* readonly package: string,
|
|
93
93
|
* readonly items: Items,
|
|
94
94
|
* readonly dir: boolean,
|
|
95
95
|
* }} Path
|
|
@@ -105,7 +105,7 @@ const parseGlobal = d => dir => items => {
|
|
|
105
105
|
const v = variants([undefined, items])
|
|
106
106
|
const r = list.first(undefined)(list.filterMap(mapDependency(d))(v))
|
|
107
107
|
if (r === undefined) { return undefined }
|
|
108
|
-
return {
|
|
108
|
+
return { package: r[0], items: list.toArray(r[1]), dir }
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/**
|
|
@@ -119,37 +119,35 @@ const parse = packageId => dependencies => local => path => {
|
|
|
119
119
|
const parsed = parseLocal(local)(path)
|
|
120
120
|
if (parsed === undefined) { return undefined }
|
|
121
121
|
const {external, dir, items } = parsed
|
|
122
|
-
if (!external) { return { packageId, items, dir } }
|
|
122
|
+
if (!external) { return { package: packageId, items, dir } }
|
|
123
123
|
return parseGlobal(dependencies)(dir)(items)
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
127
|
* @typedef {{
|
|
128
|
-
* readonly
|
|
129
|
-
* readonly file: string
|
|
128
|
+
* readonly id: module_.Id
|
|
130
129
|
* readonly source: string
|
|
131
130
|
* }| undefined} Result
|
|
132
131
|
*/
|
|
133
132
|
|
|
134
133
|
/**
|
|
135
134
|
* @type {(packageGet: package_.Get) =>
|
|
136
|
-
* (
|
|
137
|
-
* (local: string) =>
|
|
135
|
+
* (moduleId: module_.Id) =>
|
|
138
136
|
* (path: string) =>
|
|
139
137
|
* Result
|
|
140
138
|
* }
|
|
141
139
|
*/
|
|
142
|
-
const parseAndFind = packageGet =>
|
|
143
|
-
const currentPack = packageGet(
|
|
140
|
+
const parseAndFind = packageGet => moduleId => path => {
|
|
141
|
+
const currentPack = packageGet(moduleId.package)
|
|
144
142
|
if (currentPack === undefined) { return undefined }
|
|
145
|
-
const p = parse(
|
|
143
|
+
const p = parse(moduleId.package)(currentPack.dependency)(moduleId.path.join('/'))(path)
|
|
146
144
|
if (p === undefined) { return undefined }
|
|
147
|
-
const pack = packageGet(p.
|
|
145
|
+
const pack = packageGet(p.package)
|
|
148
146
|
if (pack === undefined) { return undefined }
|
|
149
147
|
/** @type {(file: string) => Result } */
|
|
150
148
|
const tryFile = file => {
|
|
151
149
|
const source = pack.file(file)
|
|
152
|
-
return source === undefined ? undefined : { package: p.
|
|
150
|
+
return source === undefined ? undefined : { id: { package: p.package, path: file.split('/') }, source }
|
|
153
151
|
}
|
|
154
152
|
const file = p.items.join('/')
|
|
155
153
|
const indexJs = list.join('/')(list.concat(p.items)(['index.js']))
|
package/commonjs/path/test.js
CHANGED
|
@@ -59,20 +59,20 @@ const stringify = g => {
|
|
|
59
59
|
if (_.parseGlobal(d => at(d)({ b: 'x' }))(false)(['d']) !== undefined) { throw 'error' }
|
|
60
60
|
{
|
|
61
61
|
const result = stringify(_.parseGlobal(d => at(d)({ b: 'x' }))(false)(['b']))
|
|
62
|
-
if (result !== '{"
|
|
62
|
+
if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
|
|
63
63
|
}
|
|
64
64
|
if (_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b']) !== undefined) { throw 'error' }
|
|
65
65
|
{
|
|
66
66
|
const result = stringify(_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b', 'r']))
|
|
67
|
-
if (result !== '{"
|
|
67
|
+
if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
|
|
68
68
|
}
|
|
69
69
|
{
|
|
70
70
|
const result = stringify(_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b', 'r', 'd', 't']))
|
|
71
|
-
if (result !== '{"
|
|
71
|
+
if (result !== '{"package":"x","items":["d","t"],"dir":false}') { throw result }
|
|
72
72
|
}
|
|
73
73
|
{
|
|
74
74
|
const result = stringify(_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(true)(['b', 'r', 'd', 't']))
|
|
75
|
-
if (result !== '{"
|
|
75
|
+
if (result !== '{"package":"x","items":["d","t"],"dir":true}') { throw result }
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -84,8 +84,8 @@ const stringify = g => {
|
|
|
84
84
|
file: path => at(path)({ 'a/c': 'return "a/c"' }),
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
const result = stringify(_.parseAndFind(p => at(p)(packages))(''
|
|
88
|
-
if (result !== '{"package":"","
|
|
87
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['a', 'b']})('../c'))
|
|
88
|
+
if (result !== '{"id":{"package":"","path":["a","c"]},"source":"return \\"a/c\\""}') { throw result }
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
{
|
|
@@ -108,32 +108,34 @@ const stringify = g => {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
{
|
|
111
|
-
const result = stringify(_.parseAndFind(p => at(p)(packages))(''
|
|
112
|
-
if (result !== '{"package":"node_modules/z","
|
|
111
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['a', 'b']})('z/a/c'))
|
|
112
|
+
if (result !== '{"id":{"package":"node_modules/z","path":["a","c","index.js"]},"source":"return \\"a/c\\""}') {
|
|
113
|
+
throw result
|
|
114
|
+
}
|
|
113
115
|
}
|
|
114
116
|
{
|
|
115
|
-
const result = stringify(_.parseAndFind(p => at(p)(packages))(''
|
|
116
|
-
if (result !== '{"package":"","
|
|
117
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['a', 'b']})('../..'))
|
|
118
|
+
if (result !== '{"id":{"package":"","path":["index.js"]},"source":"return \\"index.js\\""}') { throw result }
|
|
117
119
|
}
|
|
118
120
|
{
|
|
119
|
-
const result = stringify(_.parseAndFind(p => at(p)(packages))('')('
|
|
120
|
-
if (result !== '{"package":"","
|
|
121
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: []})('./x'))
|
|
122
|
+
if (result !== '{"id":{"package":"","path":["x.js"]},"source":"return \\"x.js\\""}') { throw result }
|
|
121
123
|
}
|
|
122
124
|
{
|
|
123
|
-
const result = stringify(_.parseAndFind(p => at(p)(packages))('')('
|
|
124
|
-
if (result !== '{"package":"","
|
|
125
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: []})('./x.js'))
|
|
126
|
+
if (result !== '{"id":{"package":"","path":["x.js"]},"source":"return \\"x.js\\""}') { throw result }
|
|
125
127
|
}
|
|
126
128
|
{
|
|
127
|
-
const result = stringify(_.parseAndFind(p => at(p)(packages))('')('
|
|
128
|
-
if (result !== '{"package":"","
|
|
129
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: []})('./x/'))
|
|
130
|
+
if (result !== '{"id":{"package":"","path":["x","index.js"]},"source":"return \\"x/index.js\\""}') { throw result }
|
|
129
131
|
}
|
|
130
132
|
{
|
|
131
|
-
const result = stringify(_.parseAndFind(p => at(p)(packages))(''
|
|
132
|
-
if (result !== '{"package":"","
|
|
133
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['x', 'a']})('../'))
|
|
134
|
+
if (result !== '{"id":{"package":"","path":["x","index.js"]},"source":"return \\"x/index.js\\""}') { throw result }
|
|
133
135
|
}
|
|
134
136
|
{
|
|
135
|
-
const result = stringify(_.parseAndFind(p => at(p)(packages))(''
|
|
136
|
-
if (result !== '{"package":"","
|
|
137
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['x', 'a']})('..'))
|
|
138
|
+
if (result !== '{"id":{"package":"","path":["x","index.js"]},"source":"return \\"x/index.js\\""}') { throw result }
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
141
|
|
|
@@ -156,12 +158,12 @@ const stringify = g => {
|
|
|
156
158
|
}
|
|
157
159
|
}
|
|
158
160
|
{
|
|
159
|
-
const result = stringify(_.parseAndFind(p => at(p)(packages))(''
|
|
160
|
-
if (result !== '{"package":"node_modules/z/a","
|
|
161
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['a', 'b']})('z/a/c'))
|
|
162
|
+
if (result !== '{"id":{"package":"node_modules/z/a","path":["c.js"]},"source":"return \\"c.js\\""}') { throw result }
|
|
161
163
|
}
|
|
162
164
|
{
|
|
163
|
-
const result = stringify(_.parseAndFind(p => at(p)(packages))(''
|
|
164
|
-
if (result !== '{"package":"node_modules/z/a","
|
|
165
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))({ package: '', path: ['a', 'b']})('z/a/c/'))
|
|
166
|
+
if (result !== '{"id":{"package":"node_modules/z/a","path":["c","index.js"]},"source":"return \\"c/index.js\\""}') { throw result }
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
|
|
@@ -184,6 +186,6 @@ const stringify = g => {
|
|
|
184
186
|
}),
|
|
185
187
|
}
|
|
186
188
|
}
|
|
187
|
-
const result = stringify(_.parseAndFind(p => at(p)(packages))(''
|
|
188
|
-
if (result !== '{"package":"node_modules/z/a/c","
|
|
189
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))({package: '', path: ['a', 'b']})('z/a/c'))
|
|
190
|
+
if (result !== '{"id":{"package":"node_modules/z/a/c","path":["index.js"]},"source":"return \\"a/c\\""}') { throw result }
|
|
189
191
|
}
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -12,6 +12,7 @@ require('./commonjs/package/test')
|
|
|
12
12
|
require('./commonjs/path/test')
|
|
13
13
|
require('./types/function/compare/test')
|
|
14
14
|
require('./types/stringSet/test')
|
|
15
|
+
require('./commonjs/build/test')
|
|
15
16
|
|
|
16
17
|
/** @type {() => never} */
|
|
17
18
|
const assert = () => { throw 'assert' }
|