Skip to content

Commit

Permalink
fix(vue-tsc): support volar v1.0.14 (#194)
Browse files Browse the repository at this point in the history
Fixes #193

volar v1.0.14 renamed the `proxy.ts` file in `index.ts` and changed `createProgramProxy` into `createProgram`.
  • Loading branch information
cexbrayat authored Dec 21, 2022
1 parent 82f30b1 commit 538a0d9
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 90 deletions.
2 changes: 1 addition & 1 deletion packages/vite-plugin-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@
"typescript": "~4.5.5",
"vls": "^0.7.6",
"vti": "^0.1.7",
"vue-tsc": "0.38.9"
"vue-tsc": "1.0.14"
}
}
14 changes: 12 additions & 2 deletions packages/vite-plugin-checker/src/checkers/vueTsc/prepareVueTsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ const _require = createRequire(import.meta.url)
const _filename = fileURLToPath(import.meta.url)
const _dirname = dirname(_filename)

const proxyPath = _require.resolve('vue-tsc/out/proxy')
let proxyPath: string
let createProgramFunction: string
try {
// vue-tsc exposes the proxy in vue-tsc/out/index after v1.0.14
proxyPath = _require.resolve('vue-tsc/out/index')
createProgramFunction = 'createProgram'
} catch (e) {
// vue-tsc exposes the proxy in vue-tsc/out/proxy before v1.0.14
proxyPath = _require.resolve('vue-tsc/out/proxy')
createProgramFunction = 'createProgramProxy'
}

const textToReplace: { target: string; replacement: string }[] = [
{
Expand All @@ -34,7 +44,7 @@ const textToReplace: { target: string; replacement: string }[] = [
target: `function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) {`,
replacement: `function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) { return require(${JSON.stringify(
proxyPath
)}).createProgramProxy(...arguments);`,
)}).${createProgramFunction}(...arguments);`,
},
{
target: `ts.executeCommandLine(ts.sys, ts.noop, ts.sys.args);`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Vitest Snapshot v1

exports[`vue-tsc-vue3 > serve > get initial error and subsequent error 1`] = `"[{\\"checkerId\\":\\"vue-tsc\\",\\"frame\\":\\" 1 | <template>/n 2 | <img alt=/\\"Vue logo/\\" src=/\\"./assets/logo.png/\\" />/n > 3 | <HelloWorld msg1=/\\"Diana/\\" />/n | ^^^^^^^^^^/n 4 | </template>/n 5 |/n 6 | <script lang=/\\"ts/\\">\\",\\"id\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3/src/App.vue\\",\\"level\\":1,\\"loc\\":{\\"column\\":4,\\"file\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3/src/App.vue\\",\\"line\\":3},\\"message\\":\\"Type '{ msg1: string; }' is not assignable to type 'IntrinsicAttributes & Partial<{}> & Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'./n Property 'msg' is missing in type '{ msg1: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.\\",\\"stack\\":\\"\\"}]"`;
exports[`vue-tsc-vue3 > serve > get initial error and subsequent error 1`] = `"[{\\"checkerId\\":\\"vue-tsc\\",\\"frame\\":\\" 1 | <template>/n 2 | <img alt=/\\"Vue logo/\\" src=/\\"./assets/logo.png/\\" />/n > 3 | <HelloWorld msg1=/\\"Diana/\\" />/n | ^^^^^^^^^^/n 4 | </template>/n 5 |/n 6 | <script lang=/\\"ts/\\">\\",\\"id\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3/src/App.vue\\",\\"level\\":1,\\"loc\\":{\\"column\\":4,\\"file\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3/src/App.vue\\",\\"line\\":3},\\"message\\":\\"Type '{ msg1: string; }' is not assignable to type 'ComponentProps<DefineComponent<{ msg: { type: StringConstructor; required: true; }; }, { count: Ref<number>; }, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 4 more ..., {}>>'./n Property 'msg' is missing in type '{ msg1: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.\\",\\"stack\\":\\"\\"}]"`;

