vue-tsc 0.38.7 → 0.39.0

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/bin/vue-tsc.js CHANGED
@@ -24,10 +24,6 @@ fs.readFileSync = (...args) => {
24
24
  );
25
25
 
26
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';`,
30
- );
31
27
  tsc = tsc.replace(
32
28
  `function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) {`,
33
29
  `function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) { return require(${JSON.stringify(proxyPath)}).createProgramProxy(...arguments);`,
package/out/proxy.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import * as ts from 'typescript/lib/tsserverlibrary';
2
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;
3
+ _options?: ts.CompilerOptions, _host?: ts.CompilerHost, _oldProgram?: ts.Program, _configFileParsingDiagnostics?: readonly ts.Diagnostic[]): any;
4
4
  export declare function loadTsLib(): typeof ts;
package/out/proxy.js CHANGED
@@ -2,85 +2,102 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadTsLib = exports.createProgramProxy = void 0;
4
4
  const ts = require("typescript/lib/tsserverlibrary");
5
- const apis = require("./apis");
5
+ const vue = require("@volar/vue-language-core");
6
6
  const vueTs = require("@volar/vue-typescript");
7
- let projectVersion = 0;
8
7
  function createProgramProxy(options, // rootNamesOrOptions: readonly string[] | CreateProgramOptions,
9
8
  _options, _host, _oldProgram, _configFileParsingDiagnostics) {
10
- var _a, _b;
11
9
  if (!options.options.noEmit && !options.options.emitDeclarationOnly)
12
10
  return doThrow('js emit is not support');
13
11
  if (!options.host)
14
12
  return doThrow('!options.host');
15
- projectVersion++;
16
- const host = options.host;
17
- const vueCompilerOptions = getVueCompilerOptions();
18
- const scripts = new Map();
19
- const vueLsHost = Object.assign(Object.assign({}, host), { resolveModuleNames: undefined, writeFile: (fileName, content) => {
20
- if (fileName.indexOf('__VLS_') === -1) {
21
- host.writeFile(fileName, content, false);
13
+ let program = options.oldProgram;
14
+ if (!program) {
15
+ const ctx = {
16
+ projectVersion: 0,
17
+ options: options,
18
+ };
19
+ const vueCompilerOptions = getVueCompilerOptions();
20
+ const scripts = new Map();
21
+ const vueLsHost = new Proxy({
22
+ resolveModuleNames: undefined,
23
+ writeFile: (fileName, content) => {
24
+ if (fileName.indexOf('__VLS_') === -1) {
25
+ ctx.options.host.writeFile(fileName, content, false);
26
+ }
27
+ },
28
+ getCompilationSettings: () => ctx.options.options,
29
+ getVueCompilationSettings: () => vueCompilerOptions,
30
+ getScriptFileNames: () => {
31
+ return ctx.options.rootNames;
32
+ },
33
+ getScriptVersion,
34
+ getScriptSnapshot,
35
+ getProjectVersion: () => {
36
+ return ctx.projectVersion.toString();
37
+ },
38
+ getProjectReferences: () => ctx.options.projectReferences,
39
+ getTypeScriptModule: () => ts,
40
+ isTsc: true,
41
+ }, {
42
+ get: (target, property) => {
43
+ if (property in target) {
44
+ return target[property];
45
+ }
46
+ return ctx.options.host[property];
47
+ },
48
+ });
49
+ const vueTsLs = vueTs.createLanguageService(vueLsHost);
50
+ program = vueTsLs.getProgram();
51
+ program.__VLS_ctx = ctx;
52
+ function getVueCompilerOptions() {
53
+ const tsConfig = ctx.options.options.configFilePath;
54
+ if (typeof tsConfig === 'string') {
55
+ return vue.tsShared.createParsedCommandLine(ts, ts.sys, tsConfig).vueOptions;
22
56
  }
23
- }, getCompilationSettings: () => options.options, getVueCompilationSettings: () => vueCompilerOptions, getScriptFileNames: () => {
24
- return options.rootNames;
25
- }, getScriptVersion,
26
- getScriptSnapshot, getProjectVersion: () => {
27
- return projectVersion.toString();
28
- }, getProjectReferences: () => options.projectReferences, isTsc: true });
29
- const vueLsCtx = (_b = (_a = options.oldProgram) === null || _a === void 0 ? void 0 : _a.__VLS_vueCtx) !== null && _b !== void 0 ? _b : vueTs.createLanguageServiceContext(ts, vueLsHost);
30
- const proxyApis = apis.register(ts, vueLsCtx);
31
- const program = new Proxy({}, {
32
- get: (_, property) => {
33
- if (property in proxyApis) {
34
- return proxyApis[property];
35
- }
36
- return vueLsCtx.typescriptLanguageService.getProgram()[property];
37
- },
38
- });
39
- program.__VLS_vueCtx = vueLsCtx;
40
- for (const rootName of options.rootNames) {
41
- // register file watchers
42
- host.getSourceFile(rootName, ts.ScriptTarget.ESNext);
43
- }
44
- return program;
45
- function getVueCompilerOptions() {
46
- const tsConfig = options.options.configFilePath;
47
- if (typeof tsConfig === 'string') {
48
- return vueTs.tsShared.createParsedCommandLine(ts, ts.sys, tsConfig).vueOptions;
57
+ return {};
49
58
  }
50
- return {};
51
- }
52
- function getScriptVersion(fileName) {
53
- var _a, _b;
54
- return (_b = (_a = getScript(fileName)) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : '';
55
- }
56
- function getScriptSnapshot(fileName) {
57
- var _a;
58
- return (_a = getScript(fileName)) === null || _a === void 0 ? void 0 : _a.scriptSnapshot;
59
- }
60
- function getScript(fileName) {
61
- var _a, _b, _c, _d, _e, _f;
62
- const script = scripts.get(fileName);
63
- if ((script === null || script === void 0 ? void 0 : script.projectVersion) === projectVersion) {
64
- return script;
59
+ function getScriptVersion(fileName) {
60
+ var _a, _b;
61
+ return (_b = (_a = getScript(fileName)) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : '';
65
62
  }
66
- const modifiedTime = (_d = (_c = (_b = (_a = ts.sys).getModifiedTime) === null || _b === void 0 ? void 0 : _b.call(_a, fileName)) === null || _c === void 0 ? void 0 : _c.valueOf()) !== null && _d !== void 0 ? _d : 0;
67
- if ((script === null || script === void 0 ? void 0 : script.modifiedTime) === modifiedTime) {
68
- return script;
63
+ function getScriptSnapshot(fileName) {
64
+ var _a;
65
+ return (_a = getScript(fileName)) === null || _a === void 0 ? void 0 : _a.scriptSnapshot;
69
66
  }
70
- if (host.fileExists(fileName)) {
71
- const fileContent = host.readFile(fileName);
72
- if (fileContent !== undefined) {
73
- const script = {
74
- projectVersion,
75
- modifiedTime,
76
- scriptSnapshot: ts.ScriptSnapshot.fromString(fileContent),
77
- version: (_f = (_e = host.createHash) === null || _e === void 0 ? void 0 : _e.call(host, fileContent)) !== null && _f !== void 0 ? _f : fileContent,
78
- };
79
- scripts.set(fileName, script);
67
+ function getScript(fileName) {
68
+ var _a, _b, _c, _d, _e, _f, _g;
69
+ const script = scripts.get(fileName);
70
+ if ((script === null || script === void 0 ? void 0 : script.projectVersion) === ctx.projectVersion) {
80
71
  return script;
81
72
  }
73
+ const modifiedTime = (_d = (_c = (_b = (_a = ts.sys).getModifiedTime) === null || _b === void 0 ? void 0 : _b.call(_a, fileName)) === null || _c === void 0 ? void 0 : _c.valueOf()) !== null && _d !== void 0 ? _d : 0;
74
+ if ((script === null || script === void 0 ? void 0 : script.modifiedTime) === modifiedTime) {
75
+ return script;
76
+ }
77
+ if (ctx.options.host.fileExists(fileName)) {
78
+ const fileContent = ctx.options.host.readFile(fileName);
79
+ if (fileContent !== undefined) {
80
+ const script = {
81
+ projectVersion: ctx.projectVersion,
82
+ modifiedTime,
83
+ scriptSnapshot: ts.ScriptSnapshot.fromString(fileContent),
84
+ version: (_g = (_f = (_e = ctx.options.host).createHash) === null || _f === void 0 ? void 0 : _f.call(_e, fileContent)) !== null && _g !== void 0 ? _g : fileContent,
85
+ };
86
+ scripts.set(fileName, script);
87
+ return script;
88
+ }
89
+ }
82
90
  }
83
91
  }
92
+ else {
93
+ program.__VLS_ctx.options = options;
94
+ program.__VLS_ctx.projectVersion++;
95
+ }
96
+ for (const rootName of options.rootNames) {
97
+ // register file watchers
98
+ options.host.getSourceFile(rootName, ts.ScriptTarget.ESNext);
99
+ }
100
+ return program;
84
101
  }
85
102
  exports.createProgramProxy = createProgramProxy;
86
103
  function loadTsLib() {
package/package.json CHANGED
@@ -1,25 +1,26 @@
1
1
  {
2
- "name": "vue-tsc",
3
- "version": "0.38.7",
4
- "license": "MIT",
5
- "files": [
6
- "bin",
7
- "out/**/*.js",
8
- "out/**/*.d.ts"
9
- ],
10
- "repository": {
11
- "type": "git",
12
- "url": "https://github.com/johnsoncodehk/volar.git",
13
- "directory": "packages/vue-tsc"
14
- },
15
- "bin": {
16
- "vue-tsc": "./bin/vue-tsc.js"
17
- },
18
- "dependencies": {
19
- "@volar/vue-typescript": "0.38.7"
20
- },
21
- "peerDependencies": {
22
- "typescript": "*"
23
- },
24
- "gitHead": "019c0539bbc10a88437074c5c247682432e12529"
2
+ "name": "vue-tsc",
3
+ "version": "0.39.0",
4
+ "license": "MIT",
5
+ "files": [
6
+ "bin",
7
+ "out/**/*.js",
8
+ "out/**/*.d.ts"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/johnsoncodehk/volar.git",
13
+ "directory": "packages/vue-tsc"
14
+ },
15
+ "bin": {
16
+ "vue-tsc": "./bin/vue-tsc.js"
17
+ },
18
+ "dependencies": {
19
+ "@volar/vue-language-core": "0.39.0",
20
+ "@volar/vue-typescript": "0.39.0"
21
+ },
22
+ "peerDependencies": {
23
+ "typescript": "*"
24
+ },
25
+ "gitHead": "569487a290141032b48d570c85df2a3601c8ed1c"
25
26
  }
package/out/apis.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import type * as ts from 'typescript/lib/tsserverlibrary';
2
- import type * as vueTs from '@volar/vue-typescript';
3
- export declare function register(ts: typeof import('typescript/lib/tsserverlibrary'), vueLsCtx: vueTs.LanguageServiceContext): {
4
- getRootFileNames: () => string[];
5
- emit: (targetSourceFile?: ts.SourceFile, _writeFile?: ts.WriteFileCallback, cancellationToken?: ts.CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: ts.CustomTransformers) => ts.EmitResult;
6
- getSyntacticDiagnostics: (sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken) => readonly ts.DiagnosticWithLocation[] | readonly ts.Diagnostic[];
7
- getSemanticDiagnostics: (sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken) => readonly ts.DiagnosticWithLocation[] | readonly ts.Diagnostic[];
8
- getGlobalDiagnostics: (cancellationToken?: ts.CancellationToken) => readonly ts.Diagnostic[];
9
- getBindAndCheckDiagnostics: (sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken) => readonly ts.DiagnosticWithLocation[] | readonly ts.Diagnostic[];
10
- };
package/out/apis.js DELETED
@@ -1,124 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.register = void 0;
4
- function register(ts, vueLsCtx) {
5
- return {
6
- getRootFileNames,
7
- emit,
8
- getSyntacticDiagnostics,
9
- getSemanticDiagnostics,
10
- getGlobalDiagnostics,
11
- getBindAndCheckDiagnostics,
12
- };
13
- function getRootFileNames() {
14
- return getProgram().getRootFileNames().filter(fileName => { var _a, _b; return (_b = (_a = vueLsCtx.typescriptLanguageServiceHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, fileName); });
15
- }
16
- // for vue-tsc --noEmit --watch
17
- function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
18
- return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getBindAndCheckDiagnostics');
19
- }
20
- // for vue-tsc --noEmit
21
- function getSyntacticDiagnostics(sourceFile, cancellationToken) {
22
- return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSyntacticDiagnostics');
23
- }
24
- function getSemanticDiagnostics(sourceFile, cancellationToken) {
25
- return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSemanticDiagnostics');
26
- }
27
- function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
28
- var _a, _b;
29
- if (sourceFile) {
30
- const mapped = vueLsCtx.sourceFiles.fromEmbeddedFileName(sourceFile.fileName);
31
- if (mapped) {
32
- if (!mapped.embedded.file.capabilities.diagnostics)
33
- return [];
34
- const program = getProgram();
35
- const errors = transformDiagnostics((_a = program === null || program === void 0 ? void 0 : program[api](sourceFile, cancellationToken)) !== null && _a !== void 0 ? _a : []);
36
- return errors;
37
- }
38
- }
39
- return transformDiagnostics((_b = getProgram()[api](sourceFile, cancellationToken)) !== null && _b !== void 0 ? _b : []);
40
- }
41
- function getGlobalDiagnostics(cancellationToken) {
42
- var _a;
43
- return transformDiagnostics((_a = getProgram().getGlobalDiagnostics(cancellationToken)) !== null && _a !== void 0 ? _a : []);
44
- }
45
- function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
46
- var _a;
47
- const scriptResult = getProgram().emit(targetSourceFile, ((_a = vueLsCtx.typescriptLanguageServiceHost.writeFile) !== null && _a !== void 0 ? _a : ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
48
- return {
49
- emitSkipped: scriptResult.emitSkipped,
50
- emittedFiles: scriptResult.emittedFiles,
51
- diagnostics: transformDiagnostics(scriptResult.diagnostics),
52
- };
53
- }
54
- function getProgram() {
55
- return vueLsCtx.typescriptLanguageService.getProgram();
56
- }
57
- // transform
58
- function transformDiagnostics(diagnostics) {
59
- var _a, _b, _c, _d, _e, _f, _g, _h;
60
- const result = [];
61
- for (const diagnostic of diagnostics) {
62
- if (diagnostic.file !== undefined
63
- && diagnostic.start !== undefined
64
- && diagnostic.length !== undefined) {
65
- let founded = false;
66
- for (const tsOrVueLoc of vueLsCtx.sourceFiles.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, data => !!data.capabilities.diagnostic)) {
67
- if (!((_b = (_a = vueLsCtx.typescriptLanguageServiceHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, tsOrVueLoc.fileName)))
68
- continue;
69
- onMapping(diagnostic, tsOrVueLoc.fileName, tsOrVueLoc.range.start, tsOrVueLoc.range.end, (_c = tsOrVueLoc.mapped) === null || _c === void 0 ? void 0 : _c.vueFile.text);
70
- founded = true;
71
- break;
72
- }
73
- // fix https://github.com/johnsoncodehk/volar/issues/1372
74
- if (!founded) {
75
- for (const start of vueLsCtx.sourceFiles.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start, diagnostic.start, data => !!data.capabilities.diagnostic)) {
76
- if (!((_e = (_d = vueLsCtx.typescriptLanguageServiceHost).fileExists) === null || _e === void 0 ? void 0 : _e.call(_d, start.fileName)))
77
- continue;
78
- for (const end of vueLsCtx.sourceFiles.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start + diagnostic.length, diagnostic.start + diagnostic.length, data => !!data.capabilities.diagnostic)) {
79
- if (!((_g = (_f = vueLsCtx.typescriptLanguageServiceHost).fileExists) === null || _g === void 0 ? void 0 : _g.call(_f, end.fileName)))
80
- continue;
81
- if (start.fileName !== end.fileName)
82
- continue;
83
- onMapping(diagnostic, start.fileName, start.range.start, end.range.end, (_h = start.mapped) === null || _h === void 0 ? void 0 : _h.vueFile.text);
84
- founded = true;
85
- break;
86
- }
87
- if (founded) {
88
- break;
89
- }
90
- }
91
- }
92
- }
93
- else if (diagnostic.file === undefined) {
94
- result.push(diagnostic);
95
- }
96
- }
97
- return result;
98
- function onMapping(diagnostic, fileName, start, end, docText) {
99
- var _a;
100
- let file = fileName === ((_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.fileName)
101
- ? diagnostic.file
102
- : undefined;
103
- if (!file) {
104
- if (docText === undefined) {
105
- const snapshot = vueLsCtx.typescriptLanguageServiceHost.getScriptSnapshot(fileName);
106
- if (snapshot) {
107
- docText = snapshot.getText(0, snapshot.getLength());
108
- }
109
- }
110
- else {
111
- file = ts.createSourceFile(fileName, docText, fileName.endsWith('.vue') || fileName.endsWith('.md') || fileName.endsWith('.html') ? ts.ScriptTarget.JSON : ts.ScriptTarget.Latest);
112
- }
113
- }
114
- const newDiagnostic = Object.assign(Object.assign({}, diagnostic), { file, start: start, length: end - start });
115
- const relatedInformation = diagnostic.relatedInformation;
116
- if (relatedInformation) {
117
- newDiagnostic.relatedInformation = transformDiagnostics(relatedInformation);
118
- }
119
- result.push(newDiagnostic);
120
- }
121
- }
122
- }
123
- exports.register = register;
124
- //# sourceMappingURL=apis.js.map