@mafly/bdev-cli 1.0.2 → 1.0.3

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.
@@ -28,19 +28,55 @@ export function findMojangPath(customPath, projectDir = process.cwd()) {
28
28
  }
29
29
  const platform = os.platform();
30
30
  if (platform === "win32") {
31
+ const appData = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
31
32
  const localAppData = process.env.LOCALAPPDATA ||
32
33
  path.join(os.homedir(), "AppData", "Local");
34
+ // Modern Windows GDK Bedrock (Shared folder contains dev packs)
35
+ const gdkShared = path.join(appData, "Minecraft Bedrock", "Users", "Shared", "games", "com.mojang");
36
+ if (fs.existsSync(gdkShared)) {
37
+ return makeLocations(gdkShared, "retail");
38
+ }
39
+ const gdkPreviewShared = path.join(appData, "Minecraft Bedrock Preview", "Users", "Shared", "games", "com.mojang");
40
+ if (fs.existsSync(gdkPreviewShared)) {
41
+ return makeLocations(gdkPreviewShared, "preview");
42
+ }
43
+ // Classic UWP Retail
33
44
  const retail = path.join(localAppData, "Packages", "Microsoft.MinecraftUWP_8wekyb3d8bbwe", "LocalState", "games", "com.mojang");
34
45
  if (fs.existsSync(retail)) {
35
46
  return makeLocations(retail, "retail");
36
47
  }
48
+ // Classic UWP Preview
37
49
  const preview = path.join(localAppData, "Packages", "Microsoft.MinecraftWindowsBeta_8wekyb3d8bbwe", "LocalState", "games", "com.mojang");
38
50
  if (fs.existsSync(preview)) {
39
51
  return makeLocations(preview, "preview");
40
52
  }
41
53
  }
