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/src/lib/ProcessInput.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// NoFlo may be freely distributed under the MIT license
|
|
5
5
|
/* eslint-disable no-underscore-dangle */
|
|
6
6
|
import debug from 'debug';
|
|
7
|
-
import IP from './IP'; // eslint-disable-line no-unused-vars
|
|
7
|
+
import IP from './IP.js'; // eslint-disable-line no-unused-vars
|
|
8
8
|
|
|
9
9
|
const debugComponent = debug('noflo:component');
|
|
10
10
|
|
|
@@ -71,13 +71,9 @@ export default class ProcessInput {
|
|
|
71
71
|
// Returns true if a port (or ports joined by logical AND) has a new IP
|
|
72
72
|
// Passing a validation callback as a last argument allows more selective
|
|
73
73
|
// checking of packets.
|
|
74
|
-
/**
|
|
75
|
-
* @callback HasValidationCallback
|
|
76
|
-
* @param {IP} ip
|
|
77
|
-
* @returns {boolean}
|
|
78
|
-
*/
|
|
79
74
|
/**
|
|
80
75
|
* @typedef {string|Array<string|number>} GetArgument
|
|
76
|
+
* @typedef {import("./InPort").HasValidationCallback} HasValidationCallback
|
|
81
77
|
*/
|
|
82
78
|
/**
|
|
83
79
|
* @typedef {GetArgument|HasValidationCallback} HasArgument
|
|
@@ -86,13 +82,14 @@ export default class ProcessInput {
|
|
|
86
82
|
* @param {...HasArgument} params
|
|
87
83
|
*/
|
|
88
84
|
has(...params) {
|
|
85
|
+
/** @type {HasValidationCallback} */
|
|
89
86
|
let validate;
|
|
90
87
|
let args = params.filter((p) => typeof p !== 'function');
|
|
91
88
|
if (!args.length) {
|
|
92
89
|
args = ['in'];
|
|
93
90
|
}
|
|
94
91
|
if (typeof params[params.length - 1] === 'function') {
|
|
95
|
-
validate = params[params.length - 1];
|
|
92
|
+
validate = /** @type {HasValidationCallback} */ (params[params.length - 1]);
|
|
96
93
|
} else {
|
|
97
94
|
validate = () => true;
|
|
98
95
|
}
|
|
@@ -106,7 +103,8 @@ export default class ProcessInput {
|
|
|
106
103
|
if (!portImpl.isAddressable()) {
|
|
107
104
|
throw new Error(`Non-addressable ports, access must be with string ${port[0]}`);
|
|
108
105
|
}
|
|
109
|
-
|
|
106
|
+
const portIdx = (typeof port[1] === 'string') ? parseInt(port[1], 10) : port[1];
|
|
107
|
+
if (!portImpl.has(this.scope, portIdx, validate)) { return false; }
|
|
110
108
|
} else if (typeof port === 'string') {
|
|
111
109
|
const portImpl = /** @type {import("./InPort").default} */ (this.ports.ports[port]);
|
|
112
110
|
if (!portImpl) {
|
|
@@ -229,7 +227,7 @@ export default class ProcessInput {
|
|
|
229
227
|
res.push(ip);
|
|
230
228
|
} else {
|
|
231
229
|
const portImpl = /** @type {import("./InPort").default} */ (this.ports.ports[name]);
|
|
232
|
-
ip = portImpl.get(this.scope,
|
|
230
|
+
ip = portImpl.get(this.scope, idxName);
|
|
233
231
|
res.push(ip);
|
|
234
232
|
}
|
|
235
233
|
}
|
package/src/lib/ProcessOutput.js
CHANGED
package/src/lib/loader/NodeJs.js
CHANGED
|
@@ -8,25 +8,34 @@ import * as path from 'path';
|
|
|
8
8
|
import * as fs from 'fs';
|
|
9
9
|
import * as manifest from 'fbp-manifest';
|
|
10
10
|
import * as fbpGraph from 'fbp-graph';
|
|
11
|
-
import
|
|
11
|
+
import { promisify } from 'util';
|
|
12
|
+
import * as utils from '../Utils.js';
|
|
13
|
+
|
|
14
|
+
const writeFile = promisify(fs.writeFile);
|
|
15
|
+
const readFile = promisify(fs.readFile);
|
|
12
16
|
|
|
13
17
|
// Type loading CoffeeScript compiler
|
|
14
18
|
let CoffeeScript;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// eslint-disable-next-line import/no-unresolved,import/no-extraneous-dependencies
|
|
20
|
+
import('coffeescript')
|
|
21
|
+
.then((compiler) => {
|
|
22
|
+
CoffeeScript = compiler;
|
|
23
|
+
})
|
|
24
|
+
.catch((e) => {
|
|
25
|
+
// If there is no CoffeeScript compiler installed, we simply don't support compiling
|
|
26
|
+
});
|
|
21
27
|
|
|
22
28
|
// Try loading TypeScript compiler
|
|
23
29
|
let typescript;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
+
// eslint-disable-next-line import/no-unresolved,import/no-extraneous-dependencies
|
|
31
|
+
import('typescript')
|
|
32
|
+
.then((compiler) => {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
typescript = compiler.default;
|
|
35
|
+
})
|
|
36
|
+
.catch((e) => {
|
|
37
|
+
// If there is no TypeScript compiler installed, we simply don't support compiling
|
|
38
|
+
});
|
|
30
39
|
|
|
31
40
|
/**
|
|
32
41
|
* @callback ErrorableCallback
|
|
@@ -43,38 +52,35 @@ try {
|
|
|
43
52
|
* @param {string} name
|
|
44
53
|
* @param {string} source
|
|
45
54
|
* @param {string} language
|
|
46
|
-
* @
|
|
47
|
-
* @returns {void}
|
|
55
|
+
* @returns {Promise<string>}
|
|
48
56
|
*/
|
|
49
|
-
function transpileSource(packageId, name, source, language
|
|
57
|
+
function transpileSource(packageId, name, source, language) {
|
|
50
58
|
let src;
|
|
51
59
|
switch (language) {
|
|
52
60
|
case 'coffeescript': {
|
|
53
61
|
if (!CoffeeScript) {
|
|
54
|
-
|
|
62
|
+
return Promise.reject(new Error(`Unsupported component source language ${language} for ${packageId}/${name}: no CoffeeScript compiler installed`));
|
|
55
63
|
}
|
|
56
64
|
try {
|
|
57
65
|
src = CoffeeScript.compile(source, {
|
|
58
66
|
bare: true,
|
|
59
67
|
});
|
|
60
68
|
} catch (err) {
|
|
61
|
-
|
|
62
|
-
return;
|
|
69
|
+
return Promise.reject(err);
|
|
63
70
|
}
|
|
64
71
|
break;
|
|
65
72
|
}
|
|
66
73
|
case 'typescript': {
|
|
67
74
|
if (!typescript) {
|
|
68
|
-
|
|
75
|
+
return Promise.reject(new Error(`Unsupported component source language ${language} for ${packageId}/${name}: no TypeScript compiler installed`));
|
|
69
76
|
}
|
|
70
77
|
try {
|
|
71
78
|
src = typescript.transpile(source, {
|
|
72
79
|
module: typescript.ModuleKind.CommonJS,
|
|
73
|
-
target: typescript.ScriptTarget.
|
|
80
|
+
target: typescript.ScriptTarget.ES2020,
|
|
74
81
|
});
|
|
75
82
|
} catch (err) {
|
|
76
|
-
|
|
77
|
-
return;
|
|
83
|
+
return Promise.reject(err);
|
|
78
84
|
}
|
|
79
85
|
break;
|
|
80
86
|
}
|
|
@@ -86,49 +92,42 @@ function transpileSource(packageId, name, source, language, callback) {
|
|
|
86
92
|
break;
|
|
87
93
|
}
|
|
88
94
|
default: {
|
|
89
|
-
|
|
90
|
-
return;
|
|
95
|
+
return Promise.reject(new Error(`Unsupported component source language ${language} for ${packageId}/${name}`));
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
|
-
|
|
98
|
+
return Promise.resolve(src);
|
|
94
99
|
}
|
|
95
100
|
|
|
96
|
-
/**
|
|
97
|
-
* @callback EvaluationCallback
|
|
98
|
-
* @param {Error|null} error
|
|
99
|
-
* @param {Object|Function} [module]
|
|
100
|
-
* @returns {void}
|
|
101
|
-
*/
|
|
102
101
|
/**
|
|
103
102
|
* @param {string} baseDir
|
|
104
103
|
* @param {string} packageId
|
|
105
104
|
* @param {string} name
|
|
106
105
|
* @param {string} source
|
|
107
|
-
* @
|
|
108
|
-
* @returns {void}
|
|
106
|
+
* @returns {Promise<Object|Function>}
|
|
109
107
|
*/
|
|
110
|
-
function evaluateModule(baseDir, packageId, name, source
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
108
|
+
function evaluateModule(baseDir, packageId, name, source) {
|
|
109
|
+
return import('module')
|
|
110
|
+
.then(({ Module }) => {
|
|
111
|
+
let implementation;
|
|
112
|
+
// Use the Node.js module API to evaluate in the correct directory context
|
|
113
|
+
let extension = '.js';
|
|
114
|
+
if (source.indexOf('require(') !== -1) {
|
|
115
|
+
// CommonJS
|
|
116
|
+
extension = '.cjs';
|
|
117
|
+
}
|
|
118
|
+
const modulePath = path.resolve(baseDir, `./components/${name}${extension}`);
|
|
119
|
+
const moduleImpl = new Module(modulePath);
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
moduleImpl.paths = Module._nodeModulePaths(path.dirname(modulePath));
|
|
122
|
+
moduleImpl.filename = modulePath;
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
moduleImpl._compile(source, modulePath);
|
|
125
|
+
implementation = moduleImpl.exports;
|
|
126
|
+
if ((typeof implementation !== 'function') && (typeof implementation.getComponent !== 'function')) {
|
|
127
|
+
return Promise.reject(new Error(`Provided source for ${packageId}/${name} failed to create a runnable component`));
|
|
128
|
+
}
|
|
129
|
+
return Promise.resolve(implementation);
|
|
130
|
+
});
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
/**
|
|
@@ -167,30 +166,31 @@ function registerSpecs(loader, packageId, name, specs) {
|
|
|
167
166
|
|
|
168
167
|
/**
|
|
169
168
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
170
|
-
* @param {
|
|
171
|
-
* @param {
|
|
169
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestModule} module
|
|
170
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestComponent} component
|
|
172
171
|
* @param {string} source
|
|
173
172
|
* @param {string} language
|
|
174
|
-
* @
|
|
175
|
-
* @returns {void}
|
|
173
|
+
* @returns {Promise<void>}
|
|
176
174
|
*/
|
|
177
|
-
function transpileAndRegisterForModule(loader, module, component, source, language
|
|
178
|
-
transpileSource(module.name, component.name, source, language
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
evaluateModule(moduleBase, module.name, component.name, src, (evalError, implementation) => {
|
|
185
|
-
if (evalError) {
|
|
186
|
-
callback(evalError);
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
175
|
+
function transpileAndRegisterForModule(loader, module, component, source, language) {
|
|
176
|
+
return transpileSource(module.name, component.name, source, language)
|
|
177
|
+
.then((src) => {
|
|
178
|
+
const moduleBase = path.resolve(loader.baseDir, module.base);
|
|
179
|
+
return evaluateModule(moduleBase, module.name, component.name, src);
|
|
180
|
+
})
|
|
181
|
+
.then((implementation) => {
|
|
189
182
|
registerSources(loader, module.name, component.name, source, language);
|
|
190
|
-
registerSpecs(loader, module.name, component.name, component.tests);
|
|
191
|
-
|
|
183
|
+
registerSpecs(loader, module.name, component.name, component.tests || '');
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
loader.registerComponent(module.name, component.name, implementation, (err) => {
|
|
186
|
+
if (err) {
|
|
187
|
+
reject(err);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
resolve();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
192
193
|
});
|
|
193
|
-
});
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
/**
|
|
@@ -206,9 +206,14 @@ export function setSource(loader, packageId, name, source, language, callback) {
|
|
|
206
206
|
transpileAndRegisterForModule(loader, {
|
|
207
207
|
name: packageId,
|
|
208
208
|
base: '',
|
|
209
|
+
components: [],
|
|
210
|
+
runtime: 'noflo',
|
|
209
211
|
}, {
|
|
210
212
|
name,
|
|
211
|
-
}, source, language
|
|
213
|
+
}, source, language)
|
|
214
|
+
.then(() => {
|
|
215
|
+
callback(null);
|
|
216
|
+
}, callback);
|
|
212
217
|
}
|
|
213
218
|
|
|
214
219
|
/**
|
|
@@ -371,9 +376,14 @@ export function getLanguages() {
|
|
|
371
376
|
*/
|
|
372
377
|
function registerCustomLoaders(loader, componentLoaders, callback) {
|
|
373
378
|
componentLoaders.reduce((chain, componentLoader) => chain
|
|
374
|
-
.then(() =>
|
|
375
|
-
|
|
376
|
-
|
|
379
|
+
.then(() => import(componentLoader))
|
|
380
|
+
.then((customLoader) => new Promise((resolve, reject) => {
|
|
381
|
+
let loaderFunc = customLoader;
|
|
382
|
+
if (typeof customLoader === 'object' && customLoader.default) {
|
|
383
|
+
// CommonJS loader
|
|
384
|
+
loaderFunc = customLoader.default;
|
|
385
|
+
}
|
|
386
|
+
loader.registerLoader(loaderFunc, (err) => {
|
|
377
387
|
if (err) {
|
|
378
388
|
reject(err);
|
|
379
389
|
return;
|
|
@@ -388,18 +398,19 @@ function registerCustomLoaders(loader, componentLoaders, callback) {
|
|
|
388
398
|
|
|
389
399
|
/**
|
|
390
400
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
391
|
-
* @param {Array<
|
|
401
|
+
* @param {Array<import("fbp-manifest/dist/lib/list").FbpManifestModule>} modules
|
|
392
402
|
* @param {ErrorableCallback} callback
|
|
393
403
|
*/
|
|
394
404
|
function registerModules(loader, modules, callback) {
|
|
395
405
|
const compatible = modules.filter((m) => ['noflo', 'noflo-nodejs'].includes(m.runtime));
|
|
406
|
+
/** @type {string[]} */
|
|
396
407
|
const componentLoaders = [];
|
|
397
408
|
Promise.all(compatible.map((m) => {
|
|
398
409
|
if (m.icon) {
|
|
399
410
|
loader.setLibraryIcon(m.name, m.icon);
|
|
400
411
|
}
|
|
401
412
|
|
|
402
|
-
if (m.noflo
|
|
413
|
+
if (m.noflo && m.noflo.loader) {
|
|
403
414
|
const loaderPath = path.resolve(loader.baseDir, m.base, m.noflo.loader);
|
|
404
415
|
componentLoaders.push(loaderPath);
|
|
405
416
|
}
|
|
@@ -408,19 +419,15 @@ function registerModules(loader, modules, callback) {
|
|
|
408
419
|
const language = utils.guessLanguageFromFilename(c.path);
|
|
409
420
|
if (language === 'typescript' || language === 'coffeescript') {
|
|
410
421
|
// We can't require a module that requires transpilation, go the setSource route
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
resolve();
|
|
422
|
-
});
|
|
423
|
-
});
|
|
422
|
+
readFile(path.resolve(loader.baseDir, c.path), 'utf-8')
|
|
423
|
+
.then((source) => transpileAndRegisterForModule(
|
|
424
|
+
loader,
|
|
425
|
+
m,
|
|
426
|
+
c,
|
|
427
|
+
source,
|
|
428
|
+
language,
|
|
429
|
+
))
|
|
430
|
+
.then(resolve, reject);
|
|
424
431
|
return;
|
|
425
432
|
}
|
|
426
433
|
registerSpecs(loader, m.name, c.name, c.tests);
|
|
@@ -444,63 +451,72 @@ function registerModules(loader, modules, callback) {
|
|
|
444
451
|
const dynamicLoader = {
|
|
445
452
|
/**
|
|
446
453
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
447
|
-
* @param {
|
|
454
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestOptions} manifestOptions
|
|
448
455
|
* @param {Function} callback
|
|
449
456
|
*/
|
|
450
457
|
listComponents(loader, manifestOptions, callback) {
|
|
451
458
|
const opts = manifestOptions;
|
|
452
459
|
opts.discover = true;
|
|
453
|
-
manifest.list.list(loader.baseDir, opts
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
460
|
+
manifest.list.list(loader.baseDir, opts)
|
|
461
|
+
.then((modules) => new Promise((resolve, reject) => {
|
|
462
|
+
registerModules(loader, modules, (err) => {
|
|
463
|
+
if (err) {
|
|
464
|
+
reject(err);
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
resolve(modules);
|
|
468
|
+
});
|
|
469
|
+
}))
|
|
470
|
+
.then((modules) => {
|
|
463
471
|
callback(null, modules);
|
|
472
|
+
}, (err) => {
|
|
473
|
+
callback(err);
|
|
464
474
|
});
|
|
465
|
-
});
|
|
466
475
|
},
|
|
467
476
|
};
|
|
468
477
|
|
|
469
478
|
const manifestLoader = {
|
|
470
479
|
/**
|
|
471
480
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
472
|
-
* @param {
|
|
481
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestOptions} options
|
|
473
482
|
* @param {Object} manifestContents
|
|
474
|
-
* @param {
|
|
483
|
+
* @param {import("fbp-manifest/src/lib/list").FbpManifestDocument} manifestContents
|
|
484
|
+
* @returns {Promise<import("fbp-manifest/dist/lib/list").FbpManifestDocument>}
|
|
475
485
|
*/
|
|
476
|
-
writeCache(loader, options, manifestContents
|
|
477
|
-
const
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
486
|
+
writeCache(loader, options, manifestContents) {
|
|
487
|
+
const manifestName = options.manifest || 'fbp.json';
|
|
488
|
+
const filePath = path.resolve(loader.baseDir, manifestName);
|
|
489
|
+
|
|
490
|
+
return writeFile(filePath, JSON.stringify(manifestContents, null, 2), {
|
|
491
|
+
encoding: 'utf-8',
|
|
492
|
+
})
|
|
493
|
+
.then(() => manifestContents);
|
|
481
494
|
},
|
|
482
495
|
|
|
483
496
|
/**
|
|
484
497
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
485
|
-
* @param {
|
|
486
|
-
* @
|
|
498
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestOptions} options
|
|
499
|
+
* @returns {Promise<import("fbp-manifest/dist/lib/list").FbpManifestDocument>}
|
|
487
500
|
*/
|
|
488
|
-
readCache(loader, options
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
501
|
+
readCache(loader, options) {
|
|
502
|
+
return manifest.load.load(loader.baseDir, {
|
|
503
|
+
...options,
|
|
504
|
+
discover: false,
|
|
505
|
+
});
|
|
492
506
|
},
|
|
493
507
|
|
|
494
508
|
/**
|
|
495
509
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
496
|
-
* @returns {
|
|
510
|
+
* @returns {import("fbp-manifest/dist/lib/list").FbpManifestOptions}
|
|
497
511
|
*/
|
|
498
512
|
prepareManifestOptions(loader) {
|
|
499
513
|
const l = loader;
|
|
500
514
|
if (!l.options) { l.options = {}; }
|
|
501
515
|
const options = {};
|
|
502
516
|
options.runtimes = l.options.runtimes || [];
|
|
503
|
-
if (options.runtimes.indexOf('noflo') === -1) {
|
|
517
|
+
if (options.runtimes.indexOf('noflo') === -1) {
|
|
518
|
+
options.runtimes.push('noflo');
|
|
519
|
+
}
|
|
504
520
|
options.recursive = typeof l.options.recursive === 'undefined' ? true : l.options.recursive;
|
|
505
521
|
options.manifest = l.options.manifest || 'fbp.json';
|
|
506
522
|
return options;
|
|
@@ -512,39 +528,42 @@ const manifestLoader = {
|
|
|
512
528
|
* @param {Function} callback
|
|
513
529
|
*/
|
|
514
530
|
listComponents(loader, manifestOptions, callback) {
|
|
515
|
-
this.readCache(loader, manifestOptions
|
|
516
|
-
|
|
531
|
+
this.readCache(loader, manifestOptions)
|
|
532
|
+
.catch((err) => {
|
|
517
533
|
if (!loader.options.discover) {
|
|
518
|
-
|
|
519
|
-
return;
|
|
534
|
+
return Promise.reject(err);
|
|
520
535
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
}
|
|
526
|
-
this.writeCache(loader, manifestOptions, {
|
|
527
|
-
version: 1,
|
|
528
|
-
modules,
|
|
529
|
-
},
|
|
530
|
-
(err3) => {
|
|
531
|
-
if (err3) {
|
|
532
|
-
callback(err3);
|
|
536
|
+
return new Promise((resolve, reject) => {
|
|
537
|
+
dynamicLoader.listComponents(loader, manifestOptions, (err2, modules) => {
|
|
538
|
+
if (err2) {
|
|
539
|
+
reject(err2);
|
|
533
540
|
return;
|
|
534
541
|
}
|
|
535
|
-
|
|
542
|
+
resolve(modules);
|
|
543
|
+
});
|
|
544
|
+
})
|
|
545
|
+
.then((modules) => {
|
|
546
|
+
const manifestContents = {
|
|
547
|
+
version: 1,
|
|
548
|
+
modules,
|
|
549
|
+
};
|
|
550
|
+
return this
|
|
551
|
+
.writeCache(loader, manifestOptions, manifestContents)
|
|
552
|
+
.then(() => manifestContents);
|
|
536
553
|
});
|
|
554
|
+
})
|
|
555
|
+
.then((manifestContents) => {
|
|
556
|
+
registerModules(loader, manifestContents.modules, (err) => {
|
|
557
|
+
if (err) {
|
|
558
|
+
callback(err);
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
callback(null, manifestContents.modules);
|
|
537
562
|
});
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
if (err2) {
|
|
542
|
-
callback(err2);
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
callback(null, manifestContents.modules);
|
|
563
|
+
})
|
|
564
|
+
.catch((err) => {
|
|
565
|
+
callback(err);
|
|
546
566
|
});
|
|
547
|
-
});
|
|
548
567
|
},
|
|
549
568
|
};
|
|
550
569
|
|
|
@@ -553,7 +572,7 @@ const manifestLoader = {
|
|
|
553
572
|
*/
|
|
554
573
|
function registerSubgraph(loader) {
|
|
555
574
|
// Inject subgraph component
|
|
556
|
-
const graphPath = path.resolve(
|
|
575
|
+
const graphPath = path.resolve(import.meta.dirname, '../../components/Graph.js');
|
|
557
576
|
loader.registerComponent(null, 'Graph', graphPath);
|
|
558
577
|
}
|
|
559
578
|
|
|
@@ -605,34 +624,22 @@ export function register(loader, callback) {
|
|
|
605
624
|
* @param {ModuleLoadingCallback} callback
|
|
606
625
|
*/
|
|
607
626
|
export function dynamicLoad(name, cPath, metadata, callback) {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
} catch (err) {
|
|
627
|
-
callback(err);
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
} else {
|
|
631
|
-
callback(new Error(`Unable to instantiate ${cPath}`));
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
if (typeof name === 'string') {
|
|
635
|
-
instance.componentName = name;
|
|
636
|
-
}
|
|
637
|
-
callback(null, instance);
|
|
627
|
+
import(cPath)
|
|
628
|
+
.then((implementation) => {
|
|
629
|
+
let instance;
|
|
630
|
+
if (typeof implementation.getComponent === 'function') {
|
|
631
|
+
instance = implementation.getComponent(metadata);
|
|
632
|
+
} else if (typeof implementation === 'function') {
|
|
633
|
+
instance = implementation(metadata);
|
|
634
|
+
} else {
|
|
635
|
+
throw new Error(`Unable to instantiate ${cPath}`);
|
|
636
|
+
}
|
|
637
|
+
if (typeof name === 'string') {
|
|
638
|
+
instance.componentName = name;
|
|
639
|
+
}
|
|
640
|
+
callback(null, instance);
|
|
641
|
+
})
|
|
642
|
+
.catch((e) => {
|
|
643
|
+
callback(e)
|
|
644
|
+
});
|
|
638
645
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable
|
|
2
2
|
global-require,
|
|
3
3
|
*/
|
|
4
|
-
import { isBrowser } from '../Platform';
|
|
4
|
+
import { isBrowser } from '../Platform.js';
|
|
5
5
|
|
|
6
6
|
if (isBrowser()) {
|
|
7
7
|
throw new Error('Generate NoFlo component loader for browsers with noflo-component-loader');
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export * from './NodeJs';
|
|
10
|
+
export * from './NodeJs.js';
|
|
File without changes
|
|
File without changes
|