@abtnode/core 1.8.27 → 1.8.29

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.
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
2
  /* eslint-disable no-await-in-loop */
3
3
  const fs = require('fs-extra');
4
+ const { fileURLToPath } = require('url');
4
5
  const path = require('path');
5
6
  const get = require('lodash/get');
6
7
  const pick = require('lodash/pick');
@@ -102,6 +103,7 @@ const {
102
103
  findAvailableDid,
103
104
  ensureMeta,
104
105
  getBlocklet,
106
+ ensureEnvDefault,
105
107
  } = require('../../util/blocklet');
106
108
  const { parseSourceUrl } = require('../../util/registry');
107
109
  const states = require('../../states');
@@ -3012,14 +3014,14 @@ class BlockletManager extends BaseBlockletManager {
3012
3014
 
3013
3015
  const tarballPath = path.join(cwd, tarballName);
3014
3016
 
3015
- const { protocol, pathname } = new URL(url);
3017
+ const { protocol } = new URL(url);
3016
3018
 
3017
3019
  const cachedTarFile = await this._getCachedTarFile(integrity);
3018
3020
  if (cachedTarFile) {
3019
3021
  logger.info('found cache tarFile', { did, tarballName, integrity });
3020
3022
  await fs.move(cachedTarFile, tarballPath, { overwrite: true });
3021
3023
  } else if (protocol.startsWith('file')) {
3022
- await fs.copy(decodeURIComponent(pathname), tarballPath);
3024
+ await fs.copy(decodeURIComponent(fileURLToPath(url)), tarballPath);
3023
3025
  } else {
3024
3026
  const cancelCtrl = new downloadFile.CancelCtrl();
3025
3027
 
@@ -3375,10 +3377,13 @@ class BlockletManager extends BaseBlockletManager {
3375
3377
 
3376
3378
  if (!childDid) {
3377
3379
  await forEachBlocklet(blocklet, async (b, { ancestors }) => {
3378
- await states.blockletExtras.setConfigs(
3379
- [...ancestors.map((x) => x.meta.did), b.meta.did],
3380
- get(b.meta, 'environments', [])
3381
- );
3380
+ const environments = get(b.meta, 'environments', []);
3381
+
3382
+ // remove default if ancestors has a value
3383
+ ensureEnvDefault(environments, ancestors);
3384
+
3385
+ // write configs to db
3386
+ await states.blockletExtras.setConfigs([...ancestors.map((x) => x.meta.did), b.meta.did], environments);
3382
3387
  });
3383
3388
  } else {
3384
3389
  const child = blocklet.children.find((x) => x.meta.did === childDid);
@@ -2,6 +2,7 @@
2
2
 
3
3
  const fs = require('fs-extra');
4
4
  const path = require('path');
5
+ const shelljs = require('shelljs');
5
6
  const os = require('os');
6
7
  const tar = require('tar');
7
8
  const get = require('lodash/get');
@@ -23,6 +24,8 @@ const hashFiles = require('@abtnode/util/lib/hash-files');
23
24
  const isPathPrefixEqual = require('@abtnode/util/lib/is-path-prefix-equal');
24
25
  const { BLOCKLET_MAX_MEM_LIMIT_IN_MB } = require('@abtnode/constant');
25
26
 
27
+ const SCRIPT_ENGINES_WHITE_LIST = ['npm', 'npx', 'pnpm', 'yarn'];
28
+
26
29
  const {
27
30
  BlockletStatus,
28
31
  BlockletSource,
@@ -52,6 +55,7 @@ const {
52
55
  isComponentBlocklet,
53
56
  getSharedConfigObj,
54
57
  getComponentName,
58
+ isEnvShareable,
55
59
  } = require('@blocklet/meta/lib/util');
56
60
  const toBlockletDid = require('@blocklet/meta/lib/did');
57
61
  const { titleSchema, descriptionSchema } = require('@blocklet/meta/lib/schema');
@@ -324,6 +328,8 @@ const getComponentSystemEnvironments = (blocklet) => {
324
328
  };
325
329
 
326
330
  const getRuntimeEnvironments = (blocklet, nodeEnvironments, ancestors) => {
331
+ const root = (ancestors || [])[0] || blocklet;
332
+
327
333
  // pm2 will force inject env variables of daemon process to blocklet process
328
334
  // we can only rewrite these private env variables to empty
329
335
  const safeNodeEnvironments = PRIVATE_NODE_ENVS.reduce((o, x) => {
@@ -339,7 +345,11 @@ const getRuntimeEnvironments = (blocklet, nodeEnvironments, ancestors) => {
339
345
  }
340
346
  : {};
341
347
 
342
- const root = (ancestors || [])[0] || blocklet;
348
+ // BLOCKLET_DEV_PORT should NOT in components of production mode
349
+ if (process.env.BLOCKLET_DEV_PORT) {
350
+ devEnvironments.BLOCKLET_DEV_PORT =
351
+ blocklet.mode === BLOCKLET_MODES.DEVELOPMENT ? process.env.BLOCKLET_DEV_PORT : '';
352
+ }
343
353
 
344
354
  const ports = {};
345
355
  forEachBlockletSync(root, (x) => {
@@ -484,6 +494,24 @@ const startBlockletProcess = async (
484
494
  options.env.BROWSER = 'none';
485
495
  options.env.PORT = options.env[BLOCKLET_DEFAULT_PORT_NAME];
486
496
  options.script = appMain;
497
+
498
+ if (process.platform === 'win32') {
499
+ const [cmd, ...args] = options.script.split(' ').filter(Boolean);
500
+
501
+ if (!SCRIPT_ENGINES_WHITE_LIST.includes(cmd)) {
502
+ throw new Error(`${cmd} script is not supported, ${SCRIPT_ENGINES_WHITE_LIST.join(', ')} are supported`);
503
+ }
504
+
505
+ const { stdout: nodejsBinPath } = shelljs.which('node');
506
+
507
+ const cmdPath = path.join(path.dirname(nodejsBinPath), 'node_modules', cmd);
508
+
509
+ const pkg = JSON.parse(fs.readFileSync(path.join(cmdPath, 'package.json')));
510
+ const cmdBinPath = pkg.bin[cmd];
511
+
512
+ options.script = path.resolve(cmdPath, cmdBinPath);
513
+ options.args = [...args].join(' ');
514
+ }
487
515
  } else {
488
516
  const blockletEngineInfo = getBlockletEngine(b.meta);
489
517
  options.args = blockletEngineInfo.args || [];
@@ -1331,6 +1359,35 @@ const getBlocklet = async ({
1331
1359
  return blocklet;
1332
1360
  };
1333
1361
 
1362
+ /**
1363
+ * this function has side effect on environments
1364
+ */
1365
+ const ensureEnvDefault = (environments, ancestors) => {
1366
+ // remove default if ancestors has a value
1367
+ const envMap = environments.reduce((o, env) => {
1368
+ o[env.name] = env;
1369
+ return o;
1370
+ }, {});
1371
+
1372
+ for (let i = ancestors.length - 1; i >= 0; i--) {
1373
+ const ancestor = ancestors[i];
1374
+ const aEnvironments = get(ancestor.meta, 'environments', []);
1375
+ const aEnv = aEnvironments.find((x) => envMap[x.name]);
1376
+
1377
+ if (!isEnvShareable(aEnv)) {
1378
+ break;
1379
+ }
1380
+
1381
+ const env = envMap[aEnv.name];
1382
+ if (isEnvShareable(env) && aEnv.default) {
1383
+ env.default = '';
1384
+ break;
1385
+ }
1386
+ }
1387
+
1388
+ return environments;
1389
+ };
1390
+
1334
1391
  module.exports = {
1335
1392
  forEachBlocklet,
1336
1393
  getBlockletMetaFromUrl: (url) => getBlockletMetaFromUrl(url, { logger }),
@@ -1370,4 +1427,5 @@ module.exports = {
1370
1427
  findAvailableDid,
1371
1428
  ensureMeta,
1372
1429
  getBlocklet,
1430
+ ensureEnvDefault,
1373
1431
  };
package/lib/util/chain.js CHANGED
@@ -1,4 +1,4 @@
1
- const axios = require('axios');
1
+ const axios = require('@abtnode/util/lib/axios');
2
2
  const get = require('lodash/get');
3
3
 
4
4
  const getFactoryState = async (endpoint, address) => {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.27",
6
+ "version": "1.8.29",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,56 +19,56 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.8.27",
23
- "@abtnode/certificate-manager": "1.8.27",
24
- "@abtnode/constant": "1.8.27",
25
- "@abtnode/cron": "1.8.27",
26
- "@abtnode/db": "1.8.27",
27
- "@abtnode/logger": "1.8.27",
28
- "@abtnode/queue": "1.8.27",
29
- "@abtnode/rbac": "1.8.27",
30
- "@abtnode/router-provider": "1.8.27",
31
- "@abtnode/static-server": "1.8.27",
32
- "@abtnode/timemachine": "1.8.27",
33
- "@abtnode/util": "1.8.27",
34
- "@arcblock/did": "1.17.20",
22
+ "@abtnode/auth": "1.8.29",
23
+ "@abtnode/certificate-manager": "1.8.29",
24
+ "@abtnode/constant": "1.8.29",
25
+ "@abtnode/cron": "1.8.29",
26
+ "@abtnode/db": "1.8.29",
27
+ "@abtnode/logger": "1.8.29",
28
+ "@abtnode/queue": "1.8.29",
29
+ "@abtnode/rbac": "1.8.29",
30
+ "@abtnode/router-provider": "1.8.29",
31
+ "@abtnode/static-server": "1.8.29",
32
+ "@abtnode/timemachine": "1.8.29",
33
+ "@abtnode/util": "1.8.29",
34
+ "@arcblock/did": "1.17.23",
35
35
  "@arcblock/did-motif": "^1.1.10",
36
- "@arcblock/did-util": "1.17.20",
37
- "@arcblock/event-hub": "1.17.20",
38
- "@arcblock/jwt": "^1.17.20",
36
+ "@arcblock/did-util": "1.17.23",
37
+ "@arcblock/event-hub": "1.17.23",
38
+ "@arcblock/jwt": "^1.17.23",
39
39
  "@arcblock/pm2-events": "^0.0.5",
40
- "@arcblock/vc": "1.17.20",
41
- "@blocklet/constant": "1.8.27",
42
- "@blocklet/meta": "1.8.27",
43
- "@blocklet/sdk": "1.8.27",
40
+ "@arcblock/vc": "1.17.23",
41
+ "@blocklet/constant": "1.8.29",
42
+ "@blocklet/meta": "1.8.29",
43
+ "@blocklet/sdk": "1.8.29",
44
44
  "@fidm/x509": "^1.2.1",
45
- "@ocap/mcrypto": "1.17.20",
46
- "@ocap/util": "1.17.20",
47
- "@ocap/wallet": "1.17.20",
45
+ "@ocap/mcrypto": "1.17.23",
46
+ "@ocap/util": "1.17.23",
47
+ "@ocap/wallet": "1.17.23",
48
48
  "@slack/webhook": "^5.0.4",
49
49
  "axios": "^0.27.2",
50
50
  "axon": "^2.0.3",
51
51
  "chalk": "^4.1.2",
52
52
  "deep-diff": "^1.0.2",
53
- "detect-port": "^1.3.0",
53
+ "detect-port": "^1.5.1",
54
54
  "flat": "^5.0.2",
55
55
  "fs-extra": "^10.1.0",
56
56
  "get-port": "^5.1.1",
57
57
  "is-base64": "^1.1.0",
58
58
  "is-ip": "^3.1.0",
59
59
  "is-url": "^1.2.4",
60
- "joi": "^17.6.0",
60
+ "joi": "^17.6.2",
61
61
  "js-yaml": "^4.1.0",
62
62
  "lodash": "^4.17.21",
63
63
  "lru-cache": "^6.0.0",
64
64
  "pm2": "^5.2.0",
65
- "semver": "^7.3.7",
65
+ "semver": "^7.3.8",
66
66
  "shelljs": "^0.8.5",
67
67
  "slugify": "^1.6.5",
68
68
  "ssri": "^8.0.1",
69
69
  "stream-throttle": "^0.1.3",
70
70
  "stream-to-promise": "^3.0.0",
71
- "systeminformation": "^5.12.4",
71
+ "systeminformation": "^5.12.6",
72
72
  "tar": "^6.1.11",
73
73
  "ua-parser-js": "^1.0.2",
74
74
  "unzipper": "^0.10.11",
@@ -78,8 +78,8 @@
78
78
  "devDependencies": {
79
79
  "compression": "^1.7.4",
80
80
  "expand-tilde": "^2.0.2",
81
- "express": "^4.18.1",
81
+ "express": "^4.18.2",
82
82
  "jest": "^27.5.1"
83
83
  },
84
- "gitHead": "84b2cb3ee703479f17e88c91650ecf3015cbf6af"
84
+ "gitHead": "ee52d838f0cf97e551d53a6509cb0da7e5f31978"
85
85
  }