vue-tsc 0.32.1 → 0.33.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/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/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,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-tsc",
3
- "version": "0.32.1",
3
+ "version": "0.33.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "bin",
@@ -15,11 +15,11 @@
15
15
  "vue-tsc": "./bin/vue-tsc.js"
16
16
  },
17
17
  "dependencies": {
18
- "@volar/shared": "0.32.1",
19
- "vscode-vue-languageservice": "0.32.1"
18
+ "@volar/shared": "0.33.0",
19
+ "@volar/vue-typescript": "0.33.0"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "typescript": "*"
23
23
  },
24
- "gitHead": "fb6912ca300ae0a0f4ca0d0aa4c17f691dd930ef"
24
+ "gitHead": "6f5f0e354fd2105e48de12fa67acdca2157202f4"
25
25
  }