@astrojs/ts-plugin 1.3.0 → 1.3.1
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/dist/index.js +60 -13
- package/package.json +8 -7
package/dist/index.js
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
const language_core_1 = require("@volar/language-core");
|
|
3
26
|
const typescript_1 = require("@volar/typescript");
|
|
27
|
+
const semver = __importStar(require("semver"));
|
|
4
28
|
const language_js_1 = require("./language.js");
|
|
5
29
|
const externalFiles = new WeakMap();
|
|
6
30
|
const init = (modules) => {
|
|
@@ -10,26 +34,49 @@ const init = (modules) => {
|
|
|
10
34
|
const virtualFiles = (0, language_core_1.createVirtualFiles)([(0, language_js_1.getLanguageModule)(ts)]);
|
|
11
35
|
(0, typescript_1.decorateLanguageService)(virtualFiles, info.languageService, true);
|
|
12
36
|
(0, typescript_1.decorateLanguageServiceHost)(virtualFiles, info.languageServiceHost, ts, ['.astro']);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
info.languageServiceHost.getScriptKind
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
37
|
+
if (semver.lt(ts.version, '5.3.0')) {
|
|
38
|
+
// HACK: AutoImportProviderProject's script kind does not match the one of the language service host here
|
|
39
|
+
// this causes TypeScript to throw and crash. So, we'll fake being a TS file here for now until they fix it
|
|
40
|
+
// Fixed by https://github.com/microsoft/TypeScript/pull/55716
|
|
41
|
+
const getScriptKind = info.languageServiceHost.getScriptKind?.bind(info.languageServiceHost.getScriptKind);
|
|
42
|
+
if (getScriptKind) {
|
|
43
|
+
info.languageServiceHost.getScriptKind = (fileName) => {
|
|
44
|
+
if (fileName.endsWith('.astro')) {
|
|
45
|
+
return ts.ScriptKind.TS;
|
|
46
|
+
}
|
|
47
|
+
return getScriptKind(fileName);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
23
50
|
}
|
|
24
51
|
return info.languageService;
|
|
25
52
|
},
|
|
26
|
-
getExternalFiles(project) {
|
|
27
|
-
if (
|
|
28
|
-
|
|
53
|
+
getExternalFiles(project, updateLevel = 0) {
|
|
54
|
+
if (
|
|
55
|
+
// @ts-expect-error wait for TS 5.3
|
|
56
|
+
updateLevel >= (1) ||
|
|
57
|
+
!externalFiles.has(project)) {
|
|
58
|
+
const oldFiles = externalFiles.get(project);
|
|
59
|
+
const newFiles = (0, typescript_1.searchExternalFiles)(ts, project, ['.astro']);
|
|
60
|
+
externalFiles.set(project, newFiles);
|
|
61
|
+
if (oldFiles && !arrayItemsEqual(oldFiles, newFiles)) {
|
|
62
|
+
project.refreshDiagnostics();
|
|
63
|
+
}
|
|
29
64
|
}
|
|
30
65
|
return externalFiles.get(project);
|
|
31
66
|
},
|
|
32
67
|
};
|
|
33
68
|
return pluginModule;
|
|
34
69
|
};
|
|
70
|
+
function arrayItemsEqual(a, b) {
|
|
71
|
+
if (a.length !== b.length) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const set = new Set(a);
|
|
75
|
+
for (const file of b) {
|
|
76
|
+
if (!set.has(file)) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
35
82
|
module.exports = init;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/ts-plugin",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "A TypeScript Plugin providing Astro intellisense",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -22,20 +22,21 @@
|
|
|
22
22
|
"author": "withastro",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@volar/language-core": "~1.10.
|
|
26
|
-
"@volar/typescript": "~1.10.
|
|
27
|
-
"@astrojs/compiler": "^2.2.
|
|
25
|
+
"@volar/language-core": "~1.10.9",
|
|
26
|
+
"@volar/typescript": "~1.10.9",
|
|
27
|
+
"@astrojs/compiler": "^2.2.2",
|
|
28
28
|
"@jridgewell/sourcemap-codec": "^1.4.15",
|
|
29
|
+
"semver": "^7.3.8",
|
|
29
30
|
"vscode-languageserver-textdocument": "^1.0.11"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/chai": "^4.3.5",
|
|
33
34
|
"@types/mocha": "^10.0.1",
|
|
34
|
-
"@types/node": "^
|
|
35
|
+
"@types/node": "^18.17.8",
|
|
36
|
+
"@types/semver": "^7.3.13",
|
|
35
37
|
"chai": "^4.3.7",
|
|
36
38
|
"glob": "^8.0.3",
|
|
37
|
-
"mocha": "^10.2.0"
|
|
38
|
-
"typescript": "~5.1.3"
|
|
39
|
+
"mocha": "^10.2.0"
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
41
42
|
"build": "tsc",
|