@needle-tools/needle-component-compiler 3.0.11 → 3.0.13

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/Changelog.md CHANGED
@@ -4,6 +4,10 @@ All notable changes to this package will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [3.0.12] - 2026-03-23
8
+ ### Fixed
9
+ - Fix nullable array types (`Texture[] | null`, `Array<Texture> | null`, `Array<Texture | null>`) not emitting as arrays in C# and Blender output
10
+
7
11
  ## [3.0.5] - 2026-03-15
8
12
  ### Added
9
13
  - `--types <path>` CLI flag to load external type mappings from a JSON file (e.g. Unity's `Types.json`)
package/dist/Compiler.js CHANGED
@@ -342,6 +342,17 @@ var Compiler = /** @class */ (function () {
342
342
  return undefined;
343
343
  // check if its an array
344
344
  if (this.isArrayType(typeNode)) {
345
+ // Unwrap union types (e.g. Texture[] | null) to find the array member
346
+ if (ts.isUnionTypeNode(typeNode)) {
347
+ for (var _i = 0, _a = typeNode.types; _i < _a.length; _i++) {
348
+ var member = _a[_i];
349
+ if (member.kind !== ts.SyntaxKind.NullKeyword &&
350
+ member.kind !== ts.SyntaxKind.UndefinedKeyword &&
351
+ member.kind !== ts.SyntaxKind.VoidKeyword) {
352
+ return this.resolveType(member, writer);
353
+ }
354
+ }
355
+ }
345
356
  if (typeNode.kind === ts.SyntaxKind.ArrayType) {
346
357
  var arrayType = typeNode;
347
358
  return this.resolveType(arrayType.elementType, writer);
@@ -381,8 +392,8 @@ var Compiler = /** @class */ (function () {
381
392
  }
382
393
  // Union types: Object3D | null | undefined → resolve the first concrete member
383
394
  if (ts.isUnionTypeNode(typeNode)) {
384
- for (var _i = 0, _a = typeNode.types; _i < _a.length; _i++) {
385
- var member = _a[_i];
395
+ for (var _b = 0, _c = typeNode.types; _b < _c.length; _b++) {
396
+ var member = _c[_b];
386
397
  if (member.kind !== ts.SyntaxKind.NullKeyword &&
387
398
  member.kind !== ts.SyntaxKind.UndefinedKeyword &&
388
399
  member.kind !== ts.SyntaxKind.VoidKeyword) {
@@ -410,6 +421,18 @@ var Compiler = /** @class */ (function () {
410
421
  Compiler.prototype.isArrayType = function (typeNode) {
411
422
  if (!typeNode)
412
423
  return false;
424
+ // Unwrap union types (e.g. Texture[] | null → Texture[])
425
+ if (ts.isUnionTypeNode(typeNode)) {
426
+ for (var _i = 0, _a = typeNode.types; _i < _a.length; _i++) {
427
+ var member = _a[_i];
428
+ if (member.kind !== ts.SyntaxKind.NullKeyword &&
429
+ member.kind !== ts.SyntaxKind.UndefinedKeyword &&
430
+ member.kind !== ts.SyntaxKind.VoidKeyword) {
431
+ return this.isArrayType(member);
432
+ }
433
+ }
434
+ return false;
435
+ }
413
436
  // check if its an array
414
437
  if (typeNode.kind === ts.SyntaxKind.ArrayType) {
415
438
  return true;
@@ -173,7 +173,7 @@ function handleDeletedFile(filePath, types) {
173
173
  }
174
174
  function runFromFile(writer, path) {
175
175
  if (!fs.existsSync(path)) {
176
- console.error("File not found", path);
176
+ log_1.logger.error("File not found", path);
177
177
  return;
178
178
  }
179
179
  var code = (0, fs_1.readFileSync)(path).toString();
package/dist/cli.js CHANGED
@@ -57,14 +57,15 @@ var target = positionalArgs[0];
57
57
  var outputDir = positionalArgs[1];
58
58
  var inputFiles = positionalArgs.slice(2);
59
59
  if (target !== "csharp" && target !== "blender") {
60
- console.error("Error: unknown target \"".concat(target, "\". Use \"csharp\" or \"blender\"."));
60
+ log_1.logger.error("Error: unknown target \"".concat(target, "\". Use \"csharp\" or \"blender\"."));
61
61
  process.exit(1);
62
62
  }
63
+ log_1.logger.log("needle-component-compiler v".concat(pkg.version));
63
64
  // Load external types if provided
64
65
  var externalTypes;
65
66
  if (typesPath) {
66
67
  if (!fs.existsSync(typesPath)) {
67
- console.warn("Warning: types file not found: ".concat(typesPath));
68
+ log_1.logger.warn("Warning: types file not found: ".concat(typesPath));
68
69
  }
69
70
  else {
70
71
  try {
@@ -72,12 +73,11 @@ if (typesPath) {
72
73
  log_1.logger.log("Loaded ".concat(Object.keys(externalTypes).length, " external type mappings from ").concat(typesPath));
73
74
  }
74
75
  catch (e) {
75
- console.error("Error reading types file: ".concat(e));
76
+ log_1.logger.error("Error reading types file: ".concat(e));
76
77
  process.exit(1);
77
78
  }
78
79
  }
79
80
  }
80
- log_1.logger.log("needle-component-compiler v".concat(pkg.version));
81
81
  var sink = new base_compiler_1.FileSink(outputDir);
82
82
  var writer = target === "csharp" ? new csharp_compiler_1.CSharpWriter(sink, externalTypes) : new blender_compiler_1.BlenderWriter(sink);
83
83
  var compiler = new Compiler_1.Compiler();
@@ -86,7 +86,7 @@ for (var _i = 0, inputFiles_1 = inputFiles; _i < inputFiles_1.length; _i++) {
86
86
  var filePath = inputFiles_1[_i];
87
87
  try {
88
88
  if (!fs.existsSync(filePath)) {
89
- console.error("Error: file not found: ".concat(filePath));
89
+ log_1.logger.error("Error: file not found: ".concat(filePath));
90
90
  hasErrors = true;
91
91
  continue;
92
92
  }
@@ -94,7 +94,7 @@ for (var _i = 0, inputFiles_1 = inputFiles; _i < inputFiles_1.length; _i++) {
94
94
  compiler.compile(writer, code, filePath);
95
95
  }
96
96
  catch (e) {
97
- console.error("Error processing ".concat(filePath, ": ").concat(e));
97
+ log_1.logger.error("Error processing ".concat(filePath, ": ").concat(e));
98
98
  hasErrors = true;
99
99
  }
100
100
  }
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.BlenderWriter = void 0;
19
19
  var base_compiler_1 = require("../base-compiler");
20
20
  var BaseWriter_1 = require("../BaseWriter");
21
+ var log_1 = require("../log");
21
22
  var supportedTypes = ["string", "float", "int", "bool", "col", "obj", "evt", "fn", "vec2", "vec3", "comp"];
22
23
  var knownBaseTypes = ["Behaviour", "IComponent"];
23
24
  var BlenderWriter = /** @class */ (function (_super) {
@@ -187,7 +188,7 @@ var BlenderWriter = /** @class */ (function (_super) {
187
188
  this.writer.endBlock("},");
188
189
  };
189
190
  BlenderWriter.prototype.writeNewTypeExpression = function (typeName, args) {
190
- console.log("new type:", typeName);
191
+ log_1.logger.log("new type:", typeName);
191
192
  };
192
193
  return BlenderWriter;
193
194
  }(BaseWriter_1.BaseWriter));
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.CSharpWriter = void 0;
19
19
  var base_compiler_1 = require("../base-compiler");
20
20
  var BaseWriter_1 = require("../BaseWriter");
21
+ var log_1 = require("../log");
21
22
  var allowDebugLogs = false;
22
23
  /** Inline type dictionary: TypeScript type name → fully-qualified C# type name */
23
24
  var TYPE_MAP = {
@@ -45,6 +46,7 @@ var TYPE_MAP = {
45
46
  "Vector3": "UnityEngine.Vector3",
46
47
  "Vector4": "UnityEngine.Vector4",
47
48
  "Quaternion": "UnityEngine.Quaternion",
49
+ "Euler": "UnityEngine.Vector3",
48
50
  "Color": "UnityEngine.Color",
49
51
  "RGBAColor": "UnityEngine.Color",
50
52
  "THREE.Color": "UnityEngine.Color",
@@ -209,7 +211,7 @@ var CSharpWriter = /** @class */ (function (_super) {
209
211
  CSharpWriter.prototype.writeMember = function (visibility, name, isArray, type, initialValue, comments) {
210
212
  var _a;
211
213
  if (allowDebugLogs)
212
- console.log("[CSharp] writeMember", name, type, comments);
214
+ log_1.logger.log("[CSharp] writeMember", name, type, comments);
213
215
  // @nonSerialized → skip entirely
214
216
  if (comments === null || comments === void 0 ? void 0 : comments.some(function (c) { return c.startsWith("@nonSerialized"); }))
215
217
  return;
@@ -290,7 +292,7 @@ var CSharpWriter = /** @class */ (function (_super) {
290
292
  var _this = this;
291
293
  var _a, _b;
292
294
  if (allowDebugLogs)
293
- console.log("[CSharp] writeMethod", name, returnType);
295
+ log_1.logger.log("[CSharp] writeMethod", name, returnType);
294
296
  // @nonSerialized → skip entirely
295
297
  if (comments === null || comments === void 0 ? void 0 : comments.some(function (c) { return c.startsWith("@nonSerialized"); }))
296
298
  return;
@@ -4,8 +4,9 @@ exports.writeTypeRegistry = writeTypeRegistry;
4
4
  var fs_1 = require("fs");
5
5
  var path = require("path");
6
6
  var base_compiler_1 = require("./base-compiler");
7
+ var log_1 = require("./log");
7
8
  function writeTypeRegistry(types, registerTypesPath) {
8
- console.log("Writing type registry to", registerTypesPath);
9
+ log_1.logger.log("Writing type registry to", registerTypesPath);
9
10
  var directory = path.dirname(registerTypesPath);
10
11
  if (!(0, fs_1.existsSync)(directory)) {
11
12
  (0, fs_1.mkdirSync)(directory);
package/dist/watcher.js CHANGED
@@ -41,7 +41,7 @@ var DirectoryWatcher = /** @class */ (function () {
41
41
  }
42
42
  }
43
43
  catch (err) {
44
- console.error(err);
44
+ log_1.logger.error(err);
45
45
  }
46
46
  });
47
47
  // call reload cmd
@@ -62,14 +62,14 @@ process.on('exit', function () {
62
62
  });
63
63
  var args = process.argv.slice(2);
64
64
  if (args.length < 3) {
65
- console.error("Missing arguments, usage: node watcher.js <directory> <output> <registerTypesPath>");
65
+ log_1.logger.error("Missing arguments, usage: node watcher.js <directory> <output> <registerTypesPath>");
66
66
  process.exit(1);
67
67
  }
68
68
  var directoryToWatch = args[0].replace("\"", "");
69
69
  var outputDirectory = args[1].replace("\"", "");
70
70
  var registerTypesPath = args[2].replace("\"", "");
71
71
  if (!fs.existsSync(directoryToWatch)) {
72
- console.error("Directory to watch does not exist");
72
+ log_1.logger.error("Directory to watch does not exist");
73
73
  process.exit(1);
74
74
  }
75
75
  if (fs.existsSync(outputDirectory))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/needle-component-compiler",
3
- "version": "3.0.11",
3
+ "version": "3.0.13",
4
4
  "description": "Compile Editor components for Needle Engine for C# and Blender",
5
5
  "main": "dist/index.js",
6
6
  "bin": "dist/cli.js",