vue-tsc 1.9.0-alpha.3 → 2.0.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 +2 -70
- package/package.json +4 -5
- package/out/index.d.ts +0 -17
- package/out/index.js +0 -126
- package/out/shared.d.ts +0 -9
- package/out/shared.js +0 -5
package/bin/vue-tsc.js
CHANGED
|
@@ -1,71 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tsPkg = require('typescript/package.json');
|
|
5
|
-
const readFileSync = fs.readFileSync;
|
|
6
|
-
const tscPath = require.resolve('typescript/lib/tsc');
|
|
7
|
-
const proxyApiPath = require.resolve('../out/index');
|
|
8
|
-
const { state } = require('../out/shared');
|
|
9
|
-
|
|
10
|
-
fs.readFileSync = (...args) => {
|
|
11
|
-
if (args[0] === tscPath) {
|
|
12
|
-
let tsc = readFileSync(...args);
|
|
13
|
-
|
|
14
|
-
// add *.vue files to allow extensions
|
|
15
|
-
tryReplace(/supportedTSExtensions = .*(?=;)/, s => s + '.concat([[".vue"]])');
|
|
16
|
-
tryReplace(/supportedJSExtensions = .*(?=;)/, s => s + '.concat([[".vue"]])');
|
|
17
|
-
tryReplace(/allSupportedExtensions = .*(?=;)/, s => s + '.concat([[".vue"]])');
|
|
18
|
-
|
|
19
|
-
// proxy createProgram apis
|
|
20
|
-
tryReplace(/function createProgram\(.+\) {/, s => s + ` return require(${JSON.stringify(proxyApiPath)}).createProgram(...arguments);`);
|
|
21
|
-
|
|
22
|
-
// patches logic for checking root file extension in build program for incremental builds
|
|
23
|
-
if (semver.gt(tsPkg.version, '5.0.0')) {
|
|
24
|
-
tryReplace(
|
|
25
|
-
`for (const existingRoot of buildInfoVersionMap.roots) {`,
|
|
26
|
-
`for (const existingRoot of buildInfoVersionMap.roots
|
|
27
|
-
.filter(file => !file.toLowerCase().includes('__vls_'))
|
|
28
|
-
.map(file => file.replace(/\.vue\.(j|t)sx?$/i, '.vue'))
|
|
29
|
-
) {`
|
|
30
|
-
);
|
|
31
|
-
tryReplace(
|
|
32
|
-
`return [toFileId(key), toFileIdListId(state.exportedModulesMap.getValues(key))];`,
|
|
33
|
-
`return [toFileId(key), toFileIdListId(new Set(arrayFrom(state.exportedModulesMap.getValues(key)).filter(file => file !== void 0)))];`
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
if (semver.gte(tsPkg.version, '5.0.4')) {
|
|
37
|
-
tryReplace(
|
|
38
|
-
`return createBuilderProgramUsingProgramBuildInfo(buildInfo, buildInfoPath, host);`,
|
|
39
|
-
s => `buildInfo.program.fileNames = buildInfo.program.fileNames
|
|
40
|
-
.filter(file => !file.toLowerCase().includes('__vls_'))
|
|
41
|
-
.map(file => file.replace(/\.vue\.(j|t)sx?$/i, '.vue'));\n` + s
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return tsc;
|
|
46
|
-
|
|
47
|
-
function tryReplace(search, replace) {
|
|
48
|
-
const before = tsc;
|
|
49
|
-
tsc = tsc.replace(search, replace);
|
|
50
|
-
const after = tsc;
|
|
51
|
-
if (after === before) {
|
|
52
|
-
throw 'Search string not found: ' + JSON.stringify(search.toString());
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return readFileSync(...args);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
(function main() {
|
|
60
|
-
try {
|
|
61
|
-
require(tscPath);
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
if (err === 'hook') {
|
|
65
|
-
state.hook.worker.then(main);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
throw err;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
})();
|
|
2
|
+
// @ts-check
|
|
3
|
+
require('../index.js').run();
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-tsc",
|
|
3
|
-
"version": "
|
|
4
|
-
"main": "out/index.js",
|
|
3
|
+
"version": "2.0.0",
|
|
5
4
|
"license": "MIT",
|
|
6
5
|
"files": [
|
|
7
6
|
"bin",
|
|
@@ -17,8 +16,8 @@
|
|
|
17
16
|
"vue-tsc": "./bin/vue-tsc.js"
|
|
18
17
|
},
|
|
19
18
|
"dependencies": {
|
|
20
|
-
"@volar/typescript": "~1.
|
|
21
|
-
"@vue/language-core": "
|
|
19
|
+
"@volar/typescript": "~2.1.0",
|
|
20
|
+
"@vue/language-core": "2.0.0",
|
|
22
21
|
"semver": "^7.5.4"
|
|
23
22
|
},
|
|
24
23
|
"peerDependencies": {
|
|
@@ -27,5 +26,5 @@
|
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@types/node": "latest"
|
|
29
28
|
},
|
|
30
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "aa47e5a7d8a6dae62cc80dbdb5db6a9bfa4f8715"
|
|
31
30
|
}
|
package/out/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
-
import * as vue from '@vue/language-core';
|
|
3
|
-
export type Hook = (program: _Program) => void;
|
|
4
|
-
export type _Program = ts.Program & {
|
|
5
|
-
__vue: ProgramContext;
|
|
6
|
-
};
|
|
7
|
-
interface ProgramContext {
|
|
8
|
-
projectVersion: number;
|
|
9
|
-
options: ts.CreateProgramOptions;
|
|
10
|
-
languageHost: vue.TypeScriptLanguageHost;
|
|
11
|
-
vueCompilerOptions: Partial<vue.VueCompilerOptions>;
|
|
12
|
-
langaugeContext: vue.LanguageContext;
|
|
13
|
-
languageService: ts.LanguageService;
|
|
14
|
-
}
|
|
15
|
-
export declare function createProgram(options: ts.CreateProgramOptions): _Program;
|
|
16
|
-
export {};
|
|
17
|
-
//# sourceMappingURL=index.d.ts.map
|
package/out/index.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createProgram = void 0;
|
|
4
|
-
const vue = require("@vue/language-core");
|
|
5
|
-
const volarTs = require("@volar/typescript");
|
|
6
|
-
const shared_1 = require("./shared");
|
|
7
|
-
const windowsPathReg = /\\/g;
|
|
8
|
-
function createProgram(options) {
|
|
9
|
-
if (!options.options.noEmit && !options.options.emitDeclarationOnly)
|
|
10
|
-
throw toThrow('js emit is not supported');
|
|
11
|
-
if (!options.options.noEmit && options.options.noEmitOnError)
|
|
12
|
-
throw toThrow('noEmitOnError is not supported');
|
|
13
|
-
if (options.options.extendedDiagnostics || options.options.generateTrace)
|
|
14
|
-
throw toThrow('--extendedDiagnostics / --generateTrace is not supported, please run `Write Virtual Files` in VSCode to write virtual files and use `--extendedDiagnostics` / `--generateTrace` via tsc instead of vue-tsc to debug.');
|
|
15
|
-
if (!options.host)
|
|
16
|
-
throw toThrow('!options.host');
|
|
17
|
-
const ts = require('typescript');
|
|
18
|
-
let program = options.oldProgram;
|
|
19
|
-
if (shared_1.state.hook) {
|
|
20
|
-
program = shared_1.state.hook.program;
|
|
21
|
-
program.__vue.options = options;
|
|
22
|
-
}
|
|
23
|
-
else if (!program) {
|
|
24
|
-
const ctx = {
|
|
25
|
-
projectVersion: 0,
|
|
26
|
-
options,
|
|
27
|
-
get languageHost() {
|
|
28
|
-
return languageHost;
|
|
29
|
-
},
|
|
30
|
-
get vueCompilerOptions() {
|
|
31
|
-
return vueCompilerOptions;
|
|
32
|
-
},
|
|
33
|
-
get languageService() {
|
|
34
|
-
return vueTsLs;
|
|
35
|
-
},
|
|
36
|
-
get langaugeContext() {
|
|
37
|
-
return languageContext;
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
const vueCompilerOptions = getVueCompilerOptions();
|
|
41
|
-
const scripts = new Map();
|
|
42
|
-
const languageHost = {
|
|
43
|
-
workspacePath: ctx.options.host.getCurrentDirectory().replace(windowsPathReg, '/'),
|
|
44
|
-
rootPath: ctx.options.host.getCurrentDirectory().replace(windowsPathReg, '/'),
|
|
45
|
-
getCompilationSettings: () => ctx.options.options,
|
|
46
|
-
getScriptFileNames: () => {
|
|
47
|
-
return ctx.options.rootNames;
|
|
48
|
-
},
|
|
49
|
-
getScriptSnapshot,
|
|
50
|
-
getProjectVersion: () => {
|
|
51
|
-
return ctx.projectVersion.toString();
|
|
52
|
-
},
|
|
53
|
-
getProjectReferences: () => ctx.options.projectReferences,
|
|
54
|
-
getCancellationToken: ctx.options.host.getCancellationToken ? () => ctx.options.host.getCancellationToken() : undefined,
|
|
55
|
-
};
|
|
56
|
-
const languageContext = vue.createLanguageContext(languageHost, vue.createLanguages(ts, languageHost.getCompilationSettings(), vueCompilerOptions));
|
|
57
|
-
const languageServiceHost = volarTs.createLanguageServiceHost(languageContext, ts, ts.sys);
|
|
58
|
-
const vueTsLs = ts.createLanguageService(languageServiceHost, volarTs.getDocumentRegistry(ts, ts.sys.useCaseSensitiveFileNames, languageHost.workspacePath));
|
|
59
|
-
volarTs.decorateLanguageService(languageContext.virtualFiles, vueTsLs, false);
|
|
60
|
-
program = volarTs.getProgram(ts, languageContext, vueTsLs, ts.sys);
|
|
61
|
-
program.__vue = ctx;
|
|
62
|
-
function getVueCompilerOptions() {
|
|
63
|
-
const tsConfig = ctx.options.options.configFilePath;
|
|
64
|
-
if (typeof tsConfig === 'string') {
|
|
65
|
-
return vue.createParsedCommandLine(ts, ts.sys, tsConfig.replace(windowsPathReg, '/')).vueOptions;
|
|
66
|
-
}
|
|
67
|
-
return {};
|
|
68
|
-
}
|
|
69
|
-
function getScriptSnapshot(fileName) {
|
|
70
|
-
return getScript(fileName)?.scriptSnapshot;
|
|
71
|
-
}
|
|
72
|
-
function getScript(fileName) {
|
|
73
|
-
const script = scripts.get(fileName);
|
|
74
|
-
if (script?.projectVersion === ctx.projectVersion) {
|
|
75
|
-
return script;
|
|
76
|
-
}
|
|
77
|
-
const modifiedTime = ts.sys.getModifiedTime?.(fileName)?.valueOf() ?? 0;
|
|
78
|
-
if (script?.modifiedTime === modifiedTime) {
|
|
79
|
-
return script;
|
|
80
|
-
}
|
|
81
|
-
if (ctx.options.host.fileExists(fileName)) {
|
|
82
|
-
const fileContent = ctx.options.host.readFile(fileName);
|
|
83
|
-
if (fileContent !== undefined) {
|
|
84
|
-
const script = {
|
|
85
|
-
projectVersion: ctx.projectVersion,
|
|
86
|
-
modifiedTime,
|
|
87
|
-
scriptSnapshot: ts.ScriptSnapshot.fromString(fileContent),
|
|
88
|
-
version: ctx.options.host.createHash?.(fileContent) ?? fileContent,
|
|
89
|
-
};
|
|
90
|
-
scripts.set(fileName, script);
|
|
91
|
-
return script;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
const ctx = program.__vue;
|
|
98
|
-
ctx.options = options;
|
|
99
|
-
ctx.projectVersion++;
|
|
100
|
-
}
|
|
101
|
-
const vueCompilerOptions = program.__vue.vueCompilerOptions;
|
|
102
|
-
if (vueCompilerOptions?.hooks) {
|
|
103
|
-
const index = (shared_1.state.hook?.index ?? -1) + 1;
|
|
104
|
-
if (index < vueCompilerOptions.hooks.length) {
|
|
105
|
-
const hookPath = vueCompilerOptions.hooks[index];
|
|
106
|
-
const hook = require(hookPath);
|
|
107
|
-
shared_1.state.hook = {
|
|
108
|
-
program,
|
|
109
|
-
index,
|
|
110
|
-
worker: (async () => await hook(program))(),
|
|
111
|
-
};
|
|
112
|
-
throw 'hook';
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
for (const rootName of options.rootNames) {
|
|
116
|
-
// register file watchers
|
|
117
|
-
options.host.getSourceFile(rootName, ts.ScriptTarget.ESNext);
|
|
118
|
-
}
|
|
119
|
-
return program;
|
|
120
|
-
}
|
|
121
|
-
exports.createProgram = createProgram;
|
|
122
|
-
function toThrow(msg) {
|
|
123
|
-
console.error(msg);
|
|
124
|
-
return msg;
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=index.js.map
|
package/out/shared.d.ts
DELETED