@abtnode/core 1.8.17 → 1.8.20
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/lib/blocklet/hooks.js +2 -1
- package/lib/blocklet/manager/disk.js +42 -9
- package/lib/util/blocklet.js +18 -17
- package/package.json +16 -16
package/lib/blocklet/hooks.js
CHANGED
|
@@ -56,7 +56,8 @@ const preStart = async (blocklet, options) => {
|
|
|
56
56
|
return runUserHook(blocklet.env.processId, 'pre-start', options);
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
const postStart = (processId, ...args) => runUserHook(processId, 'post-start', ...args);
|
|
59
60
|
const preUninstall = (processId, ...args) => runUserHook(processId, 'pre-uninstall', ...args);
|
|
60
61
|
const preStop = (processId, ...args) => runUserHook(processId, 'pre-stop', ...args);
|
|
61
62
|
|
|
62
|
-
module.exports = { preDeploy, preInstall, postInstall, preStart, preUninstall, preStop, preConfig };
|
|
63
|
+
module.exports = { preDeploy, preInstall, postInstall, preStart, postStart, preUninstall, preStop, preConfig };
|
|
@@ -385,17 +385,22 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
385
385
|
fs.mkdirSync(logsDir, { recursive: true });
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
preStart: (b, { env }) =>
|
|
393
|
-
hooks.preStart(b, {
|
|
388
|
+
const getHookFn =
|
|
389
|
+
(hookName) =>
|
|
390
|
+
(b, { env }) =>
|
|
391
|
+
hooks[hookName](b, {
|
|
394
392
|
appDir: b.env.appDir,
|
|
395
393
|
hooks: Object.assign(b.meta.hooks || {}, b.meta.scripts || {}),
|
|
396
394
|
env,
|
|
397
395
|
did, // root blocklet did,
|
|
398
|
-
})
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// start process
|
|
399
|
+
const nodeEnvironments = await states.node.getEnvironments();
|
|
400
|
+
await startBlockletProcess(blocklet, {
|
|
401
|
+
...context,
|
|
402
|
+
preStart: getHookFn('preStart'),
|
|
403
|
+
postStart: getHookFn('postStart'),
|
|
399
404
|
nodeEnvironments,
|
|
400
405
|
nodeInfo: await states.node.read(),
|
|
401
406
|
e2eMode,
|
|
@@ -555,12 +560,30 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
555
560
|
}),
|
|
556
561
|
});
|
|
557
562
|
|
|
558
|
-
|
|
563
|
+
const doc = await this._deleteBlocklet({ did, keepData, keepLogsDir, keepConfigs }, context);
|
|
564
|
+
states.notification.create({
|
|
565
|
+
title: 'Blocklet Deleted',
|
|
566
|
+
description: `Blocklet ${doc.meta.name}@${doc.meta.version} is deleted.`,
|
|
567
|
+
entityType: 'blocklet',
|
|
568
|
+
entityId: doc.meta.did,
|
|
569
|
+
severity: 'success',
|
|
570
|
+
});
|
|
571
|
+
return doc;
|
|
559
572
|
} catch (err) {
|
|
560
573
|
// If we installed a corrupted blocklet accidentally, just cleanup the disk and state db
|
|
561
574
|
if (err.code === 'BLOCKLET_CORRUPTED') {
|
|
562
575
|
logger.info('blocklet is corrupted, will delete again', { did });
|
|
563
|
-
|
|
576
|
+
const doc = await this._deleteBlocklet({ did, keepData, keepLogsDir, keepConfigs }, context);
|
|
577
|
+
|
|
578
|
+
states.notification.create({
|
|
579
|
+
title: 'Blocklet Deleted',
|
|
580
|
+
description: `Blocklet ${doc.meta.name}@${doc.meta.version} is deleted.`,
|
|
581
|
+
entityType: 'blocklet',
|
|
582
|
+
entityId: doc.meta.did,
|
|
583
|
+
severity: 'success',
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
return doc;
|
|
564
587
|
}
|
|
565
588
|
|
|
566
589
|
throw err;
|
|
@@ -676,6 +699,16 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
676
699
|
|
|
677
700
|
const newBlocklet = await this.ensureBlocklet(rootDid);
|
|
678
701
|
this.emit(BlockletEvents.upgraded, { blocklet: newBlocklet, context }); // trigger router refresh
|
|
702
|
+
|
|
703
|
+
states.notification.create({
|
|
704
|
+
title: 'Component Deleted',
|
|
705
|
+
description: `Component ${child.meta.name} of ${newBlocklet.meta.name} is successfully deleted.`,
|
|
706
|
+
entityType: 'blocklet',
|
|
707
|
+
entityId: newBlocklet.meta.did,
|
|
708
|
+
severity: 'success',
|
|
709
|
+
action: `/blocklets/${newBlocklet.meta.did}/components`,
|
|
710
|
+
});
|
|
711
|
+
|
|
679
712
|
return newBlocklet;
|
|
680
713
|
}
|
|
681
714
|
|
package/lib/util/blocklet.js
CHANGED
|
@@ -76,6 +76,7 @@ const { isBeforeInstalled, expandBundle, findInterfacePortByName, validateBlockl
|
|
|
76
76
|
const getBlockletEngineNameByPlatform = (blockletMeta) => getBlockletEngine(blockletMeta).interpreter;
|
|
77
77
|
|
|
78
78
|
const noop = () => {};
|
|
79
|
+
const noopAsync = async () => {};
|
|
79
80
|
|
|
80
81
|
const statusMap = {
|
|
81
82
|
online: BlockletStatus.running,
|
|
@@ -86,7 +87,7 @@ const statusMap = {
|
|
|
86
87
|
};
|
|
87
88
|
|
|
88
89
|
const PRIVATE_NODE_ENVS = [
|
|
89
|
-
|
|
90
|
+
'NEDB_MULTI_PORT',
|
|
90
91
|
'ABT_NODE_UPDATER_PORT',
|
|
91
92
|
'ABT_NODE_SESSION_TTL',
|
|
92
93
|
'ABT_NODE_ROUTER_PROVIDER',
|
|
@@ -219,21 +220,17 @@ const fillBlockletConfigs = (blocklet, configs) => {
|
|
|
219
220
|
};
|
|
220
221
|
|
|
221
222
|
const ensureBlockletExpanded = async (meta, appDir) => {
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const nodeModulesPath = path.join(appDir, 'node_modules');
|
|
229
|
-
if (fs.existsSync(nodeModulesPath)) {
|
|
230
|
-
fs.removeSync(nodeModulesPath);
|
|
231
|
-
}
|
|
232
|
-
await expandBundle(bundlePath, appDir);
|
|
233
|
-
fs.removeSync(bundlePath);
|
|
234
|
-
} catch (err) {
|
|
235
|
-
throw new Error(`Failed to expand blocklet bundle: ${err.message}`);
|
|
223
|
+
const bundlePath = path.join(appDir, BLOCKLET_BUNDLE_FILE);
|
|
224
|
+
if (fs.existsSync(bundlePath)) {
|
|
225
|
+
try {
|
|
226
|
+
const nodeModulesPath = path.join(appDir, 'node_modules');
|
|
227
|
+
if (fs.existsSync(nodeModulesPath)) {
|
|
228
|
+
fs.removeSync(nodeModulesPath);
|
|
236
229
|
}
|
|
230
|
+
await expandBundle(bundlePath, appDir);
|
|
231
|
+
fs.removeSync(bundlePath);
|
|
232
|
+
} catch (err) {
|
|
233
|
+
throw new Error(`Failed to expand blocklet bundle: ${err.message}`);
|
|
237
234
|
}
|
|
238
235
|
}
|
|
239
236
|
};
|
|
@@ -412,7 +409,7 @@ const getHealthyCheckTimeout = (blocklet, { checkHealthImmediately } = {}) => {
|
|
|
412
409
|
*/
|
|
413
410
|
const startBlockletProcess = async (
|
|
414
411
|
blocklet,
|
|
415
|
-
{ preStart = noop, nodeEnvironments, nodeInfo, e2eMode, skippedProcessIds = [] } = {}
|
|
412
|
+
{ preStart = noop, postStart = noopAsync, nodeEnvironments, nodeInfo, e2eMode, skippedProcessIds = [] } = {}
|
|
416
413
|
) => {
|
|
417
414
|
if (!blocklet) {
|
|
418
415
|
throw new Error('blocklet should not be empty');
|
|
@@ -487,8 +484,12 @@ const startBlockletProcess = async (
|
|
|
487
484
|
if (status === BlockletStatus.error) {
|
|
488
485
|
throw new Error(`${processId} is not running within 5 seconds`);
|
|
489
486
|
}
|
|
490
|
-
|
|
491
487
|
logger.info('blocklet started', { processId, status });
|
|
488
|
+
|
|
489
|
+
// run hook
|
|
490
|
+
postStart(b, { env }).catch((err) => {
|
|
491
|
+
logger.error('blocklet post start failed', { processId, error: err });
|
|
492
|
+
});
|
|
492
493
|
},
|
|
493
494
|
{ parallel: true }
|
|
494
495
|
);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.20",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/auth": "1.8.
|
|
23
|
-
"@abtnode/certificate-manager": "1.8.
|
|
24
|
-
"@abtnode/constant": "1.8.
|
|
25
|
-
"@abtnode/cron": "1.8.
|
|
26
|
-
"@abtnode/db": "1.8.
|
|
27
|
-
"@abtnode/logger": "1.8.
|
|
28
|
-
"@abtnode/queue": "1.8.
|
|
29
|
-
"@abtnode/rbac": "1.8.
|
|
30
|
-
"@abtnode/router-provider": "1.8.
|
|
31
|
-
"@abtnode/static-server": "1.8.
|
|
32
|
-
"@abtnode/timemachine": "1.8.
|
|
33
|
-
"@abtnode/util": "1.8.
|
|
22
|
+
"@abtnode/auth": "1.8.20",
|
|
23
|
+
"@abtnode/certificate-manager": "1.8.20",
|
|
24
|
+
"@abtnode/constant": "1.8.20",
|
|
25
|
+
"@abtnode/cron": "1.8.20",
|
|
26
|
+
"@abtnode/db": "1.8.20",
|
|
27
|
+
"@abtnode/logger": "1.8.20",
|
|
28
|
+
"@abtnode/queue": "1.8.20",
|
|
29
|
+
"@abtnode/rbac": "1.8.20",
|
|
30
|
+
"@abtnode/router-provider": "1.8.20",
|
|
31
|
+
"@abtnode/static-server": "1.8.20",
|
|
32
|
+
"@abtnode/timemachine": "1.8.20",
|
|
33
|
+
"@abtnode/util": "1.8.20",
|
|
34
34
|
"@arcblock/did": "1.17.19",
|
|
35
35
|
"@arcblock/did-motif": "^1.1.10",
|
|
36
36
|
"@arcblock/did-util": "1.17.19",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@arcblock/jwt": "^1.17.19",
|
|
39
39
|
"@arcblock/pm2-events": "^0.0.5",
|
|
40
40
|
"@arcblock/vc": "1.17.19",
|
|
41
|
-
"@blocklet/meta": "1.8.
|
|
42
|
-
"@blocklet/sdk": "1.8.
|
|
41
|
+
"@blocklet/meta": "1.8.20",
|
|
42
|
+
"@blocklet/sdk": "1.8.20",
|
|
43
43
|
"@fidm/x509": "^1.2.1",
|
|
44
44
|
"@ocap/mcrypto": "1.17.19",
|
|
45
45
|
"@ocap/util": "1.17.19",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"express": "^4.18.1",
|
|
81
81
|
"jest": "^27.5.1"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "abe47e26c9583bfe5c4969e19cd36574f436a515"
|
|
84
84
|
}
|