@astrojs/ts-plugin 1.10.10 → 1.10.12
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/astro-types.d.ts +6 -0
- package/dist/astro-types.js +41 -0
- package/dist/index.js +6 -4
- package/package.json +1 -3
package/dist/astro-types.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ import type ts from 'typescript';
|
|
|
4
4
|
* returning the directory that contains its `package.json`.
|
|
5
5
|
*/
|
|
6
6
|
export declare function findAstroPackageDirectory(tsModule: typeof import('typescript'), currentDirectory: string | string[]): string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Check whether a directory belongs to an Astro project, by looking for an `astro`
|
|
9
|
+
* dependency in the nearest `package.json` and falling back to an `astro.config.*` file
|
|
10
|
+
* next to it. Mirrors the language server's `getAstroInstall()` check.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isAstroProject(tsModule: typeof import('typescript'), currentDirectory: string): boolean;
|
|
7
13
|
/**
|
|
8
14
|
* Inject the installed Astro package's `env.d.ts` and `astro-jsx.d.ts` into the
|
|
9
15
|
* TypeScript program. Without these, the `Astro` global is undeclared and the type
|
package/dist/astro-types.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.findAstroPackageDirectory = findAstroPackageDirectory;
|
|
7
|
+
exports.isAstroProject = isAstroProject;
|
|
7
8
|
exports.addAstroTypes = addAstroTypes;
|
|
8
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
10
|
const decoratedHosts = new WeakSet();
|
|
@@ -33,6 +34,46 @@ function findAstroPackageDirectoryFrom(tsModule, currentDirectory) {
|
|
|
33
34
|
directory = parent;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Check whether a directory belongs to an Astro project, by looking for an `astro`
|
|
39
|
+
* dependency in the nearest `package.json` and falling back to an `astro.config.*` file
|
|
40
|
+
* next to it. Mirrors the language server's `getAstroInstall()` check.
|
|
41
|
+
*/
|
|
42
|
+
function isAstroProject(tsModule, currentDirectory) {
|
|
43
|
+
const packageJson = findNearestPackageJson(tsModule, currentDirectory);
|
|
44
|
+
if (!packageJson) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const content = JSON.parse(tsModule.sys.readFile(packageJson) ?? '{}');
|
|
49
|
+
const deps = [
|
|
50
|
+
...Object.keys(content.dependencies ?? {}),
|
|
51
|
+
...Object.keys(content.devDependencies ?? {}),
|
|
52
|
+
...Object.keys(content.peerDependencies ?? {}),
|
|
53
|
+
];
|
|
54
|
+
if (deps.includes('astro')) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch { }
|
|
59
|
+
return tsModule.sys
|
|
60
|
+
.readDirectory(node_path_1.default.dirname(packageJson), ['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts'], undefined, undefined, 1)
|
|
61
|
+
.some((file) => node_path_1.default.basename(file).startsWith('astro.config'));
|
|
62
|
+
}
|
|
63
|
+
function findNearestPackageJson(tsModule, currentDirectory) {
|
|
64
|
+
let directory = tsModule.sys.resolvePath(currentDirectory);
|
|
65
|
+
while (true) {
|
|
66
|
+
const packageJson = node_path_1.default.join(directory, 'package.json');
|
|
67
|
+
if (tsModule.sys.fileExists(packageJson)) {
|
|
68
|
+
return packageJson;
|
|
69
|
+
}
|
|
70
|
+
const parent = node_path_1.default.dirname(directory);
|
|
71
|
+
if (parent === directory) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
directory = parent;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
36
77
|
/**
|
|
37
78
|
* Inject the installed Astro package's `env.d.ts` and `astro-jsx.d.ts` into the
|
|
38
79
|
* TypeScript program. Without these, the `Astro` global is undeclared and the type
|
package/dist/index.js
CHANGED
|
@@ -13,10 +13,12 @@ module.exports = (0, createLanguageServicePlugin_js_1.createLanguageServicePlugi
|
|
|
13
13
|
// Make "Go To References" from `.ts` files aware of usages inside `.astro` files
|
|
14
14
|
// by injecting the Astro ambient types so type chains like `Astro.locals.*` resolve.
|
|
15
15
|
// (`.astro` files themselves already enter the program via Volar's external files.)
|
|
16
|
-
(0, astro_types_js_1.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
if ((0, astro_types_js_1.isAstroProject)(ts, currentDir)) {
|
|
17
|
+
(0, astro_types_js_1.addAstroTypes)(ts, info.languageServiceHost, [
|
|
18
|
+
currentDir,
|
|
19
|
+
...info.languageServiceHost.getScriptFileNames().map((fileName) => node_path_1.default.dirname(fileName)),
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
20
22
|
try {
|
|
21
23
|
const fileContent = ts.sys.readFile(currentDir + '/.astro/collections/collections.json');
|
|
22
24
|
if (fileContent) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/ts-plugin",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.12",
|
|
4
4
|
"description": "A TypeScript Plugin providing Astro intellisense",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -27,13 +27,11 @@
|
|
|
27
27
|
"@jridgewell/sourcemap-codec": "^1.5.5",
|
|
28
28
|
"@volar/language-core": "~2.4.28",
|
|
29
29
|
"@volar/typescript": "~2.4.28",
|
|
30
|
-
"semver": "^7.7.4",
|
|
31
30
|
"vscode-languageserver-textdocument": "^1.0.12"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
33
|
"@types/mocha": "^10.0.10",
|
|
35
34
|
"@types/node": "^22.10.6",
|
|
36
|
-
"@types/semver": "^7.7.1",
|
|
37
35
|
"@types/vscode": "^1.101.0",
|
|
38
36
|
"@vscode/test-cli": "^0.0.12",
|
|
39
37
|
"@vscode/test-electron": "^2.5.2",
|