The bundle applied the selection at runtime while Node build scripts and the context router ignored it, and a typo only failed in the browser. The generator now imports only the selected features and rejects unknown ids (D-9); declared ids stay in the index for NOT_INSTALLED reporting. Default build modules are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
133 lines
4.2 KiB
TypeScript
133 lines
4.2 KiB
TypeScript
import type { RouteObject } from "react-router-dom";
|
|
import { z } from "zod";
|
|
|
|
import { defineBoundedContextModule } from "../../src/contexts/bounded-context-module.ts";
|
|
import { defineFeatureModule } from "../../src/features/feature-module.ts";
|
|
|
|
/**
|
|
* A test-only product feature for platform tests that need a feature route: one
|
|
* that requires a session, parses a search codec, and belongs to a feature the
|
|
* runtime can switch off. Those tests install it by mocking the generated
|
|
* indexes, so they do not depend on the removable sample feature (FE-GATE-020):
|
|
*
|
|
* vi.mock("../../src/.generated/product-feature-index.ts", async () => ({
|
|
* DECLARED_PRODUCT_FEATURE_IDS: ["fixture-feature"],
|
|
* PRODUCT_FEATURE_MODULES: [(await import("../helpers/fixture-feature.tsx")).FIXTURE_FEATURE_MODULE],
|
|
* }));
|
|
* vi.mock("../../src/.generated/product-context-index.ts", async () => ({
|
|
* PRODUCT_CONTEXT_MODULES: [(await import("../helpers/fixture-feature.tsx")).FIXTURE_CONTEXT_MODULE],
|
|
* }));
|
|
*/
|
|
export const FIXTURE_FEATURE_ID = "fixture-feature";
|
|
|
|
function fixtureRoute(
|
|
routeId: string,
|
|
path: string,
|
|
searchSchema: string | null,
|
|
chunkId: string,
|
|
) {
|
|
return Object.freeze({
|
|
routeId,
|
|
path,
|
|
paramsSchema: null,
|
|
searchSchema,
|
|
access: "session-required",
|
|
loadingSurface: "fixture-page",
|
|
errorSurface: "feature-boundary",
|
|
chunkId,
|
|
title: routeId,
|
|
navigationLabel: null,
|
|
navigationOrder: null,
|
|
});
|
|
}
|
|
|
|
const FIXTURE_ROUTES = Object.freeze({
|
|
FIXTURE_ITEMS: fixtureRoute("FIXTURE_ITEMS", "/fixture/items", "FixtureItemsQuery", "route-fixture-items"),
|
|
FIXTURE_ITEM_STATUS: fixtureRoute("FIXTURE_ITEM_STATUS", "/fixture/items/status", null, "route-fixture-item-status"),
|
|
FIXTURE_ITEM_FORM: fixtureRoute("FIXTURE_ITEM_FORM", "/fixture/items/new", null, "route-fixture-item-form"),
|
|
});
|
|
|
|
const FIXTURE_TITLES: Readonly<Record<keyof typeof FIXTURE_ROUTES, string>> = {
|
|
FIXTURE_ITEMS: "Fixture items",
|
|
FIXTURE_ITEM_STATUS: "Fixture item status",
|
|
FIXTURE_ITEM_FORM: "Create fixture item",
|
|
};
|
|
|
|
const FIXTURE_MESSAGES = Object.freeze(
|
|
Object.fromEntries(
|
|
Object.entries(FIXTURE_TITLES).flatMap(([routeId, title]) => [
|
|
[`route.${routeId}.title`, title],
|
|
[`route.${routeId}.navigation`, title],
|
|
]),
|
|
),
|
|
);
|
|
|
|
export const FIXTURE_FEATURE_MODULE = defineFeatureModule({
|
|
id: FIXTURE_FEATURE_ID,
|
|
contracts: Object.freeze({
|
|
featureId: FIXTURE_FEATURE_ID,
|
|
routes: FIXTURE_ROUTES,
|
|
routeRuntimeContracts: Object.freeze(
|
|
Object.fromEntries(
|
|
Object.values(FIXTURE_ROUTES).map((route) => [
|
|
route.routeId,
|
|
Object.freeze({
|
|
routeId: route.routeId,
|
|
moduleId: `${route.chunkId}-page`,
|
|
paramsCodec: "none",
|
|
searchCodec: route.searchSchema ?? "none",
|
|
}),
|
|
]),
|
|
),
|
|
),
|
|
apiOperations: Object.freeze({}),
|
|
invalidation: Object.freeze({ topics: [], namespaces: [], edges: [] }),
|
|
topicVersions: Object.freeze([]),
|
|
schemas: Object.freeze({}),
|
|
runtimeSchemas: Object.freeze({}),
|
|
mappers: Object.freeze({}),
|
|
}),
|
|
routes: FIXTURE_ROUTES,
|
|
adapters: [],
|
|
runtimes: [
|
|
Object.freeze({
|
|
featureId: FIXTURE_FEATURE_ID,
|
|
routeCodecs: Object.freeze({
|
|
FixtureItemsQuery: z.object({
|
|
limit: z.coerce.number().int().min(1).max(100).default(20),
|
|
}),
|
|
}),
|
|
routeRuntime: Object.freeze({}),
|
|
}),
|
|
],
|
|
messages: Object.freeze({ "ko-KR": FIXTURE_MESSAGES, "en-US": FIXTURE_MESSAGES }),
|
|
contractContributions: [],
|
|
});
|
|
|
|
function FixturePage() {
|
|
return <p>Fixture page</p>;
|
|
}
|
|
|
|
export const FIXTURE_CONTEXT_ROUTES: readonly RouteObject[] = Object.freeze(
|
|
Object.values(FIXTURE_ROUTES).map((route) =>
|
|
Object.freeze({
|
|
id: route.routeId,
|
|
path: route.path,
|
|
handle: Object.freeze({
|
|
routeId: route.routeId,
|
|
runtime: Object.freeze({ moduleId: `${route.chunkId}-page`, Component: FixturePage }),
|
|
}),
|
|
}),
|
|
),
|
|
);
|
|
|
|
export const FIXTURE_CONTEXT_MODULE = defineBoundedContextModule({
|
|
id: "fixture-context",
|
|
features: [FIXTURE_FEATURE_MODULE],
|
|
budget: { maxFeatures: 1 },
|
|
route: {
|
|
path: "fixture/items/*",
|
|
loadRoutes: async () => FIXTURE_CONTEXT_ROUTES,
|
|
},
|
|
});
|