Skip to content

feat: support configuration of compileFile #339

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 12 additions & 5 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
watchEffect,
} from 'vue'
import * as defaultCompiler from 'vue/compiler-sfc'
import { compileFile } from './transform'
import { compileFile as defaultCompileFile } from './transform'
import { atou, utoa } from './utils'
import type {
SFCAsyncStyleCompileOptions,
Expand Down Expand Up @@ -43,6 +43,7 @@ export function useStore(
sfcOptions = ref({}),
compiler = shallowRef(defaultCompiler),
vueVersion = ref(null),
compileFile = ref(defaultCompileFile),

locale = ref(),
typescriptVersion = ref('latest'),
Expand All @@ -65,7 +66,9 @@ export function useStore(

function init() {
watchEffect(() => {
compileFile(store, activeFile.value).then((errs) => (errors.value = errs))
compileFile
.value(store, activeFile.value)
.then((errs) => (errors.value = errs))
})

watch(
Expand Down Expand Up @@ -137,7 +140,9 @@ export function useStore(
errors.value = []
for (const [filename, file] of Object.entries(files.value)) {
if (filename !== mainFile.value) {
compileFile(store, file).then((errs) => errors.value.push(...errs))
compileFile
.value(store, file)
.then((errs) => errors.value.push(...errs))
}
}
}
Expand Down Expand Up @@ -223,7 +228,7 @@ export function useStore(
if (activeFilename.value === oldFilename) {
activeFilename.value = newFilename
} else {
compileFile(store, file).then((errs) => (errors.value = errs))
compileFile.value(store, file).then((errs) => (errors.value = errs))
}
}
const getImportMap: Store['getImportMap'] = () => {
Expand Down Expand Up @@ -326,7 +331,7 @@ export function useStore(

const errors = []
for (const file of Object.values(files)) {
errors.push(...(await compileFile(store, file)))
errors.push(...(await compileFile.value(store, file)))
}

store.mainFile = mainFile
Expand Down Expand Up @@ -371,6 +376,7 @@ export function useStore(
compiler,
loading,
vueVersion,
compileFile,

locale,
typescriptVersion,
Expand Down Expand Up @@ -433,6 +439,7 @@ export type StoreState = ToRefs<{
compiler: typeof defaultCompiler
/* only apply for compiler-sfc */
vueVersion: string | null
compileFile: typeof defaultCompileFile

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