@esmx/core
Version:
A high-performance microfrontend framework supporting Vue, React, Preact, Solid, and Svelte with SSR and Module Linking capabilities.
53 lines (52 loc) • 2.24 kB
TypeScript
import type { ImportMap, ScopesMap, SpecifierMap } from '@esmx/import';
export interface ImportMapManifest {
name: string;
exports: Record<string, {
name: string;
file: string;
identifier: string;
pkg: boolean;
}>;
scopes: Record<string, Record<string, string>>;
}
export interface GetImportMapOptions {
manifests: readonly ImportMapManifest[];
getScope: (name: string, scope: string) => string;
getFile: (name: string, file: string) => string;
}
export declare function createImportsMap(manifests: readonly ImportMapManifest[], getFile: (name: string, file: string) => string): SpecifierMap;
export declare function createScopesMap(imports: SpecifierMap, manifests: readonly ImportMapManifest[], getScope: (name: string, scope: string) => string): ScopesMap;
/**
* Fixes the nested scope resolution issue in import maps across all browsers.
*
* Import Maps have a cross-browser issue where nested scopes are not resolved correctly.
* For example, when you have both "/shared-modules/" and "/shared-modules/vue2/" scopes,
* browsers fail to properly apply the more specific nested scope.
*
* This function works around the issue by:
* 1. Sorting scopes by path depth (shallow paths first, deeper paths last)
* 2. Manually applying scopes to matching imports in the correct order
* 3. Converting pattern-based scopes to concrete path scopes
*
* @example
* Problematic import map that fails in browsers:
* ```json
* {
* "scopes": {
* "/shared-modules/": {
* "vue": "/shared-modules/vue.d8c7a640.final.mjs"
* },
* "/shared-modules/vue2/": {
* "vue": "/shared-modules/vue2.9b4efaf3.final.mjs"
* }
* }
* }
* ```
*
* @see https://github.com/guybedford/es-module-shims/issues/529
* @see https://issues.chromium.org/issues/453147451
*/
export declare function fixImportMapNestedScopes(importMap: Required<ImportMap>): Required<ImportMap>;
export declare function compressImportMap(importMap: Required<ImportMap>): ImportMap;
export declare function createImportMap({ manifests, getFile, getScope }: GetImportMapOptions): Required<ImportMap>;
export declare function createClientImportMap(options: GetImportMapOptions): ImportMap;