vue-tsc 1.0.13 → 1.0.14

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
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  const fs = require('fs');
3
-
4
3
  const readFileSync = fs.readFileSync;
5
4
  const tscPath = require.resolve('typescript/lib/tsc');
6
- const proxyPath = require.resolve('../out/proxy');
5
+ const proxyApiPath = require.resolve('../out/index');
6
+ const { state } = require('../out/shared');
7
7
 
8
8
  fs.readFileSync = (...args) => {
9
9
  if (args[0] === tscPath) {
@@ -15,10 +15,10 @@ fs.readFileSync = (...args) => {
15
15
  tryReplace(/allSupportedExtensions = .*(?=;)/, s => s + '.concat([[".vue"]])');
16
16
 
17
17
  // proxy startTracing, dumpTracingLegend
18
- tryReplace(/ = tracingEnabled\./g, ` = require(${JSON.stringify(proxyPath)}).loadTsLib().`);
18
+ tryReplace(/ = tracingEnabled\./g, ` = require(${JSON.stringify(proxyApiPath)}).loadTsLib().`);
19
19
 
20
20
  // proxy createProgram apis
21
- tryReplace(/function createProgram\(.+\) {/, s => s + ` return require(${JSON.stringify(proxyPath)}).createProgramProxy(...arguments);`);
21
+ tryReplace(/function createProgram\(.+\) {/, s => s + ` return require(${JSON.stringify(proxyApiPath)}).createProgram(...arguments);`);
22
22
 
23
23
  return tsc;
24
24
 
@@ -34,4 +34,16 @@ fs.readFileSync = (...args) => {
34
34
  return readFileSync(...args);
35
35
  };
36
36
 
37
- require(tscPath);
37
+ (function main() {
38
+ try {
39
+ require(tscPath);
40
+ }
41
+ catch (err) {
42
+ if (err === 'hook') {
43
+ state.hook.worker.then(main);
44
+ }
45
+ else {
46
+ throw err;
47
+ }
48
+ }
49
+ })();
package/out/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import * as ts from 'typescript/lib/tsserverlibrary';
2
+ import * as vue from '@volar/vue-language-core';
3
+ import * as vueTs from '@volar/vue-typescript';
4
+ export type _Program = ts.Program & {
5
+ __vue: ProgramContext;
6
+ };
7
+ interface ProgramContext {
8
+ projectVersion: number;
9
+ options: ts.CreateProgramOptions;
10
+ languageServiceHost: vue.LanguageServiceHost;
11
+ languageService: ReturnType<typeof vueTs.createLanguageService>;
12
+ }
13
+ export declare function createProgram(options: ts.CreateProgramOptions, // rootNamesOrOptions: readonly string[] | CreateProgramOptions,
14
+ _options?: ts.CompilerOptions, _host?: ts.CompilerHost, _oldProgram?: ts.Program, _configFileParsingDiagnostics?: readonly ts.Diagnostic[]): _Program;
15
+ export declare function loadTsLib(): typeof ts;
16
+ export {};
@@ -1,21 +1,42 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.loadTsLib = exports.createProgramProxy = void 0;
11
+ exports.loadTsLib = exports.createProgram = void 0;
3
12
  const ts = require("typescript/lib/tsserverlibrary");
4
13
  const vue = require("@volar/vue-language-core");
5
14
  const vueTs = require("@volar/vue-typescript");
6
- function createProgramProxy(options, // rootNamesOrOptions: readonly string[] | CreateProgramOptions,
15
+ const shared_1 = require("./shared");
16
+ function createProgram(options, // rootNamesOrOptions: readonly string[] | CreateProgramOptions,
7
17
  _options, _host, _oldProgram, _configFileParsingDiagnostics) {
18
+ var _a, _b;
8
19
  if (!options.options.noEmit && !options.options.emitDeclarationOnly)
9
- return doThrow('js emit is not supported');
20
+ throw toThrow('js emit is not supported');
10
21
  if (!options.options.noEmit && options.options.noEmitOnError)
11
- return doThrow('noEmitOnError is not supported');
22
+ throw toThrow('noEmitOnError is not supported');
12
23
  if (!options.host)
13
- return doThrow('!options.host');
24
+ throw toThrow('!options.host');
14
25
  let program = options.oldProgram;
15
- if (!program) {
26
+ if (shared_1.state.hook) {
27
+ program = shared_1.state.hook.program;
28
+ program.__vue.options = options;
29
+ }
30
+ else if (!program) {
16
31
  const ctx = {
17
32
  projectVersion: 0,
18
- options: options,
33
+ options,
34
+ get languageServiceHost() {
35
+ return vueLsHost;
36
+ },
37
+ get languageService() {
38
+ return vueTsLs;
39
+ },
19
40
  };
20
41
  const vueCompilerOptions = getVueCompilerOptions();
21
42
  const scripts = new Map();
@@ -91,8 +112,24 @@ _options, _host, _oldProgram, _configFileParsingDiagnostics) {
91
112
  }
92
113
  }
93
114
  else {
94
- program.__vue.options = options;
95
- program.__vue.projectVersion++;
115
+ const ctx = program.__vue;
116
+ ctx.options = options;
117
+ ctx.projectVersion++;
118
+ }
119
+ const vueCompilerOptions = program.__vue.languageServiceHost.getVueCompilationSettings();
120
+ if (vueCompilerOptions.hooks) {
121
+ const index = ((_b = (_a = shared_1.state.hook) === null || _a === void 0 ? void 0 : _a.index) !== null && _b !== void 0 ? _b : -1) + 1;
122
+ if (index < vueCompilerOptions.hooks.length) {
123
+ const cbPath = vueCompilerOptions.hooks[index];
124
+ const dir = program.__vue.languageServiceHost.getCurrentDirectory();
125
+ const cb = require(require.resolve(cbPath, { paths: [dir] }));
126
+ shared_1.state.hook = {
127
+ program,
128
+ index,
129
+ worker: (() => __awaiter(this, void 0, void 0, function* () { return yield cb(program); }))(),
130
+ };
131
+ throw 'hook';
132
+ }
96
133
  }
97
134
  for (const rootName of options.rootNames) {
98
135
  // register file watchers
@@ -100,13 +137,13 @@ _options, _host, _oldProgram, _configFileParsingDiagnostics) {
100
137
  }
101
138
  return program;
102
139
  }
103
- exports.createProgramProxy = createProgramProxy;
140
+ exports.createProgram = createProgram;
104
141
  function loadTsLib() {
105
142
  return ts;
106
143
  }
107
144
  exports.loadTsLib = loadTsLib;
108
- function doThrow(msg) {
145
+ function toThrow(msg) {
109
146
  console.error(msg);
110
- throw msg;
147
+ return msg;
111
148
  }
112
- //# sourceMappingURL=proxy.js.map
149
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ import type { _Program } from './index';
2
+ export declare const state: {
3
+ hook?: {
4
+ program: _Program;
5
+ index: number;
6
+ worker: Promise<any>;
7
+ };
8
+ };
package/out/shared.js ADDED
@@ -0,0 +1,4 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.state = void 0;
3
+ exports.state = {};
4
+ //# sourceMappingURL=shared.js.map
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "vue-tsc",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
+ "main": "out/index.js",
4
5
  "license": "MIT",
5
6
  "files": [
6
7
  "bin",
@@ -16,11 +17,11 @@
16
17
  "vue-tsc": "./bin/vue-tsc.js"
17
18
  },
18
19
  "dependencies": {
19
- "@volar/vue-language-core": "1.0.13",
20
- "@volar/vue-typescript": "1.0.13"
20
+ "@volar/vue-language-core": "1.0.14",
21
+ "@volar/vue-typescript": "1.0.14"
21
22
  },
22
23
  "peerDependencies": {
23
24
  "typescript": "*"
24
25
  },
25
- "gitHead": "cba2eba187b2d82e1d45dd86b3edeab0ca7caad6"
26
+ "gitHead": "ce4d48b37db784400e15fe08282edc836e24d4cd"
26
27
  }
package/out/proxy.d.ts DELETED
@@ -1,4 +0,0 @@
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[]): any;
4
- export declare function loadTsLib(): typeof ts;