@esmx/core 3.0.0-rc.60 → 3.0.0-rc.63

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,21 +1,21 @@
1
1
  /**
2
- * 缓存处理函数的类型定义
2
+ * Type definition for cache handling function
3
3
  *
4
- * @template T - 缓存数据的类型
5
- * @param name - 缓存项的唯一标识符
6
- * @param fetch - 获取数据的异步函数
7
- * @returns 返回缓存的数据或新获取的数据
4
+ * @template T - Type of cached data
5
+ * @param name - Unique identifier for the cache item
6
+ * @param fetch - Asynchronous function to fetch data
7
+ * @returns Returns cached data or newly fetched data
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
11
  * const cache = createCache(true);
12
12
  *
13
- * // 第一次调用会执行 fetch 函数
13
+ * // First call will execute the fetch function
14
14
  * const data1 = await cache('key', async () => {
15
15
  * return await fetchSomeData();
16
16
  * });
17
17
  *
18
- * // 第二次调用会直接返回缓存的结果
18
+ * // Second call will directly return the cached result
19
19
  * const data2 = await cache('key', async () => {
20
20
  * return await fetchSomeData();
21
21
  * });
@@ -23,24 +23,24 @@
23
23
  */
24
24
  export type CacheHandle = <T>(name: string, fetch: () => Promise<T>) => Promise<T>;
25
25
  /**
26
- * 创建一个缓存处理函数
26
+ * Create a cache handling function
27
27
  *
28
- * @param enable - 是否启用缓存功能
29
- * @returns 返回一个缓存处理函数
28
+ * @param enable - Whether to enable caching functionality
29
+ * @returns Returns a cache handling function
30
30
  *
31
31
  * @description
32
- * enable true 时,会创建一个带有内存缓存的处理函数,相同的 name 只会执行一次 fetch
33
- * enable false 时,每次调用都会执行 fetch 函数,不会缓存结果。
32
+ * When enable is true, it creates a processing function with memory cache, the same name will only execute fetch once.
33
+ * When enable is false, each call will execute the fetch function and will not cache the result.
34
34
  *
35
35
  * @example
36
36
  * ```ts
37
- * // 创建一个启用缓存的处理函数
37
+ * // Create a cache-enabled processing function
38
38
  * const cacheEnabled = createCache(true);
39
39
  *
40
- * // 创建一个禁用缓存的处理函数
40
+ * // Create a cache-disabled processing function
41
41
  * const cacheDisabled = createCache(false);
42
42
  *
43
- * // 使用缓存处理函数
43
+ * // Use the cache processing function
44
44
  * const result = await cacheEnabled('userProfile', async () => {
45
45
  * return await fetchUserProfile(userId);
46
46
  * });
@@ -17,4 +17,34 @@ export interface GetImportMapOptions {
17
17
  }
18
18
  export declare function buildImportsMap(manifests: readonly ImportMapManifest[], getFile: (name: string, file: string) => string): SpecifierMap;
19
19
  export declare function buildScopesMap(imports: SpecifierMap, manifests: readonly ImportMapManifest[], getScope: (name: string, scope: string) => string): ScopesMap;
20
- export declare function getImportMap({ manifests, getFile, getScope }: GetImportMapOptions): ImportMap;
20
+ /**
21
+ * Fixes Chrome's nested scope resolution bug in import maps.
22
+ *
23
+ * Chrome has a bug where nested scopes in import maps are not resolved correctly.
24
+ * For example, when you have both "/shared-modules/" and "/shared-modules/vue2/" scopes,
25
+ * Chrome fails to properly apply the more specific nested scope.
26
+ *
27
+ * This function works around the bug by:
28
+ * 1. Sorting scopes by path depth (shallow paths first, deeper paths last)
29
+ * 2. Manually applying scopes to matching imports in the correct order
30
+ *
31
+ * @example
32
+ * Problematic import map that fails in Chrome:
33
+ * ```json
34
+ * {
35
+ * "scopes": {
36
+ * "/shared-modules/": {
37
+ * "vue": "/shared-modules/vue.d8c7a640.final.mjs"
38
+ * },
39
+ * "/shared-modules/vue2/": {
40
+ * "vue": "/shared-modules/vue2.9b4efaf3.final.mjs"
41
+ * }
42
+ * }
43
+ * }
44
+ * ```
45
+ *
46
+ * @see https://github.com/guybedford/es-module-shims/issues/529
47
+ * @see https://issues.chromium.org/issues/453147451
48
+ */
49
+ export declare function fixNestedScopesResolution(importMap: Required<ImportMap>): Required<ImportMap>;
50
+ export declare function getImportMap({ manifests, getFile, getScope }: GetImportMapOptions): Required<ImportMap>;
@@ -36,6 +36,24 @@ export function buildScopesMap(imports, manifests, getScope) {
36
36
  });
37
37
  return scopes;
38
38
  }
39
+ export function fixNestedScopesResolution(importMap) {
40
+ Object.entries(importMap.scopes).sort(([pathA], [pathB]) => {
41
+ const depthA = pathA.split("/").length;
42
+ const depthB = pathB.split("/").length;
43
+ return depthA - depthB;
44
+ }).forEach(([scopePath, scopeMappings]) => {
45
+ Object.values(importMap.imports).forEach((importPath) => {
46
+ if (importPath.startsWith(scopePath)) {
47
+ importMap.scopes[importPath] = {
48
+ ...importMap.scopes[importPath],
49
+ ...scopeMappings
50
+ };
51
+ }
52
+ });
53
+ Reflect.deleteProperty(importMap.scopes, scopePath);
54
+ });
55
+ return importMap;
56
+ }
39
57
  export function getImportMap({
40
58
  manifests,
41
59
  getFile,