Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(store): to check ImportMap after deserialize #315

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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