@volar/typescript 1.10.5 → 1.10.7

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.
@@ -1,7 +1,6 @@
1
1
  import type { LanguageContext } from '@volar/language-core';
2
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
3
- import { ServiceEnvironment } from '@volar/language-service';
4
3
  export declare function createLanguageServiceHost(ctx: LanguageContext, ts: typeof import('typescript/lib/tsserverlibrary'), sys: ts.System & {
5
4
  version?: number;
6
- }, env: ServiceEnvironment | undefined): ts.LanguageServiceHost;
5
+ }): ts.LanguageServiceHost;
7
6
  //# sourceMappingURL=languageServiceHost.d.ts.map
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLanguageServiceHost = void 0;
4
- const path_1 = require("path");
4
+ const path = require("path-browserify");
5
5
  const utilities_1 = require("./typescript/utilities");
6
6
  const fileVersions = new Map();
7
- function createLanguageServiceHost(ctx, ts, sys, env) {
7
+ function createLanguageServiceHost(ctx, ts, sys) {
8
8
  let lastProjectVersion;
9
9
  let tsProjectVersion = 0;
10
10
  let tsFileNames = [];
@@ -50,7 +50,7 @@ function createLanguageServiceHost(ctx, ts, sys, env) {
50
50
  if (ts) {
51
51
  if (ctx.virtualFiles.hasSource(fileName))
52
52
  return ts.ScriptKind.Deferred;
53
- switch (path_1.posix.extname(fileName)) {
53
+ switch (path.extname(fileName)) {
54
54
  case '.js': return ts.ScriptKind.JS;
55
55
  case '.cjs': return ts.ScriptKind.JS;
56
56
  case '.mjs': return ts.ScriptKind.JS;
@@ -70,12 +70,9 @@ function createLanguageServiceHost(ctx, ts, sys, env) {
70
70
  if (ctx.host.resolveModuleName) {
71
71
  // TODO: can this share between monorepo packages?
72
72
  const moduleCache = ts.createModuleResolutionCache(_tsHost.getCurrentDirectory(), _tsHost.useCaseSensitiveFileNames ? s => s : s => s.toLowerCase(), _tsHost.getCompilationSettings());
73
- const watching = !!env?.onDidChangeWatchedFiles?.(() => {
74
- moduleCache.clear();
75
- });
76
73
  let lastSysVersion = sys.version;
77
74
  _tsHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, sourceFile) => {
78
- if (!watching && lastSysVersion !== sys.version) {
75
+ if (lastSysVersion !== sys.version) {
79
76
  lastSysVersion = sys.version;
80
77
  moduleCache.clear();
81
78
  }
@@ -86,7 +83,7 @@ function createLanguageServiceHost(ctx, ts, sys, env) {
86
83
  });
87
84
  };
88
85
  _tsHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, options, sourceFile) => {
89
- if (!watching && lastSysVersion !== sys.version) {
86
+ if (lastSysVersion !== sys.version) {
90
87
  lastSysVersion = sys.version;
91
88
  moduleCache.clear();
92
89
  }
@@ -148,7 +145,7 @@ function createLanguageServiceHost(ctx, ts, sys, env) {
148
145
  // Update tsDirectories for `directoryExists()`
149
146
  tsDirectories.clear();
150
147
  for (const fileName of tsFileNames) {
151
- tsDirectories.add(path_1.posix.dirname(normalizePath(fileName)));
148
+ tsDirectories.add(path.dirname(normalizePath(fileName)));
152
149
  }
153
150
  }
154
151
  function readDirectory(dirName, extensions, excludes, includes, depth) {
package/out/sys.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSys = void 0;
4
- const path_1 = require("path");
4
+ const path = require("path-browserify");
5
5
  const utilities_1 = require("./typescript/utilities");
6
6
  let currentCwd = '';
7
7
  function createSys(ts, env) {
@@ -17,8 +17,8 @@ function createSys(ts, env) {
17
17
  const fileWatcher = env.onDidChangeWatchedFiles?.(({ changes }) => {
18
18
  for (const change of changes) {
19
19
  const fileName = env.uriToFileName(change.uri);
20
- const dirName = path_1.posix.dirname(fileName);
21
- const baseName = path_1.posix.basename(fileName);
20
+ const dirName = path.dirname(fileName);
21
+ const baseName = path.basename(fileName);
22
22
  const dir = getDir(dirName);
23
23
  if (dir.files.has(baseName)) { // is requested file
24
24
  version++;
@@ -84,6 +84,7 @@ function createSys(ts, env) {
84
84
  if (sys.directoryExists(rootPath)) {
85
85
  // https://github.com/vuejs/language-tools/issues/2480
86
86
  try {
87
+ // @ts-expect-error
87
88
  process.chdir(rootPath);
88
89
  }
89
90
  catch { }
@@ -91,13 +92,13 @@ function createSys(ts, env) {
91
92
  }
92
93
  return sys.resolvePath(fsPath).replace(/\\/g, '/');
93
94
  }
94
- return path_1.posix.resolve(fsPath).replace(/\\/g, '/');
95
+ return path.resolve(fsPath).replace(/\\/g, '/');
95
96
  }
96
97
  function readFile(fileName, encoding) {
97
98
  fileName = resolvePath(fileName);
98
- const dirPath = path_1.posix.dirname(fileName);
99
+ const dirPath = path.dirname(fileName);
99
100
  const dir = getDir(dirPath);
100
- const name = path_1.posix.basename(fileName);
101
+ const name = path.basename(fileName);
101
102
  readFileWorker(fileName, encoding, dir);
102
103
  return dir.files.get(name)?.text;
103
104
  }
@@ -165,8 +166,8 @@ function createSys(ts, env) {
165
166
  }
166
167
  function getFile(fileName) {
167
168
  fileName = resolvePath(fileName);
168
- const dirPath = path_1.posix.dirname(fileName);
169
- const baseName = path_1.posix.basename(fileName);
169
+ const dirPath = path.dirname(fileName);
170
+ const baseName = path.basename(fileName);
170
171
  const dir = getDir(dirPath);
171
172
  let file = dir.files.get(baseName);
172
173
  if (!file) {
@@ -195,7 +196,7 @@ function createSys(ts, env) {
195
196
  return [...new Set(matches)];
196
197
  }
197
198
  function readFileWorker(fileName, encoding, dir) {
198
- const name = path_1.posix.basename(fileName);
199
+ const name = path.basename(fileName);
199
200
  let file = dir.files.get(name);
200
201
  if (!file) {
201
202
  dir.files.set(name, file = {});
@@ -310,13 +311,13 @@ function createSys(ts, env) {
310
311
  function getDir(dirName) {
311
312
  const dirNames = [];
312
313
  let currentDirPath = dirName;
313
- let currentDirName = path_1.posix.basename(currentDirPath);
314
+ let currentDirName = path.basename(currentDirPath);
314
315
  let lastDirPath;
315
316
  while (lastDirPath !== currentDirPath) {
316
317
  lastDirPath = currentDirPath;
317
318
  dirNames.push(currentDirName);
318
- currentDirPath = path_1.posix.dirname(currentDirPath);
319
- currentDirName = path_1.posix.basename(currentDirPath);
319
+ currentDirPath = path.dirname(currentDirPath);
320
+ currentDirName = path.basename(currentDirPath);
320
321
  }
321
322
  let currentDir = root;
322
323
  for (let i = dirNames.length - 1; i >= 0; i--) {
@@ -12,6 +12,7 @@ exports.version = `${exports.versionMajorMinor}.0-dev`;
12
12
  var NativeCollections;
13
13
  (function (NativeCollections) {
14
14
  const globals = typeof globalThis !== "undefined" ? globalThis :
15
+ // @ts-expect-error node global
15
16
  typeof global !== "undefined" ? global :
16
17
  typeof self !== "undefined" ? self :
17
18
  undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/typescript",
3
- "version": "1.10.5",
3
+ "version": "1.10.7",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,10 +13,12 @@
13
13
  "directory": "packages/typescript"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "1.10.5"
16
+ "@volar/language-core": "1.10.7",
17
+ "path-browserify": "^1.0.1"
17
18
  },
18
19
  "devDependencies": {
19
- "@volar/language-service": "1.10.5"
20
+ "@types/path-browserify": "^1.0.1",
21
+ "@volar/language-service": "1.10.7"
20
22
  },
21
- "gitHead": "f087b2cb990108e71ed66727588b3e19c421b4c2"
23
+ "gitHead": "6350232bcf1e2fdf34bf6bc6fc87f46facb03730"
22
24
  }
package/out/program.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type * as ts from 'typescript/lib/tsserverlibrary';
2
- import type * as embedded from '@volar/language-core';
3
- export declare function decorateProgram({ createSourceFile }: Pick<typeof import('typescript/lib/tsserverlibrary'), 'createSourceFile'>, options: ts.CreateProgramOptions, core: embedded.LanguageContext, program: ts.Program): void;
4
- //# sourceMappingURL=program.d.ts.map
package/out/program.js DELETED
@@ -1,131 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateProgram = void 0;
4
- function decorateProgram({ createSourceFile }, options, core, program) {
5
- const _getRootFileNames = program.getRootFileNames.bind(program);
6
- const _getSyntacticDiagnostics = program.getSyntacticDiagnostics.bind(program);
7
- const _getSemanticDiagnostics = program.getSemanticDiagnostics.bind(program);
8
- const _getGlobalDiagnostics = program.getGlobalDiagnostics.bind(program);
9
- const _emit = program.emit.bind(program);
10
- // @ts-expect-error
11
- const _getBindAndCheckDiagnostics = program.getBindAndCheckDiagnostics.bind(program);
12
- program.getRootFileNames = getRootFileNames;
13
- program.getSyntacticDiagnostics = getSyntacticDiagnostics;
14
- program.getSemanticDiagnostics = getSemanticDiagnostics;
15
- program.getGlobalDiagnostics = getGlobalDiagnostics;
16
- program.emit = emit;
17
- // @ts-expect-error
18
- program.getBindAndCheckDiagnostics = getBindAndCheckDiagnostics;
19
- // TODO
20
- function getRootFileNames() {
21
- return _getRootFileNames().filter(fileName => options.host?.fileExists?.(fileName));
22
- }
23
- // for vue-tsc --noEmit --watch
24
- function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
25
- return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, _getBindAndCheckDiagnostics);
26
- }
27
- // for vue-tsc --noEmit
28
- function getSyntacticDiagnostics(sourceFile, cancellationToken) {
29
- return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, _getSyntacticDiagnostics);
30
- }
31
- function getSemanticDiagnostics(sourceFile, cancellationToken) {
32
- return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, _getSemanticDiagnostics);
33
- }
34
- function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
35
- if (sourceFile) {
36
- const [virtualFile, source] = core.virtualFiles.getVirtualFile(sourceFile.fileName);
37
- if (virtualFile && source) {
38
- if (!virtualFile.capabilities.diagnostic)
39
- return [];
40
- const errors = transformDiagnostics(api(sourceFile, cancellationToken) ?? []);
41
- return errors;
42
- }
43
- }
44
- return transformDiagnostics(api(sourceFile, cancellationToken) ?? []);
45
- }
46
- function getGlobalDiagnostics(cancellationToken) {
47
- return transformDiagnostics(_getGlobalDiagnostics(cancellationToken) ?? []);
48
- }
49
- function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
50
- const scriptResult = _emit(targetSourceFile, options.host?.writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
51
- return {
52
- emitSkipped: scriptResult.emitSkipped,
53
- emittedFiles: scriptResult.emittedFiles,
54
- diagnostics: transformDiagnostics(scriptResult.diagnostics),
55
- };
56
- }
57
- // transform
58
- function transformDiagnostics(diagnostics) {
59
- const result = [];
60
- for (const diagnostic of diagnostics) {
61
- if (diagnostic.file !== undefined
62
- && diagnostic.start !== undefined
63
- && diagnostic.length !== undefined) {
64
- const [virtualFile, source] = core.virtualFiles.getVirtualFile(diagnostic.file.fileName);
65
- if (virtualFile && source) {
66
- if (options.host?.fileExists?.(source.fileName) === false)
67
- continue;
68
- for (const [_, [sourceSnapshot, map]] of core.virtualFiles.getMaps(virtualFile)) {
69
- if (sourceSnapshot !== source.snapshot)
70
- continue;
71
- for (const start of map.toSourceOffsets(diagnostic.start)) {
72
- const reportStart = typeof start[1].data.diagnostic === 'object' ? start[1].data.diagnostic.shouldReport() : !!start[1].data.diagnostic;
73
- if (!reportStart)
74
- continue;
75
- for (const end of map.toSourceOffsets(diagnostic.start + diagnostic.length, true)) {
76
- const reportEnd = typeof end[1].data.diagnostic === 'object' ? end[1].data.diagnostic.shouldReport() : !!end[1].data.diagnostic;
77
- if (!reportEnd)
78
- continue;
79
- onMapping(diagnostic, source.fileName, start[0], end[0], source.snapshot.getText(0, source.snapshot.getLength()));
80
- break;
81
- }
82
- break;
83
- }
84
- }
85
- }
86
- else {
87
- if (options.host?.fileExists?.(diagnostic.file.fileName) === false)
88
- continue;
89
- onMapping(diagnostic, diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, diagnostic.file.text);
90
- }
91
- }
92
- else if (diagnostic.file === undefined) {
93
- result.push(diagnostic);
94
- }
95
- }
96
- return result;
97
- function onMapping(diagnostic, fileName, start, end, docText) {
98
- let file = fileName === diagnostic.file?.fileName
99
- ? diagnostic.file
100
- : undefined;
101
- if (!file) {
102
- if (docText === undefined) {
103
- const snapshot = core.host.getScriptSnapshot(fileName);
104
- if (snapshot) {
105
- docText = snapshot.getText(0, snapshot.getLength());
106
- }
107
- }
108
- else {
109
- file = createSourceFile(fileName, docText, 99, undefined, 7);
110
- // fix https://github.com/vuejs/language-tools/issues/2622 for TS 5.0
111
- file.originalFileName = fileName;
112
- file.path = fileName.toLowerCase();
113
- file.resolvedPath = fileName.toLowerCase();
114
- }
115
- }
116
- const newDiagnostic = {
117
- ...diagnostic,
118
- file,
119
- start: start,
120
- length: end - start,
121
- };
122
- const relatedInformation = diagnostic.relatedInformation;
123
- if (relatedInformation) {
124
- newDiagnostic.relatedInformation = transformDiagnostics(relatedInformation);
125
- }
126
- result.push(newDiagnostic);
127
- }
128
- }
129
- }
130
- exports.decorateProgram = decorateProgram;
131
- //# sourceMappingURL=program.js.map