@colyseus/schema 4.0.6 → 4.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/schema",
3
- "version": "4.0.6",
3
+ "version": "4.0.8",
4
4
  "description": "Binary state serializer with delta encoding for games",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,15 +1,19 @@
1
1
  import * as fs from "fs";
2
2
  import * as path from "path";
3
- import { createRequire } from "module";
4
- // import { fileURLToPath } from "url";
5
3
 
6
4
  import { File } from "./types.js";
7
5
  import { parseFiles } from "./parser.js";
8
6
 
9
- // Create require relative to this file's location (for ESM compatibility)
10
- // const __filename = fileURLToPath(import.meta.url);
11
- // const __dirname = path.dirname(__filename);
12
- const require = createRequire(import.meta.url);
7
+ // Statically import all language generators (for bundling)
8
+ import { generate as csharp } from "./languages/csharp.js";
9
+ import { generate as cpp } from "./languages/cpp.js";
10
+ import { generate as haxe } from "./languages/haxe.js";
11
+ import { generate as ts } from "./languages/ts.js";
12
+ import { generate as js } from "./languages/js.js";
13
+ import { generate as java } from "./languages/java.js";
14
+ import { generate as lua } from "./languages/lua.js";
15
+
16
+ const generators: Record<string, Function> = { csharp, cpp, haxe, ts, js, java, lua, };
13
17
 
14
18
  export interface GenerateOptions {
15
19
  files: string[],
@@ -19,12 +23,9 @@ export interface GenerateOptions {
19
23
  }
20
24
 
21
25
  export function generate(targetId: string, options: GenerateOptions) {
22
- let generator: Function;
23
-
24
- try {
25
- generator = require('./languages/' + targetId + '.js').generate;
26
+ const generator = generators[targetId];
26
27
 
27
- } catch (e) {
28
+ if (!generator) {
28
29
  throw new Error("You must provide a valid generator as argument, such as: --csharp, --haxe or --cpp");
29
30
  }
30
31
 
@@ -23,7 +23,8 @@ declare global {
23
23
  }
24
24
 
25
25
  export interface IRef {
26
- [$changes]?: ChangeTree;
26
+ // FIXME: we only commented this out to allow mixing @colyseus/schema bundled types with server types in Cocos Creator
27
+ // [$changes]?: ChangeTree;
27
28
  [$refId]?: number;
28
29
  [$getByIndex]?: (index: number, isEncodeAll?: boolean) => any;
29
30
  [$deleteByIndex]?: (index: number) => void;