@series-inc/stowkit-cli 0.6.22 → 0.6.34
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/server.js +25 -2
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -55,6 +55,8 @@ function broadcast(msg) {
|
|
|
55
55
|
ws.send(data);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
/** Tracks the most recent fire-and-forget processing promise so wait=true can join it. */
|
|
59
|
+
let activeProcessingTask = null;
|
|
58
60
|
/**
|
|
59
61
|
* Single entry point for all processing orchestration.
|
|
60
62
|
* - Skips materials (they don't need processing)
|
|
@@ -136,10 +138,15 @@ function queueProcessing(opts = {}) {
|
|
|
136
138
|
}
|
|
137
139
|
broadcast({ type: 'processing-complete' });
|
|
138
140
|
})();
|
|
141
|
+
// Track the active task so wait=true callers can join in-flight processing
|
|
142
|
+
activeProcessingTask = task.finally(() => {
|
|
143
|
+
if (activeProcessingTask === task)
|
|
144
|
+
activeProcessingTask = null;
|
|
145
|
+
});
|
|
139
146
|
if (opts.await)
|
|
140
|
-
return
|
|
147
|
+
return activeProcessingTask;
|
|
141
148
|
// Fire-and-forget: log errors but don't block caller
|
|
142
|
-
|
|
149
|
+
activeProcessingTask.catch(err => console.error('[server] queueProcessing error:', err));
|
|
143
150
|
return Promise.resolve();
|
|
144
151
|
}
|
|
145
152
|
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
@@ -1022,11 +1029,27 @@ async function handleRequest(req, res, staticApps) {
|
|
|
1022
1029
|
return;
|
|
1023
1030
|
}
|
|
1024
1031
|
// POST /api/build — build .stow packs
|
|
1032
|
+
// Pass ?wait=true or { "wait": true } to process all pending assets before packing.
|
|
1025
1033
|
if (pathname === '/api/build' && req.method === 'POST') {
|
|
1026
1034
|
if (!projectConfig) {
|
|
1027
1035
|
json(res, { error: 'No project open' }, 400);
|
|
1028
1036
|
return;
|
|
1029
1037
|
}
|
|
1038
|
+
// If wait=true, ensure all asset processing completes before building.
|
|
1039
|
+
// First join any in-flight processing, then start a new run for any remaining pending assets.
|
|
1040
|
+
const body = await readBody(req).then(b => b ? JSON.parse(b) : {}).catch(() => ({}));
|
|
1041
|
+
const wait = body.wait === true || url.searchParams.get('wait') === 'true';
|
|
1042
|
+
if (wait) {
|
|
1043
|
+
// Await any already-running background processing
|
|
1044
|
+
if (activeProcessingTask) {
|
|
1045
|
+
await activeProcessingTask;
|
|
1046
|
+
}
|
|
1047
|
+
// Pick up any assets that became pending after the previous run
|
|
1048
|
+
const pending = assets.filter(a => a.status === 'pending' || a.status === 'processing');
|
|
1049
|
+
if (pending.length > 0) {
|
|
1050
|
+
await queueProcessing({ await: true });
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1030
1053
|
const assetsById = new Map(assets.map(a => [a.id, a]));
|
|
1031
1054
|
const packs = projectConfig.config.packs ?? [{ name: 'default' }];
|
|
1032
1055
|
const cdnDir = path.resolve(projectConfig.projectDir, projectConfig.config.cdnAssetsPath ?? 'public/cdn-assets');
|