@rpgjs/vite 5.0.0-beta.1 → 5.0.0-beta.11
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 +37 -0
- package/LICENSE +19 -0
- package/dist/compatibility-v4/flag-transform.d.ts +6 -0
- package/dist/compatibility-v4/index.d.ts +22 -0
- package/dist/compatibility-v4/load-config-file.d.ts +2 -0
- package/dist/compatibility-v4/require-transform.d.ts +2 -0
- package/dist/compatibility-v4/utils.d.ts +55 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7192 -8124
- package/dist/index.js.map +1 -1
- package/dist/rpgjs-plugin.d.ts +12 -0
- package/package.json +19 -11
- package/src/compatibility-v4/flag-transform.ts +61 -0
- package/src/compatibility-v4/index.ts +713 -0
- package/src/compatibility-v4/load-config-file.ts +38 -0
- package/src/compatibility-v4/require-transform.ts +67 -0
- package/src/compatibility-v4/utils.ts +170 -0
- package/src/index.ts +2 -1
- package/src/rpgjs-plugin.ts +16 -0
- package/tests/compatibility-v4.spec.ts +105 -0
- package/tests/fixtures/v4-game/rpg.toml +11 -0
- package/tests/fixtures/v4-game/src/modules/main/characters/assets/hero.svg +2 -0
- package/tests/fixtures/v4-game/src/modules/main/characters/hero.ts +2 -0
- package/tests/fixtures/v4-game/src/modules/main/client.ts +4 -0
- package/tests/fixtures/v4-game/src/modules/main/database/potion.ts +6 -0
- package/tests/fixtures/v4-game/src/modules/main/events/npc.ts +4 -0
- package/tests/fixtures/v4-game/src/modules/main/gui/menu.vue +2 -0
- package/tests/fixtures/v4-game/src/modules/main/maps/map.tmx +2 -0
- package/tests/fixtures/v4-game/src/modules/main/maps/map.ts +7 -0
- package/tests/fixtures/v4-game/src/modules/main/player.ts +4 -0
- package/tests/fixtures/v4-game/src/modules/main/scene-map.ts +4 -0
- package/tests/fixtures/v4-game/src/modules/main/server.ts +4 -0
- package/tests/fixtures/v4-game/src/modules/main/sounds/theme.ogg +2 -0
- package/tests/fixtures/v4-game/src/modules/main/sounds/theme.ts +5 -0
- package/tests/fixtures/v4-game/src/modules/main/sprite.ts +4 -0
- package/tests/fixtures/v4-game/src/modules/main/worlds/maps/world-map.tmx +6 -0
- package/tests/fixtures/v4-game/src/modules/main/worlds/world.world +13 -0
- package/tests/remove-imports-plugin.spec.ts +56 -0
- package/vite.config.ts +7 -1
- package/dist/index-Bc9qRSkO.js +0 -5496
- package/dist/index-Bc9qRSkO.js.map +0 -1
package/dist/rpgjs-plugin.d.ts
CHANGED
|
@@ -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;
|
|
@@ -24,5 +25,16 @@ export declare function rpgjs({ server, entryPoints }: RpgjsPluginOptions): (imp
|
|
|
24
25
|
configureServer(server: import('vite').ViteDevServer): Promise<void>;
|
|
25
26
|
buildStart(): void;
|
|
26
27
|
buildEnd(): void;
|
|
28
|
+
} | {
|
|
29
|
+
name: string;
|
|
30
|
+
config(): {
|
|
31
|
+
resolve: {
|
|
32
|
+
dedupe: string[];
|
|
33
|
+
};
|
|
34
|
+
optimizeDeps: {
|
|
35
|
+
exclude: string[];
|
|
36
|
+
include: string[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
27
39
|
})[];
|
|
28
40
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpgjs/vite",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.11",
|
|
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
|
-
"@
|
|
16
|
-
"@
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
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.4",
|
|
20
|
+
"@canvasengine/tiled": "2.0.0-rc.4",
|
|
21
|
+
"@hono/vite-dev-server": "^0.25.3",
|
|
22
|
+
"@iarna/toml": "^2.2.5",
|
|
23
|
+
"@rpgjs/server": "5.0.0-beta.11",
|
|
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
|
-
"typescript": "^
|
|
24
|
-
"vite": "^
|
|
25
|
-
"vite-plugin-dts": "^
|
|
26
|
-
"vitest": "^4.
|
|
27
|
-
"ws": "^8.
|
|
29
|
+
"typescript": "^6.0.3",
|
|
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
|
+
}
|