@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.
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/dist/app.d.ts +27 -27
- package/dist/core.d.ts +274 -272
- package/dist/core.mjs +235 -232
- package/dist/pack-config.d.ts +92 -92
- package/dist/render-context.d.ts +465 -465
- package/dist/render-context.mjs +338 -338
- package/dist/utils/cache.d.ts +15 -15
- package/dist/utils/import-map.d.ts +31 -1
- package/dist/utils/import-map.mjs +18 -0
- package/dist/utils/import-map.test.mjs +577 -1
- package/dist/utils/middleware.d.ts +19 -19
- package/dist/utils/static-import-lexer.d.ts +12 -12
- package/dist/utils/static-import-lexer.mjs +1 -1
- package/package.json +3 -3
- package/src/app.ts +34 -34
- package/src/core.ts +320 -317
- package/src/pack-config.ts +92 -92
- package/src/render-context.ts +465 -465
- package/src/utils/cache.ts +15 -15
- package/src/utils/import-map.test.ts +713 -1
- package/src/utils/import-map.ts +53 -1
- package/src/utils/middleware.ts +19 -19
- package/src/utils/static-import-lexer.ts +18 -18
package/dist/utils/cache.d.ts
CHANGED
|
@@ -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
|
-
* //
|
|
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
|
-
*
|
|
33
|
-
*
|
|
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
|
-
|
|
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,
|