@@ -33,7 +33,8 @@ const config: DenoPluginConfig = {
3333 enable : true ,
3434} ;
3535
36- let parsedImportMap : ImportMaps | null = null ;
36+ let parsedImportMap : ImportMaps ;
37+
3738let projectDirectory : string ;
3839
3940module . exports = function init (
@@ -140,12 +141,10 @@ module.exports = function init(
140141
141142 const resolvedModules : ( ResolvedModuleFull | undefined ) [ ] = [ ] ;
142143
143- if ( config . importmap != null ) {
144- parsedImportMap = parseImportMapFromFile (
145- projectDirectory ,
146- config . importmap ,
147- ) ;
148- }
144+ parsedImportMap = parseImportMapFromFile (
145+ projectDirectory ,
146+ config . importmap ,
147+ ) ;
149148
150149 // try resolve typeReferenceDirectives
151150 for ( let moduleName of moduleNames ) {
@@ -157,15 +156,15 @@ module.exports = function init(
157156 ) ;
158157
159158 if ( parsedModuleName == null ) {
160- logger . info ( `module "${ moduleName } " can not parsed` )
159+ logger . info ( `module "${ moduleName } " can not parsed` ) ;
161160 resolvedModules . push ( undefined ) ;
162161 continue ;
163162 }
164163
165164 const resolvedModule = resolveDenoModule ( parsedModuleName ) ;
166165
167166 if ( ! resolvedModule ) {
168- logger . info ( `module "${ moduleName } " can not resolved` )
167+ logger . info ( `module "${ moduleName } " can not resolved` ) ;
169168 resolvedModules . push ( undefined ) ;
170169 continue ;
171170 }
@@ -380,7 +379,8 @@ module.exports = function init(
380379
381380 if ( isHttpURL ( parsedModuleName ) ) {
382381 d . code = 10002 ; // RemoteModuleNotExist
383- d . messageText = `The remote module "${ moduleName } " have not cached locally` ;
382+ d . messageText =
383+ `The remote module "${ moduleName } " have not cached locally` ;
384384 return d ;
385385 }
386386
@@ -419,12 +419,10 @@ module.exports = function init(
419419 logger . info ( "config change to:\n" + JSON . stringify ( c , null , " " ) ) ;
420420 Object . assign ( config , c ) ;
421421
422- if ( config . importmap != null ) {
423- parsedImportMap = parseImportMapFromFile (
424- projectDirectory ,
425- config . importmap ,
426- ) ;
427- }
422+ parsedImportMap = parseImportMapFromFile (
423+ projectDirectory ,
424+ config . importmap ,
425+ ) ;
428426
429427 pluginInfo . project . markAsDirty ( ) ;
430428 pluginInfo . project . refreshDiagnostics ( ) ;
@@ -434,15 +432,24 @@ module.exports = function init(
434432 } ;
435433} ;
436434
437- function parseImportMapFromFile ( cwd : string , file : string ) : ImportMaps | null {
435+ function parseImportMapFromFile ( cwd : string , file ?: string ) : ImportMaps {
436+ const importmps : ImportMaps = {
437+ imports : { } ,
438+ scopes : { } ,
439+ } ;
440+
441+ if ( file == null ) {
442+ return importmps ;
443+ }
444+
438445 if ( ! path . isAbsolute ( file ) ) {
439446 file = path . resolve ( cwd , file ) ;
440447 }
441448
442449 const fullFilePath = normalizeFilepath ( file ) ;
443450
444451 if ( ! pathExistsSync ( fullFilePath ) ) {
445- return null ;
452+ return importmps ;
446453 }
447454
448455 const content = fs . readFileSync ( fullFilePath , {
@@ -452,7 +459,7 @@ function parseImportMapFromFile(cwd: string, file: string): ImportMaps | null {
452459 try {
453460 return parseFromString ( content , `file://${ cwd } /` ) ;
454461 } catch {
455- return null ;
462+ return importmps ;
456463 }
457464}
458465
0 commit comments