vue-tsc 0.32.1 → 0.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,7 +13,7 @@ Roadmap:
13
13
  - [x] Make `typescript` as peerDependencies
14
14
  - [x] Cleaner dependencies (remove `prettyhtml`, `prettier` etc.) (with `vscode-vue-languageservice` version >= 0.26.4)
15
15
  - [x] dts emit support
16
- - [ ] Watch mode support
16
+ - [x] Watch mode support
17
17
 
18
18
  ## Using
19
19
 
@@ -29,8 +29,8 @@ Check out https://github.com/johnsoncodehk/volar/discussions/640#discussioncomme
29
29
 
30
30
  ## Sponsors
31
31
 
32
- This company is [sponsoring this project](https://github.com/sponsors/johnsoncodehk) to improve your DX. 💪
33
-
34
- <a href="https://github.com/Leniolabs">
35
- <img itemprop="image" src="https://github.com/Leniolabs.png" width="100" height="100">
36
- </a>
32
+ <p align="center">
33
+ <a href="https://cdn.jsdelivr.net/gh/johnsoncodehk/sponsors/sponsors.svg">
34
+ <img src='https://cdn.jsdelivr.net/gh/johnsoncodehk/sponsors/sponsors.svg'/>
35
+ </a>
36
+ </p>
package/bin/vue-tsc.js CHANGED
@@ -8,13 +8,25 @@ const proxyPath = require.resolve('../out/proxy');
8
8
  fs.readFileSync = (...args) => {
9
9
  if (args[0] === tscPath) {
10
10
  let tsc = readFileSync(...args);
11
+
12
+ // add *.vue files to allow extensions
11
13
  tsc = tsc.replace(
12
- `function createIncrementalProgram(_a) {`,
13
- `function createIncrementalProgram(_a) { console.error('incremental mode is not yet supported'); throw 'incremental mode is not yet supported';`,
14
+ `ts.supportedTSExtensions = [[".ts", ".tsx", ".d.ts"], [".cts", ".d.cts"], [".mts", ".d.mts"]];`,
15
+ `ts.supportedTSExtensions = [[".ts", ".tsx", ".d.ts"], [".cts", ".d.cts"], [".mts", ".d.mts"], [".vue"]];`,
16
+ );
17
+ tsc = tsc.replace(
18
+ `ts.supportedJSExtensions = [[".js", ".jsx"], [".mjs"], [".cjs"]];`,
19
+ `ts.supportedJSExtensions = [[".js", ".jsx"], [".mjs"], [".cjs"], [".vue"]];`,
14
20
  );
15
21
  tsc = tsc.replace(
16
- `function createWatchProgram(host) {`,
17
- `function createWatchProgram(host) { console.error('watch mode is not yet supported'); throw 'watch mode is not yet supported';`,
22
+ `var allSupportedExtensions = [[".ts", ".tsx", ".d.ts", ".js", ".jsx"], [".cts", ".d.cts", ".cjs"], [".mts", ".d.mts", ".mjs"]];`,
23
+ `var allSupportedExtensions = [[".ts", ".tsx", ".d.ts", ".js", ".jsx"], [".cts", ".d.cts", ".cjs"], [".mts", ".d.mts", ".mjs"], [".vue"]];`,
24
+ );
25
+
26
+ // proxy createProgram apis
27
+ tsc = tsc.replace(
28
+ `function createIncrementalProgram(_a) {`,
29
+ `function createIncrementalProgram(_a) { console.error('incremental mode is not yet supported'); throw 'incremental mode is not yet supported';`,
18
30
  );
19
31
  tsc = tsc.replace(
20
32
  `function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) {`,
package/out/apis.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type * as ts from 'typescript/lib/tsserverlibrary';
2
+ import type { TypeScriptFeaturesRuntimeContext } from '@volar/vue-typescript';
3
+ export declare function register(ts: typeof import('typescript/lib/tsserverlibrary'), { vueDocuments, templateTsLsRaw, scriptTsLsRaw, templateTsHost, scriptTsHost, vueHost }: TypeScriptFeaturesRuntimeContext): {
4
+ getRootFileNames: () => string[];
5
+ emit: (targetSourceFile?: ts.SourceFile | undefined, _writeFile?: ts.WriteFileCallback | undefined, cancellationToken?: ts.CancellationToken | undefined, emitOnlyDtsFiles?: boolean | undefined, customTransformers?: ts.CustomTransformers | undefined) => ts.EmitResult;
6
+ getSyntacticDiagnostics: (sourceFile?: ts.SourceFile | undefined, cancellationToken?: ts.CancellationToken | undefined) => readonly ts.DiagnosticWithLocation[] | readonly ts.Diagnostic[];
7
+ getSemanticDiagnostics: (sourceFile?: ts.SourceFile | undefined, cancellationToken?: ts.CancellationToken | undefined) => readonly ts.DiagnosticWithLocation[] | readonly ts.Diagnostic[];
8
+ getGlobalDiagnostics: (cancellationToken?: ts.CancellationToken | undefined) => readonly ts.Diagnostic[];
9
+ getBindAndCheckDiagnostics: (sourceFile?: ts.SourceFile | undefined, cancellationToken?: ts.CancellationToken | undefined) => readonly ts.DiagnosticWithLocation[] | readonly ts.Diagnostic[];
10
+ };
package/out/apis.js ADDED
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.register = void 0;
4
+ const shared = require("@volar/shared");
5
+ const lsTypes = ['script', 'template'];
6
+ function register(ts, { vueDocuments, templateTsLsRaw, scriptTsLsRaw, templateTsHost, scriptTsHost, vueHost }) {
7
+ return {
8
+ getRootFileNames,
9
+ emit,
10
+ getSyntacticDiagnostics,
11
+ getSemanticDiagnostics,
12
+ getGlobalDiagnostics,
13
+ getBindAndCheckDiagnostics,
14
+ };
15
+ function getRootFileNames() {
16
+ const set = new Set([
17
+ ...getProgram('script').getRootFileNames().filter(fileName => { var _a; return (_a = scriptTsHost.fileExists) === null || _a === void 0 ? void 0 : _a.call(scriptTsHost, fileName); }),
18
+ ...getProgram('template').getRootFileNames().filter(fileName => { var _a; return (_a = templateTsHost.fileExists) === null || _a === void 0 ? void 0 : _a.call(templateTsHost, fileName); }),
19
+ ]);
20
+ return [...set.values()];
21
+ }
22
+ // for vue-tsc --noEmit --watch
23
+ function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
24
+ return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getBindAndCheckDiagnostics');
25
+ }
26
+ // for vue-tsc --noEmit
27
+ function getSyntacticDiagnostics(sourceFile, cancellationToken) {
28
+ return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSyntacticDiagnostics');
29
+ }
30
+ function getSemanticDiagnostics(sourceFile, cancellationToken) {
31
+ return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSemanticDiagnostics');
32
+ }
33
+ function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
34
+ if (sourceFile) {
35
+ const sourceMap = vueDocuments.fromEmbeddedDocumentUri('script', shared.fsPathToUri(sourceFile.fileName));
36
+ const vueDocument = sourceMap ? vueDocuments.get(sourceMap.sourceDocument.uri) : undefined;
37
+ if (vueDocument) {
38
+ let results = [];
39
+ const sourceMaps = vueDocument.getSourceMaps();
40
+ for (const sourceMap of sourceMaps) {
41
+ if (sourceMap.lsType === 'nonTs' || !sourceMap.capabilities.diagnostics)
42
+ continue;
43
+ const program = getProgram(sourceMap.lsType);
44
+ const embeddedSourceFile = program.getSourceFile(shared.uriToFsPath(sourceMap.mappedDocument.uri));
45
+ if (embeddedSourceFile) {
46
+ const errors = transformDiagnostics(sourceMap.lsType, program[api](embeddedSourceFile, cancellationToken));
47
+ results = results.concat(errors);
48
+ }
49
+ }
50
+ return results;
51
+ }
52
+ else {
53
+ return getProgram('script')[api](sourceFile, cancellationToken);
54
+ }
55
+ }
56
+ return lsTypes.map(lsType => transformDiagnostics(lsType, getProgram(lsType)[api](sourceFile, cancellationToken))).flat();
57
+ }
58
+ function getGlobalDiagnostics(cancellationToken) {
59
+ return lsTypes.map(lsType => transformDiagnostics(lsType, getProgram(lsType).getGlobalDiagnostics(cancellationToken))).flat();
60
+ }
61
+ function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
62
+ var _a;
63
+ const scriptResult = getProgram('script').emit(targetSourceFile, ((_a = vueHost.writeFile) !== null && _a !== void 0 ? _a : ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
64
+ const templateResult = getProgram('template').emit(targetSourceFile, undefined, cancellationToken, emitOnlyDtsFiles, customTransformers);
65
+ return {
66
+ emitSkipped: scriptResult.emitSkipped,
67
+ emittedFiles: scriptResult.emittedFiles,
68
+ diagnostics: [
69
+ ...transformDiagnostics('script', scriptResult.diagnostics),
70
+ ...transformDiagnostics('template', templateResult.diagnostics),
71
+ ],
72
+ };
73
+ }
74
+ function getProgram(lsType) {
75
+ const program = (lsType === 'script' ? scriptTsLsRaw : templateTsLsRaw).getProgram();
76
+ if (!program)
77
+ throw '!program';
78
+ return program;
79
+ }
80
+ // transform
81
+ function transformDiagnostics(lsType, diagnostics) {
82
+ var _a, _b;
83
+ const result = [];
84
+ for (const diagnostic of diagnostics) {
85
+ if (diagnostic.file !== undefined
86
+ && diagnostic.start !== undefined
87
+ && diagnostic.length !== undefined) {
88
+ const fileName = shared.normalizeFileName(diagnostic.file.fileName);
89
+ for (const tsOrVueLoc of vueDocuments.fromEmbeddedLocation(lsType, shared.fsPathToUri(fileName), diagnostic.start, diagnostic.start + diagnostic.length, data => !!data.capabilities.diagnostic)) {
90
+ if (!((_a = vueHost.fileExists) === null || _a === void 0 ? void 0 : _a.call(vueHost, shared.uriToFsPath(tsOrVueLoc.uri))))
91
+ continue;
92
+ if (tsOrVueLoc.type === 'source-ts' && lsType !== 'script')
93
+ continue;
94
+ let file = shared.uriToFsPath(tsOrVueLoc.uri) === fileName
95
+ ? diagnostic.file
96
+ : undefined;
97
+ if (!file) {
98
+ let docText = (_b = tsOrVueLoc.sourceMap) === null || _b === void 0 ? void 0 : _b.sourceDocument.getText();
99
+ if (docText === undefined) {
100
+ const snapshot = vueHost.getScriptSnapshot(shared.uriToFsPath(tsOrVueLoc.uri));
101
+ if (snapshot) {
102
+ docText = snapshot.getText(0, snapshot.getLength());
103
+ }
104
+ }
105
+ if (docText !== undefined) {
106
+ file = ts.createSourceFile(shared.uriToFsPath(tsOrVueLoc.uri), docText, tsOrVueLoc.uri.endsWith('.vue') ? ts.ScriptTarget.JSON : ts.ScriptTarget.Latest);
107
+ }
108
+ }
109
+ const newDiagnostic = {
110
+ ...diagnostic,
111
+ file,
112
+ start: tsOrVueLoc.range.start,
113
+ length: tsOrVueLoc.range.end - tsOrVueLoc.range.start,
114
+ };
115
+ const relatedInformation = diagnostic.relatedInformation;
116
+ if (relatedInformation) {
117
+ newDiagnostic.relatedInformation = transformDiagnostics(lsType, relatedInformation);
118
+ }
119
+ result.push(newDiagnostic);
120
+ }
121
+ }
122
+ else if (diagnostic.file === undefined) {
123
+ result.push(diagnostic);
124
+ }
125
+ }
126
+ return result;
127
+ }
128
+ }
129
+ exports.register = register;
130
+ //# sourceMappingURL=apis.js.map
package/out/proxy.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import * as ts from 'typescript/lib/tsserverlibrary';
2
+ export declare function createProgramProxy(options: ts.CreateProgramOptions, // rootNamesOrOptions: readonly string[] | CreateProgramOptions,
3
+ _options?: ts.CompilerOptions, _host?: ts.CompilerHost, _oldProgram?: ts.Program, _configFileParsingDiagnostics?: readonly ts.Diagnostic[]): void | ts.Program;
package/out/proxy.js CHANGED
@@ -2,56 +2,48 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createProgramProxy = void 0;
4
4
  const ts = require("typescript/lib/tsserverlibrary");
5
- const vue = require("vscode-vue-languageservice");
6
- const path = require("path");
7
5
  const shared = require("@volar/shared");
8
- function createProgramProxy(options) {
6
+ const apis = require("./apis");
7
+ const vue_typescript_1 = require("@volar/vue-typescript");
8
+ function createProgramProxy(options, // rootNamesOrOptions: readonly string[] | CreateProgramOptions,
9
+ _options, _host, _oldProgram, _configFileParsingDiagnostics) {
9
10
  if (!options.options.noEmit && !options.options.emitDeclarationOnly)
10
11
  return doThrow('js emit is not support');
11
12
  if (!options.host)
12
13
  return doThrow('!options.host');
13
- if (!options.host.readDirectory)
14
- return doThrow('!options.host.readDirectory');
15
14
  const host = options.host;
16
- const readDirectory = options.host.readDirectory;
17
- const parseConfigHost = {
18
- useCaseSensitiveFileNames: host.useCaseSensitiveFileNames(),
19
- readDirectory: (path, extensions, exclude, include, depth) => {
20
- return readDirectory(path, ['.vue'], exclude, include, depth);
21
- },
22
- fileExists: fileName => host.fileExists(fileName),
23
- readFile: fileName => host.readFile(fileName),
24
- };
25
- const fileNames = [
26
- ...options.rootNames,
27
- ...getVueFileNames(),
28
- ];
29
15
  const vueCompilerOptions = getVueCompilerOptions();
30
- const scriptSnapshots = new Map();
16
+ const scripts = new Map();
31
17
  const vueLsHost = {
32
18
  ...host,
19
+ resolveModuleNames: undefined,
33
20
  writeFile: undefined,
34
21
  getCompilationSettings: () => options.options,
35
22
  getVueCompilationSettings: () => vueCompilerOptions,
36
- getScriptFileNames: () => fileNames,
37
- getScriptVersion: () => '',
23
+ getScriptFileNames: () => options.rootNames,
24
+ getScriptVersion: (fileName) => { var _a, _b; return (_b = (_a = scripts.get(fileName)) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : ''; },
38
25
  getScriptSnapshot,
39
26
  getProjectVersion: () => '',
40
27
  getVueProjectVersion: () => '',
41
28
  getProjectReferences: () => options.projectReferences,
42
29
  };
43
- const vueLs = vue.createLanguageService({ typescript: ts }, vueLsHost);
44
- const program = vueLs.__internal__.tsProgramProxy;
45
- return program;
46
- function getVueFileNames() {
47
- const tsConfig = options.options.configFilePath;
48
- if (typeof tsConfig === 'string') {
49
- const tsConfigFile = ts.readJsonConfigFile(tsConfig, host.readFile);
50
- const { fileNames } = ts.parseJsonSourceFileConfigFileContent(tsConfigFile, parseConfigHost, path.dirname(tsConfig), options.options, path.basename(tsConfig));
51
- return fileNames;
52
- }
53
- return [];
30
+ const services = (0, vue_typescript_1.createBasicRuntime)();
31
+ const tsRuntime = (0, vue_typescript_1.createTypeScriptRuntime)({ typescript: ts, ...services, compilerOptions: vueCompilerOptions }, vueLsHost, false);
32
+ const tsProgram = tsRuntime.context.scriptTsLsRaw.getProgram(); // TODO: handle template ls?
33
+ if (!tsProgram)
34
+ throw '!tsProgram';
35
+ const tsProgramApis_2 = apis.register(ts, tsRuntime.context);
36
+ const tsProgramProxy = new Proxy(tsProgram, {
37
+ get: (target, property) => {
38
+ tsRuntime.update(true);
39
+ return tsProgramApis_2[property] || target[property];
40
+ },
41
+ });
42
+ for (const rootName of options.rootNames) {
43
+ // register file watchers
44
+ host.getSourceFile(rootName, ts.ScriptTarget.ESNext);
54
45
  }
46
+ return tsProgramProxy;
55
47
  function getVueCompilerOptions() {
56
48
  const tsConfig = options.options.configFilePath;
57
49
  if (typeof tsConfig === 'string') {
@@ -60,15 +52,19 @@ function createProgramProxy(options) {
60
52
  return {};
61
53
  }
62
54
  function getScriptSnapshot(fileName) {
63
- const scriptSnapshot = scriptSnapshots.get(fileName);
64
- if (scriptSnapshot) {
65
- return scriptSnapshot;
55
+ var _a, _b, _c;
56
+ const script = scripts.get(fileName);
57
+ if (script) {
58
+ return script.scriptSnapshot;
66
59
  }
67
60
  if (host.fileExists(fileName)) {
68
61
  const fileContent = host.readFile(fileName);
69
62
  if (fileContent !== undefined) {
70
63
  const scriptSnapshot = ts.ScriptSnapshot.fromString(fileContent);
71
- scriptSnapshots.set(fileName, scriptSnapshot);
64
+ scripts.set(fileName, {
65
+ scriptSnapshot: scriptSnapshot,
66
+ version: (_c = (_b = (_a = ts.sys).createHash) === null || _b === void 0 ? void 0 : _b.call(_a, fileContent)) !== null && _c !== void 0 ? _c : fileContent,
67
+ });
72
68
  return scriptSnapshot;
73
69
  }
74
70
  }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "vue-tsc",
3
- "version": "0.32.1",
3
+ "version": "0.33.1",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "bin",
7
- "out/proxy.js"
7
+ "out/**/*.js",
8
+ "out/**/*.d.ts"
8
9
  ],
9
10
  "repository": {
10
11
  "type": "git",
@@ -15,11 +16,11 @@
15
16
  "vue-tsc": "./bin/vue-tsc.js"
16
17
  },
17
18
  "dependencies": {
18
- "@volar/shared": "0.32.1",
19
- "vscode-vue-languageservice": "0.32.1"
19
+ "@volar/shared": "0.33.1",
20
+ "@volar/vue-typescript": "0.33.1"
20
21
  },
21
22
  "peerDependencies": {
22
23
  "typescript": "*"
23
24
  },
24
- "gitHead": "fb6912ca300ae0a0f4ca0d0aa4c17f691dd930ef"
25
+ "gitHead": "03eaf26e0b1259ffa2b5690168a2d6a8baa81cbc"
25
26
  }