42
- // Check WSL
54
+ // Check Linux / Bedrock-on-linux / Proton / WSL
43
55
  if (platform === "linux") {
56
+ // 1. Bedrock-on-Linux (Proton / Wine)
57
+ const bolBase = path.join(os.homedir(), ".local", "share", "bedrock-on-linux");
58
+ if (fs.existsSync(bolBase)) {
59
+ const profilesDir = path.join(bolBase, "profiles");
60
+ if (fs.existsSync(profilesDir)) {
61
+ try {
62
+ const profiles = fs.readdirSync(profilesDir);
63
+ for (const prof of profiles) {
64
+ const sharedPfx = path.join(profilesDir, prof, "compatdata", "pfx", "drive_c", "users", "steamuser", "AppData", "Roaming", "Minecraft Bedrock", "Users", "Shared", "games", "com.mojang");
65
+ if (fs.existsSync(sharedPfx)) {
66
+ return makeLocations(sharedPfx, "linux");
67
+ }
68
+ }
69
+ }
70
+ catch {
71
+ // ignore profile read errors
72
+ }
73
+ }
74
+ const defaultShared = path.join(bolBase, "compatdata", "pfx", "drive_c", "users", "steamuser", "AppData", "Roaming", "Minecraft Bedrock", "Users", "Shared", "games", "com.mojang");
75
+ if (fs.existsSync(defaultShared)) {
76
+ return makeLocations(defaultShared, "linux");
77
+ }
78
+ }
79
+ // 2. Check WSL
44
80
  try {
45
81
  const isWsl = Boolean(process.env.WSL_DISTRO_NAME) ||
46
82
  fs.readFileSync("/proc/version", "utf-8").toLowerCase().includes("microsoft");
@@ -49,14 +85,14 @@ export function findMojangPath(customPath, projectDir = process.cwd()) {
49
85
  if (fs.existsSync(mntCUsers)) {
50
86
  const users = fs.readdirSync(mntCUsers);
51
87
  for (const u of users) {
88
+ const gdk = path.join(mntCUsers, u, "AppData", "Roaming", "Minecraft Bedrock", "Users", "Shared", "games", "com.mojang");
89
+ if (fs.existsSync(gdk)) {
90
+ return makeLocations(gdk, "wsl");
91
+ }
52
92
  const retail = path.join(mntCUsers, u, "AppData", "Local", "Packages", "Microsoft.MinecraftUWP_8wekyb3d8bbwe", "LocalState", "games", "com.mojang");
53
93
  if (fs.existsSync(retail)) {
54
94
  return makeLocations(retail, "wsl");
55
95
  }
56
- const preview = path.join(mntCUsers, u, "AppData", "Local", "Packages", "Microsoft.MinecraftWindowsBeta_8wekyb3d8bbwe", "LocalState", "games", "com.mojang");
57
- if (fs.existsSync(preview)) {
58
- return makeLocations(preview, "wsl");
59
- }
60
96
  }
61
97
  }
62
98
  }
@@ -64,7 +100,7 @@ export function findMojangPath(customPath, projectDir = process.cwd()) {
64
100
  catch {
65
101
  // Ignore read errors
66
102
  }
67
- // Native Linux launcher locations
103
+ // 3. Native Linux mcpelauncher locations
68
104
  const linuxMcpelauncherPaths = [
69
105
  path.join(os.homedir(), ".var", "app", "io.mrarm.mcpelauncher", "data", "mcpelauncher", "games", "com.mojang"),
70
106
  path.join(os.homedir(), ".local", "share", "mcpelauncher", "games", "com.mojang"),
@@ -78,10 +114,22 @@ export function findMojangPath(customPath, projectDir = process.cwd()) {
78
114
  return null;
79
115
  }
80
116
  function makeLocations(root, type) {
117
+ // If pointing to a specific user XUID directory in Bedrock GDK (e.g. Users/<XUID>/games/com.mojang),
118
+ // Bedrock GDK only scans packs from Users/Shared/games/com.mojang.
119
+ let packsRoot = root;
120
+ try {
121
+ const sharedCandidate = path.resolve(root, "..", "..", "..", "Shared", "games", "com.mojang");
122
+ if (fs.existsSync(sharedCandidate)) {
123
+ packsRoot = sharedCandidate;
124
+ }
125
+ }
126
+ catch {
127
+ // Ignore resolution errors
128
+ }
81
129
  return {
82
- root,
83
- devBehaviorPacks: path.join(root, "development_behavior_packs"),
84
- devResourcePacks: path.join(root, "development_resource_packs"),
130
+ root: packsRoot,
131
+ devBehaviorPacks: path.join(packsRoot, "development_behavior_packs"),
132
+ devResourcePacks: path.join(packsRoot, "development_resource_packs"),
85
133
  type,
86
134
  };
87
135
  }
@@ -35,12 +35,19 @@ export class BedrockHotReloadServer {
35
35
  server.on("connection", (socket) => {
36
36
  this.clients.add(socket);
37
37
  logger.success(pc.green("Minecraft connected to WebSocket hot reload!"));
38
- // Delay welcome message 500ms so Bedrock completes internal handshake
39
- setTimeout(() => {
40
- if (socket.readyState === WebSocket.OPEN) {
41
- this.sendCommandToSocket(socket, 'tellraw @a {"rawtext":[{"text":"§a[bdev] Connected to hot reload server!"}]}');
42
- }
43
- }, 500);
38
+ // Bedrock expects an event subscription to establish connection cleanly
39
+ const subscribePayload = {
40
+ header: {
41
+ version: 1,
42
+ requestId: uuidv4(),
43
+ messageType: "commandRequest",
44
+ messagePurpose: "subscribe",
45
+ },
46
+ body: {
47
+ eventName: "PlayerMessage",
48
+ },
49
+ };
50
+ socket.send(JSON.stringify(subscribePayload));
44
51
  socket.on("message", (data) => {
45
52
  try {
46
53
  const res = JSON.parse(data.toString());
@@ -69,7 +76,8 @@ export class BedrockHotReloadServer {
69
76
  }
70
77
  }
71
78
  sendCommandToSocket(socket, commandLine) {
72
- const formatted = commandLine.startsWith("/") ? commandLine : `/${commandLine}`;
79
+ // Bedrock commandLine must NOT have a leading slash
80
+ const cleanCmd = commandLine.startsWith("/") ? commandLine.slice(1) : commandLine;
73
81
  const payload = {
74
82
  header: {
75
83
  version: 1,
@@ -79,7 +87,7 @@ export class BedrockHotReloadServer {
79
87
  },
80
88
  body: {
81
89
  version: 1,
82
- commandLine: formatted,
90
+ commandLine: cleanCmd,
83
91
  origin: {
84
92
  type: "player",
85
93
  },
@@ -91,9 +99,7 @@ export class BedrockHotReloadServer {
91
99
  if (this.clients.size === 0) {
92
100
  return;
93
101
  }
94
- // Notify in game chat and execute reload command
95
- this.sendCommand('tellraw @a {"rawtext":[{"text":"§e[bdev] Reloading scripts..."}]}');
96
- this.sendCommand("/reload");
102
+ this.sendCommand("reload");
97
103
  }
98
104
  get clientCount() {
99
105
  return this.clients.size;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mafly/bdev-cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Modern CLI tool for Minecraft Bedrock Edition Addon development",
5
5
  "author": "Mafly",
6
6
  "license": "MIT",