Skip to content

Commit fc27b02

Browse files
committed
package the plugin for distribution
1 parent 128b67d commit fc27b02

File tree

8 files changed

+267
-24
lines changed

8 files changed

+267
-24
lines changed
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
let a;
2-
31
export function A(b: number): number {
4-
if (true) {
5-
return 1;
6-
} {
7-
3;
8-
}
9-
}
2+
return b;
3+
}
4+
A("test")
5+
6+
7+
let a: { m: number[] };
8+
let b = { m: [""] };
9+
a = b;
10+
11+
// Extra Properties
12+
13+
type A = { m: number };
14+
const w: A = { m: 10, n: "" };
15+
16+
// Union Assignments
17+
18+
type Thing = "none" | { name: string };
19+
const e: Thing = { name: 0 };

packages/language-service-plugin/example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"version": "0.1.0",
44
"dependencies": {
55
"ts-error-translator-tssplugin": "file:..",
6-
"typescript": "^4.8.3"
6+
"typescript": "^4.5.3"
77
}
88
}

packages/language-service-plugin/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
"license": "MIT",
55
"main": "./out/index.js",
66
"private": true,
7-
"files": ["./out/**"],
7+
"files": [
8+
"./out/**"
9+
],
810
"scripts": {
911
"dev": "tsc --watch",
10-
"build": "tsc"
12+
"build": "rollup -c rollup.config.mjs"
1113
},
1214
"devDependencies": {
15+
"@rollup/plugin-commonjs": "^24.0.1",
16+
"@rollup/plugin-json": "^6.0.0",
17+
"@rollup/plugin-node-resolve": "^15.0.1",
18+
"@rollup/plugin-typescript": "^11.0.0",
19+
"rollup": "^3.14.0",
1320
"tsconfig": "workspace:*",
1421
"typescript": "^4.5.3"
22+
},
23+
"dependencies": {
24+
"@total-typescript/error-translation-engine": "workspace:*"
1525
}
1626
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { nodeResolve } from '@rollup/plugin-node-resolve';
2+
import typescript from '@rollup/plugin-typescript';
3+
import commonjs from '@rollup/plugin-commonjs';
4+
import json from '@rollup/plugin-json';
5+
6+
export default {
7+
input: 'src/index.ts',
8+
output: {
9+
file: 'out/index.js',
10+
sourcemap: true,
11+
format: 'cjs'
12+
},
13+
plugins: [
14+
nodeResolve({
15+
extensions: ['.mjs', '.js', '.json', '.node', '.ts']
16+
}),
17+
commonjs({ extensions: ['.js', '.ts'] }),
18+
typescript(),
19+
json()
20+
]
21+
};

packages/language-service-plugin/src/index.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1-
function init(modules: { typescript: typeof import("typescript/lib/tsserverlibrary") }) {
1+
import { parseErrors } from '@total-typescript/error-translation-engine';
2+
3+
export default function init(modules: { typescript: typeof import("typescript/lib/tsserverlibrary") }) {
24
const ts = modules.typescript;
35

6+
function withParsedError(messageText: string): string {
7+
const parsed = parseErrors(messageText);
8+
const allMessages = parsed.map(err => err.error).join('\n\n');
9+
return `${messageText}\n\nIn other words,\n${allMessages}\n`;
10+
}
11+
412
function enrichDiagnostic(diagnostic: ts.Diagnostic): ts.Diagnostic {
5-
// diagnostic.code: number
6-
// diagnostic.category === ts.DiagnosticCategory (Error, Message, Suggestion, Warning)
7-
diagnostic.messageText = `${diagnostic.messageText}\n\nHello from plugin!\n`
13+
if (typeof diagnostic.messageText === 'string') {
14+
diagnostic.messageText = withParsedError(diagnostic.messageText);
15+
return diagnostic;
16+
}
17+
if (diagnostic.messageText.category === ts.DiagnosticCategory.Error) {
18+
const msg = withParsedError(diagnostic.messageText.messageText);
19+
diagnostic.messageText.messageText = msg;
20+
21+
const nextMesgs = diagnostic.messageText.next;
22+
if (nextMesgs) {
23+
for (let i = 0; i < nextMesgs.length; i++) {
24+
let nextMsg = nextMesgs[i];
25+
nextMesgs[i].messageText = withParsedError(nextMsg.messageText);
26+
}
27+
}
28+
}
829
return diagnostic;
930
}
1031

@@ -29,4 +50,4 @@ function init(modules: { typescript: typeof import("typescript/lib/tsserverlibra
2950

3051
}
3152

32-
export = init;
53+
// export = init;
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
{
22
"extends": "tsconfig/base.json",
33
"compilerOptions": {
4-
"module": "commonjs",
5-
"target": "ES2019",
4+
"module": "ESNext",
5+
"target": "ESNext",
66
"outDir": "./out",
77
"rootDir": "src",
88
"strict": true,
99
"declaration": true,
10-
"sourceMap": true,
11-
"skipLibCheck": true
10+
"sourceMap": true
1211
},
1312
"include": [
14-
"src"
13+
"src/**/*"
1514
],
1615
"exclude": [
17-
"node_modules"
16+
"node_modules", "out"
1817
]
1918
}

0 commit comments

Comments
 (0)