functionalscript 0.3.15 → 0.4.0

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.
Files changed (47) hide show
  1. package/package.json +2 -3
  2. package/com/cpp/module.f.d.ts +0 -10
  3. package/com/cpp/module.f.js +0 -106
  4. package/com/cpp/test.f.d.ts +0 -2
  5. package/com/cpp/test.f.js +0 -40
  6. package/com/cpp/testlib.f.d.ts +0 -2
  7. package/com/cpp/testlib.f.js +0 -5
  8. package/com/cs/module.f.d.ts +0 -12
  9. package/com/cs/module.f.js +0 -79
  10. package/com/cs/test.f.d.ts +0 -2
  11. package/com/cs/test.f.js +0 -43
  12. package/com/cs/testlib.f.d.ts +0 -2
  13. package/com/cs/testlib.f.js +0 -5
  14. package/com/rust/module.f.d.ts +0 -15
  15. package/com/rust/module.f.js +0 -164
  16. package/com/rust/test.f.d.ts +0 -2
  17. package/com/rust/test.f.js +0 -123
  18. package/com/rust/testlib.f.d.ts +0 -2
  19. package/com/rust/testlib.f.js +0 -5
  20. package/com/test/build.f.d.ts +0 -20
  21. package/com/test/build.f.js +0 -58
  22. package/com/types/module.f.d.ts +0 -28
  23. package/com/types/module.f.js +0 -7
  24. package/com/types/testlib.f.d.ts +0 -44
  25. package/com/types/testlib.f.js +0 -28
  26. package/commonjs/build/module.f.d.ts +0 -6
  27. package/commonjs/build/module.f.js +0 -66
  28. package/commonjs/build/test.f.d.ts +0 -2
  29. package/commonjs/build/test.f.js +0 -92
  30. package/commonjs/module/function/module.f.d.ts +0 -8
  31. package/commonjs/module/function/module.f.js +0 -4
  32. package/commonjs/module/module.f.d.ts +0 -18
  33. package/commonjs/module/module.f.js +0 -11
  34. package/commonjs/module.f.d.ts +0 -6
  35. package/commonjs/module.f.js +0 -1
  36. package/commonjs/package/dependencies/module.f.d.ts +0 -7
  37. package/commonjs/package/dependencies/module.f.js +0 -13
  38. package/commonjs/package/dependencies/test.f.d.ts +0 -2
  39. package/commonjs/package/dependencies/test.f.js +0 -15
  40. package/commonjs/package/module.f.d.ts +0 -17
  41. package/commonjs/package/module.f.js +0 -18
  42. package/commonjs/package/test.f.d.ts +0 -2
  43. package/commonjs/package/test.f.js +0 -27
  44. package/commonjs/path/module.f.d.ts +0 -24
  45. package/commonjs/path/module.f.js +0 -112
  46. package/commonjs/path/test.f.d.ts +0 -25
  47. package/commonjs/path/test.f.js +0 -221
