@astrojs/ts-plugin 0.4.2 → 0.4.3
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/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
@astrojs/ts-plugin:build: cache hit, replaying output
|
|
1
|
+
@astrojs/ts-plugin:build: cache hit, replaying output 492757a083494d7d
|
|
2
2
|
@astrojs/ts-plugin:build:
|
|
3
|
-
@astrojs/ts-plugin:build: > @astrojs/ts-plugin@0.4.
|
|
3
|
+
@astrojs/ts-plugin:build: > @astrojs/ts-plugin@0.4.3 build /home/runner/work/language-tools/language-tools/packages/ts-plugin
|
|
4
4
|
@astrojs/ts-plugin:build: > astro-scripts build "src/**/*.ts"
|
|
5
5
|
@astrojs/ts-plugin:build:
|
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,13 +17,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
18
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
25
|
var diagnostics_exports = {};
|
|
20
26
|
__export(diagnostics_exports, {
|
|
27
|
+
DiagnosticCodes: () => DiagnosticCodes,
|
|
21
28
|
decorateDiagnostics: () => decorateDiagnostics
|
|
22
29
|
});
|
|
23
30
|
module.exports = __toCommonJS(diagnostics_exports);
|
|
31
|
+
var import_tsserverlibrary = __toESM(require("typescript/lib/tsserverlibrary"));
|
|
24
32
|
var import_utils = require("../utils.js");
|
|
33
|
+
var DiagnosticCodes = /* @__PURE__ */ ((DiagnosticCodes2) => {
|
|
34
|
+
DiagnosticCodes2[DiagnosticCodes2["CANNOT_FIND_MODULE"] = 2307] = "CANNOT_FIND_MODULE";
|
|
35
|
+
return DiagnosticCodes2;
|
|
36
|
+
})(DiagnosticCodes || {});
|
|
25
37
|
function decorateDiagnostics(ls) {
|
|
26
38
|
decorateSyntacticDiagnostics(ls);
|
|
27
39
|
decorateSemanticDiagnostics(ls);
|
|
@@ -42,7 +54,15 @@ function decorateSemanticDiagnostics(ls) {
|
|
|
42
54
|
if ((0, import_utils.isAstroFilePath)(fileName)) {
|
|
43
55
|
return [];
|
|
44
56
|
}
|
|
45
|
-
|
|
57
|
+
let diagnostics = getSemanticDiagnostics(fileName);
|
|
58
|
+
diagnostics = diagnostics.map((diag) => {
|
|
59
|
+
const message = import_tsserverlibrary.default.flattenDiagnosticMessageText(diag.messageText, import_tsserverlibrary.default.sys.newLine);
|
|
60
|
+
if (diag.code === 2307 /* CANNOT_FIND_MODULE */ && message.includes("astro:content") && !message.includes("content collections")) {
|
|
61
|
+
diag.messageText = message + `${import_tsserverlibrary.default.sys.newLine}${import_tsserverlibrary.default.sys.newLine}If you're using content collections, make sure to run \`astro dev\`, \`astro build\` or \`astro sync\` to first generate the types so you can import from them. If you already ran one of those commands, restarting the TS Server might be necessary in order for the change to take effect`;
|
|
62
|
+
}
|
|
63
|
+
return diag;
|
|
64
|
+
});
|
|
65
|
+
return diagnostics;
|
|
46
66
|
};
|
|
47
67
|
}
|
|
48
68
|
function decorateSuggestionDiagnostics(ls) {
|
|
@@ -56,6 +76,7 @@ function decorateSuggestionDiagnostics(ls) {
|
|
|
56
76
|
}
|
|
57
77
|
// Annotate the CommonJS export names for ESM import in node:
|
|
58
78
|
0 && (module.exports = {
|
|
79
|
+
DiagnosticCodes,
|
|
59
80
|
decorateDiagnostics
|
|
60
81
|
});
|
|
61
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
82
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL2xhbmd1YWdlLXNlcnZpY2UvZGlhZ25vc3RpY3MudHMiXSwKICAibWFwcGluZ3MiOiAiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQSw2QkFBZTtBQUNmLG1CQUFnQztBQUV6QixJQUFLLGtCQUFMLGtCQUFLQSxxQkFBTDtBQUNOLEVBQUFBLGtDQUFBLHdCQUFxQixRQUFyQjtBQURXLFNBQUFBO0FBQUEsR0FBQTtBQUlMLFNBQVMsb0JBQW9CLElBQThCO0FBQ2pFLCtCQUE2QixFQUFFO0FBQy9CLDhCQUE0QixFQUFFO0FBQzlCLGdDQUE4QixFQUFFO0FBQ2pDO0FBRUEsU0FBUyw2QkFBNkIsSUFBOEI7QUFDbkUsUUFBTSwwQkFBMEIsR0FBRztBQUNuQyxLQUFHLDBCQUEwQixDQUFDLGFBQXFCO0FBR2xELFlBQUksOEJBQWdCLFFBQVEsR0FBRztBQUM5QixhQUFPLENBQUM7QUFBQSxJQUNUO0FBQ0EsV0FBTyx3QkFBd0IsUUFBUTtBQUFBLEVBQ3hDO0FBQ0Q7QUFFQSxTQUFTLDRCQUE0QixJQUE4QjtBQUNsRSxRQUFNLHlCQUF5QixHQUFHO0FBQ2xDLEtBQUcseUJBQXlCLENBQUMsYUFBcUI7QUFHakQsWUFBSSw4QkFBZ0IsUUFBUSxHQUFHO0FBQzlCLGFBQU8sQ0FBQztBQUFBLElBQ1Q7QUFFQSxRQUFJLGNBQWMsdUJBQXVCLFFBQVE7QUFDakQsa0JBQWMsWUFBWSxJQUFJLENBQUMsU0FBUztBQUN2QyxZQUFNLFVBQVUsdUJBQUFDLFFBQUcsNkJBQTZCLEtBQUssYUFBYSx1QkFBQUEsUUFBRyxJQUFJLE9BQU87QUFDaEYsVUFDQyxLQUFLLFNBQVMsaUNBQ2QsUUFBUSxTQUFTLGVBQWUsS0FHaEMsQ0FBQyxRQUFRLFNBQVMscUJBQXFCLEdBQ3RDO0FBQ0QsYUFBSyxjQUNKLFVBQ0EsR0FBRyx1QkFBQUEsUUFBRyxJQUFJLFVBQVUsdUJBQUFBLFFBQUcsSUFBSTtBQUFBLE1BRTdCO0FBRUEsYUFBTztBQUFBLElBQ1IsQ0FBQztBQUVELFdBQU87QUFBQSxFQUNSO0FBQ0Q7QUFFQSxTQUFTLDhCQUE4QixJQUE4QjtBQUNwRSxRQUFNLDJCQUEyQixHQUFHO0FBQ3BDLEtBQUcsMkJBQTJCLENBQUMsYUFBcUI7QUFHbkQsWUFBSSw4QkFBZ0IsUUFBUSxHQUFHO0FBQzlCLGFBQU8sQ0FBQztBQUFBLElBQ1Q7QUFDQSxXQUFPLHlCQUF5QixRQUFRO0FBQUEsRUFDekM7QUFDRDsiLAogICJuYW1lcyI6IFsiRGlhZ25vc3RpY0NvZGVzIiwgInRzIl0KfQo=
|
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import { isAstroFilePath } from '../utils.js';
|
|
3
3
|
|
|
4
|
+
export enum DiagnosticCodes {
|
|
5
|
+
CANNOT_FIND_MODULE = 2307, // Cannot find module '{0}' or its corresponding type declarations.
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
export function decorateDiagnostics(ls: ts.LanguageService): void {
|
|
5
9
|
decorateSyntacticDiagnostics(ls);
|
|
6
10
|
decorateSemanticDiagnostics(ls);
|
|
@@ -27,7 +31,27 @@ function decorateSemanticDiagnostics(ls: ts.LanguageService): void {
|
|
|
27
31
|
if (isAstroFilePath(fileName)) {
|
|
28
32
|
return [];
|
|
29
33
|
}
|
|
30
|
-
|
|
34
|
+
|
|
35
|
+
let diagnostics = getSemanticDiagnostics(fileName);
|
|
36
|
+
diagnostics = diagnostics.map((diag) => {
|
|
37
|
+
const message = ts.flattenDiagnosticMessageText(diag.messageText, ts.sys.newLine);
|
|
38
|
+
if (
|
|
39
|
+
diag.code === DiagnosticCodes.CANNOT_FIND_MODULE &&
|
|
40
|
+
message.includes('astro:content') &&
|
|
41
|
+
// TypeScript will keep the diagnostics here in cache, so if we just blindly always add to it, our added message will be there twice
|
|
42
|
+
// Not sure if there's a generic way to ensure that we only add it once, so for now we'll just check for the message we want to add
|
|
43
|
+
!message.includes('content collections')
|
|
44
|
+
) {
|
|
45
|
+
diag.messageText =
|
|
46
|
+
message +
|
|
47
|
+
`${ts.sys.newLine}${ts.sys.newLine}` +
|
|
48
|
+
"If you're using content collections, make sure to run `astro dev`, `astro build` or `astro sync` to first generate the types so you can import from them. If you already ran one of those commands, restarting the TS Server might be necessary in order for the change to take effect";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return diag;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return diagnostics;
|
|
31
55
|
};
|
|
32
56
|
}
|
|
33
57
|
|