@rpgjs/vite 5.0.0-beta.8 → 5.0.0-beta.9

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/compatibility-v4/flag-transform.d.ts +6 -0
  3. package/dist/compatibility-v4/index.d.ts +22 -0
  4. package/dist/compatibility-v4/load-config-file.d.ts +2 -0
  5. package/dist/compatibility-v4/require-transform.d.ts +2 -0
  6. package/dist/compatibility-v4/utils.d.ts +55 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +1329 -164
  9. package/dist/index.js.map +1 -1
  10. package/dist/rpgjs-plugin.d.ts +1 -0
  11. package/package.json +17 -9
  12. package/src/compatibility-v4/flag-transform.ts +61 -0
  13. package/src/compatibility-v4/index.ts +713 -0
  14. package/src/compatibility-v4/load-config-file.ts +38 -0
  15. package/src/compatibility-v4/require-transform.ts +67 -0
  16. package/src/compatibility-v4/utils.ts +170 -0
  17. package/src/index.ts +2 -1
  18. package/tests/compatibility-v4.spec.ts +105 -0
  19. package/tests/fixtures/v4-game/rpg.toml +11 -0
  20. package/tests/fixtures/v4-game/src/modules/main/characters/assets/hero.svg +2 -0
  21. package/tests/fixtures/v4-game/src/modules/main/characters/hero.ts +2 -0
  22. package/tests/fixtures/v4-game/src/modules/main/client.ts +4 -0
  23. package/tests/fixtures/v4-game/src/modules/main/database/potion.ts +6 -0
  24. package/tests/fixtures/v4-game/src/modules/main/events/npc.ts +4 -0
  25. package/tests/fixtures/v4-game/src/modules/main/gui/menu.vue +2 -0
  26. package/tests/fixtures/v4-game/src/modules/main/maps/map.tmx +2 -0
  27. package/tests/fixtures/v4-game/src/modules/main/maps/map.ts +7 -0
  28. package/tests/fixtures/v4-game/src/modules/main/player.ts +4 -0
  29. package/tests/fixtures/v4-game/src/modules/main/scene-map.ts +4 -0
  30. package/tests/fixtures/v4-game/src/modules/main/server.ts +4 -0
  31. package/tests/fixtures/v4-game/src/modules/main/sounds/theme.ogg +2 -0
  32. package/tests/fixtures/v4-game/src/modules/main/sounds/theme.ts +5 -0
  33. package/tests/fixtures/v4-game/src/modules/main/sprite.ts +4 -0
  34. package/tests/fixtures/v4-game/src/modules/main/worlds/maps/world-map.tmx +6 -0
  35. package/tests/fixtures/v4-game/src/modules/main/worlds/world.world +13 -0
  36. package/vite.config.ts +7 -1
@@ -12,6 +12,7 @@ interface RpgjsPluginOptions {
12
12
  }
