@defold-typescript/tstl-plugin 0.8.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.
@@ -0,0 +1,6 @@
1
+ import type * as ts from "typescript";
2
+ export default function init(modules: {
3
+ typescript: typeof import("typescript");
4
+ }): {
5
+ create(info: ts.server.PluginCreateInfo): ts.LanguageService;
6
+ };
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ // src/index.ts
2
+ import { getProgramDiagnostics } from "@defold-typescript/transpiler";
3
+ function init(modules) {
4
+ const ts = modules.typescript;
5
+ function create(info) {
6
+ const proxy = Object.create(null);
7
+ const base = info.languageService;
8
+ for (const key of Object.keys(base)) {
9
+ const member = base[key];
10
+ if (typeof member === "function") {
11
+ proxy[key] = (...args) => member.apply(base, args);
12
+ }
13
+ }
14
+ proxy.getSemanticDiagnostics = (fileName) => {
15
+ const prior = base.getSemanticDiagnostics(fileName);
16
+ const program = base.getProgram();
17
+ if (!program) {
18
+ return prior;
19
+ }
20
+ const transpiler = getProgramDiagnostics(program, program.getSourceFile(fileName)).map((diagnostic) => ({ ...diagnostic, category: ts.DiagnosticCategory.Suggestion }));
21
+ return [...prior, ...transpiler];
22
+ };
23
+ return proxy;
24
+ }
25
+ return { create };
26
+ }
27
+ export {
28
+ init as default
29
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@defold-typescript/tstl-plugin",
3
+ "version": "0.8.1",
4
+ "description": "TypeScript language-service plugin surfacing Defold transpiler diagnostics live in the editor.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/defold-typescript/toolchain.git",
9
+ "directory": "packages/tstl-plugin"
10
+ },
11
+ "homepage": "https://github.com/defold-typescript/toolchain#readme",
12
+ "bugs": "https://github.com/defold-typescript/toolchain/issues",
13
+ "type": "module",
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "bun": "./src/index.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "src",
26
+ "!src/**/*.test.ts",
27
+ "!src/**/__snapshots__"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "build": "rm -rf dist && bun build src/index.ts --target=node --format=esm --packages=external --outdir=dist && tsc -p tsconfig.build.json --emitDeclarationOnly",
34
+ "typecheck": "tsc -p tsconfig.json --noEmit",
35
+ "test": "bun test"
36
+ },
37
+ "dependencies": {
38
+ "@defold-typescript/transpiler": "0.8.1"
39
+ },
40
+ "peerDependencies": {
41
+ "typescript": ">=5.0.0"
42
+ }
43
+ }
package/src/index.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { getProgramDiagnostics } from "@defold-typescript/transpiler";
2
+ import type * as ts from "typescript";
3
+
4
+ // A TS language-service plugin is loaded by package name and its main is called
5
+ // as this `init` factory; the editor passes its own `typescript` instance so the
6
+ // plugin shares the editor's `ts` (notably `DiagnosticCategory`).
7
+ export default function init(modules: { typescript: typeof import("typescript") }): {
8
+ create(info: ts.server.PluginCreateInfo): ts.LanguageService;
9
+ } {
10
+ const ts = modules.typescript;
11
+
12
+ function create(info: ts.server.PluginCreateInfo): ts.LanguageService {
13
+ const proxy = Object.create(null) as ts.LanguageService;
14
+ const base = info.languageService;
15
+ for (const key of Object.keys(base) as Array<keyof ts.LanguageService>) {
16
+ const member = base[key];
17
+ if (typeof member === "function") {
18
+ // biome-ignore lint/suspicious/noExplicitAny: opaque LS member forwarding.
19
+ (proxy as any)[key] = (...args: unknown[]) => (member as any).apply(base, args);
20
+ }
21
+ }
22
+
23
+ proxy.getSemanticDiagnostics = (fileName: string): ts.Diagnostic[] => {
24
+ const prior = base.getSemanticDiagnostics(fileName);
25
+ const program = base.getProgram();
26
+ if (!program) {
27
+ return prior;
28
+ }
29
+ // Advisory category so a valid project's `tsc --noEmit` stays clean — the
30
+ // plugin adds signal, never hard errors on supported code.
31
+ const transpiler = getProgramDiagnostics(program, program.getSourceFile(fileName)).map(
32
+ (diagnostic) => ({ ...diagnostic, category: ts.DiagnosticCategory.Suggestion }),
33
+ );
34
+ return [...prior, ...transpiler];
35
+ };
36
+
37
+ return proxy;
38
+ }
39
+
40
+ return { create };
41
+ }