@@ -1,20 +0,0 @@
1
- import { type List } from '../../types/list/module.f.ts';
2
- type Platform = 'aix' | 'android' | 'darwin' | 'freebsd' | 'haiku' | 'linux' | 'openbsd' | 'sunos' | 'win32' | 'cygwin' | 'netbsd';
3
- type NodeJs = {
4
- readonly dirname: string;
5
- readonly platform: Platform;
6
- };
7
- type Output = {
8
- readonly file: {
9
- readonly name: string;
10
- readonly content: string;
11
- };
12
- readonly line: List<List<string>>;
13
- };
14
- export type Func = (nodejs: NodeJs) => Output;
15
- declare const _default: {
16
- cpp: Func;
17
- cs: Func;
18
- rust: Func;
19
- };
20
- export default _default;
@@ -1,58 +0,0 @@
1
- import { flat } from "../../types/list/module.f.js";
2
- import cppContent from "../cpp/testlib.f.js";
3
- import csContent from "../cs/testlib.f.js";
4
- import rustContent from "../rust/testlib.f.js";
5
- const flags = (platform) => {
6
- switch (platform) {
7
- case 'win32':
8
- return [];
9
- case 'linux':
10
- return ['-std=c++17', '-lstdc++', '-fPIC'];
11
- default:
12
- return ['-std=c++17', '-lc++'];
13
- }
14
- };
15
- const output = (platform) => (name) => {
16
- switch (platform) {
17
- case 'win32': return `${name}.dll`;
18
- case 'darwin': return `lib${name}.dylib`;
19
- default: return `lib${name}.so`;
20
- }
21
- };
22
- const cpp = ({ dirname, platform }) => ({
23
- file: {
24
- name: `${dirname}/cpp/_result.hpp`,
25
- content: cppContent(),
26
- },
27
- line: [
28
- flat([
29
- ['clang', '-shared', '-o', output(platform)('testc')],
30
- flags(platform),
31
- [`${dirname}/cpp/main.cpp`],
32
- ]),
33
- ],
34
- });
35
- const cs = ({ dirname, platform }) => ({
36
- file: {
37
- name: `${dirname}/cs/_result.cs`,
38
- content: csContent,
39
- },
40
- line: [
41
- platform === 'win32'
42
- ? ['dotnet', 'run', '--project', `${dirname}/cs/cs.csproj`]
43
- // .Net on Linux and MacOS doesn't properly support COM object marshalling
44
- : ['dotnet', 'build', `${dirname}/cs/cs.csproj`]
45
- ],
46
- });
47
- const rust = ({ dirname }) => ({
48
- file: {
49
- name: `${dirname}/rust/src/_result.rs`,
50
- content: rustContent,
51
- },
52
- line: [['cargo', 'build' /**, '--locked' */]]
53
- });
54
- export default {
55
- cpp,
56
- cs,
57
- rust,
58
- };
@@ -1,28 +0,0 @@
1
- import type * as O from '../../types/object/module.f.ts';
2
- import { type List } from '../../types/list/module.f.ts';
3
- export type Library = {
4
- readonly [k in string]: Definition;
5
- };
6
- export type Definition = Struct | Interface;
7
- export type Struct = {
8
- readonly struct: FieldArray;
9
- };
10
- export type FieldArray = {
11
- readonly [k in string]: Type;
12
- };
13
- export type Field = O.Entry<Type>;
14
- export type Interface = {
15
- readonly interface: MethodArray;
16
- readonly guid: string;
17
- };
18
- type MethodArray = {
19
- readonly [k in string]: FieldArray;
20
- };
21
- export type Method = O.Entry<FieldArray>;
22
- export type Type = BaseType | Id | Pointer;
23
- type Id = readonly [string];
24
- export type BaseType = 'u8' | 'i8' | 'u16' | 'i16' | 'u32' | 'i32' | 'u64' | 'i64' | 'usize' | 'isize' | 'f32' | 'f64' | 'bool';
25
- type Pointer = readonly ['*', Type];
26
- export declare const paramList: (fa: FieldArray) => List<Field>;
27
- export declare const result: <T>(v: T) => (f: (type: Type) => T) => (fa: FieldArray) => T;
28
- export {};
@@ -1,7 +0,0 @@
1
- import { filter } from "../../types/list/module.f.js";
2
- import { compose } from "../../types/function/module.f.js";
3
- const { entries } = Object;
4
- const isParam = ([name]) => name !== '_';
5
- const filterParam = filter(isParam);
6
- export const paramList = compose(entries)(filterParam);
7
- export const result = (v) => (f) => (fa) => '_' in fa ? f(fa._) : v;
@@ -1,44 +0,0 @@
1
- declare const _default: {
2
- Slice: {
3
- struct: {
4
- Start: ["*", "u8"];
5
- Size: "usize";
6
- };
7
- };
8
- ManagedStruct: {
9
- struct: {
10
- M: ["IMy"];
11
- };
12
- };
13
- IMy: {
14
- guid: string;
15
- interface: {
16
- GetSlice: {
17
- _: ["Slice"];
18
- };
19
- SetSlice: {
20
- slice: ["Slice"];
21
- };
22
- GetUnsafe: {
23
- _: ["*", "bool"];
24
- };
25
- SetUnsafe: {
26
- p: ["*", ["Slice"]];
27
- size: "u32";
28
- };
29
- Some: {
30
- p: ["IMy"];
31
- _: "bool";
32
- };
33
- GetIMy: {
34
- a: "u16";
35
- b: "i16";
36
- _: ["IMy"];
37
- };
38
- SetManagedStruct: {
39
- a: ["ManagedStruct"];
40
- };
41
- };
42
- };
43
- };
44
- export default _default;
@@ -1,28 +0,0 @@
1
- export default {
2
- Slice: {
3
- struct: {
4
- Start: ['*', 'u8'],
5
- Size: 'usize',
6
- },
7
- },
8
- ManagedStruct: {
9
- struct: {
10
- M: ['IMy']
11
- }
12
- },
13
- IMy: {
14
- guid: 'C66FB270-2D80-49AD-BB6E-88C1F90B805D',
15
- interface: {
16
- GetSlice: { _: ['Slice'] },
17
- SetSlice: { slice: ['Slice'] },
18
- GetUnsafe: { _: ['*', 'bool'] },
19
- SetUnsafe: {
20
- p: ['*', ['Slice']],
21
- size: 'u32'
22
- },
23
- Some: { p: ['IMy'], _: 'bool' },
24
- GetIMy: { a: 'u16', b: 'i16', _: ['IMy'] },
25
- SetManagedStruct: { a: ['ManagedStruct'] },
26
- },
27
- }
28
- };
@@ -1,6 +0,0 @@
1
- import type * as package_ from '../package/module.f.ts';
2
- import { type MapInterface, type Id, type State } from '../module/module.f.ts';
3
- import type * as function_ from '../module/function/module.f.ts';
4
- type Result<M> = readonly [State, M];
5
- export declare const getOrBuild: (compile: function_.Compile) => (packageGet: package_.Get) => <M>(moduleMapInterface: MapInterface<M>) => (moduleId: Id) => (moduleMap: M) => Result<M>;
6
- export {};
@@ -1,66 +0,0 @@
1
- import { idToString, dir, } from "../module/module.f.js";
2
- import { empty as mapEmpty, setReplace } from "../../types/map/module.f.js";
3
- import * as object from "../../types/object/module.f.js";
4
- const { fromMap } = object;
5
- import * as path from "../path/module.f.js";
6
- const { parseAndFind } = path;
7
- import * as stringSet from "../../types/string_set/module.f.js";
8
- const { set: setSet, contains: setContains, empty: stringSetEmpty } = stringSet;
9
- const notFound = (moduleMap) => [['error', ['file not found']], moduleMap];
10
- export const getOrBuild = compile => packageGet => moduleMapInterface => {
11
- const build = buildSet => moduleId => {
12
- const moduleIdStr = idToString(moduleId);
13
- const buildSet1 = setSet(moduleIdStr)(buildSet);
14
- const moduleDir = dir(moduleId);
15
- const require_ = p => ([requireMap, m]) => {
16
- const error = e => [['error', e], [requireMap, m]];
17
- if (moduleDir === null) {
18
- return error('file not found');
19
- }
20
- const r = parseAndFind(packageGet)(moduleDir)(p);
21
- if (r === null) {
22
- return error('file not found');
23
- }
24
- const rIdStr = idToString(r.id);
25
- if (setContains(rIdStr)(buildSet1)) {
26
- return error('circular reference');
27
- }
28
- const [state, m1] = build(buildSet1)(r.id)(r.source)(m);
29
- return [state[0] === 'error' ? state : ['ok', state[1].exports], [setReplace(p)(rIdStr)(requireMap), m1]];
30
- };
31
- return source => moduleMap => {
32
- const set = s => m => [s, moduleMapInterface.setReplace(moduleIdStr)(s)(m)];
33
- const error = e => set(['error', e]);
34
- // check compilation
35
- const [kind, result] = compile(source);
36
- if (kind === 'error') {
37
- return error(['compilation error', result])(moduleMap);
38
- }
39
- // build
40
- const [[state, value], [requireMap, moduleMap2]] = result(require_)([mapEmpty, moduleMap]);
41
- const x = state === 'error' ?
42
- error(['runtime error', value]) :
43
- set(['ok', { exports: value, requireMap: fromMap(requireMap) }]);
44
- return x(moduleMap2);
45
- };
46
- };
47
- const f = (moduleId) => (moduleMap) => {
48
- const moduleIdStr = idToString(moduleId);
49
- // check moduleMap
50
- {
51
- const m = moduleMapInterface.at(moduleIdStr)(moduleMap);
52
- if (m !== null) {
53
- return [m, moduleMap];
54
- }
55
- }
56
- // check package
57
- const p = packageGet(moduleId.package);
58
- if (p === null) {
59
- return notFound(moduleMap);
60
- }
61
- // check file
62
- const source = p.file(moduleId.path.join('/'));
63
- return (source === null ? notFound : build(stringSetEmpty)(moduleId)(source))(moduleMap);
64
- };
65
- return f;
66
- };
@@ -1,2 +0,0 @@
1
- declare const _default: () => void;
2
- export default _default;
@@ -1,92 +0,0 @@
1
- import * as _ from "./module.f.js";
2
- import * as map from "../../types/map/module.f.js";
3
- import { at } from "../../types/object/module.f.js";
4
- const compileMap = {
5
- ':index.js': [
6
- 'ok',
7
- require_ => m0 => {
8
- let [r, m] = require_('./b')(m0);
9
- if (r[0] === 'error') {
10
- throw JSON.stringify(r);
11
- }
12
- [r, m] = require_('./a/')(m);
13
- if (r[0] === 'error') {
14
- throw JSON.stringify(r);
15
- }
16
- [r, m] = require_('x/r')(m);
17
- if (r[0] === 'error') {
18
- throw JSON.stringify(r);
19
- }
20
- return [['ok', ':index.js'], m];
21
- }
22
- ],
23
- ':b.js': [
24
- 'ok',
25
- () => m0 => [['ok', ':b.js'], m0]
26
- ],
27
- ':a/index.js': [
28
- 'ok',
29
- () => m0 => [['ok', ':a/index.js'], m0]
30
- ],
31
- 'x:r.js': [
32
- 'ok',
33
- () => m0 => [['ok', 'x:r.js'], m0]
34
- ],
35
- };
36
- const compile = source => compileMap[source] ?? ['error', 'invalid source'];
37
- const packageMap = {
38
- '': {
39
- dependencies: {
40
- 'x': '/node_modules/x'
41
- },
42
- files: {
43
- 'index.js': ':index.js',
44
- 'b.js': ':b.js',
45
- 'a/index.js': ':a/index.js',
46
- }
47
- },
48
- '/node_modules/x': {
49
- dependencies: {},
50
- files: {
51
- 'r.js': 'x:r.js'
52
- }
53
- },
54
- };
55
- const packageGet = packageId => {
56
- const p = at(packageId)(packageMap);
57
- return p === null ? null :
58
- {
59
- dependency: dependency => at(dependency)(p.dependencies),
60
- file: file => at(file)(p.files),
61
- };
62
- };
63
- const getOrBuild = _.getOrBuild(compile)(packageGet)(map);
64
- export default () => {
65
- let [r, m] = getOrBuild({ package: '', path: ['index.js'] })(map.empty);
66
- {
67
- if (r === null) {
68
- throw 'r === null';
69
- }
70
- const x = JSON.stringify(r);
71
- if (x !==
72
- '["ok",{"exports":":index.js","requireMap":{"./a/":"/a/index.js","./b":"/b.js","x/r":"/node_modules/x/r.js"}}]') {
73
- throw `0:${x}`;
74
- }
75
- }
76
- {
77
- [r, m] = getOrBuild({ package: '', path: ['b.js'] })(m);
78
- const x = JSON.stringify(r);
79
- if (x !==
80
- '["ok",{"exports":":b.js","requireMap":{}}]') {
81
- throw x;
82
- }
83
- }
84
- {
85
- [r, m] = getOrBuild({ package: '', path: ['c.js'] })(m);
86
- const x = JSON.stringify(r);
87
- if (x !==
88
- '["error",["file not found"]]') {
89
- throw x;
90
- }
91
- }
92
- };
@@ -1,8 +0,0 @@
1
- /**
2
- * An IO interface for creating and running module functions.
3
- */
4
- import type * as TypesResult from '../../../types/result/module.f.ts';
5
- export type Function_ = <M>(require: Require<M>) => (prior: M) => Result<M>;
6
- export type Result<M> = readonly [TypesResult.Result<unknown, unknown>, M];
7
- export type Require<M> = (path: string) => (prior: M) => Result<M>;
8
- export type Compile = (source: string) => TypesResult.Result<Function_, unknown>;
@@ -1,4 +0,0 @@
1
- /**
2
- * An IO interface for creating and running module functions.
3
- */
4
- export {};
@@ -1,18 +0,0 @@
1
- import type * as O from '../../types/object/module.f.ts';
2
- export type MapInterface<M> = {
3
- readonly at: (moduleId: string) => (moduleMap: M) => State | null;
4
- readonly setReplace: (moduleId: string) => (moduleState: State) => (moduleMap: M) => M;
5
- };
6
- export type State = readonly ['ok', Module] | readonly ['error', Error];
7
- type Module = {
8
- readonly exports: unknown;
9
- readonly requireMap: O.Map<string>;
10
- };
11
- export type Error = ['file not found'] | ['compilation error', unknown] | ['runtime error', unknown] | ['circular reference'];
12
- export type Id = {
13
- readonly package: string;
14
- readonly path: readonly string[];
15
- };
16
- export declare const dir: (id: Id) => Id | null;
17
- export declare const idToString: (id: Id) => string;
18
- export {};
@@ -1,11 +0,0 @@
1
- export const dir = (id) => {
2
- const len = id.path.length;
3
- if (len < 1) {
4
- return null;
5
- }
6
- return {
7
- package: id.package,
8
- path: id.path.slice(0, len - 1)
9
- };
10
- };
11
- export const idToString = (id) => `${id.package}/${id.path.join('/')}`;
@@ -1,6 +0,0 @@
1
- type PackageMap = (packageName: string) => PackageMap | Package | null;
2
- type Package = readonly [
3
- string,
4
- PackageMap,
5
- (fileName: string) => string | null
6
- ];
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,7 +0,0 @@
1
- import { type Unknown } from '../../../json/module.f.ts';
2
- type DependencyMapJson = {
3
- readonly [k in string]: string;
4
- };
5
- export type DependenciesJson = DependencyMapJson | null;
6
- export declare const isDependenciesJson: (j: Unknown) => j is DependenciesJson;
7
- export {};
@@ -1,13 +0,0 @@
1
- import { isObject } from "../../../json/module.f.js";
2
- import { map, every } from "../../../types/list/module.f.js";
3
- const { entries } = Object;
4
- const isDependencyJson = ([, v]) => typeof v === 'string';
5
- export const isDependenciesJson = (j) => {
6
- if (j === null) {
7
- return true;
8
- }
9
- if (!isObject(j)) {
10
- return false;
11
- }
12
- return every(map(isDependencyJson)(entries(j)));
13
- };
@@ -1,2 +0,0 @@
1
- declare const _default: () => void;
2
- export default _default;
@@ -1,15 +0,0 @@
1
- import * as _ from "./module.f.js";
2
- export default () => {
3
- if (!_.isDependenciesJson(null)) {
4
- throw 'error';
5
- }
6
- if (!_.isDependenciesJson({})) {
7
- throw 'error';
8
- }
9
- if (!_.isDependenciesJson({ 'a': 'b' })) {
10
- throw 'error';
11
- }
12
- if (_.isDependenciesJson({ 'a': 12 })) {
13
- throw 'error';
14
- }
15
- };
@@ -1,17 +0,0 @@
1
- import { type Unknown } from '../../json/module.f.ts';
2
- import { type DependenciesJson } from './dependencies/module.f.ts';
3
- type PackageJson = {
4
- readonly name: string;
5
- readonly version: string;
6
- readonly dependencies?: DependenciesJson;
7
- };
8
- export declare const isPackageJson: (j: Unknown) => j is PackageJson;
9
- export type Package = {
10
- readonly dependency: (localPackageId: string) => string | null;
11
- readonly file: (localFileId: string) => string | null;
12
- };
13
- /**
14
- * @note Current package has an empty string '' as a packageId.
15
- */
16
- export type Get = (packageId: string) => Package | null;
17
- export {};
@@ -1,18 +0,0 @@
1
- import { isObject } from "../../json/module.f.js";
2
- import { isDependenciesJson } from "./dependencies/module.f.js";
3
- import { at } from "../../types/object/module.f.js";
4
- export const isPackageJson = (j) => {
5
- if (!isObject(j)) {
6
- return false;
7
- }
8
- if (typeof j.name !== 'string') {
9
- return false;
10
- }
11
- if (typeof j.version !== 'string') {
12
- return false;
13
- }
14
- if (!isDependenciesJson(at('dependencies')(j))) {
15
- return false;
16
- }
17
- return true;
18
- };
@@ -1,2 +0,0 @@
1
- declare const _default: () => void;
2
- export default _default;
@@ -1,27 +0,0 @@
1
- import * as _ from "./module.f.js";
2
- export default () => {
3
- if (_.isPackageJson(null)) {
4
- throw 'error';
5
- }
6
- if (_.isPackageJson({})) {
7
- throw 'error';
8
- }
9
- if (_.isPackageJson({ name: 'x', version: 12 })) {
10
- throw 'error';
11
- }
12
- if (!_.isPackageJson({ name: 'x', version: "12" })) {
13
- throw 'error';
14
- }
15
- if (_.isPackageJson({ version: "", dependencies: [] })) {
16
- throw 'error';
17
- }
18
- if (!_.isPackageJson({ name: 'a', version: "", dependencies: {} })) {
19
- throw 'error';
20
- }
21
- if (_.isPackageJson({ name: 'b', version: "", dependencies: { x: 12 } })) {
22
- throw 'error';
23
- }
24
- if (!_.isPackageJson({ name: 'c', version: "", dependencies: { x: "12" } })) {
25
- throw 'error';
26
- }
27
- };
@@ -1,24 +0,0 @@
1
- import { type List } from '../../types/list/module.f.ts';
2
- import type * as Package from '../package/module.f.ts';
3
- import type * as Module from '../module/module.f.ts';
4
- type Items = readonly string[];
5
- type LocalPath = {
6
- readonly external: boolean;
7
- readonly dir: boolean;
8
- readonly items: Items;
9
- };
10
- export declare const parseLocal: (local: string) => (path: string) => LocalPath | null;
11
- export type Path = {
12
- readonly package: string;
13
- readonly items: Items;
14
- readonly dir: boolean;
15
- };
16
- export declare const parseGlobal: (d: (local: string) => string | null) => (dir: boolean) => (items: List<string>) => Path | null;
17
- export declare const parse: (packageId: string) => (dependencies: (local: string) => string | null) => (local: string) => (path: string) => Path | null;
18
- export type FoundResult = {
19
- readonly id: Module.Id;
20
- readonly source: string;
21
- };
22
- export type Result = FoundResult | null;
23
- export declare const parseAndFind: (packageGet: Package.Get) => (moduleId: Module.Id) => (path: string) => Result;
24
- export {};
@@ -1,112 +0,0 @@
1
- import { next, fold, reverse, first, flat, toArray, filterMap, isEmpty, concat, empty } from "../../types/list/module.f.js";
2
- import { join } from "../../types/string/module.f.js";
3
- const split = path => path.split('/');
4
- const normItemsOp = (first) => (prior) => {
5
- if (prior === null) {
6
- return null;
7
- }
8
- const tail = prior[0];
9
- switch (first) {
10
- case '':
11
- case '.': {
12
- return prior;
13
- }
14
- case '..': {
15
- const result = next(tail);
16
- if (result === null) {
17
- return null;
18
- }
19
- return [result.tail];
20
- }
21
- default: {
22
- return [{ first, tail }];
23
- }
24
- }
25
- };
26
- const normItems = (items) => {
27
- const result = fold(normItemsOp)([empty])(items);
28
- return result === null ? result : [reverse(result[0])];
29
- };
30
- const firstNull = first(null);
31
- export const parseLocal = (local) => {
32
- const fSeq = (path) => {
33
- const pathSeq = split(path);
34
- const dir = [null, '', '.', '..'].includes(pathSeq[pathSeq.length - 1]);
35
- return ['.', '..'].includes(firstNull(pathSeq)) ?
36
- [false, dir, flat([split(local), pathSeq])] :
37
- [true, dir, pathSeq];
38
- };
39
- return path => {
40
- const [external, dir, items] = fSeq(path);
41
- const n = normItems(items);
42
- if (n === null) {
43
- return null;
44
- }
45
- return {
46
- external,
47
- dir,
48
- items: toArray(n[0])
49
- };
50
- };
51
- };
52
- const variants = (prior) => () => {
53
- const [a, b] = prior;
54
- const r = next(b);
55
- if (r === empty) {
56
- return empty;
57
- }
58
- const { first, tail } = r;
59
- const n = [a === null ? first : `${a}/${first}`, tail];
60
- return { first: n, tail: variants(n) };
61
- };
62
- const mapDependency = (d) => ([external, internal]) => {
63
- const id = d(external);
64
- return id === null ? null : [id, internal];
65
- };
66
- export const parseGlobal = dependencies => {
67
- const fMap = filterMap(mapDependency(dependencies));
68
- return dir => items => {
69
- const v = variants([null, items]);
70
- const r = firstNull(fMap(v));
71
- if (r === null) {
72
- return null;
73
- }
74
- return { package: r[0], items: toArray(r[1]), dir };
75
- };
76
- };
77
- export const parse = packageId => dependencies => {
78
- const pg = parseGlobal(dependencies);
79
- return local => path => {
80
- const parsed = parseLocal(local)(path);
81
- if (parsed === null) {
82
- return null;
83
- }
84
- const { external, dir, items } = parsed;
85
- if (!external) {
86
- return { package: packageId, items, dir };
87
- }
88
- return pg(dir)(items);
89
- };
90
- };
91
- export const parseAndFind = packageGet => moduleId => path => {
92
- const currentPack = packageGet(moduleId.package);
93
- if (currentPack === null) {
94
- return null;
95
- }
96
- const p = parse(moduleId.package)(currentPack.dependency)(moduleId.path.join('/'))(path);
97
- if (p === null) {
98
- return null;
99
- }
100
- const pack = packageGet(p.package);
101
- if (pack === null) {
102
- return null;
103
- }
104
- const tryFile = file => {
105
- const source = pack.file(file);
106
- return source === null ? null : { id: { package: p.package, path: file.split('/') }, source };
107
- };
108
- const file = p.items.join('/');
109
- const indexJs = join('/')(concat(p.items)(['index.js']));
110
- const fileList = p.dir || isEmpty(p.items) ? [indexJs] : [file, `${file}.js`, indexJs];
111
- return firstNull(filterMap(tryFile)(fileList));
112
- };