13
13
  export declare function rpgjs({ server, entryPoints }: RpgjsPluginOptions): (import('vite').Plugin<any> | {
14
14
  name: string;
15
+ config(config: any, { command }: any): void;
15
16
  transform(code: string, id: string): {
16
17
  code: string;
17
18
  map: null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpgjs/vite",
3
- "version": "5.0.0-beta.8",
3
+ "version": "5.0.0-beta.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "keywords": [],
@@ -12,21 +12,29 @@
12
12
  "access": "public"
13
13
  },
14
14
  "dependencies": {
15
- "@canvasengine/tiled": "2.0.0-beta.58",
16
- "@canvasengine/compiler": "2.0.0-beta.58",
15
+ "@babel/generator": "^7.29.1",
16
+ "@babel/parser": "^7.29.3",
17
+ "@babel/traverse": "^7.29.0",
18
+ "@babel/types": "^7.29.0",
19
+ "@canvasengine/compiler": "2.0.0-rc.1",
20
+ "@canvasengine/tiled": "2.0.0-rc.1",
17
21
  "@hono/vite-dev-server": "^0.25.3",
18
- "@rpgjs/server": "5.0.0-beta.8",
19
- "@types/node": "^25.6.0",
22
+ "@iarna/toml": "^2.2.5",
23
+ "@rpgjs/server": "5.0.0-beta.9",
24
+ "@types/node": "^25.8.0",
20
25
  "acorn": "^8.16.0",
21
26
  "acorn-walk": "^8.3.5",
27
+ "image-size": "^2.0.2",
22
28
  "magic-string": "^0.30.21",
23
29
  "typescript": "^6.0.3",
24
- "vite": "^8.0.10",
25
- "vite-plugin-dts": "^4.5.4",
26
- "vitest": "^4.1.5",
27
- "ws": "^8.20.0"
30
+ "vite": "^8.0.13",
31
+ "vite-plugin-dts": "^5.0.0",
32
+ "vitest": "^4.1.6",
33
+ "ws": "^8.20.1"
28
34
  },
29
35
  "devDependencies": {
36
+ "@types/babel__generator": "^7.27.0",
37
+ "@types/babel__traverse": "^7.28.0",
30
38
  "@types/ws": "^8.18.1"
31
39
  },
32
40
  "scripts": {
@@ -0,0 +1,61 @@
1
+ import type { Plugin } from "vite";
2
+
3
+ export function flagTransform(options: { side?: "client" | "server"; mode?: string; type?: "rpg" | "mmorpg" } = {}): Plugin {
4
+ function getImportSide(importer?: string): "client" | "server" {
5
+ if (importer?.includes("?server") || importer?.includes("server-entry")) return "server";
6
+ if (importer?.includes("?client") || importer?.includes("client-entry") || importer?.includes("standalone-entry")) return "client";
7
+ return options.side ?? "client";
8
+ }
9
+
10
+ function hasFlag(id: string, flag: string) {
11
+ return id.endsWith(`?${flag}`) || id.includes(`?${flag}&`);
12
+ }
13
+
14
+ function getSideFromId(id: string): "client" | "server" {
15
+ const side = id.match(/[?&]side=(client|server)/)?.[1];
16
+ return side === "server" ? "server" : "client";
17
+ }
18
+
19
+ return {
20
+ name: "rpgjs-v4-flag-transform",
21
+ async resolveId(this: any, source: string, importer?: string, resolveOptions?: any) {
22
+ const flags = ["client!", "server!", "rpg!", "mmorpg!", "production!", "development!"];
23
+ for (const flag of flags) {
24
+ if (!source.startsWith(flag)) continue;
25
+ const id = source.slice(flag.length);
26
+ const resolution = await this.resolve(id, importer, {
27
+ skipSelf: true,
28
+ ...resolveOptions,
29
+ });
30
+ if (!resolution) return null;
31
+ const importSide = getImportSide(importer);
32
+ return {
33
+ ...resolution,
34
+ id: `${resolution.id}?${flag.slice(0, -1)}&side=${importSide}`,
35
+ };
36
+ }
37
+ return null;
38
+ },
39
+ transform(code, id) {
40
+ const { mode = "development", type = "mmorpg" } = options;
41
+ const side = getSideFromId(id);
42
+
43
+ if (mode === "test") return { code, map: null };
44
+
45
+ if (hasFlag(id, side === "client" ? "server" : "client") && type !== "rpg") {
46
+ return { code: "export default null;", map: null };
47
+ }
48
+
49
+ if (
50
+ (hasFlag(id, "production") && mode !== "production") ||
51
+ (hasFlag(id, "development") && mode !== "development") ||
52
+ (hasFlag(id, "rpg") && type !== "rpg") ||
53
+ (hasFlag(id, "mmorpg") && type !== "mmorpg")
54
+ ) {
55
+ return { code: "export default null;", map: null };
56
+ }
57
+
58
+ return { code, map: null };
59
+ },
60
+ };
61
+ }