@@ -147,15 +147,22 @@ export async function loadAndUpgradeImportMap(workingDir: string): Promise<Impor
147
147
for ( const filename of Array . from ( [ 'import_map' , 'import-map' , 'importmap' ] ) . map ( name => `${ name } .json` ) ) {
148
148
importMapFile = join ( workingDir , filename )
149
149
if ( existsFileSync ( importMapFile ) ) {
150
- const data = JSON . parse ( await Deno . readTextFile ( importMapFile ) )
151
- const imports : Record < string , string > = toPlainStringRecord ( data . imports )
152
- const scopes : Record < string , Record < string , string > > = { }
153
- if ( util . isPlainObject ( data . scopes ) ) {
154
- Object . entries ( data . scopes ) . forEach ( ( [ scope , imports ] ) => {
155
- scopes [ scope ] = toPlainStringRecord ( imports )
156
- } )
150
+ try {
151
+ const data = JSON . parse ( await Deno . readTextFile ( importMapFile ) )
152
+ const imports : Record < string , string > = toPlainStringRecord ( data . imports )
153
+ const scopes : Record < string , Record < string , string > > = { }
154
+ if ( util . isPlainObject ( data . scopes ) ) {
155
+ Object . entries ( data . scopes ) . forEach ( ( [ scope , imports ] ) => {
156
+ scopes [ scope ] = toPlainStringRecord ( imports )
157
+ } )
158
+ }
159
+ Object . assign ( importMap , { imports, scopes } )
160
+ } catch ( e ) {
161
+ log . error ( `invalid '${ filename } ':` , e . message )
162
+ if ( ! confirm ( 'Continue?' ) ) {
163
+ Deno . exit ( 1 )
164
+ }
157
165
}
158
- Object . assign ( importMap , { imports, scopes } )
159
166
break
160
167
}
161
168
}
0 commit comments