Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+27
@@ -13,6 +13,9 @@ const routePathCases: Array<{
|
||||
}> = [
|
||||
{ routeId: "index", expected: undefined, note: "root index" },
|
||||
{ routeId: "admin/index", expected: "admin", note: "nested index" },
|
||||
{ routeId: "_index", expected: undefined, note: "v2 flat root index" },
|
||||
{ routeId: "app.$tenant/files._index", expected: "app/:tenant/files", note: "v2 flat module index strips trailing _index" },
|
||||
{ routeId: "app.$tenant/files.$id", expected: "app/:tenant/files/:id", note: "v2 flat nested param sibling" },
|
||||
{ routeId: "__auth/login", expected: "login", note: "pathless layout segment" },
|
||||
{ routeId: "account/(settings)", expected: "account/settings?", note: "optional segment" },
|
||||
{ routeId: "docs/[sitemap.xml]", expected: "docs/sitemap.xml", note: "escaped dot segment" },
|
||||
@@ -151,6 +154,30 @@ describe("v1 route convention path creation", () => {
|
||||
expect(Object.values(promotedTenantRoutes).every((entry) => typeof entry.file === "string")).toBe(true);
|
||||
});
|
||||
|
||||
it("registers v2 flat _index module routes at the parent path, not /_index", () => {
|
||||
tempAppDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "v1-route-convention-"));
|
||||
|
||||
writeRouteFixture("routes/_index.tsx");
|
||||
writeRouteFixture("routes/app.$tenant.tsx");
|
||||
writeRouteFixture("routes/app.$tenant/files._index.tsx");
|
||||
writeRouteFixture("routes/app.$tenant/files.$id.tsx");
|
||||
writeRouteFixture("routes/app.$tenant/contacts._index.tsx");
|
||||
|
||||
const manifest = createRoutesFromFolders(defineRouteManifest, {
|
||||
appDirectory: tempAppDirectory,
|
||||
});
|
||||
const byId = Object.fromEntries(Object.values(manifest).map((entry) => [entry.id, { path: entry.path, index: entry.index }]));
|
||||
|
||||
// Root _index is the index of the layout tree (no path).
|
||||
expect(byId["routes/_index"]).toEqual({ path: undefined, index: true });
|
||||
// A flat module _index becomes the leaf route AT the module path (renders /:tenant/files),
|
||||
// not a literal "/files/_index" segment, and is not itself an index route.
|
||||
expect(byId["routes/app.$tenant/files._index"]).toEqual({ path: "files", index: undefined });
|
||||
expect(byId["routes/app.$tenant/contacts._index"]).toEqual({ path: "contacts", index: undefined });
|
||||
// Sibling param route keeps its nested path.
|
||||
expect(byId["routes/app.$tenant/files.$id"]).toEqual({ path: "files/:id", index: undefined });
|
||||
});
|
||||
|
||||
it("ignores server-only files when requested by the route config", () => {
|
||||
tempAppDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "v1-route-convention-"));
|
||||
|
||||
|
||||
+15
-7
@@ -106,7 +106,11 @@ export function createRoutesFromFolders(defineRoutes: DefineRoutesFunction, opti
|
||||
for (let routeId of childRouteIds) {
|
||||
let routePath: string | undefined = createRoutePath(routeId.slice((parentId || routesDirectory).length + 1));
|
||||
|
||||
let isIndexRoute = routeId.endsWith("/index");
|
||||
// Index when the parent-relative path resolves to nothing and the final
|
||||
// segment is the index marker. Supports the v1 `index` filename and the
|
||||
// v2 flat `_index` filename. A flat `foo._index` (relative path "foo") is
|
||||
// NOT an index — it is the leaf route at `/foo`.
|
||||
let isIndexRoute = routePath === undefined && /(?:^|[/.])_?index$/.test(routeId);
|
||||
let fullPath = createRoutePath(routeId.slice(routesDirectory.length + 1));
|
||||
fullPath = promoteTenantAppRoutePath(fullPath);
|
||||
routePath = promoteTenantAppRoutePath(routePath);
|
||||
@@ -196,7 +200,11 @@ export function createRoutesFromFolders(defineRoutes: DefineRoutesFunction, opti
|
||||
|
||||
for (let routeId of childRouteIds) {
|
||||
const routePath = createAdminHostRoutePath(routeId, parentId);
|
||||
let isIndexRoute = routeId.endsWith("/index");
|
||||
// Index when the parent-relative path resolves to nothing and the final
|
||||
// segment is the index marker. Supports the v1 `index` filename and the
|
||||
// v2 flat `_index` filename. A flat `foo._index` (relative path "foo") is
|
||||
// NOT an index — it is the leaf route at `/foo`.
|
||||
let isIndexRoute = routePath === undefined && /(?:^|[/.])_?index$/.test(routeId);
|
||||
|
||||
if (isIndexRoute) {
|
||||
defineRoute(routePath, files[routeId], { index: true, id: getAdminHostRouteId(routeId) });
|
||||
@@ -297,8 +305,8 @@ export function createRoutePath(partialRouteId: string): string | undefined {
|
||||
}
|
||||
|
||||
if (isSegmentSeparator(char)) {
|
||||
if (rawSegmentBuffer === "index" && result.endsWith("index")) {
|
||||
result = result.replace(/\/?index$/, "");
|
||||
if ((rawSegmentBuffer === "index" || rawSegmentBuffer === "_index") && result.endsWith("index")) {
|
||||
result = result.replace(/\/?_?index$/, "");
|
||||
} else {
|
||||
result += "/";
|
||||
}
|
||||
@@ -327,13 +335,13 @@ export function createRoutePath(partialRouteId: string): string | undefined {
|
||||
result += char;
|
||||
}
|
||||
|
||||
if (rawSegmentBuffer === "index" && result.endsWith("index")) {
|
||||
result = result.replace(/\/?index$/, "");
|
||||
if ((rawSegmentBuffer === "index" || rawSegmentBuffer === "_index") && result.endsWith("index")) {
|
||||
result = result.replace(/\/?_?index$/, "");
|
||||
} else {
|
||||
result = result.replace(/\/$/, "");
|
||||
}
|
||||
|
||||
if (rawSegmentBuffer === "index" && result.endsWith("index?")) {
|
||||
if ((rawSegmentBuffer === "index" || rawSegmentBuffer === "_index") && result.endsWith("index?")) {
|
||||
throw new Error(`Invalid route path: ${partialRouteId}. Make index route optional by using (index)`);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user