@defold-typescript/cli 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/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,
@@ -772,9 +779,9 @@ function createBuildSession(opts) {
772
779
  if (lua === undefined) {
773
780
  continue;
774
781
  }
775
- const luaRel = computeLuaRel(rel, config);
776
- writeLuaFile(cwd, luaRel, lua, result.sourceMaps[rel]);
777
- written.push(luaRel);
782
+ const scriptRel = computeScriptRel(rel, config);
783
+ writeScriptFile(cwd, scriptRel, lua, result.sourceMaps[rel]);
784
+ written.push(scriptRel);
778
785
  }
779
786
  throwIfFailures(failures);
780
787
  return { written };
@@ -809,9 +816,9 @@ function createBuildSession(opts) {
809
816
  }
810
817
  const result = session.update(changes);
811
818
  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 });
819
+ const scriptAbs = path8.join(cwd, computeScriptRel(rel, config));
820
+ rmSync2(scriptAbs, { force: true });
821
+ rmSync2(`${scriptAbs}.map`, { force: true });
815
822
  }
816
823
  return writeOutputs(result, sourceChanged);
817
824
  }
@@ -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,
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.0",
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.0",
35
+ "@defold-typescript/types": "0.5.0"
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,
@@ -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
  }