@needle-tools/needle-component-compiler 3.0.4 → 3.0.5-next.6bdc30f
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 +9 -1
- package/dist/cli.js +34 -3
- package/dist/impl/csharp-compiler.d.ts +3 -1
- package/dist/impl/csharp-compiler.js +19 -5
- package/package.json +1 -1
package/Changelog.md
CHANGED
|
@@ -4,8 +4,16 @@ 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.
|
|
7
|
+
## [3.0.5] - 2026-03-15
|
|
8
|
+
### Added
|
|
9
|
+
- `--types <path>` CLI flag to load external type mappings from a JSON file (e.g. Unity's `Types.json`)
|
|
10
|
+
- `@serializable()` decorator on getter/setter accessors now generates C# fields, with deduplication when both getter and setter are decorated
|
|
11
|
+
- Support for `@type`, `@nonSerialized`, and `@serializeField` comment directives on accessor properties
|
|
8
12
|
|
|
13
|
+
### Fixed
|
|
14
|
+
- Fix `npx` scoped package name resolution by changing `bin` to a string
|
|
15
|
+
|
|
16
|
+
## [3.0.3] - 2026-03-11
|
|
9
17
|
### Fixed
|
|
10
18
|
- Fix `Promise<T>` return types passing through as `Promise` instead of resolving to `void`
|
|
11
19
|
- Fix unknown/web-only types (e.g. user-defined interfaces) in method parameters passing through instead of becoming `object`
|
package/dist/cli.js
CHANGED
|
@@ -16,12 +16,15 @@ if (args.includes("--version") || args.includes("-v")) {
|
|
|
16
16
|
if (args.includes("--help") || args.includes("-h") || args.length < 3) {
|
|
17
17
|
console.log("needle-component-compiler v".concat(pkg.version));
|
|
18
18
|
console.log("");
|
|
19
|
-
console.log("Usage: needle-component-compiler <target> <output_dir> <input_files...>");
|
|
19
|
+
console.log("Usage: needle-component-compiler <target> <output_dir> [options] <input_files...>");
|
|
20
20
|
console.log("");
|
|
21
21
|
console.log(" target csharp or blender");
|
|
22
22
|
console.log(" output_dir directory for generated files");
|
|
23
23
|
console.log(" input_files one or more .ts source files");
|
|
24
24
|
console.log("");
|
|
25
|
+
console.log("Options:");
|
|
26
|
+
console.log(" --types <path> path to Types.json with extra type mappings");
|
|
27
|
+
console.log("");
|
|
25
28
|
console.log("Flags:");
|
|
26
29
|
console.log(" --version, -v print version");
|
|
27
30
|
console.log(" --help, -h print this help");
|
|
@@ -32,14 +35,42 @@ if (args.includes("--help") || args.includes("-h") || args.length < 3) {
|
|
|
32
35
|
}
|
|
33
36
|
var target = args[0];
|
|
34
37
|
var outputDir = args[1];
|
|
35
|
-
|
|
38
|
+
// Parse --types flag from remaining args
|
|
39
|
+
var typesPath;
|
|
40
|
+
var inputFiles = [];
|
|
41
|
+
var remaining = args.slice(2);
|
|
42
|
+
for (var i = 0; i < remaining.length; i++) {
|
|
43
|
+
if (remaining[i] === "--types" && i + 1 < remaining.length) {
|
|
44
|
+
typesPath = remaining[++i];
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
inputFiles.push(remaining[i]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
36
50
|
if (target !== "csharp" && target !== "blender") {
|
|
37
51
|
console.error("Error: unknown target \"".concat(target, "\". Use \"csharp\" or \"blender\"."));
|
|
38
52
|
process.exit(1);
|
|
39
53
|
}
|
|
54
|
+
// Load external types if provided
|
|
55
|
+
var externalTypes;
|
|
56
|
+
if (typesPath) {
|
|
57
|
+
if (!fs.existsSync(typesPath)) {
|
|
58
|
+
console.warn("Warning: types file not found: ".concat(typesPath));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
try {
|
|
62
|
+
externalTypes = JSON.parse(fs.readFileSync(typesPath, "utf-8"));
|
|
63
|
+
console.log("Loaded ".concat(Object.keys(externalTypes).length, " external type mappings from ").concat(typesPath));
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
console.error("Error reading types file: ".concat(e));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
40
71
|
console.log("needle-component-compiler v".concat(pkg.version));
|
|
41
72
|
var sink = new base_compiler_1.FileSink(outputDir);
|
|
42
|
-
var writer = target === "csharp" ? new csharp_compiler_1.CSharpWriter(sink) : new blender_compiler_1.BlenderWriter(sink);
|
|
73
|
+
var writer = target === "csharp" ? new csharp_compiler_1.CSharpWriter(sink, externalTypes) : new blender_compiler_1.BlenderWriter(sink);
|
|
43
74
|
var compiler = new Compiler_1.Compiler();
|
|
44
75
|
var hasErrors = false;
|
|
45
76
|
for (var _i = 0, inputFiles_1 = inputFiles; _i < inputFiles_1.length; _i++) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Argument, Visibility } from "../base-compiler";
|
|
1
|
+
import { Argument, ISink, Visibility } from "../base-compiler";
|
|
2
2
|
import { BaseWriter } from "../BaseWriter";
|
|
3
3
|
export declare class CSharpWriter extends BaseWriter {
|
|
4
|
+
private externalTypes;
|
|
5
|
+
constructor(sink?: ISink, externalTypes?: Record<string, string>);
|
|
4
6
|
resolveCSharpTypeName(typescriptTypeName: string): string | void;
|
|
5
7
|
/** Tries to resolve a C# type name; returns undefined if the type is not known.
|
|
6
8
|
* Checks TYPE_MAP keys/values and the enum registry. */
|
|
@@ -122,21 +122,23 @@ function isEditorType(typeName) {
|
|
|
122
122
|
}
|
|
123
123
|
var CSharpWriter = /** @class */ (function (_super) {
|
|
124
124
|
__extends(CSharpWriter, _super);
|
|
125
|
-
function CSharpWriter() {
|
|
126
|
-
|
|
125
|
+
function CSharpWriter(sink, externalTypes) {
|
|
126
|
+
var _this = _super.call(this, sink) || this;
|
|
127
|
+
_this.externalTypes = externalTypes;
|
|
128
|
+
return _this;
|
|
127
129
|
}
|
|
128
130
|
CSharpWriter.prototype.resolveCSharpTypeName = function (typescriptTypeName) {
|
|
129
|
-
var _a, _b;
|
|
131
|
+
var _a, _b, _c, _d, _e, _f;
|
|
130
132
|
if (!typescriptTypeName)
|
|
131
133
|
return undefined;
|
|
132
134
|
// Strip THREE. prefix for lookup fallback
|
|
133
135
|
var stripped = typescriptTypeName.startsWith("THREE.") ? typescriptTypeName.substring(6) : typescriptTypeName;
|
|
134
|
-
return (_b = (_a = TYPE_MAP[typescriptTypeName]) !== null && _a !== void 0 ? _a : TYPE_MAP[stripped]) !== null && _b !== void 0 ? _b : typescriptTypeName;
|
|
136
|
+
return (_f = (_d = (_b = (_a = TYPE_MAP[typescriptTypeName]) !== null && _a !== void 0 ? _a : TYPE_MAP[stripped]) !== null && _b !== void 0 ? _b : (_c = this.externalTypes) === null || _c === void 0 ? void 0 : _c[typescriptTypeName]) !== null && _d !== void 0 ? _d : (_e = this.externalTypes) === null || _e === void 0 ? void 0 : _e[stripped]) !== null && _f !== void 0 ? _f : typescriptTypeName;
|
|
135
137
|
};
|
|
136
138
|
/** Tries to resolve a C# type name; returns undefined if the type is not known.
|
|
137
139
|
* Checks TYPE_MAP keys/values and the enum registry. */
|
|
138
140
|
CSharpWriter.prototype.resolveKnownCSharpTypeName = function (typeName) {
|
|
139
|
-
var _a;
|
|
141
|
+
var _a, _b;
|
|
140
142
|
if (!typeName)
|
|
141
143
|
return undefined;
|
|
142
144
|
// Check if it's a TS type name in the map
|
|
@@ -147,6 +149,18 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
147
149
|
// Check if it's already a resolved C# type (e.g. "float", "UnityEngine.Vector3")
|
|
148
150
|
if (KNOWN_CSHARP_TYPES.has(typeName))
|
|
149
151
|
return typeName;
|
|
152
|
+
// Check external types (key lookup and reverse-lookup by value)
|
|
153
|
+
if (this.externalTypes) {
|
|
154
|
+
var ext = (_b = this.externalTypes[typeName]) !== null && _b !== void 0 ? _b : this.externalTypes[stripped];
|
|
155
|
+
if (ext)
|
|
156
|
+
return ext;
|
|
157
|
+
// Check if typeName is already a resolved external C# type
|
|
158
|
+
for (var _i = 0, _c = Object.values(this.externalTypes); _i < _c.length; _i++) {
|
|
159
|
+
var val = _c[_i];
|
|
160
|
+
if (val === typeName)
|
|
161
|
+
return typeName;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
150
164
|
// Check if it's a registered enum type
|
|
151
165
|
if (this._enumRegistry.has(typeName.toLowerCase()))
|
|
152
166
|
return typeName;
|
package/package.json
CHANGED