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: fix the ts version selected by the user #305

Merged
merged 9 commits into from
Feb 19, 2025
2 changes: 1 addition & 1 deletion src/monaco/vue.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ self.onmessage = async (msg: MessageEvent<WorkerMessage>) => {
async function importTsFromCdn(tsVersion: string) {
const _module = globalThis.module
;(globalThis as any).module = { exports: {} }
const tsUrl = `https://cdn.jsdelivr.net/npm/typescript@${tsVersion}/lib/typescript.js`
const tsUrl = `https://cdn.jsdelivr.net/npm/typescript@${tsVersion || 'latest'}/lib/typescript.js`
await import(/* @vite-ignore */ tsUrl)
const ts = globalThis.module.exports
globalThis.module = _module
Expand Down
7 changes: 5 additions & 2 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function useStore(
vueVersion = ref(null),

locale = ref(),
typescriptVersion = ref('latest'),
typescriptVersion = ref(null),
dependencyVersion = ref(Object.create(null)),
reloadLanguageTools = ref(),
}: Partial<StoreState> = {},
Expand Down Expand Up @@ -270,6 +270,7 @@ export function useStore(
}
}
if (vueVersion.value) files._version = vueVersion.value
if (typescriptVersion.value) files._tsVersion = typescriptVersion.value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I wonder if typescriptVersion === latest can be ignored ?
By default, all data may have a _tsVersion file.
But the default vueVersion is null.

Copy link
Contributor Author

@huangmingfu huangmingfu Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if the ts version is not transmitted, request 404.

const store = (window.store = useStore(
  {
    //  ...
    // typescriptVersion: ref('4.9.3')
  },
  location.hash,
))

image

My latest submission has solved this problem.
image
It is similar to the writing of vue version request.
image

return '#' + utoa(JSON.stringify(files))
}
const deserialize: ReplStore['deserialize'] = (
Expand All @@ -289,6 +290,8 @@ export function useStore(
for (const filename in saved) {
if (filename === '_version') {
vueVersion.value = saved[filename]
} else if (filename === '_tsVersion') {
typescriptVersion.value = saved[filename]
} else {
setFile(files.value, filename, saved[filename])
}
Expand Down Expand Up @@ -431,7 +434,7 @@ export type StoreState = ToRefs<{

// volar-related
locale: string | undefined
typescriptVersion: string
typescriptVersion: string | null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type 'string | null' is not assignable to type 'string'.
https://github.com/vuejs/repl/blob/main/src/monaco/env.ts#L140
https://github.com/vuejs/repl/blob/main/src/monaco/env.ts#L77


Perhaps the impact of this change would be minimal.

// L273
if (typescriptVersion.value !== 'latest' || files._tsVersion) {
  files._tsVersion = typescriptVersion.value
}

Copy link
Contributor Author

@huangmingfu huangmingfu Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to run the typecheck command to check. Thank you for your suggestion. I have already modified it.❤️

/** \{ dependencyName: version \} */
dependencyVersion: Record<string, string>
reloadLanguageTools?: (() => void) | undefined
Expand Down