Skip to content

Commit

Permalink
fix: apply builtin import map after deserialize (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangcch authored Feb 17, 2025
1 parent b549715 commit e62ddda
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ export function useStore(
if (vueVersion.value) files._version = vueVersion.value
return '#' + utoa(JSON.stringify(files))
}
const deserialize: ReplStore['deserialize'] = (serializedState: string) => {
const deserialize: ReplStore['deserialize'] = (
serializedState: string,
checkBuiltinImportMap = true,
) => {
if (serializedState.startsWith('#'))
serializedState = serializedState.slice(1)
let saved: any
Expand All @@ -290,6 +293,9 @@ export function useStore(
setFile(files.value, filename, saved[filename])
}
}
if (checkBuiltinImportMap) {
applyBuiltinImportMap()
}
}
const getFiles: ReplStore['getFiles'] = () => {
const exported: Record<string, string> = {}
Expand Down Expand Up @@ -333,7 +339,7 @@ export function useStore(
}

if (serializedState) {
deserialize(serializedState)
deserialize(serializedState, false)
} else {
setDefaultFile()
}
Expand Down Expand Up @@ -444,7 +450,12 @@ export interface ReplStore extends UnwrapRef<StoreState> {
setImportMap(map: ImportMap, merge?: boolean): void
getTsConfig(): Record<string, any>
serialize(): string
deserialize(serializedState: string): void
/**
* Deserializes the given string to restore the REPL store state.
* @param serializedState - The serialized state string.
* @param checkBuiltinImportMap - Whether to check the built-in import map. Default to true
*/
deserialize(serializedState: string, checkBuiltinImportMap?: boolean): void
getFiles(): Record<string, string>
setFiles(newFiles: Record<string, string>, mainFile?: string): Promise<void>
}
Expand Down

0 comments on commit e62ddda

Please sign in to comment.