Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit dc94a0d

Browse files
committed
Show prompt when the import_map is incorrect
1 parent 8798587 commit dc94a0d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

server/config.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,22 @@ export async function loadAndUpgradeImportMap(workingDir: string): Promise<Impor
147147
for (const filename of Array.from(['import_map', 'import-map', 'importmap']).map(name => `${name}.json`)) {
148148
importMapFile = join(workingDir, filename)
149149
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+
}
157165
}
158-
Object.assign(importMap, { imports, scopes })
159166
break
160167
}
161168
}

0 commit comments

Comments
 (0)