noflo 1.4.2 → 1.5.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.
- package/.ecrc +3 -0
- package/.eslintignore +2 -0
- package/{CHANGES.md → CHANGELOG.md} +520 -523
- package/README.md +1 -1
- package/bin/noflo-cache-preheat +17 -15
- 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 +81 -10
- package/lib/InPort.js +83 -19
- 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 +13 -13
- package/lib/NoFlo.js +29 -27
- package/lib/OutPort.d.ts +74 -32
- package/lib/OutPort.js +79 -23
- package/lib/Platform.d.ts +1 -1
- package/lib/Platform.js +9 -4
- package/lib/Ports.d.ts +14 -21
- package/lib/Ports.js +11 -13
- 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 +104 -105
- package/lib/loader/register.d.ts +1 -1
- package/lib/loader/register.js +8 -4
- package/package.json +16 -11
- 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 +2 -38
- 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 +1 -1
- package/spec/fixtures/componentloader/spec/Repeat.yaml +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 +4 -3
- 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 +86 -21
- 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 +15 -13
- package/src/lib/OutPort.js +83 -22
- package/src/lib/Platform.js +9 -4
- package/src/lib/Ports.js +9 -11
- package/src/lib/ProcessInput.js +7 -9
- package/src/lib/ProcessOutput.js +1 -1
- package/src/lib/loader/NodeJs.js +122 -116
- 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/Ports.js
CHANGED
|
@@ -3,17 +3,11 @@
|
|
|
3
3
|
// (c) 2014-2017 Flowhub UG
|
|
4
4
|
// NoFlo may be freely distributed under the MIT license
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
|
-
import InPort from './InPort';
|
|
7
|
-
import OutPort from './OutPort';
|
|
6
|
+
import InPort from './InPort.js';
|
|
7
|
+
import OutPort from './OutPort.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @typedef PortOptions
|
|
11
|
-
* @property {string} [description='']
|
|
12
|
-
* @property {string} [datatype='all']
|
|
13
|
-
* @property {string} [schema=null]
|
|
14
|
-
* @property {string} [type=null]
|
|
15
|
-
* @property {boolean} [required=false]
|
|
16
|
-
* @property {boolean} [scoped=true]
|
|
10
|
+
* @typedef {import("./BasePort").BaseOptions} PortOptions
|
|
17
11
|
*/
|
|
18
12
|
|
|
19
13
|
// NoFlo ports collections
|
|
@@ -83,7 +77,7 @@ class Ports extends EventEmitter {
|
|
|
83
77
|
}
|
|
84
78
|
|
|
85
79
|
/**
|
|
86
|
-
* @typedef {{ [key: string]: InPort|PortOptions }} InPortsOptions
|
|
80
|
+
* @typedef {{ [key: string]: InPort|import("./InPort").PortOptions }} InPortsOptions
|
|
87
81
|
*/
|
|
88
82
|
export class InPorts extends Ports {
|
|
89
83
|
/**
|
|
@@ -91,11 +85,13 @@ export class InPorts extends Ports {
|
|
|
91
85
|
*/
|
|
92
86
|
constructor(ports = {}) {
|
|
93
87
|
super(ports, InPort);
|
|
88
|
+
const basePorts = this.ports;
|
|
89
|
+
this.ports = /** @type {Object<string, InPort>} */ (basePorts);
|
|
94
90
|
}
|
|
95
91
|
}
|
|
96
92
|
|
|
97
93
|
/**
|
|
98
|
-
* @typedef {{ [key: string]: OutPort|PortOptions }} OutPortsOptions
|
|
94
|
+
* @typedef {{ [key: string]: OutPort|import("./OutPort").PortOptions }} OutPortsOptions
|
|
99
95
|
*/
|
|
100
96
|
export class OutPorts extends Ports {
|
|
101
97
|
/**
|
|
@@ -103,6 +99,8 @@ export class OutPorts extends Ports {
|
|
|
103
99
|
*/
|
|
104
100
|
constructor(ports = {}) {
|
|
105
101
|
super(ports, OutPort);
|
|
102
|
+
const basePorts = this.ports;
|
|
103
|
+
this.ports = /** @type {Object<string, OutPort>} */ (basePorts);
|
|
106
104
|
}
|
|
107
105
|
|
|
108
106
|
connect(name, socketId) {
|
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,7 +8,11 @@ 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;
|
|
@@ -43,29 +47,27 @@ try {
|
|
|
43
47
|
* @param {string} name
|
|
44
48
|
* @param {string} source
|
|
45
49
|
* @param {string} language
|
|
46
|
-
* @
|
|
47
|
-
* @returns {void}
|
|
50
|
+
* @returns {Promise<string>}
|
|
48
51
|
*/
|
|
49
|
-
function transpileSource(packageId, name, source, language
|
|
52
|
+
function transpileSource(packageId, name, source, language) {
|
|
50
53
|
let src;
|
|
51
54
|
switch (language) {
|
|
52
55
|
case 'coffeescript': {
|
|
53
56
|
if (!CoffeeScript) {
|
|
54
|
-
|
|
57
|
+
return Promise.reject(new Error(`Unsupported component source language ${language} for ${packageId}/${name}: no CoffeeScript compiler installed`));
|
|
55
58
|
}
|
|
56
59
|
try {
|
|
57
60
|
src = CoffeeScript.compile(source, {
|
|
58
61
|
bare: true,
|
|
59
62
|
});
|
|
60
63
|
} catch (err) {
|
|
61
|
-
|
|
62
|
-
return;
|
|
64
|
+
return Promise.reject(err);
|
|
63
65
|
}
|
|
64
66
|
break;
|
|
65
67
|
}
|
|
66
68
|
case 'typescript': {
|
|
67
69
|
if (!typescript) {
|
|
68
|
-
|
|
70
|
+
return Promise.reject(new Error(`Unsupported component source language ${language} for ${packageId}/${name}: no TypeScript compiler installed`));
|
|
69
71
|
}
|
|
70
72
|
try {
|
|
71
73
|
src = typescript.transpile(source, {
|
|
@@ -73,8 +75,7 @@ function transpileSource(packageId, name, source, language, callback) {
|
|
|
73
75
|
target: typescript.ScriptTarget.ES2015,
|
|
74
76
|
});
|
|
75
77
|
} catch (err) {
|
|
76
|
-
|
|
77
|
-
return;
|
|
78
|
+
return Promise.reject(err);
|
|
78
79
|
}
|
|
79
80
|
break;
|
|
80
81
|
}
|
|
@@ -86,28 +87,20 @@ function transpileSource(packageId, name, source, language, callback) {
|
|
|
86
87
|
break;
|
|
87
88
|
}
|
|
88
89
|
default: {
|
|
89
|
-
|
|
90
|
-
return;
|
|
90
|
+
return Promise.reject(new Error(`Unsupported component source language ${language} for ${packageId}/${name}`));
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
return Promise.resolve(src);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
/**
|
|
97
|
-
* @callback EvaluationCallback
|
|
98
|
-
* @param {Error|null} error
|
|
99
|
-
* @param {Object|Function} [module]
|
|
100
|
-
* @returns {void}
|
|
101
|
-
*/
|
|
102
96
|
/**
|
|
103
97
|
* @param {string} baseDir
|
|
104
98
|
* @param {string} packageId
|
|
105
99
|
* @param {string} name
|
|
106
100
|
* @param {string} source
|
|
107
|
-
* @
|
|
108
|
-
* @returns {void}
|
|
101
|
+
* @returns {Promise<Object|Function>}
|
|
109
102
|
*/
|
|
110
|
-
function evaluateModule(baseDir, packageId, name, source
|
|
103
|
+
function evaluateModule(baseDir, packageId, name, source) {
|
|
111
104
|
const Module = require('module');
|
|
112
105
|
let implementation;
|
|
113
106
|
try {
|
|
@@ -121,14 +114,12 @@ function evaluateModule(baseDir, packageId, name, source, callback) {
|
|
|
121
114
|
moduleImpl._compile(source, modulePath);
|
|
122
115
|
implementation = moduleImpl.exports;
|
|
123
116
|
} catch (e) {
|
|
124
|
-
|
|
125
|
-
return;
|
|
117
|
+
return Promise.reject(e);
|
|
126
118
|
}
|
|
127
119
|
if ((typeof implementation !== 'function') && (typeof implementation.getComponent !== 'function')) {
|
|
128
|
-
|
|
129
|
-
return;
|
|
120
|
+
return Promise.reject(new Error(`Provided source for ${packageId}/${name} failed to create a runnable component`));
|
|
130
121
|
}
|
|
131
|
-
|
|
122
|
+
return Promise.resolve(implementation);
|
|
132
123
|
}
|
|
133
124
|
|
|
134
125
|
/**
|
|
@@ -167,30 +158,31 @@ function registerSpecs(loader, packageId, name, specs) {
|
|
|
167
158
|
|
|
168
159
|
/**
|
|
169
160
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
170
|
-
* @param {
|
|
171
|
-
* @param {
|
|
161
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestModule} module
|
|
162
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestComponent} component
|
|
172
163
|
* @param {string} source
|
|
173
164
|
* @param {string} language
|
|
174
|
-
* @
|
|
175
|
-
* @returns {void}
|
|
165
|
+
* @returns {Promise<void>}
|
|
176
166
|
*/
|
|
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
|
-
}
|
|
167
|
+
function transpileAndRegisterForModule(loader, module, component, source, language) {
|
|
168
|
+
return transpileSource(module.name, component.name, source, language)
|
|
169
|
+
.then((src) => {
|
|
170
|
+
const moduleBase = path.resolve(loader.baseDir, module.base);
|
|
171
|
+
return evaluateModule(moduleBase, module.name, component.name, src);
|
|
172
|
+
})
|
|
173
|
+
.then((implementation) => {
|
|
189
174
|
registerSources(loader, module.name, component.name, source, language);
|
|
190
|
-
registerSpecs(loader, module.name, component.name, component.tests);
|
|
191
|
-
|
|
175
|
+
registerSpecs(loader, module.name, component.name, component.tests || '');
|
|
176
|
+
return new Promise((resolve, reject) => {
|
|
177
|
+
loader.registerComponent(module.name, component.name, implementation, (err) => {
|
|
178
|
+
if (err) {
|
|
179
|
+
reject(err);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
resolve();
|
|
183
|
+
});
|
|
184
|
+
});
|
|
192
185
|
});
|
|
193
|
-
});
|
|
194
186
|
}
|
|
195
187
|
|
|
196
188
|
/**
|
|
@@ -206,9 +198,14 @@ export function setSource(loader, packageId, name, source, language, callback) {
|
|
|
206
198
|
transpileAndRegisterForModule(loader, {
|
|
207
199
|
name: packageId,
|
|
208
200
|
base: '',
|
|
201
|
+
components: [],
|
|
202
|
+
runtime: 'noflo',
|
|
209
203
|
}, {
|
|
210
204
|
name,
|
|
211
|
-
}, source, language
|
|
205
|
+
}, source, language)
|
|
206
|
+
.then(() => {
|
|
207
|
+
callback(null);
|
|
208
|
+
}, callback);
|
|
212
209
|
}
|
|
213
210
|
|
|
214
211
|
/**
|
|
@@ -388,18 +385,19 @@ function registerCustomLoaders(loader, componentLoaders, callback) {
|
|
|
388
385
|
|
|
389
386
|
/**
|
|
390
387
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
391
|
-
* @param {Array<
|
|
388
|
+
* @param {Array<import("fbp-manifest/dist/lib/list").FbpManifestModule>} modules
|
|
392
389
|
* @param {ErrorableCallback} callback
|
|
393
390
|
*/
|
|
394
391
|
function registerModules(loader, modules, callback) {
|
|
395
392
|
const compatible = modules.filter((m) => ['noflo', 'noflo-nodejs'].includes(m.runtime));
|
|
393
|
+
/** @type {string[]} */
|
|
396
394
|
const componentLoaders = [];
|
|
397
395
|
Promise.all(compatible.map((m) => {
|
|
398
396
|
if (m.icon) {
|
|
399
397
|
loader.setLibraryIcon(m.name, m.icon);
|
|
400
398
|
}
|
|
401
399
|
|
|
402
|
-
if (m.noflo
|
|
400
|
+
if (m.noflo && m.noflo.loader) {
|
|
403
401
|
const loaderPath = path.resolve(loader.baseDir, m.base, m.noflo.loader);
|
|
404
402
|
componentLoaders.push(loaderPath);
|
|
405
403
|
}
|
|
@@ -408,19 +406,15 @@ function registerModules(loader, modules, callback) {
|
|
|
408
406
|
const language = utils.guessLanguageFromFilename(c.path);
|
|
409
407
|
if (language === 'typescript' || language === 'coffeescript') {
|
|
410
408
|
// 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
|
-
});
|
|
409
|
+
readFile(path.resolve(loader.baseDir, c.path), 'utf-8')
|
|
410
|
+
.then((source) => transpileAndRegisterForModule(
|
|
411
|
+
loader,
|
|
412
|
+
m,
|
|
413
|
+
c,
|
|
414
|
+
source,
|
|
415
|
+
language,
|
|
416
|
+
))
|
|
417
|
+
.then(resolve, reject);
|
|
424
418
|
return;
|
|
425
419
|
}
|
|
426
420
|
registerSpecs(loader, m.name, c.name, c.tests);
|
|
@@ -444,63 +438,72 @@ function registerModules(loader, modules, callback) {
|
|
|
444
438
|
const dynamicLoader = {
|
|
445
439
|
/**
|
|
446
440
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
447
|
-
* @param {
|
|
441
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestOptions} manifestOptions
|
|
448
442
|
* @param {Function} callback
|
|
449
443
|
*/
|
|
450
444
|
listComponents(loader, manifestOptions, callback) {
|
|
451
445
|
const opts = manifestOptions;
|
|
452
446
|
opts.discover = true;
|
|
453
|
-
manifest.list.list(loader.baseDir, opts
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
447
|
+
manifest.list.list(loader.baseDir, opts)
|
|
448
|
+
.then((modules) => new Promise((resolve, reject) => {
|
|
449
|
+
registerModules(loader, modules, (err) => {
|
|
450
|
+
if (err) {
|
|
451
|
+
reject(err);
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
resolve(modules);
|
|
455
|
+
});
|
|
456
|
+
}))
|
|
457
|
+
.then((modules) => {
|
|
463
458
|
callback(null, modules);
|
|
459
|
+
}, (err) => {
|
|
460
|
+
callback(err);
|
|
464
461
|
});
|
|
465
|
-
});
|
|
466
462
|
},
|
|
467
463
|
};
|
|
468
464
|
|
|
469
465
|
const manifestLoader = {
|
|
470
466
|
/**
|
|
471
467
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
472
|
-
* @param {
|
|
468
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestOptions} options
|
|
473
469
|
* @param {Object} manifestContents
|
|
474
|
-
* @param {
|
|
470
|
+
* @param {import("fbp-manifest/src/lib/list").FbpManifestDocument} manifestContents
|
|
471
|
+
* @returns {Promise<import("fbp-manifest/dist/lib/list").FbpManifestDocument>}
|
|
475
472
|
*/
|
|
476
|
-
writeCache(loader, options, manifestContents
|
|
477
|
-
const
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
473
|
+
writeCache(loader, options, manifestContents) {
|
|
474
|
+
const manifestName = options.manifest || 'fbp.json';
|
|
475
|
+
const filePath = path.resolve(loader.baseDir, manifestName);
|
|
476
|
+
|
|
477
|
+
return writeFile(filePath, JSON.stringify(manifestContents, null, 2), {
|
|
478
|
+
encoding: 'utf-8',
|
|
479
|
+
})
|
|
480
|
+
.then(() => manifestContents);
|
|
481
481
|
},
|
|
482
482
|
|
|
483
483
|
/**
|
|
484
484
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
485
|
-
* @param {
|
|
486
|
-
* @
|
|
485
|
+
* @param {import("fbp-manifest/dist/lib/list").FbpManifestOptions} options
|
|
486
|
+
* @returns {Promise<import("fbp-manifest/dist/lib/list").FbpManifestDocument>}
|
|
487
487
|
*/
|
|
488
|
-
readCache(loader, options
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
488
|
+
readCache(loader, options) {
|
|
489
|
+
return manifest.load.load(loader.baseDir, {
|
|
490
|
+
...options,
|
|
491
|
+
discover: false,
|
|
492
|
+
});
|
|
492
493
|
},
|
|
493
494
|
|
|
494
495
|
/**
|
|
495
496
|
* @param {import("../ComponentLoader").ComponentLoader} loader
|
|
496
|
-
* @returns {
|
|
497
|
+
* @returns {import("fbp-manifest/dist/lib/list").FbpManifestOptions}
|
|
497
498
|
*/
|
|
498
499
|
prepareManifestOptions(loader) {
|
|
499
500
|
const l = loader;
|
|
500
501
|
if (!l.options) { l.options = {}; }
|
|
501
502
|
const options = {};
|
|
502
503
|
options.runtimes = l.options.runtimes || [];
|
|
503
|
-
if (options.runtimes.indexOf('noflo') === -1) {
|
|
504
|
+
if (options.runtimes.indexOf('noflo') === -1) {
|
|
505
|
+
options.runtimes.push('noflo');
|
|
506
|
+
}
|
|
504
507
|
options.recursive = typeof l.options.recursive === 'undefined' ? true : l.options.recursive;
|
|
505
508
|
options.manifest = l.options.manifest || 'fbp.json';
|
|
506
509
|
return options;
|
|
@@ -512,39 +515,42 @@ const manifestLoader = {
|
|
|
512
515
|
* @param {Function} callback
|
|
513
516
|
*/
|
|
514
517
|
listComponents(loader, manifestOptions, callback) {
|
|
515
|
-
this.readCache(loader, manifestOptions
|
|
516
|
-
|
|
518
|
+
this.readCache(loader, manifestOptions)
|
|
519
|
+
.catch((err) => {
|
|
517
520
|
if (!loader.options.discover) {
|
|
518
|
-
|
|
519
|
-
return;
|
|
521
|
+
return Promise.reject(err);
|
|
520
522
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
}
|
|
526
|
-
this.writeCache(loader, manifestOptions, {
|
|
527
|
-
version: 1,
|
|
528
|
-
modules,
|
|
529
|
-
},
|
|
530
|
-
(err3) => {
|
|
531
|
-
if (err3) {
|
|
532
|
-
callback(err3);
|
|
523
|
+
return new Promise((resolve, reject) => {
|
|
524
|
+
dynamicLoader.listComponents(loader, manifestOptions, (err2, modules) => {
|
|
525
|
+
if (err2) {
|
|
526
|
+
reject(err2);
|
|
533
527
|
return;
|
|
534
528
|
}
|
|
535
|
-
|
|
529
|
+
resolve(modules);
|
|
530
|
+
});
|
|
531
|
+
})
|
|
532
|
+
.then((modules) => {
|
|
533
|
+
const manifestContents = {
|
|
534
|
+
version: 1,
|
|
535
|
+
modules,
|
|
536
|
+
};
|
|
537
|
+
return this
|
|
538
|
+
.writeCache(loader, manifestOptions, manifestContents)
|
|
539
|
+
.then(() => manifestContents);
|
|
536
540
|
});
|
|
541
|
+
})
|
|
542
|
+
.then((manifestContents) => {
|
|
543
|
+
registerModules(loader, manifestContents.modules, (err) => {
|
|
544
|
+
if (err) {
|
|
545
|
+
callback(err);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
callback(null, manifestContents.modules);
|
|
537
549
|
});
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
if (err2) {
|
|
542
|
-
callback(err2);
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
callback(null, manifestContents.modules);
|
|
550
|
+
})
|
|
551
|
+
.catch((err) => {
|
|
552
|
+
callback(err);
|
|
546
553
|
});
|
|
547
|
-
});
|
|
548
554
|
},
|
|
549
555
|
};
|
|
550
556
|
|
|
@@ -553,7 +559,7 @@ const manifestLoader = {
|
|
|
553
559
|
*/
|
|
554
560
|
function registerSubgraph(loader) {
|
|
555
561
|
// Inject subgraph component
|
|
556
|
-
const graphPath = path.resolve(
|
|
562
|
+
const graphPath = path.resolve(import.meta.dirname, '../../components/Graph.js');
|
|
557
563
|
loader.registerComponent(null, 'Graph', graphPath);
|
|
558
564
|
}
|
|
559
565
|
|
|
@@ -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
|