@colyseus/schema 4.0.27 → 4.0.29
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/README.md +23 -0
- package/build/codegen/cli.cjs +13 -5
- package/build/codegen/cli.cjs.map +1 -1
- package/build/index.cjs.map +1 -1
- package/build/index.mjs.map +1 -1
- package/build/types/custom/MapSchema.d.ts +1 -1
- package/package.json +9 -3
- package/src/codegen/cli.ts +4 -4
- package/src/codegen/parser.ts +10 -1
- package/src/types/custom/MapSchema.ts +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,26 @@ export class MyState extends Schema {
|
|
|
40
40
|
}
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
## TypeScript support
|
|
44
|
+
|
|
45
|
+
Compatible with TypeScript **5.x**, **6.x** and **7.x**.
|
|
46
|
+
|
|
47
|
+
The `@type()` decorator uses legacy decorators — enable them in your `tsconfig.json`:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"compilerOptions": {
|
|
52
|
+
"experimentalDecorators": true,
|
|
53
|
+
"useDefineForClassFields": false
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
> **Note:** `schema-codegen` requires TypeScript 5.x or 6.x installed in your
|
|
59
|
+
> project — TypeScript 7's native compiler no longer ships the JS compiler API
|
|
60
|
+
> that codegen uses to parse your schema files. The runtime and your build are
|
|
61
|
+
> not affected by this.
|
|
62
|
+
|
|
43
63
|
## Supported types
|
|
44
64
|
|
|
45
65
|
### Primitive Types
|
|
@@ -276,6 +296,9 @@ up-to-date version of the schema definitions.
|
|
|
276
296
|
|
|
277
297
|
You can generate the client-side schema files based on the TypeScript schema definitions automatically.
|
|
278
298
|
|
|
299
|
+
> `schema-codegen` requires TypeScript 5.x or 6.x installed in your project
|
|
300
|
+
> (TypeScript 7+ no longer ships the JS compiler API it uses for parsing).
|
|
301
|
+
|
|
279
302
|
```
|
|
280
303
|
# C#/Unity
|
|
281
304
|
schema-codegen ./schemas/State.ts --output ./unity-project/ --csharp
|
package/build/codegen/cli.cjs
CHANGED
|
@@ -472,6 +472,11 @@ function inspectNode(node, context, decoratorName) {
|
|
|
472
472
|
}
|
|
473
473
|
let parsedFiles;
|
|
474
474
|
function parseFiles(fileNames, decoratorName = "type", context = new Context()) {
|
|
475
|
+
if (typeof ts__namespace.createSourceFile !== "function") {
|
|
476
|
+
// typescript@7+ (native) no longer ships the JS compiler API
|
|
477
|
+
throw new Error(`schema-codegen requires the TypeScript compiler API, which the installed "typescript@${ts__namespace.version}" package does not provide.\n` +
|
|
478
|
+
`TypeScript 7+ no longer ships the JS compiler API — install typescript 5.x or 6.x (e.g. \`npm install --save-dev typescript@6\`) to use schema-codegen.`);
|
|
479
|
+
}
|
|
475
480
|
/**
|
|
476
481
|
* Re-set globalContext for each test case
|
|
477
482
|
*/
|
|
@@ -508,7 +513,10 @@ function parseFiles(fileNames, decoratorName = "type", context = new Context())
|
|
|
508
513
|
break;
|
|
509
514
|
}
|
|
510
515
|
catch (e) {
|
|
511
|
-
//
|
|
516
|
+
// only swallow fs errors (ENOENT/EISDIR) while probing alternatives
|
|
517
|
+
if (!e?.code) {
|
|
518
|
+
throw e;
|
|
519
|
+
}
|
|
512
520
|
}
|
|
513
521
|
}
|
|
514
522
|
if (sourceFile) {
|
|
@@ -2286,7 +2294,7 @@ function recursiveFiles(dir) {
|
|
|
2286
2294
|
return collect;
|
|
2287
2295
|
}
|
|
2288
2296
|
|
|
2289
|
-
function displayHelp() {
|
|
2297
|
+
function displayHelp(exitCode = 0) {
|
|
2290
2298
|
console.log(`\nschema-codegen [path/to/Schema.ts]
|
|
2291
2299
|
|
|
2292
2300
|
Usage (C#/Unity)
|
|
@@ -2305,7 +2313,7 @@ ${Object.
|
|
|
2305
2313
|
Optional:
|
|
2306
2314
|
--namespace: generate namespace on output code
|
|
2307
2315
|
--decorator: custom name for @type decorator to scan for`);
|
|
2308
|
-
process.exit();
|
|
2316
|
+
process.exit(exitCode);
|
|
2309
2317
|
}
|
|
2310
2318
|
const args = argv(process.argv.slice(2));
|
|
2311
2319
|
if (args.help) {
|
|
@@ -2319,7 +2327,7 @@ for (let target in generators) {
|
|
|
2319
2327
|
}
|
|
2320
2328
|
if (!args.output) {
|
|
2321
2329
|
console.error("You must provide a valid --output directory.");
|
|
2322
|
-
displayHelp();
|
|
2330
|
+
displayHelp(1);
|
|
2323
2331
|
}
|
|
2324
2332
|
try {
|
|
2325
2333
|
args.files = args._;
|
|
@@ -2334,6 +2342,6 @@ try {
|
|
|
2334
2342
|
catch (e) {
|
|
2335
2343
|
console.error(e.message);
|
|
2336
2344
|
console.error(e.stack);
|
|
2337
|
-
displayHelp();
|
|
2345
|
+
displayHelp(1);
|
|
2338
2346
|
}
|
|
2339
2347
|
//# sourceMappingURL=cli.cjs.map
|