@tokenoftrust/storefront-runner 2.4.28 → 2.4.29
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.29",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
|
|
6
6
|
"packageManager": "pnpm@11.9.0",
|
|
@@ -305,3 +305,75 @@ export function describeOwner(topology, urlPath) {
|
|
|
305
305
|
dir: spaceDir(space) || ".",
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Route changed workspace files to the repository that ships them. Paths are relative to the
|
|
311
|
+
* root checkout (a space's files as `spaces/<id>/...`). Each file lands in its owning space's
|
|
312
|
+
* group; a root file whose URL a mounted space owns is ALSO named as misrouted (it ships with the
|
|
313
|
+
* root and still never reaches a visitor); a file under `spaces/` naming no declared space is
|
|
314
|
+
* unowned. Pure.
|
|
315
|
+
* @param {Topology} topology
|
|
316
|
+
* @param {string[]} files
|
|
317
|
+
* @returns {{ groups: Array<{ space: TopologySpace, files: string[] }>,
|
|
318
|
+
* misrouted: Array<{ file: string, owner: TopologySpace }>, unowned: string[] }}
|
|
319
|
+
*/
|
|
320
|
+
export function routeWorkspaceChanges(topology, files) {
|
|
321
|
+
const root = rootSpace(topology);
|
|
322
|
+
/** @type {Map<string, string[]>} */
|
|
323
|
+
const byId = new Map(topology.spaces.map((space) => [space.id, []]));
|
|
324
|
+
const misrouted = [];
|
|
325
|
+
const unowned = [];
|
|
326
|
+
for (const file of files) {
|
|
327
|
+
const owner = spaceForWorkspaceFile(topology, file);
|
|
328
|
+
if (!owner) { unowned.push(file); continue; }
|
|
329
|
+
/** @type {string[]} */ (byId.get(owner.space.id)).push(file);
|
|
330
|
+
if (owner.space.mount === "/") {
|
|
331
|
+
const urlPath = rootFileUrlPath(root, file);
|
|
332
|
+
const served = urlPath ? owningSpace(topology, urlPath) : null;
|
|
333
|
+
if (served?.space && served.space.mount !== "/") misrouted.push({ file, owner: served.space });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return {
|
|
337
|
+
groups: topology.spaces.map((space) => ({ space, files: /** @type {string[]} */ (byId.get(space.id)) })),
|
|
338
|
+
misrouted,
|
|
339
|
+
unowned,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Parse `git status --porcelain=v1 -z` into changed paths (a rename yields its new path). Pure.
|
|
345
|
+
* @param {string} out
|
|
346
|
+
* @returns {string[]}
|
|
347
|
+
*/
|
|
348
|
+
export function parsePorcelainZ(out) {
|
|
349
|
+
const parts = String(out).split("\0");
|
|
350
|
+
const paths = [];
|
|
351
|
+
for (let i = 0; i < parts.length; i++) {
|
|
352
|
+
const entry = parts[i];
|
|
353
|
+
if (!entry || entry.length < 4) continue;
|
|
354
|
+
const status = entry.slice(0, 2);
|
|
355
|
+
paths.push(entry.slice(3));
|
|
356
|
+
if (status[0] === "R" || status[0] === "C") i++; // the next field is the rename's source
|
|
357
|
+
}
|
|
358
|
+
return paths;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Every changed file in a workspace, relative to the root checkout: the root repository's own
|
|
363
|
+
* changes plus each cloned space's (`spaces/<id>/...`). `git(dir, args)` runs git in `dir`.
|
|
364
|
+
* @param {string} workspace
|
|
365
|
+
* @param {Topology} topology
|
|
366
|
+
* @param {(dir: string, args: string[]) => string} git
|
|
367
|
+
* @returns {string[]}
|
|
368
|
+
*/
|
|
369
|
+
export function workspaceChangedFiles(workspace, topology, git) {
|
|
370
|
+
const files = parsePorcelainZ(git(workspace, ["status", "--porcelain=v1", "-z", "--untracked-files=all"]));
|
|
371
|
+
for (const space of mountedSpaces(topology)) {
|
|
372
|
+
const dir = join(workspace, spaceDir(space));
|
|
373
|
+
if (!existsSync(join(dir, ".git"))) continue;
|
|
374
|
+
for (const file of parsePorcelainZ(git(dir, ["status", "--porcelain=v1", "-z", "--untracked-files=all"]))) {
|
|
375
|
+
files.push(`${spaceDir(space)}/${file}`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return files;
|
|
379
|
+
}
|