@mafly/bdev-cli 1.0.5 → 1.0.6
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/dist/commands/dev.js +36 -13
- package/package.json +1 -1
package/dist/commands/dev.js
CHANGED
|
@@ -100,8 +100,11 @@ export async function devCommand(dirArg, options = {}) {
|
|
|
100
100
|
logger.info(`Starting file watcher on: ${watchPaths.map((p) => path.relative(rootDir, p)).join(", ")}`);
|
|
101
101
|
logger.info("Press Ctrl+C to stop.");
|
|
102
102
|
let isRebuilding = false;
|
|
103
|
-
let
|
|
103
|
+
let queuedFilePath = null;
|
|
104
104
|
let rebuildTimeout = null;
|
|
105
|
+
let lastReloadTime = 0;
|
|
106
|
+
const RELOAD_COOLDOWN_MS = 1200;
|
|
107
|
+
const DEBOUNCE_MS = 350;
|
|
105
108
|
const ignoredPatterns = [
|
|
106
109
|
/(^|[/\\])\../, // dotfiles
|
|
107
110
|
/node_modules/,
|
|
@@ -119,10 +122,24 @@ export async function devCommand(dirArg, options = {}) {
|
|
|
119
122
|
persistent: true,
|
|
120
123
|
ignoreInitial: true,
|
|
121
124
|
});
|
|
125
|
+
const scheduleRebuild = (filePath) => {
|
|
126
|
+
queuedFilePath = filePath;
|
|
127
|
+
if (rebuildTimeout) {
|
|
128
|
+
clearTimeout(rebuildTimeout);
|
|
129
|
+
}
|
|
130
|
+
rebuildTimeout = setTimeout(() => {
|
|
131
|
+
rebuildTimeout = null;
|
|
132
|
+
if (!isRebuilding && queuedFilePath) {
|
|
133
|
+
const target = queuedFilePath;
|
|
134
|
+
queuedFilePath = null;
|
|
135
|
+
runRebuildCycle(target);
|
|
136
|
+
}
|
|
137
|
+
}, DEBOUNCE_MS);
|
|
138
|
+
};
|
|
122
139
|
const runRebuildCycle = async (triggerPath) => {
|
|
123
140
|
isRebuilding = true;
|
|
124
|
-
rebuildPending = false;
|
|
125
141
|
const rel = path.relative(rootDir, triggerPath);
|
|
142
|
+
const isManifestRelated = triggerPath.endsWith("manifest.json") || triggerPath.endsWith("package.json");
|
|
126
143
|
try {
|
|
127
144
|
// If resource_pack was added while dev server is running
|
|
128
145
|
if (!hasRp && fs.existsSync(rpDir)) {
|
|
@@ -155,9 +172,15 @@ export async function devCommand(dirArg, options = {}) {
|
|
|
155
172
|
const buildOk = await buildCommand(rootDir);
|
|
156
173
|
if (buildOk && hotReloadServer) {
|
|
157
174
|
if (hotReloadServer.clientCount > 0) {
|
|
158
|
-
// Buffer
|
|
159
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
175
|
+
// Buffer 200ms before reload command so Proton/Wine file cache flushes
|
|
176
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
177
|
+
// Enforce reload cooldown so rapid saves cannot crash Minecraft scripting engine
|
|
178
|
+
const elapsed = Date.now() - lastReloadTime;
|
|
179
|
+
if (elapsed < RELOAD_COOLDOWN_MS) {
|
|
180
|
+
await new Promise((resolve) => setTimeout(resolve, RELOAD_COOLDOWN_MS - elapsed));
|
|
181
|
+
}
|
|
160
182
|
hotReloadServer.reload();
|
|
183
|
+
lastReloadTime = Date.now();
|
|
161
184
|
logger.success("Sent /reload to Minecraft via WebSocket");
|
|
162
185
|
}
|
|
163
186
|
else {
|
|
@@ -165,14 +188,19 @@ export async function devCommand(dirArg, options = {}) {
|
|
|
165
188
|
}
|
|
166
189
|
}
|
|
167
190
|
}
|
|
191
|
+
if (isManifestRelated) {
|
|
192
|
+
logger.warn("Note: Minecraft /reload only reloads scripts. Re-enter world to apply manifest/package.json changes.");
|
|
193
|
+
}
|
|
168
194
|
}
|
|
169
195
|
catch (err) {
|
|
170
196
|
logger.error(`Error during rebuild: ${err.message}`);
|
|
171
197
|
}
|
|
172
198
|
finally {
|
|
173
199
|
isRebuilding = false;
|
|
174
|
-
if (
|
|
175
|
-
|
|
200
|
+
if (queuedFilePath) {
|
|
201
|
+
const nextTarget = queuedFilePath;
|
|
202
|
+
queuedFilePath = null;
|
|
203
|
+
scheduleRebuild(nextTarget);
|
|
176
204
|
}
|
|
177
205
|
}
|
|
178
206
|
};
|
|
@@ -185,15 +213,10 @@ export async function devCommand(dirArg, options = {}) {
|
|
|
185
213
|
const rel = path.relative(rootDir, filePath);
|
|
186
214
|
logger.info(`Change detected in ${rel}`);
|
|
187
215
|
if (isRebuilding) {
|
|
188
|
-
|
|
216
|
+
queuedFilePath = filePath;
|
|
189
217
|
return;
|
|
190
218
|
}
|
|
191
|
-
|
|
192
|
-
clearTimeout(rebuildTimeout);
|
|
193
|
-
}
|
|
194
|
-
rebuildTimeout = setTimeout(() => {
|
|
195
|
-
runRebuildCycle(filePath);
|
|
196
|
-
}, 300);
|
|
219
|
+
scheduleRebuild(filePath);
|
|
197
220
|
};
|
|
198
221
|
watcher.on("change", triggerRebuild);
|
|
199
222
|
watcher.on("add", triggerRebuild);
|