@jskit-ai/jskit-catalog 0.2.93 → 0.2.95
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/catalog/packages.json +271 -266
- package/package.json +1 -1
- package/scripts/navigation.mjs +32 -6
package/package.json
CHANGED
package/scripts/navigation.mjs
CHANGED
|
@@ -301,6 +301,8 @@ function normalisePath(value) {
|
|
|
301
301
|
return trimmed === "/" ? "/" : trimmed;
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
+
const PARAM_SEGMENT = /^:[\w$]+$/u;
|
|
305
|
+
|
|
304
306
|
// Whether a literal path is one a page's route pattern serves: segment by segment, each `:param` stands for exactly
|
|
305
307
|
// one non-empty segment and every other segment is the same text. /modules/:moduleKey serves /modules/incidents, not
|
|
306
308
|
// /modules or /modules/incidents/open; a catch-all (:rest*) matches only its own text.
|
|
@@ -308,7 +310,20 @@ function patternServes(pattern, literal) {
|
|
|
308
310
|
const patternSegments = pattern.split("/");
|
|
309
311
|
const literalSegments = literal.split("/");
|
|
310
312
|
return patternSegments.length === literalSegments.length && patternSegments.every((segment, index) =>
|
|
311
|
-
segment === literalSegments[index] || (
|
|
313
|
+
segment === literalSegments[index] || (PARAM_SEGMENT.test(segment) && literalSegments[index] !== ""));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Whether route pattern `a` ranks above `b` for a literal path both serve, as the router ranks them: at the first
|
|
317
|
+
// segment where one is static and the other a :param, the static one wins. /jobs/new comes before /jobs/:jobId, and
|
|
318
|
+
// /jobs/:jobId before /:section/new.
|
|
319
|
+
function outranks(a, b) {
|
|
320
|
+
const aSegments = a.split("/");
|
|
321
|
+
const bSegments = b.split("/");
|
|
322
|
+
for (const [index, segment] of aSegments.entries()) {
|
|
323
|
+
const param = PARAM_SEGMENT.test(segment);
|
|
324
|
+
if (param !== PARAM_SEGMENT.test(bSegments[index])) return !param;
|
|
325
|
+
}
|
|
326
|
+
return false;
|
|
312
327
|
}
|
|
313
328
|
|
|
314
329
|
// unplugin-vue-router file routes: src/pages/home/suppliers/[supplierId]/edit.vue is home/suppliers/:supplierId/edit,
|
|
@@ -556,6 +571,14 @@ async function checkPageParents({ root, appFiles, pageFiles, report }) {
|
|
|
556
571
|
if (page.layout) page.shell = await shellPlacement(page.file, page.source, drawsShellBar, known);
|
|
557
572
|
}
|
|
558
573
|
const surfaces = readSurfaces(configSource, [...pages.values()].map(({ file }) => routeOf(file)));
|
|
574
|
+
const packageRoutes = await readPackageRoutes(root, known);
|
|
575
|
+
// Every route the router has, by its address: the app's pages and the packages' routes.
|
|
576
|
+
const routes = [...[...pages.values()].map(({ file }) => normalisePath(routePattern(routeOf(file)))),
|
|
577
|
+
...packageRoutes.map((route) => normalisePath(route.path))];
|
|
578
|
+
// Whether the route at an address is the one the router renders for a literal path: it serves the path and no route
|
|
579
|
+
// that ranks above it does. A link to /jobs/new leads to jobs/new.vue when there is one, not to jobs/[jobId].
|
|
580
|
+
const leadsTo = (address, literal) => patternServes(address, literal)
|
|
581
|
+
&& !routes.some((other) => patternServes(other, literal) && outranks(other, address));
|
|
559
582
|
const scripts = appFiles.filter((file) => /\.(?:[cm]?[jt]s|vue)$/u.test(file));
|
|
560
583
|
const navigation = readMainNavigation(await Promise.all(scripts.map(async (file) => ({ file, source: blankJsComments(await read(file)) }))));
|
|
561
584
|
for (const { file, source, offset, computed } of navigation.unreadable) {
|
|
@@ -566,14 +589,17 @@ async function checkPageParents({ root, appFiles, pageFiles, report }) {
|
|
|
566
589
|
const addressOf = (relative, surface) => normalisePath(routePattern(`${surface.pagesRoot}${relative}`));
|
|
567
590
|
const shownOn = (owners, surface) => owners.length === 0 || owners.includes(surface.id) || owners.includes("*");
|
|
568
591
|
// A destination by its suffix on the surface, or by its address (`to`). A page with a dynamic route (one page for
|
|
569
|
-
// every module, at /modules/:moduleKey) is a destination when a destination's literal path is one it serves
|
|
592
|
+
// every module, at /modules/:moduleKey) is a destination when a destination's literal path is one it serves and no
|
|
593
|
+
// route the router prefers (a static page such as /modules/new) serves too.
|
|
570
594
|
const isDestination = (relative, surface) => navigation.destinations.some(({ suffix, to, surfaces: owners }) =>
|
|
571
|
-
to === undefined
|
|
595
|
+
to === undefined
|
|
596
|
+
? shownOn(owners, surface) && leadsTo(addressOf(relative, surface), addressOf(suffix, surface))
|
|
597
|
+
: leadsTo(addressOf(relative, surface), to));
|
|
572
598
|
// A global route's address is a destination when a link's `to` names it, or a suffix leads there on a surface.
|
|
573
599
|
const isAddress = (address) => navigation.destinations.some(({ suffix, to, surfaces: owners }) =>
|
|
574
600
|
to === undefined
|
|
575
|
-
? surfaces.some((surface) => shownOn(owners, surface) &&
|
|
576
|
-
:
|
|
601
|
+
? surfaces.some((surface) => shownOn(owners, surface) && leadsTo(address, addressOf(suffix, surface)))
|
|
602
|
+
: leadsTo(address, to));
|
|
577
603
|
// An App.vue that wraps every page in the shell's bar leaves no page outside it.
|
|
578
604
|
const appShell = appFiles.includes("src/App.vue") && await drawsShellBar("src/App.vue");
|
|
579
605
|
const judged = [];
|
|
@@ -626,7 +652,7 @@ async function checkPageParents({ root, appFiles, pageFiles, report }) {
|
|
|
626
652
|
report({ rule: "nav/missing-parent", file, ...at, message: `Inner page ${relative} of ${surface.id} has no parent. Declare it once in the page's route meta (or its layout's, for tabs), so Up works after a direct entry.` });
|
|
627
653
|
}
|
|
628
654
|
}
|
|
629
|
-
for (const route of
|
|
655
|
+
for (const route of packageRoutes) {
|
|
630
656
|
if (!pageFiles.includes(route.file) && !pageFiles.includes(route.manifest)) continue;
|
|
631
657
|
const verdict = await judgePackageRoute(route, { surfaces, appShell, drawsShellBar, isDestination, isAddress, readable: navigation.unreadable.length === 0, report });
|
|
632
658
|
if (verdict) judged.push(verdict);
|