noflo 1.4.3 → 1.5.1
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/.ecrc +3 -0
- package/.eslintignore +2 -0
- package/{CHANGES.md → CHANGELOG.md} +527 -527
- package/README.md +1 -1
- package/bin/noflo-cache-preheat +4 -4
- package/components/Graph.d.ts +50 -15
- package/components/Graph.js +94 -68
- package/examples/http/HelloController.js +9 -6
- package/examples/spreadsheet/parse.fbp +3 -3
- package/lib/AsCallback.d.ts +22 -9
- package/lib/AsCallback.js +69 -18
- package/lib/AsComponent.d.ts +1 -1
- package/lib/AsComponent.js +5 -3
- package/lib/BaseNetwork.d.ts +16 -6
- package/lib/BaseNetwork.js +65 -31
- package/lib/BasePort.d.ts +39 -12
- package/lib/BasePort.js +34 -6
- package/lib/Component.d.ts +8 -8
- package/lib/Component.js +23 -20
- package/lib/ComponentLoader.d.ts +3 -4
- package/lib/ComponentLoader.js +9 -10
- package/lib/IP.d.ts +12 -8
- package/lib/IP.js +6 -4
- package/lib/InPort.d.ts +64 -9
- package/lib/InPort.js +72 -13
- package/lib/InternalSocket.d.ts +53 -7
- package/lib/InternalSocket.js +51 -14
- package/lib/LegacyNetwork.d.ts +12 -2
- package/lib/LegacyNetwork.js +5 -5
- package/lib/Network.d.ts +13 -2
- package/lib/Network.js +10 -10
- package/lib/NoFlo.d.ts +48 -13
- package/lib/NoFlo.js +55 -27
- package/lib/OutPort.d.ts +64 -13
- package/lib/OutPort.js +73 -15
- package/lib/Platform.d.ts +1 -1
- package/lib/Platform.js +9 -4
- package/lib/Ports.d.ts +11 -12
- package/lib/Ports.js +8 -4
- package/lib/ProcessInput.d.ts +5 -9
- package/lib/ProcessInput.js +8 -9
- package/lib/ProcessOutput.d.ts +2 -2
- package/lib/ProcessOutput.js +5 -5
- package/lib/loader/NodeJs.d.ts +0 -1
- package/lib/loader/NodeJs.js +152 -161
- package/lib/loader/register.d.ts +1 -1
- package/lib/loader/register.js +8 -4
- package/package.json +25 -16
- package/spec/.eslintrc +5 -2
- package/spec/AsCallback.js +9 -13
- package/spec/AsComponent.js +10 -4
- package/spec/AsPromise.js +38 -0
- package/spec/CommonJS.cjs +10 -0
- package/spec/ComponentLoader.js +19 -7
- package/spec/ESModule.mjs +11 -0
- package/spec/Network.js +32 -11
- package/spec/NetworkSync.js +892 -0
- package/spec/Scoping.js +27 -42
- package/spec/Subgraph.js +6 -11
- package/spec/fixtures/componentloader/components/Output.js +1 -1
- package/spec/fixtures/componentloader/components/Repeat.ts +1 -1
- package/spec/fixtures/componentloader/components/RepeatAsync.coffee +1 -1
- package/spec/fixtures/componentloader/node_modules/example/components/Forward.js +1 -1
- package/spec/fixtures/componentloader/node_modules/example/package.json +1 -1
- package/spec/fixtures/componentloader/package.json +2 -1
- package/spec/fixtures/componentloader/spec/Repeat.yaml +1 -1
- package/spec/utils/inject.js +1 -1
- package/src/.eslintrc +9 -2
- package/src/components/Graph.js +105 -71
- package/src/lib/AsCallback.js +71 -16
- package/src/lib/AsComponent.js +5 -4
- package/src/lib/BaseNetwork.js +48 -15
- package/src/lib/BasePort.js +43 -9
- package/src/lib/Component.js +8 -8
- package/src/lib/ComponentLoader.js +3 -4
- package/src/lib/IP.js +7 -4
- package/src/lib/InPort.js +74 -13
- package/src/lib/InternalSocket.js +49 -9
- package/src/lib/LegacyNetwork.js +2 -2
- package/src/lib/Network.js +2 -2
- package/src/lib/NoFlo.js +43 -13
- package/src/lib/OutPort.js +77 -14
- package/src/lib/Platform.js +9 -4
- package/src/lib/Ports.js +6 -2
- package/src/lib/ProcessInput.js +7 -9
- package/src/lib/ProcessOutput.js +1 -1
- package/src/lib/loader/NodeJs.js +185 -178
- package/src/lib/loader/register.js +2 -2
- /package/{karma.config.js → karma.config.cjs} +0 -0
- /package/{webpack.config.js → webpack.config.cjs} +0 -0
package/lib/ProcessOutput.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export default class ProcessOutput {
|
|
|
6
6
|
constructor(ports: import("./Ports").OutPorts, context: import("./ProcessContext").default);
|
|
7
7
|
ports: import("./Ports").OutPorts;
|
|
8
8
|
context: import("./ProcessContext").default;
|
|
9
|
-
nodeInstance: import("./Component").Component;
|
|
9
|
+
nodeInstance: import("./Component.js").Component;
|
|
10
10
|
ip: IP;
|
|
11
11
|
result: {
|
|
12
12
|
[x: string]: any;
|
|
@@ -47,4 +47,4 @@ export default class ProcessOutput {
|
|
|
47
47
|
*/
|
|
48
48
|
done(error?: Error | Array<Error>): void;
|
|
49
49
|
}
|
|
50
|
-
import IP from "./IP";
|
|
50
|
+
import IP from "./IP.js";
|
package/lib/ProcessOutput.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
/* eslint-disable no-underscore-dangle */
|
|
8
8
|
const debug_1 = require("debug");
|
|
9
|
-
const
|
|
10
|
-
const debugComponent = debug_1.default('noflo:component');
|
|
9
|
+
const IP_js_1 = require("./IP.js");
|
|
10
|
+
const debugComponent = (0, debug_1.default)('noflo:component');
|
|
11
11
|
// Checks if a value is an Error
|
|
12
12
|
/**
|
|
13
13
|
* @param {any} err
|
|
@@ -40,11 +40,11 @@ class ProcessOutput {
|
|
|
40
40
|
if (this.ports.ports.error
|
|
41
41
|
&& (this.ports.ports.error.isAttached() || !this.ports.ports.error.isRequired())) {
|
|
42
42
|
if (errs.length > 1) {
|
|
43
|
-
this.sendIP('error', new
|
|
43
|
+
this.sendIP('error', new IP_js_1.default('openBracket'));
|
|
44
44
|
}
|
|
45
45
|
errs.forEach((e) => { this.sendIP('error', e); });
|
|
46
46
|
if (errs.length > 1) {
|
|
47
|
-
this.sendIP('error', new
|
|
47
|
+
this.sendIP('error', new IP_js_1.default('closeBracket'));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
@@ -58,7 +58,7 @@ class ProcessOutput {
|
|
|
58
58
|
* @returns {void}
|
|
59
59
|
*/
|
|
60
60
|
sendIP(port, packet) {
|
|
61
|
-
const ip =
|
|
61
|
+
const ip = IP_js_1.default.isIP(packet) ? packet : new IP_js_1.default('data', packet);
|
|
62
62
|
if ((this.scope !== null) && (ip.scope === null)) {
|
|
63
63
|
ip.scope = this.scope;
|
|
64
64
|
}
|
package/lib/loader/NodeJs.d.ts
CHANGED
|
@@ -55,7 +55,6 @@ export function register(loader: import("../ComponentLoader").ComponentLoader, c
|
|
|
55
55
|
export function dynamicLoad(name: string, cPath: string, metadata: any, callback: ModuleLoadingCallback): void;
|
|
56
56
|
export type ErrorableCallback = (error: Error | null) => any;
|
|
57
57
|
export type TranspileCallback = (error: Error | null, source?: string) => void;
|
|
58
|
-
export type EvaluationCallback = (error: Error | null, module?: any | Function) => void;
|
|
59
58
|
export type SourceCallback = (error: Error | null, source?: any, name?: string, library?: string, code?: string, language?: string, tests?: string) => void;
|
|
60
59
|
export type RegistrationCallback = (error: Error | null, modules?: {
|
|
61
60
|
[x: string]: string;
|
package/lib/loader/NodeJs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.dynamicLoad = exports.register = exports.getLanguages = exports.getSource = exports.setSource = void 0;
|
|
4
5
|
/* eslint-disable
|
|
@@ -11,25 +12,29 @@ const path = require("path");
|
|
|
11
12
|
const fs = require("fs");
|
|
12
13
|
const manifest = require("fbp-manifest");
|
|
13
14
|
const fbpGraph = require("fbp-graph");
|
|
14
|
-
const
|
|
15
|
+
const util_1 = require("util");
|
|
16
|
+
const utils = require("../Utils.js");
|
|
17
|
+
const writeFile = (0, util_1.promisify)(fs.writeFile);
|
|
18
|
+
const readFile = (0, util_1.promisify)(fs.readFile);
|
|
15
19
|
// Type loading CoffeeScript compiler
|
|
16
20
|
let CoffeeScript;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
CoffeeScript =
|
|
20
|
-
}
|
|
21
|
-
catch
|
|
21
|
+
// eslint-disable-next-line import/no-unresolved,import/no-extraneous-dependencies
|
|
22
|
+
Promise.resolve().then(() => require('coffeescript')).then((compiler) => {
|
|
23
|
+
CoffeeScript = compiler;
|
|
24
|
+
})
|
|
25
|
+
.catch((e) => {
|
|
22
26
|
// If there is no CoffeeScript compiler installed, we simply don't support compiling
|
|
23
|
-
}
|
|
27
|
+
});
|
|
24
28
|
// Try loading TypeScript compiler
|
|
25
29
|
let typescript;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
// eslint-disable-next-line import/no-unresolved,import/no-extraneous-dependencies
|
|
31
|
+
Promise.resolve().then(() => require('typescript')).then((compiler) => {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
typescript = compiler.default;
|
|
34
|
+
})
|
|
35
|
+
.catch((e) => {
|
|
31
36
|
// If there is no TypeScript compiler installed, we simply don't support compiling
|
|
32
|
-
}
|
|
37
|
+
});
|
|
33
38
|
/**
|
|
34
39
|
* @callback ErrorableCallback
|
|
35
40
|
* @param {Error|null} error
|
|
@@ -45,15 +50,14 @@ catch (e) {
|
|
|
45
50
|
* @param {string} name
|
|
46
51
|
* @param {string} source
|
|
47
52
|
* @param {string} language
|
|
48
|
-
* @
|
|
49
|
-
* @returns {void}
|
|
53
|
+
* @returns {Promise<string>}
|
|
50
54
|
*/
|
|
51
|
-
function transpileSource(packageId, name, source, language
|
|
55
|
+
function transpileSource(packageId, name, source, language) {
|
|
52
56
|
let src;
|
|
53
57
|
switch (language) {
|
|
54
58
|
case 'coffeescript': {
|
|
55
59
|
if (!CoffeeScript) {
|
|
56
|
-
|
|
60
|
+
return Promise.reject(new Error(`Unsupported component source language ${language} for ${packageId}/${name}: no CoffeeScript compiler installed`));
|
|
57
61
|
}
|
|
58
62
|
try {
|
|
59
63
|
src = CoffeeScript.compile(source, {
|
|
@@ -61,24 +65,22 @@ function transpileSource(packageId, name, source, language, callback) {
|
|
|
61
65
|
});
|
|
62
66
|
}
|
|
63
67
|
catch (err) {
|
|
64
|
-
|
|
65
|
-
return;
|
|
68
|
+
return Promise.reject(err);
|
|
66
69
|
}
|
|
67
70
|
break;
|
|
68
71
|
}
|
|
69
72
|
case 'typescript': {
|
|
70
73
|
if (!typescript) {
|
|
71
|
-
|
|
74
|
+
return Promise.reject(new Error(`Unsupported component source language ${language} for ${packageId}/${name}: no TypeScript compiler installed`));
|
|
72
75
|
}
|
|
73
76
|
try {
|
|
74
77
|
src = typescript.transpile(source, {
|
|
75
78
|
module: typescript.ModuleKind.CommonJS,
|
|
76
|
-
target: typescript.ScriptTarget.
|
|
79
|
+
target: typescript.ScriptTarget.ES2020,
|
|
77
80
|
});
|
|
78
81
|
}
|
|
79
82
|
catch (err) {
|
|
80
|
-
|
|
81
|
-
return;
|
|
83
|
+
return Promise.reject(err);
|
|
82
84
|
}
|
|
83
85
|
break;
|
|
84
86
|
}
|
|
@@ -90,49 +92,40 @@ function transpileSource(packageId, name, source, language, callback) {
|
|
|
90
92
|
break;
|
|
91
93
|
}
|
|
92
94
|
default: {
|
|
93
|
-
|
|
94
|
-
return;
|
|
95
|
+
return Promise.reject(new Error(`Unsupported component source language ${language} for ${packageId}/${name}`));
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
+
return Promise.resolve(src);
|
|
98
99
|
}
|
|
99
|
-
/**
|
|
100
|
-
* @callback EvaluationCallback
|
|
101
|
-
* @param {Error|null} error
|
|
102
|
-
* @param {Object|Function} [module]
|
|
103
|
-
* @returns {void}
|
|
104
|
-
*/
|
|
105
100
|
/**
|
|
106
101
|
* @param {string} baseDir
|
|
107
102
|
* @param {string} packageId
|
|
108
103
|
* @param {string} name
|
|
109
104
|
* @param {string} source
|
|
110
|
-
* @
|
|
111
|
-
* @returns {void}
|
|
105
|
+
* @returns {Promise<Object|Function>}
|
|
112
106
|
*/
|
|
113
|
-
function evaluateModule(baseDir, packageId, name, source
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
try {
|
|
107
|
+
function evaluateModule(baseDir, packageId, name, source) {
|
|
108
|
+
return Promise.resolve().then(() => require('module')).then(({ Module }) => {
|
|
109
|
+
let implementation;
|
|
117
110
|
// Use the Node.js module API to evaluate in the correct directory context
|
|
118
|
-
|
|
119
|
-
|
|
111
|
+
let extension = '.js';
|
|
112
|
+
if (source.indexOf('require(') !== -1) {
|
|
113
|
+
// CommonJS
|
|
114
|
+
extension = '.cjs';
|
|
115
|
+
}
|
|
116
|
+
const modulePath = path.resolve(baseDir, `./components/${name}${extension}`);
|
|
117
|
+
const moduleImpl = new Module(modulePath);
|
|
120
118
|
// @ts-ignore
|
|
121
119
|
moduleImpl.paths = Module._nodeModulePaths(path.dirname(modulePath));
|
|
122
120
|
moduleImpl.filename = modulePath;
|
|
123
121
|
// @ts-ignore
|
|
124
122
|
moduleImpl._compile(source, modulePath);
|
|
125
123
|
implementation = moduleImpl.exports;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if ((typeof implementation !== 'function') && (typeof implementation.getComponent !== 'function')) {
|
|
132
|
-
callback(new Error(`Provided source for ${packageId}/${name} failed to create a runnable component`));
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
callback(null, implementation);
|
|
124
|
+
if ((typeof implementation !== 'function') && (typeof implementation.getComponent !== 'function')) {
|
|
125
|
+
return Promise.reject(new Error(`Provided source for ${packageId}/${name} failed to create a runnable component`));
|
|
126
|
+
}
|
|
127
|
+
return Promise.resolve(implementation);
|
|
128
|
+
});
|
|
136
129
|
}
|
|
137
130
|
/**
|
|
138
131
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
@@ -168,28 +161,29 @@ function registerSpecs(loader, packageId, name, specs) {
|
|
|
168
161
|
}
|
|
169
162
|
/**
|
|
170
163
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
171
|
-
* @param {
|
|
172
|
-
* @param {
|
|
164
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestModule} module
|
|
165
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestComponent} component
|
|
173
166
|
* @param {string} source
|
|
174
167
|
* @param {string} language
|
|
175
|
-
* @
|
|
176
|
-
* @returns {void}
|
|
168
|
+
* @returns {Promise<void>}
|
|
177
169
|
*/
|
|
178
|
-
function transpileAndRegisterForModule(loader, module, component, source, language
|
|
179
|
-
transpileSource(module.name, component.name, source, language
|
|
180
|
-
|
|
181
|
-
callback(transpileError);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
170
|
+
function transpileAndRegisterForModule(loader, module, component, source, language) {
|
|
171
|
+
return transpileSource(module.name, component.name, source, language)
|
|
172
|
+
.then((src) => {
|
|
184
173
|
const moduleBase = path.resolve(loader.baseDir, module.base);
|
|
185
|
-
evaluateModule(moduleBase, module.name, component.name, src
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
174
|
+
return evaluateModule(moduleBase, module.name, component.name, src);
|
|
175
|
+
})
|
|
176
|
+
.then((implementation) => {
|
|
177
|
+
registerSources(loader, module.name, component.name, source, language);
|
|
178
|
+
registerSpecs(loader, module.name, component.name, component.tests || '');
|
|
179
|
+
return new Promise((resolve, reject) => {
|
|
180
|
+
loader.registerComponent(module.name, component.name, implementation, (err) => {
|
|
181
|
+
if (err) {
|
|
182
|
+
reject(err);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
resolve();
|
|
186
|
+
});
|
|
193
187
|
});
|
|
194
188
|
});
|
|
195
189
|
}
|
|
@@ -206,9 +200,14 @@ function setSource(loader, packageId, name, source, language, callback) {
|
|
|
206
200
|
transpileAndRegisterForModule(loader, {
|
|
207
201
|
name: packageId,
|
|
208
202
|
base: '',
|
|
203
|
+
components: [],
|
|
204
|
+
runtime: 'noflo',
|
|
209
205
|
}, {
|
|
210
206
|
name,
|
|
211
|
-
}, source, language
|
|
207
|
+
}, source, language)
|
|
208
|
+
.then(() => {
|
|
209
|
+
callback(null);
|
|
210
|
+
}, callback);
|
|
212
211
|
}
|
|
213
212
|
exports.setSource = setSource;
|
|
214
213
|
/**
|
|
@@ -366,9 +365,14 @@ exports.getLanguages = getLanguages;
|
|
|
366
365
|
*/
|
|
367
366
|
function registerCustomLoaders(loader, componentLoaders, callback) {
|
|
368
367
|
componentLoaders.reduce((chain, componentLoader) => chain
|
|
369
|
-
.then(() =>
|
|
370
|
-
|
|
371
|
-
|
|
368
|
+
.then(() => { var _a; return _a = componentLoader, Promise.resolve().then(() => require(_a)); })
|
|
369
|
+
.then((customLoader) => new Promise((resolve, reject) => {
|
|
370
|
+
let loaderFunc = customLoader;
|
|
371
|
+
if (typeof customLoader === 'object' && customLoader.default) {
|
|
372
|
+
// CommonJS loader
|
|
373
|
+
loaderFunc = customLoader.default;
|
|
374
|
+
}
|
|
375
|
+
loader.registerLoader(loaderFunc, (err) => {
|
|
372
376
|
if (err) {
|
|
373
377
|
reject(err);
|
|
374
378
|
return;
|
|
@@ -382,17 +386,18 @@ function registerCustomLoaders(loader, componentLoaders, callback) {
|
|
|
382
386
|
}
|
|
383
387
|
/**
|
|
384
388
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
385
|
-
* @param {Array<
|
|
389
|
+
* @param {Array<import("fbp-manifest/dist/lib/list").FbpManifestModule>} modules
|
|
386
390
|
* @param {ErrorableCallback} callback
|
|
387
391
|
*/
|
|
388
392
|
function registerModules(loader, modules, callback) {
|
|
389
393
|
const compatible = modules.filter((m) => ['noflo', 'noflo-nodejs'].includes(m.runtime));
|
|
394
|
+
/** @type {string[]} */
|
|
390
395
|
const componentLoaders = [];
|
|
391
396
|
Promise.all(compatible.map((m) => {
|
|
392
397
|
if (m.icon) {
|
|
393
398
|
loader.setLibraryIcon(m.name, m.icon);
|
|
394
399
|
}
|
|
395
|
-
if (m.noflo
|
|
400
|
+
if (m.noflo && m.noflo.loader) {
|
|
396
401
|
const loaderPath = path.resolve(loader.baseDir, m.base, m.noflo.loader);
|
|
397
402
|
componentLoaders.push(loaderPath);
|
|
398
403
|
}
|
|
@@ -400,19 +405,9 @@ function registerModules(loader, modules, callback) {
|
|
|
400
405
|
const language = utils.guessLanguageFromFilename(c.path);
|
|
401
406
|
if (language === 'typescript' || language === 'coffeescript') {
|
|
402
407
|
// We can't require a module that requires transpilation, go the setSource route
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
transpileAndRegisterForModule(loader, m, c, source, language, (err) => {
|
|
409
|
-
if (err) {
|
|
410
|
-
reject(err);
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
resolve();
|
|
414
|
-
});
|
|
415
|
-
});
|
|
408
|
+
readFile(path.resolve(loader.baseDir, c.path), 'utf-8')
|
|
409
|
+
.then((source) => transpileAndRegisterForModule(loader, m, c, source, language))
|
|
410
|
+
.then(resolve, reject);
|
|
416
411
|
return;
|
|
417
412
|
}
|
|
418
413
|
registerSpecs(loader, m.name, c.name, c.tests);
|
|
@@ -432,51 +427,59 @@ function registerModules(loader, modules, callback) {
|
|
|
432
427
|
const dynamicLoader = {
|
|
433
428
|
/**
|
|
434
429
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
435
|
-
* @param {
|
|
430
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestOptions} manifestOptions
|
|
436
431
|
* @param {Function} callback
|
|
437
432
|
*/
|
|
438
433
|
listComponents(loader, manifestOptions, callback) {
|
|
439
434
|
const opts = manifestOptions;
|
|
440
435
|
opts.discover = true;
|
|
441
|
-
manifest.list.list(loader.baseDir, opts
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
registerModules(loader, modules, (err2) => {
|
|
447
|
-
if (err2) {
|
|
448
|
-
callback(err2);
|
|
436
|
+
manifest.list.list(loader.baseDir, opts)
|
|
437
|
+
.then((modules) => new Promise((resolve, reject) => {
|
|
438
|
+
registerModules(loader, modules, (err) => {
|
|
439
|
+
if (err) {
|
|
440
|
+
reject(err);
|
|
449
441
|
return;
|
|
450
442
|
}
|
|
451
|
-
|
|
443
|
+
resolve(modules);
|
|
452
444
|
});
|
|
445
|
+
}))
|
|
446
|
+
.then((modules) => {
|
|
447
|
+
callback(null, modules);
|
|
448
|
+
}, (err) => {
|
|
449
|
+
callback(err);
|
|
453
450
|
});
|
|
454
451
|
},
|
|
455
452
|
};
|
|
456
453
|
const manifestLoader = {
|
|
457
454
|
/**
|
|
458
455
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
459
|
-
* @param {
|
|
456
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestOptions} options
|
|
460
457
|
* @param {Object} manifestContents
|
|
461
|
-
* @param {
|
|
458
|
+
* @param {import("fbp-manifest/src/lib/list").FbpManifestDocument} manifestContents
|
|
459
|
+
* @returns {Promise<import("fbp-manifest/dist/lib/list").FbpManifestDocument>}
|
|
462
460
|
*/
|
|
463
|
-
writeCache(loader, options, manifestContents
|
|
464
|
-
const
|
|
465
|
-
|
|
461
|
+
writeCache(loader, options, manifestContents) {
|
|
462
|
+
const manifestName = options.manifest || 'fbp.json';
|
|
463
|
+
const filePath = path.resolve(loader.baseDir, manifestName);
|
|
464
|
+
return writeFile(filePath, JSON.stringify(manifestContents, null, 2), {
|
|
465
|
+
encoding: 'utf-8',
|
|
466
|
+
})
|
|
467
|
+
.then(() => manifestContents);
|
|
466
468
|
},
|
|
467
469
|
/**
|
|
468
470
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
469
|
-
* @param {
|
|
470
|
-
* @
|
|
471
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestOptions} options
|
|
472
|
+
* @returns {Promise<import("fbp-manifest/dist/lib/list").FbpManifestDocument>}
|
|
471
473
|
*/
|
|
472
|
-
readCache(loader, options
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
474
|
+
readCache(loader, options) {
|
|
475
|
+
return manifest.load.load(loader.baseDir, {
|
|
476
|
+
...options,
|
|
477
|
+
discover: false,
|
|
478
|
+
});
|
|
476
479
|
},
|
|
477
480
|
/**
|
|
478
481
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
479
|
-
* @returns {
|
|
482
|
+
* @returns {import("fbp-manifest/dist/lib/list").FbpManifestOptions}
|
|
480
483
|
*/
|
|
481
484
|
prepareManifestOptions(loader) {
|
|
482
485
|
const l = loader;
|
|
@@ -498,37 +501,41 @@ const manifestLoader = {
|
|
|
498
501
|
* @param {Function} callback
|
|
499
502
|
*/
|
|
500
503
|
listComponents(loader, manifestOptions, callback) {
|
|
501
|
-
this.readCache(loader, manifestOptions
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
504
|
+
this.readCache(loader, manifestOptions)
|
|
505
|
+
.catch((err) => {
|
|
506
|
+
if (!loader.options.discover) {
|
|
507
|
+
return Promise.reject(err);
|
|
508
|
+
}
|
|
509
|
+
return new Promise((resolve, reject) => {
|
|
507
510
|
dynamicLoader.listComponents(loader, manifestOptions, (err2, modules) => {
|
|
508
511
|
if (err2) {
|
|
509
|
-
|
|
512
|
+
reject(err2);
|
|
510
513
|
return;
|
|
511
514
|
}
|
|
512
|
-
|
|
513
|
-
version: 1,
|
|
514
|
-
modules,
|
|
515
|
-
}, (err3) => {
|
|
516
|
-
if (err3) {
|
|
517
|
-
callback(err3);
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
callback(null, modules);
|
|
521
|
-
});
|
|
515
|
+
resolve(modules);
|
|
522
516
|
});
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
517
|
+
})
|
|
518
|
+
.then((modules) => {
|
|
519
|
+
const manifestContents = {
|
|
520
|
+
version: 1,
|
|
521
|
+
modules,
|
|
522
|
+
};
|
|
523
|
+
return this
|
|
524
|
+
.writeCache(loader, manifestOptions, manifestContents)
|
|
525
|
+
.then(() => manifestContents);
|
|
526
|
+
});
|
|
527
|
+
})
|
|
528
|
+
.then((manifestContents) => {
|
|
529
|
+
registerModules(loader, manifestContents.modules, (err) => {
|
|
530
|
+
if (err) {
|
|
531
|
+
callback(err);
|
|
528
532
|
return;
|
|
529
533
|
}
|
|
530
534
|
callback(null, manifestContents.modules);
|
|
531
535
|
});
|
|
536
|
+
})
|
|
537
|
+
.catch((err) => {
|
|
538
|
+
callback(err);
|
|
532
539
|
});
|
|
533
540
|
},
|
|
534
541
|
};
|
|
@@ -585,40 +592,24 @@ exports.register = register;
|
|
|
585
592
|
* @param {ModuleLoadingCallback} callback
|
|
586
593
|
*/
|
|
587
594
|
function dynamicLoad(name, cPath, metadata, callback) {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
implementation = require(cPath);
|
|
592
|
-
}
|
|
593
|
-
catch (err) {
|
|
594
|
-
callback(err);
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
if (typeof implementation.getComponent === 'function') {
|
|
598
|
-
try {
|
|
595
|
+
(_a = cPath, Promise.resolve().then(() => require(_a))).then((implementation) => {
|
|
596
|
+
let instance;
|
|
597
|
+
if (typeof implementation.getComponent === 'function') {
|
|
599
598
|
instance = implementation.getComponent(metadata);
|
|
600
599
|
}
|
|
601
|
-
|
|
602
|
-
callback(err);
|
|
603
|
-
return;
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
else if (typeof implementation === 'function') {
|
|
607
|
-
try {
|
|
600
|
+
else if (typeof implementation === 'function') {
|
|
608
601
|
instance = implementation(metadata);
|
|
609
602
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
return;
|
|
603
|
+
else {
|
|
604
|
+
throw new Error(`Unable to instantiate ${cPath}`);
|
|
613
605
|
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
}
|
|
622
|
-
callback(null, instance);
|
|
606
|
+
if (typeof name === 'string') {
|
|
607
|
+
instance.componentName = name;
|
|
608
|
+
}
|
|
609
|
+
callback(null, instance);
|
|
610
|
+
})
|
|
611
|
+
.catch((e) => {
|
|
612
|
+
callback(e);
|
|
613
|
+
});
|
|
623
614
|
}
|
|
624
615
|
exports.dynamicLoad = dynamicLoad;
|
package/lib/loader/register.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./NodeJs";
|
|
1
|
+
export * from "./NodeJs.js";
|
package/lib/loader/register.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -13,8 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
17
|
/* eslint-disable
|
|
14
18
|
global-require,
|
|
15
19
|
*/
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
20
|
+
const Platform_js_1 = require("../Platform.js");
|
|
21
|
+
if ((0, Platform_js_1.isBrowser)()) {
|
|
18
22
|
throw new Error('Generate NoFlo component loader for browsers with noflo-component-loader');
|
|
19
23
|
}
|
|
20
|
-
__exportStar(require("./NodeJs"), exports);
|
|
24
|
+
__exportStar(require("./NodeJs.js"), exports);
|