@defold-typescript/transpiler 0.4.3 → 0.5.0
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 +30 -12
- package/package.json +2 -2
- package/src/session.ts +3 -0
- package/src/transpile.ts +42 -19
package/dist/index.js
CHANGED
|
@@ -120,7 +120,7 @@ var lifecycleErasurePlugin = {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
// src/transpile.ts
|
|
123
|
-
import { readFileSync } from "node:fs";
|
|
123
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
124
124
|
import { createRequire } from "node:module";
|
|
125
125
|
import * as path from "node:path";
|
|
126
126
|
import * as tstl from "typescript-to-lua";
|
|
@@ -136,18 +136,34 @@ var TSTL_LANG_EXT_ROOT = path.dirname(requireFromHere.resolve("@typescript-to-lu
|
|
|
136
136
|
function readAmbient(rel) {
|
|
137
137
|
return readFileSync(path.join(TYPES_PKG_ROOT, rel), "utf8");
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
139
|
+
function buildAmbientFiles() {
|
|
140
|
+
const files = {
|
|
141
|
+
"node_modules/@typescript-to-lua/language-extensions/index.d.ts": readFileSync(path.join(TSTL_LANG_EXT_ROOT, "index.d.ts"), "utf8"),
|
|
142
|
+
"node_modules/@defold-typescript/types/src/core-types.ts": readAmbient("src/core-types.ts"),
|
|
143
|
+
"node_modules/@defold-typescript/types/src/msg-overloads.d.ts": readAmbient("src/msg-overloads.d.ts"),
|
|
144
|
+
"node_modules/@defold-typescript/types/src/lifecycle.ts": readAmbient("src/lifecycle.ts"),
|
|
145
|
+
"node_modules/@defold-typescript/types/index.ts": [
|
|
146
|
+
'export { defineGuiScript, defineRenderScript, defineScript } from "./src/lifecycle";',
|
|
147
|
+
'export type { GuiScriptHooks, InputAction, InputTouch, RenderScriptHooks, ScriptHooks } from "./src/lifecycle";',
|
|
148
|
+
'export type { Hash, Matrix4, Quaternion, Url, Vector, Vector3, Vector4 } from "./src/core-types";',
|
|
149
|
+
""
|
|
150
|
+
].join(`
|
|
151
|
+
`),
|
|
152
|
+
"node_modules/@defold-typescript/types/script.d.ts": `export {};
|
|
153
|
+
`,
|
|
154
|
+
"node_modules/@defold-typescript/types/gui-script.d.ts": `export {};
|
|
155
|
+
`,
|
|
156
|
+
"node_modules/@defold-typescript/types/render-script.d.ts": `export {};
|
|
149
157
|
`
|
|
150
|
-
};
|
|
158
|
+
};
|
|
159
|
+
for (const entry of readdirSync(path.join(TYPES_PKG_ROOT, "generated"))) {
|
|
160
|
+
if (entry.endsWith(".d.ts")) {
|
|
161
|
+
files[`node_modules/@defold-typescript/types/generated/${entry}`] = readAmbient(`generated/${entry}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return files;
|
|
165
|
+
}
|
|
166
|
+
var AMBIENT_FILES = buildAmbientFiles();
|
|
151
167
|
function collectOutputs(transpiledFiles, diagnostics, userKeys) {
|
|
152
168
|
const lua = {};
|
|
153
169
|
const sourceMaps = {};
|
|
@@ -174,6 +190,7 @@ function transpileProject(input) {
|
|
|
174
190
|
const result = tstl.transpileVirtualProject(merged, {
|
|
175
191
|
luaTarget: tstl.LuaTarget.Lua54,
|
|
176
192
|
sourceMap: true,
|
|
193
|
+
skipLibCheck: true,
|
|
177
194
|
luaPlugins: [{ plugin: lifecycleErasurePlugin }]
|
|
178
195
|
});
|
|
179
196
|
return collectOutputs(result.transpiledFiles, result.diagnostics, userKeys);
|
|
@@ -192,6 +209,7 @@ var requireFromHere2 = createRequire2(import.meta.url);
|
|
|
192
209
|
var COMPILER_OPTIONS = {
|
|
193
210
|
luaTarget: tstl2.LuaTarget.Lua54,
|
|
194
211
|
sourceMap: true,
|
|
212
|
+
skipLibCheck: true,
|
|
195
213
|
luaPlugins: [{ plugin: lifecycleErasurePlugin }]
|
|
196
214
|
};
|
|
197
215
|
function normalizeSlashes(p) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defold-typescript/transpiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "TypeScript-to-Lua build pipeline tuned for Defold's runtime.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"test": "bun test"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@defold-typescript/types": "0.
|
|
31
|
+
"@defold-typescript/types": "0.5.0",
|
|
32
32
|
"@typescript-to-lua/language-extensions": "1.19.0",
|
|
33
33
|
"typescript-to-lua": "^1.36.0"
|
|
34
34
|
}
|
package/src/session.ts
CHANGED
|
@@ -16,6 +16,9 @@ const requireFromHere = createRequire(import.meta.url);
|
|
|
16
16
|
const COMPILER_OPTIONS: tstl.CompilerOptions = {
|
|
17
17
|
luaTarget: tstl.LuaTarget.Lua54,
|
|
18
18
|
sourceMap: true,
|
|
19
|
+
// Don't cross-check the seeded ambient .d.ts surface against itself; only user
|
|
20
|
+
// files matter (mirrors transpileProject and the editor's skipLibCheck).
|
|
21
|
+
skipLibCheck: true,
|
|
19
22
|
luaPlugins: [{ plugin: lifecycleErasurePlugin }],
|
|
20
23
|
};
|
|
21
24
|
|
package/src/transpile.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
1
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import type * as ts from "typescript";
|
|
@@ -47,24 +47,44 @@ function readAmbient(rel: string): string {
|
|
|
47
47
|
return readFileSync(path.join(TYPES_PKG_ROOT, rel), "utf8");
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
50
|
+
function buildAmbientFiles(): Record<string, string> {
|
|
51
|
+
const files: Record<string, string> = {
|
|
52
|
+
"node_modules/@typescript-to-lua/language-extensions/index.d.ts": readFileSync(
|
|
53
|
+
path.join(TSTL_LANG_EXT_ROOT, "index.d.ts"),
|
|
54
|
+
"utf8",
|
|
55
|
+
),
|
|
56
|
+
"node_modules/@defold-typescript/types/src/core-types.ts": readAmbient("src/core-types.ts"),
|
|
57
|
+
"node_modules/@defold-typescript/types/src/msg-overloads.d.ts":
|
|
58
|
+
readAmbient("src/msg-overloads.d.ts"),
|
|
59
|
+
"node_modules/@defold-typescript/types/src/lifecycle.ts": readAmbient("src/lifecycle.ts"),
|
|
60
|
+
// Mirror the consumer-facing re-exports of the real package index so a user
|
|
61
|
+
// file can `import { defineScript }` and `import type { Hash, Vector3 }`.
|
|
62
|
+
"node_modules/@defold-typescript/types/index.ts": [
|
|
63
|
+
'export { defineGuiScript, defineRenderScript, defineScript } from "./src/lifecycle";',
|
|
64
|
+
'export type { GuiScriptHooks, InputAction, InputTouch, RenderScriptHooks, ScriptHooks } from "./src/lifecycle";',
|
|
65
|
+
'export type { Hash, Matrix4, Quaternion, Url, Vector, Vector3, Vector4 } from "./src/core-types";',
|
|
66
|
+
"",
|
|
67
|
+
].join("\n"),
|
|
68
|
+
// Per-kind subpath entrypoints exist as package exports for the editor.
|
|
69
|
+
// Their namespaces are already seeded ambiently below, so the transpiler
|
|
70
|
+
// only needs the specifiers to resolve — an empty module is enough.
|
|
71
|
+
"node_modules/@defold-typescript/types/script.d.ts": "export {};\n",
|
|
72
|
+
"node_modules/@defold-typescript/types/gui-script.d.ts": "export {};\n",
|
|
73
|
+
"node_modules/@defold-typescript/types/render-script.d.ts": "export {};\n",
|
|
74
|
+
};
|
|
75
|
+
// Seed every generated namespace so real multi-namespace user code (sprite,
|
|
76
|
+
// physics, label, ...) resolves — not just the historical vmath/msg/go subset.
|
|
77
|
+
for (const entry of readdirSync(path.join(TYPES_PKG_ROOT, "generated"))) {
|
|
78
|
+
if (entry.endsWith(".d.ts")) {
|
|
79
|
+
files[`node_modules/@defold-typescript/types/generated/${entry}`] = readAmbient(
|
|
80
|
+
`generated/${entry}`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return files;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const AMBIENT_FILES: Readonly<Record<string, string>> = buildAmbientFiles();
|
|
68
88
|
|
|
69
89
|
interface CollectableFile {
|
|
70
90
|
readonly sourceFiles: readonly ts.SourceFile[];
|
|
@@ -108,6 +128,9 @@ export function transpileProject(input: TranspileProjectInput): TranspileProject
|
|
|
108
128
|
const result = tstl.transpileVirtualProject(merged, {
|
|
109
129
|
luaTarget: tstl.LuaTarget.Lua54,
|
|
110
130
|
sourceMap: true,
|
|
131
|
+
// Don't cross-check the seeded ambient .d.ts surface against itself; we only
|
|
132
|
+
// care about diagnostics on user files (mirrors the editor's skipLibCheck).
|
|
133
|
+
skipLibCheck: true,
|
|
111
134
|
luaPlugins: [{ plugin: lifecycleErasurePlugin }],
|
|
112
135
|
});
|
|
113
136
|
|