@defold-typescript/cli 0.4.3 → 0.5.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.
package/dist/bin.js CHANGED
@@ -120,14 +120,14 @@ function stripIncludeBase(pattern) {
120
120
  const lastSlash = upToWildcard.lastIndexOf("/");
121
121
  return lastSlash === -1 ? "" : upToWildcard.slice(0, lastSlash + 1);
122
122
  }
123
- function computeLuaRel(rel, config) {
123
+ function computeScriptRel(rel, config) {
124
124
  const { outDir, include } = config;
125
125
  if (outDir === undefined || outDir === "" || outDir === ".") {
126
- return rel.replace(/\.ts$/, ".lua");
126
+ return rel.replace(/\.ts$/, ".ts.script");
127
127
  }
128
128
  const includeBase = include.map(stripIncludeBase).filter((base) => rel.startsWith(base)).sort((a, b) => b.length - a.length)[0] ?? "";
129
129
  const relUnderBase = rel.slice(includeBase.length);
130
- return path2.posix.join(outDir, relUnderBase.replace(/\.ts$/, ".lua"));
130
+ return path2.posix.join(outDir, relUnderBase.replace(/\.ts$/, ".ts.script"));
131
131
  }
132
132
  function collectFailures(diagnostics) {
133
133
  const failures = new Map;
@@ -151,17 +151,17 @@ function throwIfFailures(failures) {
151
151
  throw new Error(`defold-typescript build: ${failures.size} file(s) failed:
152
152
  ${formatted}`);
153
153
  }
154
- function writeLuaFile(cwd, luaRel, lua, map) {
155
- const luaAbs = path2.join(cwd, luaRel);
156
- mkdirSync(path2.dirname(luaAbs), { recursive: true });
154
+ function writeScriptFile(cwd, scriptRel, lua, map) {
155
+ const scriptAbs = path2.join(cwd, scriptRel);
156
+ mkdirSync(path2.dirname(scriptAbs), { recursive: true });
157
157
  if (map) {
158
- const mapBasename = `${path2.posix.basename(luaRel)}.map`;
159
- writeFileSync(`${luaAbs}.map`, map);
160
- writeFileSync(luaAbs, `${lua}
158
+ const mapBasename = `${path2.posix.basename(scriptRel)}.map`;
159
+ writeFileSync(`${scriptAbs}.map`, map);
160
+ writeFileSync(scriptAbs, `${lua}
161
161
  --# sourceMappingURL=${mapBasename}
162
162
  `);
163
163
  } else {
164
- writeFileSync(luaAbs, lua);
164
+ writeFileSync(scriptAbs, lua);
165
165
  }
166
166
  }
167
167
 
@@ -201,9 +201,9 @@ function runBuild(opts) {
201
201
  if (!lua) {
202
202
  continue;
203
203
  }
204
- const luaRel = computeLuaRel(rel, config);
205
- writeLuaFile(cwd, luaRel, lua, result.sourceMaps[rel]);
206
- written.push(luaRel);
204
+ const scriptRel = computeScriptRel(rel, config);
205
+ writeScriptFile(cwd, scriptRel, lua, result.sourceMaps[rel]);
206
+ written.push(scriptRel);
207
207
  }
208
208
  throwIfFailures(failures);
209
209
  return { written };
@@ -242,14 +242,21 @@ var SKIP_SEGMENTS = new Set(["node_modules", ".defold-types", "build"]);
242
242
  function isSkipped(relPath) {
243
243
  return relPath.split(/[/\\]/).some((segment) => SKIP_SEGMENTS.has(segment));
244
244
  }
245
+ var GENERATED_SCRIPT_SUFFIX = ".ts.script";
246
+ function isGeneratedScript(relPath) {
247
+ return relPath.endsWith(GENERATED_SCRIPT_SUFFIX);
248
+ }
245
249
  function isComponentPath(relPath) {
250
+ if (isGeneratedScript(relPath)) {
251
+ return false;
252
+ }
246
253
  return Object.keys(KIND_BY_EXT).some((ext) => relPath.endsWith(ext));
247
254
  }
248
255
  function detectScriptKinds(cwd) {
249
256
  const kinds = new Set;
250
257
  for (const [ext, kind] of Object.entries(KIND_BY_EXT)) {
251
258
  for (const match of scanFilesSync(cwd, `**/*${ext}`)) {
252
- if (!isSkipped(match)) {
259
+ if (!isSkipped(match) && !isGeneratedScript(match)) {
253
260
  kinds.add(kind);
254
261
  break;
255
262
  }
@@ -299,11 +306,11 @@ var TSCONFIG_COMPILER_OPTIONS = {
299
306
  strict: true,
300
307
  skipLibCheck: true
301
308
  };
302
- var GITIGNORE_LINES = ["src/**/*.lua", "src/**/*.lua.map"];
309
+ var GITIGNORE_LINES = ["src/**/*.ts.script", "src/**/*.ts.script.map"];
303
310
  var BIOME_JSON_CONTENT = {
304
311
  $schema: "https://biomejs.dev/schemas/2.4.15/schema.json",
305
312
  files: {
306
- includes: ["src/**/*.ts", "!**/dist", "!**/node_modules", "!**/*.lua"]
313
+ includes: ["src/**/*.ts", "!**/dist", "!**/node_modules", "!**/*.ts.script"]
307
314
  },
308
315
  formatter: {
309
316
  enabled: true,
@@ -643,6 +650,8 @@ function materializeApiSurface(opts) {
643
650
  const overloads = ["msg-overloads.d.ts", "go-overloads.d.ts"].filter((file) => existsSync3(path7.join(srcDir, file)));
644
651
  const coreTypesSrc = path7.join(srcDir, "core-types.ts");
645
652
  const includeCoreTypes = overloads.length > 0 && existsSync3(coreTypesSrc);
653
+ const engineGlobalsSrc = path7.join(srcDir, "engine-globals.d.ts");
654
+ const includeEngineGlobals = includeCoreTypes && existsSync3(engineGlobalsSrc);
646
655
  const wanted = new Set(sources);
647
656
  for (const file of overloads) {
648
657
  wanted.add(file);
@@ -650,6 +659,9 @@ function materializeApiSurface(opts) {
650
659
  if (includeCoreTypes) {
651
660
  wanted.add("core-types.d.ts");
652
661
  }
662
+ if (includeEngineGlobals) {
663
+ wanted.add("engine-globals.d.ts");
664
+ }
653
665
  for (const existing of readdirSync2(absDir)) {
654
666
  if (existing.endsWith(".d.ts") && existing !== "index.d.ts" && !wanted.has(existing)) {
655
667
  rmSync(path7.join(absDir, existing));
@@ -661,10 +673,16 @@ function materializeApiSurface(opts) {
661
673
  if (includeCoreTypes) {
662
674
  writeFileSync3(path7.join(absDir, "core-types.d.ts"), readFileSync6(coreTypesSrc, "utf8"));
663
675
  }
676
+ if (includeEngineGlobals) {
677
+ writeFileSync3(path7.join(absDir, "engine-globals.d.ts"), readFileSync6(engineGlobalsSrc, "utf8"));
678
+ }
664
679
  for (const file of overloads) {
665
680
  writeFileSync3(path7.join(absDir, file), readFileSync6(path7.join(srcDir, file), "utf8"));
666
681
  }
667
682
  const modules = [...sources, ...overloads].map((file) => file.replace(/\.d\.ts$/, ""));
683
+ if (includeEngineGlobals) {
684
+ modules.push("engine-globals");
685
+ }
668
686
  const imports = modules.map((mod) => `import "./${mod}";`).join(`
669
687
  `);
670
688
  writeFileSync3(path7.join(absDir, "index.d.ts"), `${imports}
@@ -740,6 +758,10 @@ async function materializeRefDocSurface(opts) {
740
758
  ...excludeModules.length > 0 ? { excludeModules } : {}
741
759
  });
742
760
  copyFileSync(path7.join(root, "src", "core-types.ts"), path7.join(absDir, "core-types.d.ts"));
761
+ copyFileSync(path7.join(root, "src", "engine-globals.d.ts"), path7.join(absDir, "engine-globals.d.ts"));
762
+ const indexPath = path7.join(absDir, "index.d.ts");
763
+ writeFileSync3(indexPath, `import "./engine-globals";
764
+ ${readFileSync6(indexPath, "utf8")}`);
743
765
  } catch {
744
766
  rmSync(absDir, { recursive: true, force: true });
745
767
  return { materializedDir: null, active: null };
@@ -772,9 +794,9 @@ function createBuildSession(opts) {
772
794
  if (lua === undefined) {
773
795
  continue;
774
796
  }
775
- const luaRel = computeLuaRel(rel, config);
776
- writeLuaFile(cwd, luaRel, lua, result.sourceMaps[rel]);
777
- written.push(luaRel);
797
+ const scriptRel = computeScriptRel(rel, config);
798
+ writeScriptFile(cwd, scriptRel, lua, result.sourceMaps[rel]);
799
+ written.push(scriptRel);
778
800
  }
779
801
  throwIfFailures(failures);
780
802
  return { written };
@@ -809,9 +831,9 @@ function createBuildSession(opts) {
809
831
  }
810
832
  const result = session.update(changes);
811
833
  for (const rel of sourceRemoved) {
812
- const luaAbs = path8.join(cwd, computeLuaRel(rel, config));
813
- rmSync2(luaAbs, { force: true });
814
- rmSync2(`${luaAbs}.map`, { force: true });
834
+ const scriptAbs = path8.join(cwd, computeScriptRel(rel, config));
835
+ rmSync2(scriptAbs, { force: true });
836
+ rmSync2(`${scriptAbs}.map`, { force: true });
815
837
  }
816
838
  return writeOutputs(result, sourceChanged);
817
839
  }
@@ -6,7 +6,7 @@ export interface BuildConfig {
6
6
  export declare function toPosix(p: string, sep?: string): string;
7
7
  export declare function isTranspilerSource(rel: string): boolean;
8
8
  export declare function readBuildConfig(cwd: string): BuildConfig;
9
- export declare function computeLuaRel(rel: string, config: BuildConfig): string;
9
+ export declare function computeScriptRel(rel: string, config: BuildConfig): string;
10
10
  export declare function collectFailures(diagnostics: readonly TranspileDiagnostic[]): Map<string, string[]>;
11
11
  export declare function throwIfFailures(failures: ReadonlyMap<string, string[]>): void;
12
- export declare function writeLuaFile(cwd: string, luaRel: string, lua: string, map: string | undefined): void;
12
+ export declare function writeScriptFile(cwd: string, scriptRel: string, lua: string, map: string | undefined): void;
package/dist/index.js CHANGED
@@ -39,14 +39,14 @@ function stripIncludeBase(pattern) {
39
39
  const lastSlash = upToWildcard.lastIndexOf("/");
40
40
  return lastSlash === -1 ? "" : upToWildcard.slice(0, lastSlash + 1);
41
41
  }
42
- function computeLuaRel(rel, config) {
42
+ function computeScriptRel(rel, config) {
43
43
  const { outDir, include } = config;
44
44
  if (outDir === undefined || outDir === "" || outDir === ".") {
45
- return rel.replace(/\.ts$/, ".lua");
45
+ return rel.replace(/\.ts$/, ".ts.script");
46
46
  }
47
47
  const includeBase = include.map(stripIncludeBase).filter((base) => rel.startsWith(base)).sort((a, b) => b.length - a.length)[0] ?? "";
48
48
  const relUnderBase = rel.slice(includeBase.length);
49
- return path.posix.join(outDir, relUnderBase.replace(/\.ts$/, ".lua"));
49
+ return path.posix.join(outDir, relUnderBase.replace(/\.ts$/, ".ts.script"));
50
50
  }
51
51
  function collectFailures(diagnostics) {
52
52
  const failures = new Map;
@@ -70,17 +70,17 @@ function throwIfFailures(failures) {
70
70
  throw new Error(`defold-typescript build: ${failures.size} file(s) failed:
71
71
  ${formatted}`);
72
72
  }
73
- function writeLuaFile(cwd, luaRel, lua, map) {
74
- const luaAbs = path.join(cwd, luaRel);
75
- mkdirSync(path.dirname(luaAbs), { recursive: true });
73
+ function writeScriptFile(cwd, scriptRel, lua, map) {
74
+ const scriptAbs = path.join(cwd, scriptRel);
75
+ mkdirSync(path.dirname(scriptAbs), { recursive: true });
76
76
  if (map) {
77
- const mapBasename = `${path.posix.basename(luaRel)}.map`;
78
- writeFileSync(`${luaAbs}.map`, map);
79
- writeFileSync(luaAbs, `${lua}
77
+ const mapBasename = `${path.posix.basename(scriptRel)}.map`;
78
+ writeFileSync(`${scriptAbs}.map`, map);
79
+ writeFileSync(scriptAbs, `${lua}
80
80
  --# sourceMappingURL=${mapBasename}
81
81
  `);
82
82
  } else {
83
- writeFileSync(luaAbs, lua);
83
+ writeFileSync(scriptAbs, lua);
84
84
  }
85
85
  }
86
86
 
@@ -107,9 +107,9 @@ function createBuildSession(opts) {
107
107
  if (lua === undefined) {
108
108
  continue;
109
109
  }
110
- const luaRel = computeLuaRel(rel, config);
111
- writeLuaFile(cwd, luaRel, lua, result.sourceMaps[rel]);
112
- written.push(luaRel);
110
+ const scriptRel = computeScriptRel(rel, config);
111
+ writeScriptFile(cwd, scriptRel, lua, result.sourceMaps[rel]);
112
+ written.push(scriptRel);
113
113
  }
114
114
  throwIfFailures(failures);
115
115
  return { written };
@@ -144,9 +144,9 @@ function createBuildSession(opts) {
144
144
  }
145
145
  const result = session.update(changes);
146
146
  for (const rel of sourceRemoved) {
147
- const luaAbs = path3.join(cwd, computeLuaRel(rel, config));
148
- rmSync(luaAbs, { force: true });
149
- rmSync(`${luaAbs}.map`, { force: true });
147
+ const scriptAbs = path3.join(cwd, computeScriptRel(rel, config));
148
+ rmSync(scriptAbs, { force: true });
149
+ rmSync(`${scriptAbs}.map`, { force: true });
150
150
  }
151
151
  return writeOutputs(result, sourceChanged);
152
152
  }
@@ -265,9 +265,9 @@ function runBuild(opts) {
265
265
  if (!lua) {
266
266
  continue;
267
267
  }
268
- const luaRel = computeLuaRel(rel, config);
269
- writeLuaFile(cwd, luaRel, lua, result.sourceMaps[rel]);
270
- written.push(luaRel);
268
+ const scriptRel = computeScriptRel(rel, config);
269
+ writeScriptFile(cwd, scriptRel, lua, result.sourceMaps[rel]);
270
+ written.push(scriptRel);
271
271
  }
272
272
  throwIfFailures(failures);
273
273
  return { written };
@@ -306,14 +306,21 @@ var SKIP_SEGMENTS = new Set(["node_modules", ".defold-types", "build"]);
306
306
  function isSkipped(relPath) {
307
307
  return relPath.split(/[/\\]/).some((segment) => SKIP_SEGMENTS.has(segment));
308
308
  }
309
+ var GENERATED_SCRIPT_SUFFIX = ".ts.script";
310
+ function isGeneratedScript(relPath) {
311
+ return relPath.endsWith(GENERATED_SCRIPT_SUFFIX);
312
+ }
309
313
  function isComponentPath(relPath) {
314
+ if (isGeneratedScript(relPath)) {
315
+ return false;
316
+ }
310
317
  return Object.keys(KIND_BY_EXT).some((ext) => relPath.endsWith(ext));
311
318
  }
312
319
  function detectScriptKinds(cwd) {
313
320
  const kinds = new Set;
314
321
  for (const [ext, kind] of Object.entries(KIND_BY_EXT)) {
315
322
  for (const match of scanFilesSync(cwd, `**/*${ext}`)) {
316
- if (!isSkipped(match)) {
323
+ if (!isSkipped(match) && !isGeneratedScript(match)) {
317
324
  kinds.add(kind);
318
325
  break;
319
326
  }
@@ -363,11 +370,11 @@ var TSCONFIG_COMPILER_OPTIONS = {
363
370
  strict: true,
364
371
  skipLibCheck: true
365
372
  };
366
- var GITIGNORE_LINES = ["src/**/*.lua", "src/**/*.lua.map"];
373
+ var GITIGNORE_LINES = ["src/**/*.ts.script", "src/**/*.ts.script.map"];
367
374
  var BIOME_JSON_CONTENT = {
368
375
  $schema: "https://biomejs.dev/schemas/2.4.15/schema.json",
369
376
  files: {
370
- includes: ["src/**/*.ts", "!**/dist", "!**/node_modules", "!**/*.lua"]
377
+ includes: ["src/**/*.ts", "!**/dist", "!**/node_modules", "!**/*.ts.script"]
371
378
  },
372
379
  formatter: {
373
380
  enabled: true,
@@ -707,6 +714,8 @@ function materializeApiSurface(opts) {
707
714
  const overloads = ["msg-overloads.d.ts", "go-overloads.d.ts"].filter((file) => existsSync3(path8.join(srcDir, file)));
708
715
  const coreTypesSrc = path8.join(srcDir, "core-types.ts");
709
716
  const includeCoreTypes = overloads.length > 0 && existsSync3(coreTypesSrc);
717
+ const engineGlobalsSrc = path8.join(srcDir, "engine-globals.d.ts");
718
+ const includeEngineGlobals = includeCoreTypes && existsSync3(engineGlobalsSrc);
710
719
  const wanted = new Set(sources);
711
720
  for (const file of overloads) {
712
721
  wanted.add(file);
@@ -714,6 +723,9 @@ function materializeApiSurface(opts) {
714
723
  if (includeCoreTypes) {
715
724
  wanted.add("core-types.d.ts");
716
725
  }
726
+ if (includeEngineGlobals) {
727
+ wanted.add("engine-globals.d.ts");
728
+ }
717
729
  for (const existing of readdirSync2(absDir)) {
718
730
  if (existing.endsWith(".d.ts") && existing !== "index.d.ts" && !wanted.has(existing)) {
719
731
  rmSync2(path8.join(absDir, existing));
@@ -725,10 +737,16 @@ function materializeApiSurface(opts) {
725
737
  if (includeCoreTypes) {
726
738
  writeFileSync3(path8.join(absDir, "core-types.d.ts"), readFileSync7(coreTypesSrc, "utf8"));
727
739
  }
740
+ if (includeEngineGlobals) {
741
+ writeFileSync3(path8.join(absDir, "engine-globals.d.ts"), readFileSync7(engineGlobalsSrc, "utf8"));
742
+ }
728
743
  for (const file of overloads) {
729
744
  writeFileSync3(path8.join(absDir, file), readFileSync7(path8.join(srcDir, file), "utf8"));
730
745
  }
731
746
  const modules = [...sources, ...overloads].map((file) => file.replace(/\.d\.ts$/, ""));
747
+ if (includeEngineGlobals) {
748
+ modules.push("engine-globals");
749
+ }
732
750
  const imports = modules.map((mod) => `import "./${mod}";`).join(`
733
751
  `);
734
752
  writeFileSync3(path8.join(absDir, "index.d.ts"), `${imports}
@@ -804,6 +822,10 @@ async function materializeRefDocSurface(opts) {
804
822
  ...excludeModules.length > 0 ? { excludeModules } : {}
805
823
  });
806
824
  copyFileSync(path8.join(root, "src", "core-types.ts"), path8.join(absDir, "core-types.d.ts"));
825
+ copyFileSync(path8.join(root, "src", "engine-globals.d.ts"), path8.join(absDir, "engine-globals.d.ts"));
826
+ const indexPath = path8.join(absDir, "index.d.ts");
827
+ writeFileSync3(indexPath, `import "./engine-globals";
828
+ ${readFileSync7(indexPath, "utf8")}`);
807
829
  } catch {
808
830
  rmSync2(absDir, { recursive: true, force: true });
809
831
  return { materializedDir: null, active: null };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/cli",
3
- "version": "0.4.3",
3
+ "version": "0.5.1",
4
4
  "description": "End-user CLI for scaffolding and building Defold projects written in TypeScript.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  "test": "bun test"
32
32
  },
33
33
  "dependencies": {
34
- "@defold-typescript/transpiler": "0.4.3",
35
- "@defold-typescript/types": "0.4.3"
34
+ "@defold-typescript/transpiler": "0.5.1",
35
+ "@defold-typescript/types": "0.5.1"
36
36
  }
37
37
  }
@@ -54,10 +54,10 @@ function stripIncludeBase(pattern: string): string {
54
54
  return lastSlash === -1 ? "" : upToWildcard.slice(0, lastSlash + 1);
55
55
  }
56
56
 
57
- export function computeLuaRel(rel: string, config: BuildConfig): string {
57
+ export function computeScriptRel(rel: string, config: BuildConfig): string {
58
58
  const { outDir, include } = config;
59
59
  if (outDir === undefined || outDir === "" || outDir === ".") {
60
- return rel.replace(/\.ts$/, ".lua");
60
+ return rel.replace(/\.ts$/, ".ts.script");
61
61
  }
62
62
  const includeBase =
63
63
  include
@@ -65,7 +65,7 @@ export function computeLuaRel(rel: string, config: BuildConfig): string {
65
65
  .filter((base) => rel.startsWith(base))
66
66
  .sort((a, b) => b.length - a.length)[0] ?? "";
67
67
  const relUnderBase = rel.slice(includeBase.length);
68
- return path.posix.join(outDir, relUnderBase.replace(/\.ts$/, ".lua"));
68
+ return path.posix.join(outDir, relUnderBase.replace(/\.ts$/, ".ts.script"));
69
69
  }
70
70
 
71
71
  export function collectFailures(
@@ -94,19 +94,19 @@ export function throwIfFailures(failures: ReadonlyMap<string, string[]>): void {
94
94
  throw new Error(`defold-typescript build: ${failures.size} file(s) failed:\n${formatted}`);
95
95
  }
96
96
 
97
- export function writeLuaFile(
97
+ export function writeScriptFile(
98
98
  cwd: string,
99
- luaRel: string,
99
+ scriptRel: string,
100
100
  lua: string,
101
101
  map: string | undefined,
102
102
  ): void {
103
- const luaAbs = path.join(cwd, luaRel);
104
- mkdirSync(path.dirname(luaAbs), { recursive: true });
103
+ const scriptAbs = path.join(cwd, scriptRel);
104
+ mkdirSync(path.dirname(scriptAbs), { recursive: true });
105
105
  if (map) {
106
- const mapBasename = `${path.posix.basename(luaRel)}.map`;
107
- writeFileSync(`${luaAbs}.map`, map);
108
- writeFileSync(luaAbs, `${lua}\n--# sourceMappingURL=${mapBasename}\n`);
106
+ const mapBasename = `${path.posix.basename(scriptRel)}.map`;
107
+ writeFileSync(`${scriptAbs}.map`, map);
108
+ writeFileSync(scriptAbs, `${lua}\n--# sourceMappingURL=${mapBasename}\n`);
109
109
  } else {
110
- writeFileSync(luaAbs, lua);
110
+ writeFileSync(scriptAbs, lua);
111
111
  }
112
112
  }
@@ -8,12 +8,12 @@ import {
8
8
  import {
9
9
  type BuildConfig,
10
10
  collectFailures,
11
- computeLuaRel,
11
+ computeScriptRel,
12
12
  isTranspilerSource,
13
13
  readBuildConfig,
14
14
  throwIfFailures,
15
15
  toPosix,
16
- writeLuaFile,
16
+ writeScriptFile,
17
17
  } from "./build-output";
18
18
  import { scanFilesSync } from "./scan";
19
19
 
@@ -46,9 +46,9 @@ export function createBuildSession(opts: CreateBuildSessionOptions): BuildSessio
46
46
  if (lua === undefined) {
47
47
  continue;
48
48
  }
49
- const luaRel = computeLuaRel(rel, config);
50
- writeLuaFile(cwd, luaRel, lua, result.sourceMaps[rel]);
51
- written.push(luaRel);
49
+ const scriptRel = computeScriptRel(rel, config);
50
+ writeScriptFile(cwd, scriptRel, lua, result.sourceMaps[rel]);
51
+ written.push(scriptRel);
52
52
  }
53
53
  throwIfFailures(failures);
54
54
  return { written };
@@ -89,9 +89,9 @@ export function createBuildSession(opts: CreateBuildSessionOptions): BuildSessio
89
89
  const result = session.update(changes);
90
90
 
91
91
  for (const rel of sourceRemoved) {
92
- const luaAbs = path.join(cwd, computeLuaRel(rel, config));
93
- rmSync(luaAbs, { force: true });
94
- rmSync(`${luaAbs}.map`, { force: true });
92
+ const scriptAbs = path.join(cwd, computeScriptRel(rel, config));
93
+ rmSync(scriptAbs, { force: true });
94
+ rmSync(`${scriptAbs}.map`, { force: true });
95
95
  }
96
96
 
97
97
  return writeOutputs(result, sourceChanged);
package/src/build.ts CHANGED
@@ -3,11 +3,11 @@ import * as path from "node:path";
3
3
  import { transpileProject } from "@defold-typescript/transpiler";
4
4
  import {
5
5
  collectFailures,
6
- computeLuaRel,
6
+ computeScriptRel,
7
7
  readBuildConfig,
8
8
  throwIfFailures,
9
9
  toPosix,
10
- writeLuaFile,
10
+ writeScriptFile,
11
11
  } from "./build-output";
12
12
  import { scanFilesSync } from "./scan";
13
13
 
@@ -52,9 +52,9 @@ export function runBuild(opts: RunBuildOptions): RunBuildResult {
52
52
  if (!lua) {
53
53
  continue;
54
54
  }
55
- const luaRel = computeLuaRel(rel, config);
56
- writeLuaFile(cwd, luaRel, lua, result.sourceMaps[rel]);
57
- written.push(luaRel);
55
+ const scriptRel = computeScriptRel(rel, config);
56
+ writeScriptFile(cwd, scriptRel, lua, result.sourceMaps[rel]);
57
+ written.push(scriptRel);
58
58
  }
59
59
 
60
60
  throwIfFailures(failures);
package/src/init.ts CHANGED
@@ -35,12 +35,12 @@ const TSCONFIG_COMPILER_OPTIONS = {
35
35
  skipLibCheck: true,
36
36
  };
37
37
 
38
- const GITIGNORE_LINES = ["src/**/*.lua", "src/**/*.lua.map"];
38
+ const GITIGNORE_LINES = ["src/**/*.ts.script", "src/**/*.ts.script.map"];
39
39
 
40
40
  const BIOME_JSON_CONTENT = {
41
41
  $schema: "https://biomejs.dev/schemas/2.4.15/schema.json",
42
42
  files: {
43
- includes: ["src/**/*.ts", "!**/dist", "!**/node_modules", "!**/*.lua"],
43
+ includes: ["src/**/*.ts", "!**/dist", "!**/node_modules", "!**/*.ts.script"],
44
44
  },
45
45
  formatter: {
46
46
  enabled: true,
@@ -70,6 +70,8 @@ export function materializeApiSurface(
70
70
  );
71
71
  const coreTypesSrc = path.join(srcDir, "core-types.ts");
72
72
  const includeCoreTypes = overloads.length > 0 && existsSync(coreTypesSrc);
73
+ const engineGlobalsSrc = path.join(srcDir, "engine-globals.d.ts");
74
+ const includeEngineGlobals = includeCoreTypes && existsSync(engineGlobalsSrc);
73
75
 
74
76
  const wanted = new Set(sources);
75
77
  for (const file of overloads) {
@@ -78,6 +80,9 @@ export function materializeApiSurface(
78
80
  if (includeCoreTypes) {
79
81
  wanted.add("core-types.d.ts");
80
82
  }
83
+ if (includeEngineGlobals) {
84
+ wanted.add("engine-globals.d.ts");
85
+ }
81
86
 
82
87
  for (const existing of readdirSync(absDir)) {
83
88
  if (existing.endsWith(".d.ts") && existing !== "index.d.ts" && !wanted.has(existing)) {
@@ -94,11 +99,17 @@ export function materializeApiSurface(
94
99
  if (includeCoreTypes) {
95
100
  writeFileSync(path.join(absDir, "core-types.d.ts"), readFileSync(coreTypesSrc, "utf8"));
96
101
  }
102
+ if (includeEngineGlobals) {
103
+ writeFileSync(path.join(absDir, "engine-globals.d.ts"), readFileSync(engineGlobalsSrc, "utf8"));
104
+ }
97
105
  for (const file of overloads) {
98
106
  writeFileSync(path.join(absDir, file), readFileSync(path.join(srcDir, file), "utf8"));
99
107
  }
100
108
 
101
109
  const modules = [...sources, ...overloads].map((file) => file.replace(/\.d\.ts$/, ""));
110
+ if (includeEngineGlobals) {
111
+ modules.push("engine-globals");
112
+ }
102
113
  const imports = modules.map((mod) => `import "./${mod}";`).join("\n");
103
114
  writeFileSync(path.join(absDir, "index.d.ts"), `${imports}\n\nexport {};\n`);
104
115
 
@@ -216,6 +227,12 @@ export async function materializeRefDocSurface(
216
227
  ...(excludeModules.length > 0 ? { excludeModules } : {}),
217
228
  });
218
229
  copyFileSync(path.join(root, "src", "core-types.ts"), path.join(absDir, "core-types.d.ts"));
230
+ copyFileSync(
231
+ path.join(root, "src", "engine-globals.d.ts"),
232
+ path.join(absDir, "engine-globals.d.ts"),
233
+ );
234
+ const indexPath = path.join(absDir, "index.d.ts");
235
+ writeFileSync(indexPath, `import "./engine-globals";\n${readFileSync(indexPath, "utf8")}`);
219
236
  } catch {
220
237
  rmSync(absDir, { recursive: true, force: true });
221
238
  return { materializedDir: null, active: null };
@@ -16,7 +16,19 @@ export function isSkipped(relPath: string): boolean {
16
16
  return relPath.split(/[/\\]/).some((segment) => SKIP_SEGMENTS.has(segment));
17
17
  }
18
18
 
19
+ // Emitted transpiler output is `<name>.ts.script`, which ends in `.script`;
20
+ // without this guard the kind detector would read our own build artifacts as
21
+ // real Defold `.script` components and break the per-kind API wall.
22
+ const GENERATED_SCRIPT_SUFFIX = ".ts.script";
23
+
24
+ function isGeneratedScript(relPath: string): boolean {
25
+ return relPath.endsWith(GENERATED_SCRIPT_SUFFIX);
26
+ }
27
+
19
28
  export function isComponentPath(relPath: string): boolean {
29
+ if (isGeneratedScript(relPath)) {
30
+ return false;
31
+ }
20
32
  return Object.keys(KIND_BY_EXT).some((ext) => relPath.endsWith(ext));
21
33
  }
22
34
 
@@ -24,7 +36,7 @@ export function detectScriptKinds(cwd: string): Set<ScriptKind> {
24
36
  const kinds = new Set<ScriptKind>();
25
37
  for (const [ext, kind] of Object.entries(KIND_BY_EXT)) {
26
38
  for (const match of scanFilesSync(cwd, `**/*${ext}`)) {
27
- if (!isSkipped(match)) {
39
+ if (!isSkipped(match) && !isGeneratedScript(match)) {
28
40
  kinds.add(kind);
29
41
  break;
30
42
  }