@esmx/core 3.0.0-rc.62 → 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/core.mjs +2 -1
- 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/package.json +3 -3
- package/src/core.ts +2 -1
- package/src/utils/import-map.test.ts +713 -1
- package/src/utils/import-map.ts +53 -1
package/src/utils/import-map.ts
CHANGED
|
@@ -80,12 +80,64 @@ export function buildScopesMap(
|
|
|
80
80
|
|
|
81
81
|
return scopes;
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Fixes Chrome's nested scope resolution bug in import maps.
|
|
85
|
+
*
|
|
86
|
+
* Chrome has a bug where nested scopes in import maps are not resolved correctly.
|
|
87
|
+
* For example, when you have both "/shared-modules/" and "/shared-modules/vue2/" scopes,
|
|
88
|
+
* Chrome fails to properly apply the more specific nested scope.
|
|
89
|
+
*
|
|
90
|
+
* This function works around the bug by:
|
|
91
|
+
* 1. Sorting scopes by path depth (shallow paths first, deeper paths last)
|
|
92
|
+
* 2. Manually applying scopes to matching imports in the correct order
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* Problematic import map that fails in Chrome:
|
|
96
|
+
* ```json
|
|
97
|
+
* {
|
|
98
|
+
* "scopes": {
|
|
99
|
+
* "/shared-modules/": {
|
|
100
|
+
* "vue": "/shared-modules/vue.d8c7a640.final.mjs"
|
|
101
|
+
* },
|
|
102
|
+
* "/shared-modules/vue2/": {
|
|
103
|
+
* "vue": "/shared-modules/vue2.9b4efaf3.final.mjs"
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @see https://github.com/guybedford/es-module-shims/issues/529
|
|
110
|
+
* @see https://issues.chromium.org/issues/453147451
|
|
111
|
+
*/
|
|
112
|
+
export function fixNestedScopesResolution(
|
|
113
|
+
importMap: Required<ImportMap>
|
|
114
|
+
): Required<ImportMap> {
|
|
115
|
+
Object.entries(importMap.scopes)
|
|
116
|
+
.sort(([pathA], [pathB]) => {
|
|
117
|
+
const depthA = pathA.split('/').length;
|
|
118
|
+
const depthB = pathB.split('/').length;
|
|
119
|
+
return depthA - depthB;
|
|
120
|
+
})
|
|
121
|
+
.forEach(([scopePath, scopeMappings]) => {
|
|
122
|
+
Object.values(importMap.imports).forEach((importPath) => {
|
|
123
|
+
if (importPath.startsWith(scopePath)) {
|
|
124
|
+
importMap.scopes[importPath] = {
|
|
125
|
+
...importMap.scopes[importPath],
|
|
126
|
+
...scopeMappings
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
Reflect.deleteProperty(importMap.scopes, scopePath);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return importMap;
|
|
134
|
+
}
|
|
83
135
|
|
|
84
136
|
export function getImportMap({
|
|
85
137
|
manifests,
|
|
86
138
|
getFile,
|
|
87
139
|
getScope
|
|
88
|
-
}: GetImportMapOptions): ImportMap {
|
|
140
|
+
}: GetImportMapOptions): Required<ImportMap> {
|
|
89
141
|
const imports = buildImportsMap(manifests, getFile);
|
|
90
142
|
|
|
91
143
|
const scopes = buildScopesMap(imports, manifests, getScope);
|