Skip to content

Commit cb39157

Browse files
committed
refactor: replace 'vue' imports with 'core'
1 parent 335eca3 commit cb39157

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

packages/component-meta/lib/base.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createLanguageServiceHost, resolveFileLanguageId, type TypeScriptProjectHost } from '@volar/typescript';
2-
import * as vue from '@vue/language-core';
2+
import * as core from '@vue/language-core';
33
import { posix as path } from 'path-browserify';
44
import type * as ts from 'typescript';
55

@@ -28,15 +28,15 @@ export function createCheckerByJsonConfigBase(
2828
return baseCreate(
2929
ts,
3030
() => {
31-
const commandLine = vue.createParsedCommandLineByJson(ts, ts.sys, rootDir, json);
31+
const commandLine = core.createParsedCommandLineByJson(ts, ts.sys, rootDir, json);
3232
const { fileNames } = ts.parseJsonConfigFileContent(
3333
json,
3434
ts.sys,
3535
rootDir,
3636
{},
3737
undefined,
3838
undefined,
39-
vue.getAllExtensions(commandLine.vueOptions)
39+
core.getAllExtensions(commandLine.vueOptions)
4040
.map(extension => ({
4141
extension: extension.slice(1),
4242
isMixedContent: true,
@@ -60,15 +60,15 @@ export function createCheckerBase(
6060
return baseCreate(
6161
ts,
6262
() => {
63-
const commandLine = vue.createParsedCommandLine(ts, ts.sys, tsconfig);
63+
const commandLine = core.createParsedCommandLine(ts, ts.sys, tsconfig);
6464
const { fileNames } = ts.parseJsonSourceFileConfigFileContent(
6565
ts.readJsonConfigFile(tsconfig, ts.sys.readFile),
6666
ts.sys,
6767
path.dirname(tsconfig),
6868
{},
6969
tsconfig,
7070
undefined,
71-
vue.getAllExtensions(commandLine.vueOptions)
71+
core.getAllExtensions(commandLine.vueOptions)
7272
.map(extension => ({
7373
extension: extension.slice(1),
7474
isMixedContent: true,
@@ -86,7 +86,7 @@ export function createCheckerBase(
8686
function baseCreate(
8787
ts: typeof import('typescript'),
8888
getConfigAndFiles: () => [
89-
commandLine: vue.ParsedCommandLine,
89+
commandLine: core.ParsedCommandLine,
9090
fileNames: string[],
9191
],
9292
checkerOptions: MetaCheckerOptions,
@@ -100,7 +100,7 @@ function baseCreate(
100100
let fileNamesSet = new Set(fileNames.map(path => path.replace(windowsPathReg, '/')));
101101
let projectVersion = 0;
102102

103-
vueOptions.globalTypesPath = vue.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
103+
vueOptions.globalTypesPath = core.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
104104

105105
const projectHost: TypeScriptProjectHost = {
106106
getCurrentDirectory: () => rootPath,
@@ -123,13 +123,13 @@ function baseCreate(
123123
];
124124
};
125125

126-
const vueLanguagePlugin = vue.createVueLanguagePlugin<string>(
126+
const vueLanguagePlugin = core.createVueLanguagePlugin<string>(
127127
ts,
128128
projectHost.getCompilationSettings(),
129129
vueOptions,
130130
id => id,
131131
);
132-
const language = vue.createLanguage(
132+
const language = core.createLanguage(
133133
[
134134
vueLanguagePlugin,
135135
{
@@ -138,7 +138,7 @@ function baseCreate(
138138
},
139139
},
140140
],
141-
new vue.FileMap(ts.sys.useCaseSensitiveFileNames),
141+
new core.FileMap(ts.sys.useCaseSensitiveFileNames),
142142
fileName => {
143143
let snapshot = scriptSnapshots.get(fileName);
144144

@@ -210,7 +210,7 @@ function baseCreate(
210210
},
211211
reload() {
212212
[{ vueOptions, options, projectReferences }, fileNames] = getConfigAndFiles();
213-
vueOptions.globalTypesPath = vue.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
213+
vueOptions.globalTypesPath = core.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
214214
fileNamesSet = new Set(fileNames.map(path => path.replace(windowsPathReg, '/')));
215215
this.clearCache();
216216
},
@@ -348,7 +348,7 @@ interface ComponentMeta<T> {
348348

349349
const vueFile = sourceScript.generated?.root;
350350
const vueDefaults = vueFile && exportName === 'default'
351-
? (vueFile instanceof vue.VueVirtualCode ? readVueComponentDefaultProps(vueFile, printer, ts) : {})
351+
? (vueFile instanceof core.VueVirtualCode ? readVueComponentDefaultProps(vueFile, printer, ts) : {})
352352
: {};
353353
const tsDefaults = !vueFile
354354
? readTsComponentDefaultProps(
@@ -493,7 +493,7 @@ function createSchemaResolvers(
493493
symbolNode: ts.Expression,
494494
{ rawType, schema: options, noDeclarations }: MetaCheckerOptions,
495495
ts: typeof import('typescript'),
496-
language: vue.Language<string>,
496+
language: core.Language<string>,
497497
) {
498498
const visited = new Set<ts.Type>();
499499

@@ -758,7 +758,7 @@ function createSchemaResolvers(
758758
}
759759

760760
function readVueComponentDefaultProps(
761-
root: vue.VueVirtualCode,
761+
root: core.VueVirtualCode,
762762
printer: ts.Printer | undefined,
763763
ts: typeof import('typescript'),
764764
) {
@@ -779,7 +779,7 @@ function readVueComponentDefaultProps(
779779
}
780780
const { ast } = sfc.scriptSetup;
781781

782-
const codegen = vue.tsCodegen.get(sfc);
782+
const codegen = core.tsCodegen.get(sfc);
783783
const scriptSetupRanges = codegen?.getScriptSetupRanges();
784784

785785
if (scriptSetupRanges?.withDefaults?.argNode) {

packages/tsc/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { runTsc } from '@volar/typescript/lib/quickstart/runTsc';
2-
import * as vue from '@vue/language-core';
2+
import * as core from '@vue/language-core';
33

44
const windowsPathReg = /\\/g;
55

@@ -14,16 +14,16 @@ export function run(tscPath = require.resolve('typescript/lib/tsc')) {
1414
(ts, options) => {
1515
const { configFilePath } = options.options;
1616
const vueOptions = typeof configFilePath === 'string'
17-
? vue.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions
18-
: vue.createParsedCommandLineByJson(ts, ts.sys, (options.host ?? ts.sys).getCurrentDirectory(), {})
17+
? core.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions
18+
: core.createParsedCommandLineByJson(ts, ts.sys, (options.host ?? ts.sys).getCurrentDirectory(), {})
1919
.vueOptions;
20-
vueOptions.globalTypesPath = vue.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
21-
const allExtensions = vue.getAllExtensions(vueOptions);
20+
vueOptions.globalTypesPath = core.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
21+
const allExtensions = core.getAllExtensions(vueOptions);
2222
if (
2323
runExtensions.length === allExtensions.length
2424
&& runExtensions.every(ext => allExtensions.includes(ext))
2525
) {
26-
const vueLanguagePlugin = vue.createVueLanguagePlugin<string>(
26+
const vueLanguagePlugin = core.createVueLanguagePlugin<string>(
2727
ts,
2828
options.options,
2929
vueOptions,

packages/tsc/tests/dts.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { proxyCreateProgram } from '@volar/typescript';
2-
import * as vue from '@vue/language-core';
2+
import * as core from '@vue/language-core';
33
import * as fs from 'node:fs';
44
import * as path from 'node:path';
55
import * as ts from 'typescript';
@@ -24,20 +24,21 @@ describe('vue-tsc-dts', () => {
2424
options: compilerOptions,
2525
};
2626

27-
let vueOptions: vue.VueCompilerOptions;
27+
let vueOptions: core.VueCompilerOptions;
2828

2929
const createProgram = proxyCreateProgram(ts, ts.createProgram, (ts, options) => {
3030
const { configFilePath } = options.options;
3131
if (typeof configFilePath === 'string') {
32-
vueOptions = vue.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions;
32+
vueOptions = core.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions;
3333
}
3434
else {
35-
vueOptions = vue.createParsedCommandLineByJson(ts, ts.sys, workspace.replace(windowsPathReg, '/'), {}).vueOptions;
35+
vueOptions =
36+
core.createParsedCommandLineByJson(ts, ts.sys, workspace.replace(windowsPathReg, '/'), {}).vueOptions;
3637
vueOptions.target = 99;
3738
vueOptions.extensions = ['vue', 'cext'];
3839
}
39-
vueOptions.globalTypesPath = vue.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
40-
const vueLanguagePlugin = vue.createVueLanguagePlugin<string>(
40+
vueOptions.globalTypesPath = core.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
41+
const vueLanguagePlugin = core.createVueLanguagePlugin<string>(
4142
ts,
4243
options.options,
4344
vueOptions,

packages/typescript-plugin/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createLanguageServicePlugin } from '@volar/typescript/lib/quickstart/createLanguageServicePlugin';
2-
import * as vue from '@vue/language-core';
2+
import * as core from '@vue/language-core';
33
import type * as ts from 'typescript';
44
import { createVueLanguageServiceProxy } from './lib/common';
55
import type { Requests } from './lib/requests';
@@ -17,13 +17,13 @@ import { isRefAtPosition } from './lib/requests/isRefAtPosition';
1717
export = createLanguageServicePlugin(
1818
(ts, info) => {
1919
const vueOptions = getVueCompilerOptions();
20-
const languagePlugin = vue.createVueLanguagePlugin<string>(
20+
const languagePlugin = core.createVueLanguagePlugin<string>(
2121
ts,
2222
info.languageServiceHost.getCompilationSettings(),
2323
vueOptions,
2424
id => id,
2525
);
26-
vueOptions.globalTypesPath = vue.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
26+
vueOptions.globalTypesPath = core.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
2727
addVueCommands();
2828

2929
return {
@@ -43,10 +43,10 @@ export = createLanguageServicePlugin(
4343
function getVueCompilerOptions() {
4444
if (info.project.projectKind === ts.server.ProjectKind.Configured) {
4545
const tsconfig = info.project.getProjectName();
46-
return vue.createParsedCommandLine(ts, ts.sys, tsconfig.replace(/\\/g, '/')).vueOptions;
46+
return core.createParsedCommandLine(ts, ts.sys, tsconfig.replace(/\\/g, '/')).vueOptions;
4747
}
4848
else {
49-
return vue.createParsedCommandLineByJson(ts, ts.sys, info.languageServiceHost.getCurrentDirectory(), {})
49+
return core.createParsedCommandLineByJson(ts, ts.sys, info.languageServiceHost.getCurrentDirectory(), {})
5050
.vueOptions;
5151
}
5252
}
@@ -187,7 +187,7 @@ export = createLanguageServicePlugin(
187187
throw new Error('No source script found for file: ' + fileName);
188188
}
189189
const virtualCode = sourceScript.generated?.root;
190-
if (!(virtualCode instanceof vue.VueVirtualCode)) {
190+
if (!(virtualCode instanceof core.VueVirtualCode)) {
191191
throw new Error('No virtual code found for file: ' + fileName);
192192
}
193193
return {

0 commit comments

Comments
 (0)