11/* eslint-disable @typescript-eslint/no-explicit-any */
2- import _ from "lodash" ;
2+ import memoize from "lodash.memoize " ;
33import { ExternalModuleResolver } from "./ExternalModuleResolver.js" ;
44import { LocalModuleResolver } from "./LocalModuleResolver.js" ;
55
66let importShimCreated = false ;
77
88function createBlob ( source : string ) {
99 return URL . createObjectURL (
10- new Blob ( [ source ] , { type : "application/javascript" } )
10+ new Blob ( [ source ] , { type : "application/javascript" } ) ,
1111 ) ;
1212}
1313
@@ -16,11 +16,11 @@ export class ImportShimResolver {
1616
1717 public constructor (
1818 private readonly resolvers : ExternalModuleResolver [ ] ,
19- private readonly localResolver : LocalModuleResolver
19+ private readonly localResolver : LocalModuleResolver ,
2020 ) {
2121 if ( importShimCreated ) {
2222 throw new Error (
23- "only 1 ImportShimResolver can exists because it uses a global importShim"
23+ "only 1 ImportShimResolver can exists because it uses a global importShim" ,
2424 ) ;
2525 }
2626 importShimCreated = true ;
@@ -30,7 +30,7 @@ export class ImportShimResolver {
3030 * Resolve a moduleName (e.g.: "lodash", "d3") to the actual module
3131 * using the resolvers passed to the constructor
3232 */
33- public resolveImport = _ . memoize ( this . doResolveImport ) ;
33+ public resolveImport = memoize ( this . doResolveImport ) ;
3434
3535 private async doResolveImport ( moduleName : string ) {
3636 await this . initializeImportShim ( ) ;
@@ -56,7 +56,7 @@ export class ImportShimResolver {
5656 for ( const resolver of this . resolvers ) {
5757 try {
5858 const module = await this . importShim (
59- "use$" + resolver . name + "$" + moduleName
59+ "use$" + resolver . name + "$" + moduleName ,
6060 ) ;
6161 console . log ( "loaded module" , moduleName , "using" , resolver . name ) ;
6262 return {
@@ -79,7 +79,7 @@ export class ImportShimResolver {
7979 resolver : ExternalModuleResolver ,
8080 moduleName : string , // can be a relative URL, absolute URL, or "package name"
8181 parent : string , // the parent URL the package is loaded from
82- importShimResolve : any // the original resolve function from es-module-shims
82+ importShimResolve : any , // the original resolve function from es-module-shims
8383 ) : Promise < string > {
8484 // first try to see if the LocalResolver wants to resolve this module
8585 const localURL = await this . tryLocalResolver ( moduleName ) ;
@@ -107,7 +107,7 @@ export class ImportShimResolver {
107107 // that we want to override with a package from LocalResolver
108108 const localURL = await this . tryLocalResolver (
109109 parsedModule . module ,
110- parsedModule . mode
110+ parsedModule . mode ,
111111 ) ;
112112 if ( localURL ) {
113113 return localURL ;
@@ -121,7 +121,7 @@ export class ImportShimResolver {
121121 resolver ,
122122 "maplibre-gl" ,
123123 parent ,
124- importShimResolve
124+ importShimResolve ,
125125 ) ;
126126 }
127127 }
@@ -142,7 +142,7 @@ export class ImportShimResolver {
142142
143143 private async tryLocalResolver (
144144 moduleName : string ,
145- mode ?: string
145+ mode ?: string ,
146146 ) : Promise < string | undefined > {
147147 const local = await this . localResolver . getModule ( moduleName , mode ) ;
148148 if ( local ) {
@@ -169,11 +169,11 @@ export class ImportShimResolver {
169169 private getLocalURLForModule (
170170 loadedModule : any ,
171171 moduleName : string ,
172- mode ?: string
172+ mode ?: string ,
173173 ) {
174174 const safeName = ( moduleName + "/" + mode ) . replaceAll (
175175 / [ ^ a - z A - Z 0 - 9 _ ] / g,
176- "$"
176+ "$" ,
177177 ) ;
178178
179179 if ( ( window as any ) [ "__typecell_url_" + safeName ] ) {
@@ -183,7 +183,7 @@ export class ImportShimResolver {
183183
184184 ( window as any ) [ "__typecell_pkg_" + safeName ] = loadedModule ;
185185 const list = Object . keys ( loadedModule ) . filter (
186- ( key ) => key !== "default" && key !== "window"
186+ ( key ) => key !== "default" && key !== "window" ,
187187 ) ;
188188
189189 const url = createBlob ( `
@@ -202,7 +202,7 @@ export class ImportShimResolver {
202202 private onImportShimResolve = async (
203203 id : string ,
204204 parent : string ,
205- importShimResolve : any
205+ importShimResolve : any ,
206206 ) => {
207207 // by default, try the first resolver
208208 let resolver = this . resolvers [ 0 ] ;
@@ -221,7 +221,7 @@ export class ImportShimResolver {
221221 // when there is a parent, this is expected (because it's a nested module).
222222 console . warn (
223223 "no explicit resolver detected in import, falling back to default" ,
224- id
224+ id ,
225225 ) ;
226226 }
227227 }
@@ -230,7 +230,7 @@ export class ImportShimResolver {
230230 resolver ,
231231 id ,
232232 parent ,
233- importShimResolve
233+ importShimResolve ,
234234 ) ;
235235 return ret ;
236236 } ;
0 commit comments