Skip to content

Commit

Permalink
feat: save vue version
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Feb 10, 2024
1 parent 804e1ff commit 08b4492
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/import-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useVueImportMap(
}

const productionMode = ref(false)
const vueVersion = ref<string | undefined>()
const vueVersion = ref<string | null>(null)
const importMap = computed<ImportMap>(() => {
const vue =
(!vueVersion.value &&
Expand Down
11 changes: 8 additions & 3 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function useStore(
outputMode = ref('preview'),
sfcOptions = ref({}),
compiler = shallowRef(defaultCompiler),
vueVersion = ref(),
vueVersion = ref(null),

locale = ref(),
typescriptVersion = ref('latest'),
Expand Down Expand Up @@ -257,7 +257,11 @@ export function useStore(
serializedState = serializedState.slice(1)
const saved = JSON.parse(atou(serializedState))
for (const filename in saved) {
setFile(files.value, filename, saved[filename])
if (filename === '_version') {
vueVersion.value = saved[filename]
} else {
setFile(files.value, filename, saved[filename])
}
}
}
const getFiles: ReplStore['getFiles'] = () => {
Expand All @@ -266,6 +270,7 @@ export function useStore(
const normalized = stripSrcPrefix(filename)
exported[normalized] = file.code
}
if (vueVersion.value) exported._version = vueVersion.value
return exported
}
const setFiles: ReplStore['setFiles'] = async (
Expand Down Expand Up @@ -385,7 +390,7 @@ export type StoreState = ToRefs<{
/** `@vue/compiler-sfc` */
compiler: typeof defaultCompiler
/* only apply for compiler-sfc */
vueVersion: string | undefined
vueVersion: string | null

// volar-related
locale: string | undefined
Expand Down

0 comments on commit 08b4492

Please sign in to comment.