@needle-tools/needle-component-compiler 3.0.17 → 3.0.19-next.e2b9a6e
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 +12 -0
- package/dist/BaseWriter.d.ts +1 -1
- package/dist/Compiler.js +1 -1
- package/dist/base-compiler.d.ts +1 -1
- package/dist/cli.js +42 -1
- package/dist/impl/blender-compiler.d.ts +1 -1
- package/dist/impl/blender-compiler.js +17 -11
- package/dist/impl/csharp-compiler.d.ts +1 -1
- package/dist/impl/csharp-compiler.js +8 -5
- package/dist/impl/react-three-fiber-compiler.d.ts +1 -1
- package/dist/impl/react-three-fiber-compiler.js +1 -1
- package/package.json +1 -1
package/Changelog.md
CHANGED
|
@@ -4,6 +4,18 @@ 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.19] - 2026-04-28
|
|
8
|
+
### Fixed
|
|
9
|
+
- C#: skip `= undefined` initializers — `undefined` is not valid in C#
|
|
10
|
+
|
|
11
|
+
## [3.0.18] - 2026-04-28
|
|
12
|
+
### Added
|
|
13
|
+
- CLI: Blender write types automatically
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- Blender: fix custom enum type parsing
|
|
17
|
+
- Blender: fix missing default values in component.json
|
|
18
|
+
|
|
7
19
|
## [3.0.17] - 2026-04-17
|
|
8
20
|
### Added
|
|
9
21
|
- Support for string literal union types (e.g. `axis: "x" | "y" | "z" = "y"`)
|
package/dist/BaseWriter.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare abstract class BaseWriter implements IWriter {
|
|
|
8
8
|
/** Enum registry: lowercased enum name → members */
|
|
9
9
|
protected _enumRegistry: Map<string, EnumMember[]>;
|
|
10
10
|
registerEnum(name: string, members: EnumMember[]): void;
|
|
11
|
-
abstract
|
|
11
|
+
abstract resolveNeedleTypeName(typescriptTypeName: string, baseTypes?: string[]): string | void;
|
|
12
12
|
abstract startNewType(filePath: string, typeName: string, baseType: string[], comments?: string[]): boolean | void;
|
|
13
13
|
abstract endNewType(filePath: string, typeName: string): void;
|
|
14
14
|
abstract writeMember(visibility: Visibility, name: string, isArray: boolean, type: string, initialValue?: string, comments?: string[]): void;
|
package/dist/Compiler.js
CHANGED
|
@@ -429,7 +429,7 @@ var Compiler = /** @class */ (function () {
|
|
|
429
429
|
return this.resolveTypeFromString(typeNode.getText(), writer);
|
|
430
430
|
};
|
|
431
431
|
Compiler.prototype.resolveTypeFromString = function (type, writer) {
|
|
432
|
-
var resolved = writer.
|
|
432
|
+
var resolved = writer.resolveNeedleTypeName(type);
|
|
433
433
|
return resolved || type;
|
|
434
434
|
};
|
|
435
435
|
Compiler.prototype.isArrayType = function (typeNode) {
|
package/dist/base-compiler.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export type EnumMember = {
|
|
|
44
44
|
export interface IWriter {
|
|
45
45
|
get outputInfo(): TypeSourceInformation;
|
|
46
46
|
begin(filePath: string | null): void;
|
|
47
|
-
|
|
47
|
+
resolveNeedleTypeName(typescriptTypeName: string, baseTypes?: string[]): string | void;
|
|
48
48
|
end(filePath: string | null): void;
|
|
49
49
|
startNewType(filePath: string | null, typeName: string, baseType: string[], comments?: string[]): void | boolean;
|
|
50
50
|
endNewType(filePath: string | null, typeName: string): void;
|
package/dist/cli.js
CHANGED
|
@@ -8,6 +8,7 @@ var base_compiler_1 = require("./base-compiler");
|
|
|
8
8
|
var csharp_compiler_1 = require("./impl/csharp-compiler");
|
|
9
9
|
var blender_compiler_1 = require("./impl/blender-compiler");
|
|
10
10
|
var log_1 = require("./log");
|
|
11
|
+
var register_types_1 = require("./register-types");
|
|
11
12
|
var pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf-8"));
|
|
12
13
|
var rawArgs = process.argv.slice(2);
|
|
13
14
|
if (rawArgs.includes("--version") || rawArgs.includes("-v")) {
|
|
@@ -24,7 +25,8 @@ if (rawArgs.includes("--help") || rawArgs.includes("-h") || rawArgs.length < 3)
|
|
|
24
25
|
console.log(" input_files one or more .ts source files");
|
|
25
26
|
console.log("");
|
|
26
27
|
console.log("Options:");
|
|
27
|
-
console.log(" --types <path>
|
|
28
|
+
console.log(" --types <path> path to Types.json with extra type mappings");
|
|
29
|
+
console.log(" --register-types <bool> auto-generate register-types (default: true)");
|
|
28
30
|
console.log("");
|
|
29
31
|
console.log("Flags:");
|
|
30
32
|
console.log(" --silent, -s only output errors and CMD: lines");
|
|
@@ -38,11 +40,16 @@ if (rawArgs.includes("--help") || rawArgs.includes("-h") || rawArgs.length < 3)
|
|
|
38
40
|
// Extract flags from anywhere in the args
|
|
39
41
|
var typesPath;
|
|
40
42
|
var silent = false;
|
|
43
|
+
var registerTypes = true;
|
|
41
44
|
var positionalArgs = [];
|
|
42
45
|
for (var i = 0; i < rawArgs.length; i++) {
|
|
43
46
|
if (rawArgs[i] === "--types" && i + 1 < rawArgs.length) {
|
|
44
47
|
typesPath = rawArgs[++i];
|
|
45
48
|
}
|
|
49
|
+
else if (rawArgs[i] === "--register-types" && i + 1 < rawArgs.length) {
|
|
50
|
+
var val = rawArgs[++i].toLowerCase();
|
|
51
|
+
registerTypes = val !== "false" && val !== "0";
|
|
52
|
+
}
|
|
46
53
|
else if (rawArgs[i] === "--silent" || rawArgs[i] === "-s") {
|
|
47
54
|
silent = true;
|
|
48
55
|
}
|
|
@@ -98,6 +105,40 @@ for (var _i = 0, inputFiles_1 = inputFiles; _i < inputFiles_1.length; _i++) {
|
|
|
98
105
|
hasErrors = true;
|
|
99
106
|
}
|
|
100
107
|
}
|
|
108
|
+
// Auto-detect and write register-types files using needle.config.json
|
|
109
|
+
if (registerTypes && target === "blender") {
|
|
110
|
+
var codegenDir = void 0;
|
|
111
|
+
// Search upward from outputDir for needle.config.json
|
|
112
|
+
var searchDir = path.resolve(outputDir);
|
|
113
|
+
while (searchDir !== path.dirname(searchDir)) {
|
|
114
|
+
var configPath = path.join(searchDir, "needle.config.json");
|
|
115
|
+
if (fs.existsSync(configPath)) {
|
|
116
|
+
try {
|
|
117
|
+
var config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
118
|
+
if (config.codegenDirectory) {
|
|
119
|
+
codegenDir = path.resolve(searchDir, config.codegenDirectory);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (_e) { }
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
searchDir = path.dirname(searchDir);
|
|
126
|
+
}
|
|
127
|
+
if (codegenDir) {
|
|
128
|
+
var candidates = [
|
|
129
|
+
path.join(codegenDir, "register-types.js"),
|
|
130
|
+
path.join(codegenDir, "register-types.ts"),
|
|
131
|
+
path.join(codegenDir, "register_types.ts"),
|
|
132
|
+
path.join(codegenDir, "register_types.js"),
|
|
133
|
+
];
|
|
134
|
+
for (var _a = 0, candidates_1 = candidates; _a < candidates_1.length; _a++) {
|
|
135
|
+
var candidate = candidates_1[_a];
|
|
136
|
+
if (fs.existsSync(candidate)) {
|
|
137
|
+
(0, register_types_1.writeTypeRegistry)(writer.outputInfo, candidate);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
101
142
|
if (hasErrors) {
|
|
102
143
|
process.exit(1);
|
|
103
144
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Visibility } from "../base-compiler";
|
|
2
2
|
import { BaseWriter } from "../BaseWriter";
|
|
3
3
|
export declare class BlenderWriter extends BaseWriter {
|
|
4
|
-
|
|
4
|
+
resolveNeedleTypeName(typeName: string, comments?: string[]): string | void;
|
|
5
5
|
startNewType(filePath: string | null, typeName: string, baseTypes: string[], comments?: string[]): void | boolean;
|
|
6
6
|
endNewType(filePath: string | null, typeName: string): void;
|
|
7
7
|
writeMember(visibility: Visibility, name: string, isArray: boolean, type: string, initialValue?: string, comments?: string[]): void;
|
|
@@ -26,7 +26,7 @@ var BlenderWriter = /** @class */ (function (_super) {
|
|
|
26
26
|
function BlenderWriter() {
|
|
27
27
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
28
28
|
}
|
|
29
|
-
BlenderWriter.prototype.
|
|
29
|
+
BlenderWriter.prototype.resolveNeedleTypeName = function (typeName, comments) {
|
|
30
30
|
typeName = typeName.toLocaleLowerCase();
|
|
31
31
|
if (typeName.startsWith("three."))
|
|
32
32
|
typeName = typeName.substring("three.".length);
|
|
@@ -59,17 +59,23 @@ var BlenderWriter = /** @class */ (function (_super) {
|
|
|
59
59
|
case "eventlist":
|
|
60
60
|
return "evt";
|
|
61
61
|
case "behaviour":
|
|
62
|
-
case "animation": // Animation component ref
|
|
63
|
-
case "animator": // Animator component ref
|
|
64
|
-
case "camera":
|
|
65
|
-
case "light":
|
|
66
|
-
case "rigidbody":
|
|
67
|
-
case "renderer": // Renderer component ref
|
|
68
|
-
case "canvas": // Canvas component ref
|
|
69
|
-
case "charactercontroller": // CharacterController component ref
|
|
70
|
-
case "videoplayer": // VideoPlayer component ref
|
|
71
|
-
case "lookatconstraint": // LookAtConstraint component ref
|
|
72
62
|
return "comp";
|
|
63
|
+
case "animation": return "Animation";
|
|
64
|
+
case "animator": return "Animator";
|
|
65
|
+
case "camera": return "Camera";
|
|
66
|
+
case "light": return "Light";
|
|
67
|
+
case "rigidbody": return "Rigidbody";
|
|
68
|
+
case "renderer": return "Renderer";
|
|
69
|
+
case "canvas": return "Canvas";
|
|
70
|
+
case "videoplayer": return "VideoPlayer";
|
|
71
|
+
case "audiosource": return "AudioSource";
|
|
72
|
+
case "spherecollider": return "SphereCollider";
|
|
73
|
+
case "meshcollider": return "MeshCollider";
|
|
74
|
+
case "boxcollider": return "BoxCollider";
|
|
75
|
+
case "playabledirector": return "PlayableDirector";
|
|
76
|
+
case "dragcontrols": return "DragControls";
|
|
77
|
+
case "button": return "Button";
|
|
78
|
+
case "text": return "Text";
|
|
73
79
|
case "texture":
|
|
74
80
|
return "tex";
|
|
75
81
|
case "image":
|
|
@@ -3,7 +3,7 @@ import { BaseWriter } from "../BaseWriter";
|
|
|
3
3
|
export declare class CSharpWriter extends BaseWriter {
|
|
4
4
|
private externalTypes;
|
|
5
5
|
constructor(sink?: ISink, externalTypes?: Record<string, string>);
|
|
6
|
-
|
|
6
|
+
resolveNeedleTypeName(typescriptTypeName: string): string | void;
|
|
7
7
|
/** Tries to resolve a C# type name; returns undefined if the type is not known.
|
|
8
8
|
* Checks TYPE_MAP keys/values and the enum registry. */
|
|
9
9
|
resolveKnownCSharpTypeName(typeName: string): string | undefined;
|
|
@@ -129,7 +129,7 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
129
129
|
_this.externalTypes = externalTypes;
|
|
130
130
|
return _this;
|
|
131
131
|
}
|
|
132
|
-
CSharpWriter.prototype.
|
|
132
|
+
CSharpWriter.prototype.resolveNeedleTypeName = function (typescriptTypeName) {
|
|
133
133
|
var _a, _b, _c, _d, _e;
|
|
134
134
|
if (!typescriptTypeName)
|
|
135
135
|
return undefined;
|
|
@@ -191,7 +191,7 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
191
191
|
}
|
|
192
192
|
else if (baseTypes === null || baseTypes === void 0 ? void 0 : baseTypes.length) {
|
|
193
193
|
var first = baseTypes[0];
|
|
194
|
-
resolvedBase = (_a = this.
|
|
194
|
+
resolvedBase = (_a = this.resolveNeedleTypeName(first)) !== null && _a !== void 0 ? _a : "UnityEngine.MonoBehaviour";
|
|
195
195
|
}
|
|
196
196
|
// Abstract modifier
|
|
197
197
|
var isAbstract = comments === null || comments === void 0 ? void 0 : comments.includes("@abstract");
|
|
@@ -222,7 +222,7 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
222
222
|
var typeOverride = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@type "); });
|
|
223
223
|
var csharpType = typeOverride
|
|
224
224
|
? typeOverride.substring("@type ".length).trim()
|
|
225
|
-
: ((_a = this.
|
|
225
|
+
: ((_a = this.resolveNeedleTypeName(type)) !== null && _a !== void 0 ? _a : type);
|
|
226
226
|
// Determine visibility string
|
|
227
227
|
var vis = "public";
|
|
228
228
|
if (visibility === base_compiler_1.Visibility.Private || visibility === base_compiler_1.Visibility.Protected) {
|
|
@@ -245,7 +245,10 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
245
245
|
// Resolve assignment
|
|
246
246
|
var assignment = "";
|
|
247
247
|
if (initialValue !== undefined && initialValue !== null) {
|
|
248
|
-
if (initialValue === "
|
|
248
|
+
if (initialValue === "undefined") {
|
|
249
|
+
// skip — `undefined` is not valid in C#
|
|
250
|
+
}
|
|
251
|
+
else if (initialValue === "null") {
|
|
249
252
|
// keep null for reference types, skip for value types
|
|
250
253
|
}
|
|
251
254
|
else if (isArray && initialValue === "[]") {
|
|
@@ -387,7 +390,7 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
387
390
|
if (!match)
|
|
388
391
|
return expr;
|
|
389
392
|
var typeName = match[1], argsStr = match[2];
|
|
390
|
-
var csharpType = (_a = this.
|
|
393
|
+
var csharpType = (_a = this.resolveNeedleTypeName(typeName)) !== null && _a !== void 0 ? _a : typeName;
|
|
391
394
|
// Convert numeric literals to float
|
|
392
395
|
var csharpArgs = argsStr.replace(/(\d+\.?\d*)/g, function (n) {
|
|
393
396
|
return n.includes(".") ? "".concat(n, "f") : "".concat(n, "f");
|
|
@@ -4,7 +4,7 @@ export declare class ReactThreeFiberCompiler implements IWriter {
|
|
|
4
4
|
get outputInfo(): TypeSourceInformation;
|
|
5
5
|
private readonly _typeSourceInformation;
|
|
6
6
|
constructor();
|
|
7
|
-
|
|
7
|
+
resolveNeedleTypeName(typescriptTypeName: string): string | void;
|
|
8
8
|
begin(filePath: string): void;
|
|
9
9
|
end(filePath: string): void;
|
|
10
10
|
startNewType(filePath: string, typeName: string, baseType: string[], comments?: string[]): boolean | void;
|
|
@@ -12,7 +12,7 @@ var ReactThreeFiberCompiler = /** @class */ (function () {
|
|
|
12
12
|
enumerable: false,
|
|
13
13
|
configurable: true
|
|
14
14
|
});
|
|
15
|
-
ReactThreeFiberCompiler.prototype.
|
|
15
|
+
ReactThreeFiberCompiler.prototype.resolveNeedleTypeName = function (typescriptTypeName) {
|
|
16
16
|
return typescriptTypeName;
|
|
17
17
|
};
|
|
18
18
|
ReactThreeFiberCompiler.prototype.begin = function (filePath) {
|
package/package.json
CHANGED