@blocklet/resolver 1.16.23-beta-ce222a8b → 1.16.23-beta-06c3a221

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.
Files changed (2) hide show
  1. package/index.js +12 -4
  2. package/package.json +6 -5
package/index.js CHANGED
@@ -7,6 +7,7 @@ exports.parseOptionalComponents = exports.filterRequiredComponents = exports.par
7
7
  /* eslint-disable prettier/prettier */
8
8
  /* eslint-disable no-await-in-loop */
9
9
  const semver_1 = __importDefault(require("semver"));
10
+ const lru_cache_1 = __importDefault(require("lru-cache"));
10
11
  const did_1 = require("@arcblock/did");
11
12
  const constant_1 = require("@blocklet/constant");
12
13
  const util_1 = require("@blocklet/meta/lib/util");
@@ -184,7 +185,8 @@ const filterRequiredComponents = (component, children) => {
184
185
  return requiredChildren;
185
186
  };
186
187
  exports.filterRequiredComponents = filterRequiredComponents;
187
- const parseOptionalComponents = async (children) => {
188
+ const dynamicComponentsCache = new lru_cache_1.default({ max: 300, maxAge: 60 * 60 * 1000 * 3 }); // 3 hours
189
+ const parseOptionalComponents = async (children, logger = console) => {
188
190
  if (!children || !children.length) {
189
191
  return [];
190
192
  }
@@ -223,7 +225,12 @@ const parseOptionalComponents = async (children) => {
223
225
  continue;
224
226
  }
225
227
  try {
226
- const { dynamicComponents } = await (0, exports.parseComponents)(child);
228
+ let dynamicComponents = dynamicComponentsCache.get(child.meta.did);
229
+ if (!dynamicComponents) {
230
+ const components = await (0, exports.parseComponents)(child);
231
+ dynamicComponents = components.dynamicComponents;
232
+ dynamicComponentsCache.set(child.meta.did, dynamicComponents);
233
+ }
227
234
  for (const component of dynamicComponents) {
228
235
  const { mountPoint, bundleSource, meta } = component;
229
236
  if (!optionalNames.has(meta.name) || appendNames.has(meta.name)) {
@@ -237,12 +244,13 @@ const parseOptionalComponents = async (children) => {
237
244
  bundleSource,
238
245
  meta,
239
246
  };
240
- appendNames.add(meta.name);
247
+ appendNames.add(optionalChild.meta.name);
241
248
  optionalComponents.push(optionalChild);
242
249
  }
243
250
  }
244
251
  catch (err) {
245
- throw new Error(`Can not parse optional child: ${child.meta.name}`);
252
+ // FIXME: parseComponents 有一些错误是符合预期的, 这里不应该抛出
253
+ logger.warn(`Can not parse optional child: ${child.meta.name}, error:`, err);
246
254
  }
247
255
  }
248
256
  return optionalComponents;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.23-beta-ce222a8b",
6
+ "version": "1.16.23-beta-06c3a221",
7
7
  "description": "Blocklet meta resolver",
8
8
  "main": "index.js",
9
9
  "files": [
@@ -21,12 +21,13 @@
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
23
  "@arcblock/did": "^1.18.108",
24
- "@blocklet/constant": "1.16.23-beta-ce222a8b",
25
- "@blocklet/meta": "1.16.23-beta-ce222a8b",
24
+ "@blocklet/constant": "1.16.23-beta-06c3a221",
25
+ "@blocklet/meta": "1.16.23-beta-06c3a221",
26
+ "lru-cache": "^6.0.0",
26
27
  "semver": "^7.3.8"
27
28
  },
28
29
  "devDependencies": {
29
- "@abtnode/types": "1.16.23-beta-ce222a8b",
30
+ "@abtnode/types": "1.16.23-beta-06c3a221",
30
31
  "@arcblock/eslint-config-ts": "^0.2.4",
31
32
  "@types/jest": "^29.5.11",
32
33
  "@types/node": "^18.11.0",
@@ -38,5 +39,5 @@
38
39
  "ts-jest": "^29.1.1",
39
40
  "typescript": "^5.0.4"
40
41
  },
41
- "gitHead": "12e2bb15e23b349041139ae79691312067975812"
42
+ "gitHead": "10d2351eb9a0a222781d803798e15390622e421b"
42
43
  }