exports[`vue-tsc-vue3 > serve > get initial error and subsequent error 2`] = `
"
ERROR(vue-tsc) Type '{ msg1: string; }' is not assignable to type 'IntrinsicAttributes & Partial<{}> & Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.
ERROR(vue-tsc) Type '{ msg1: string; }' is not assignable to type 'ComponentProps<DefineComponent<{ msg: { type: StringConstructor; required: true; }; }, { count: Ref<number>; }, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 4 more ..., {}>>'.
Property 'msg' is missing in type '{ msg1: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.
FILE <PROJECT_ROOT>/playground-temp/vue-tsc-vue3/src/App.vue:3:4
Expand All @@ -19,11 +19,11 @@ exports[`vue-tsc-vue3 > serve > get initial error and subsequent error 2`] = `
[vue-tsc] Found 1 error. Watching for file changes."
`;
exports[`vue-tsc-vue3 > serve > get initial error and subsequent error 3`] = `"[{\\"checkerId\\":\\"vue-tsc\\",\\"frame\\":\\" 1 | <template>/n 2 | <img alt=/\\"Vue logo/\\" src=/\\"./assets/logo.png/\\" />/n > 3 | <HelloWorld msg2=/\\"Diana/\\" />/n | ^^^^^^^^^^/n 4 | </template>/n 5 |/n 6 | <script lang=/\\"ts/\\">\\",\\"id\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3/src/App.vue\\",\\"level\\":1,\\"loc\\":{\\"column\\":4,\\"file\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3/src/App.vue\\",\\"line\\":3},\\"message\\":\\"Type '{ msg2: string; }' is not assignable to type 'IntrinsicAttributes & Partial<{}> & Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'./n Property 'msg' is missing in type '{ msg2: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.\\",\\"stack\\":\\"\\"}]"`;
exports[`vue-tsc-vue3 > serve > get initial error and subsequent error 3`] = `"[{\\"checkerId\\":\\"vue-tsc\\",\\"frame\\":\\" 1 | <template>/n 2 | <img alt=/\\"Vue logo/\\" src=/\\"./assets/logo.png/\\" />/n > 3 | <HelloWorld msg2=/\\"Diana/\\" />/n | ^^^^^^^^^^/n 4 | </template>/n 5 |/n 6 | <script lang=/\\"ts/\\">\\",\\"id\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3/src/App.vue\\",\\"level\\":1,\\"loc\\":{\\"column\\":4,\\"file\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3/src/App.vue\\",\\"line\\":3},\\"message\\":\\"Type '{ msg2: string; }' is not assignable to type 'ComponentProps<DefineComponent<{ msg: { type: StringConstructor; required: true; }; }, { count: Ref<number>; }, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 4 more ..., {}>>'./n Property 'msg' is missing in type '{ msg2: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.\\",\\"stack\\":\\"\\"}]"`;
exports[`vue-tsc-vue3 > serve > get initial error and subsequent error 4`] = `
"
ERROR(vue-tsc) Type '{ msg2: string; }' is not assignable to type 'IntrinsicAttributes & Partial<{}> & Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.
ERROR(vue-tsc) Type '{ msg2: string; }' is not assignable to type 'ComponentProps<DefineComponent<{ msg: { type: StringConstructor; required: true; }; }, { count: Ref<number>; }, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 4 more ..., {}>>'.
Property 'msg' is missing in type '{ msg2: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.
FILE <PROJECT_ROOT>/playground-temp/vue-tsc-vue3/src/App.vue:3:4
Expand Down
2 changes: 1 addition & 1 deletion playground/vue-tsc-vue3/__tests__/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('vue-tsc-vue3', () => {

describe.runIf(isBuild)('build', () => {
it('should fail', async () => {
const expectedMsg = `src/App.vue(3,4): error TS2322: Type '{ msg1: string; }' is not assignable to type 'IntrinsicAttributes & Partial<{}> & Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.`
const expectedMsg = `src/App.vue(3,4): error TS2322: Type '{ msg1: string; }' is not assignable to type 'ComponentProps<DefineComponent<{ msg: { type: StringConstructor; required: true; }; }, { count: Ref<number>; }, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 4 more ..., {}>>'.`
expectStderrContains(log, expectedMsg)
})
})
Expand Down
2 changes: 1 addition & 1 deletion playground/vue-tsc-vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"typescript": "~4.5.5",
"vite": "^3.0.4",
"vite-plugin-checker": "workspace:*",
"vue-tsc": "^0.39.5"
"vue-tsc": "^1.0.14"
}
}
Loading

0 comments on commit 538a0d9

Please sign in to comment.