create-ailk 0.38.0 → 0.39.0
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/add-route.js +1 -1
- package/dist/derive-architecture.js +3 -1
- package/dist/remove-module.js +18 -14
- package/dist/routes.d.ts +29 -2
- package/dist/routes.js +269 -23
- package/dist/site-manifest.js +6 -4
- package/dist/site-roster.d.ts +11 -3
- package/dist/site-roster.js +42 -22
- package/dist/surfaces.d.ts +11 -3
- package/dist/surfaces.js +69 -22
- package/dist/sync-routes.js +22 -5
- package/dist/template-record.js +3 -1
- package/dist/topology.d.ts +11 -0
- package/dist/topology.js +253 -3
- package/package.json +3 -3
- package/templates/apps/web/CLAUDE.md +26 -4
- package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +5 -1
- package/templates/apps/web/__tests__/__mocks__/next-intl.ts +5 -1
- package/templates/apps/web/__tests__/auth/seam.test.ts +34 -0
- package/templates/apps/web/account.config.tsx +2 -3
- package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
- package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
- package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +1 -1
- package/templates/apps/web/app/[locale]/layout.tsx +1 -1
- package/templates/apps/web/auth.config.tsx +107 -0
- package/templates/apps/web/auth.ts +2 -1
- package/templates/apps/web/i18n/request.ts +9 -2
- package/templates/apps/web/jest.config.cjs +4 -0
- package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +3 -0
- package/templates/apps/web/lib/__tests__/server-api.test.ts +1 -1
- package/templates/apps/web/lib/server-api.ts +1 -1
- package/templates/apps/web/lib/topology.generated.ts +5 -0
- package/templates/apps/web/messages/en.json +0 -152
- package/templates/apps/web/middleware.ts +12 -25
- package/templates/apps/web/next.config.mjs +8 -0
- package/templates/apps/web/package.json +1 -0
- package/templates/apps/web/types/messages.d.ts +6 -1
- package/versions.json +49 -48
- package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +0 -322
- package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +0 -554
- package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/consent-actions.test.ts +0 -56
- package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/page.test.tsx +0 -164
- package/templates/apps/web/app/[locale]/(auth)/consent/consent-form.tsx +0 -132
- package/templates/apps/web/app/[locale]/(auth)/consent/consent.actions.ts +0 -51
- package/templates/apps/web/app/[locale]/(auth)/consent/page.tsx +0 -144
- package/templates/apps/web/app/[locale]/(auth)/forgot-password/forgot-password-card.tsx +0 -101
- package/templates/apps/web/app/[locale]/(auth)/forgot-password/page.tsx +0 -111
- package/templates/apps/web/app/[locale]/(auth)/layout.tsx +0 -81
- package/templates/apps/web/app/[locale]/(auth)/legal-footnote.tsx +0 -35
- package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +0 -179
- package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +0 -157
- package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +0 -126
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/next-path.test.ts +0 -54
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +0 -628
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +0 -43
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +0 -266
- package/templates/apps/web/app/[locale]/(auth)/sign-in/next-path.ts +0 -20
- package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +0 -234
- package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +0 -37
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +0 -323
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +0 -93
- package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/page.test.tsx +0 -301
- package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +0 -309
- package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +0 -201
- package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +0 -366
- package/templates/apps/web/app/[locale]/(auth)/use-auth-card-flow.ts +0 -116
- package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +0 -94
- package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +0 -77
- package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +0 -154
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +0 -10
- package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +0 -3
- package/templates/apps/web/app/api/auth/[...all]/route.ts +0 -16
- package/templates/apps/web/app/api/auth/hub/__tests__/continuation.test.ts +0 -143
- package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +0 -749
- package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +0 -964
- package/templates/apps/web/app/api/auth/hub/authorize/route.ts +0 -390
- package/templates/apps/web/app/api/auth/hub/continuation.ts +0 -127
- package/templates/apps/web/app/api/auth/hub/continue/[ref]/__tests__/route.test.ts +0 -188
- package/templates/apps/web/app/api/auth/hub/continue/[ref]/route.ts +0 -53
- package/templates/apps/web/app/api/auth/hub/email/route.ts +0 -111
- package/templates/apps/web/app/api/auth/hub/entry-shared.ts +0 -163
- package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +0 -86
- package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +0 -368
- package/templates/apps/web/app/api/auth/hub/password/return.ts +0 -86
- package/templates/apps/web/app/api/auth/hub/password/route.ts +0 -171
- package/templates/apps/web/app/api/auth/hub/purchase/route.ts +0 -230
- package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +0 -174
- package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +0 -60
- package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +0 -97
- package/templates/apps/web/app/api/auth/mcp/__tests__/continuation.test.ts +0 -92
- package/templates/apps/web/app/api/auth/mcp/continuation.ts +0 -89
- package/templates/apps/web/app/api/auth/mcp/continue/[ref]/__tests__/route.test.ts +0 -59
- package/templates/apps/web/app/api/auth/mcp/continue/[ref]/route.ts +0 -41
- package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +0 -1166
- package/templates/apps/web/app/api/hub-session/callback/route.ts +0 -134
- package/templates/apps/web/app/api/hub-session/email/route.ts +0 -125
- package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +0 -49
- package/templates/apps/web/app/api/hub-session/one-tap/route.ts +0 -106
- package/templates/apps/web/app/api/hub-session/open/route.ts +0 -111
- package/templates/apps/web/app/api/hub-session/password/return/route.ts +0 -69
- package/templates/apps/web/app/api/hub-session/password/route.ts +0 -106
- package/templates/apps/web/app/api/hub-session/sign-in/route.ts +0 -91
- package/templates/apps/web/app/api/hub-session/sign-out/route.ts +0 -54
- package/templates/apps/web/components/sign-out-trigger.tsx +0 -62
- package/templates/apps/web/lib/__tests__/auth-routes.test.ts +0 -140
- package/templates/apps/web/lib/auth-routes.ts +0 -125
- package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +0 -433
- package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +0 -332
- package/templates/apps/web/lib/hub-session/config.ts +0 -110
- package/templates/apps/web/lib/hub-session/entry.ts +0 -238
- package/templates/apps/web/lib/hub-session/index.ts +0 -21
- package/templates/apps/web/lib/hub-session/one-tap.tsx +0 -148
- package/templates/apps/web/lib/hub-session/reseal.ts +0 -90
- package/templates/apps/web/lib/hub-session/seal.ts +0 -86
- package/templates/apps/web/lib/hub-session/session.ts +0 -298
- package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +0 -277
- package/templates/apps/web/lib/next-path.ts +0 -35
package/dist/add-route.js
CHANGED
|
@@ -331,7 +331,7 @@ const MAGNET_PATH_RE = /^\/[a-z0-9]+(-[a-z0-9]+)*(\/[a-z0-9]+(-[a-z0-9]+)*){0,2}
|
|
|
331
331
|
const RESERVED_LAST_SEGMENTS = new Set(["start", "apply"]);
|
|
332
332
|
/**
|
|
333
333
|
* First segments a pair may not take: the API and relay prefixes, the flows
|
|
334
|
-
* routes, the account and Admin areas, and
|
|
334
|
+
* routes, the account and Admin areas, and `@working-theory/auth/edge`'s
|
|
335
335
|
* `AUTH_SEGMENTS` (restated — create-ailk cannot import `apps/web`).
|
|
336
336
|
*/
|
|
337
337
|
const RESERVED_FIRST_SEGMENTS = new Set([
|
|
@@ -20,7 +20,7 @@ import { SITE_FONTS_PATH } from "./site-fonts.js";
|
|
|
20
20
|
import { SITE_LISTING_PATH } from "./site-listing-path.js";
|
|
21
21
|
import { SPOKE_CHECKOUT_CONFIG_PATH } from "./spoke-checkout.js";
|
|
22
22
|
import { CORE_SURFACE_PATHS, NAV_CONFIG_PATH, RECOGNIZED_SURFACES, resolveSurfaces, } from "./surfaces.js";
|
|
23
|
-
import { SPOKE_SEAM_FILES } from "./topology.js";
|
|
23
|
+
import { AUTH_CONFIG_PATH, SPOKE_SEAM_FILES } from "./topology.js";
|
|
24
24
|
/** The npm scope a site consumes and never forks (#9191). */
|
|
25
25
|
const PACKAGE_SCOPE = "@working-theory/";
|
|
26
26
|
/** Apps whose `package.json` name is not `@working-theory/<dir>`, because the published package took it (#9564, #9570). */
|
|
@@ -347,6 +347,8 @@ export function deriveArchitecture(modules = ["marketing"], surfaces, options =
|
|
|
347
347
|
MODULE_FLAGS_PATH,
|
|
348
348
|
PAID_MCP_TOOLS_PATH,
|
|
349
349
|
...SPOKE_SEAM_FILES,
|
|
350
|
+
// #11257 D4 — rewritten in its spoke shape on a spoke, as the seams are.
|
|
351
|
+
AUTH_CONFIG_PATH,
|
|
350
352
|
SPOKE_CHECKOUT_CONFIG_PATH,
|
|
351
353
|
SPOKE_BILLING_ACTION_PATH,
|
|
352
354
|
SITE_LISTING_PATH,
|
package/dist/remove-module.js
CHANGED
|
@@ -42,9 +42,9 @@ import { deriveArchitecture } from "./derive-architecture.js";
|
|
|
42
42
|
import { MODULE_SLICES, normalizeModules } from "./module-architecture.js";
|
|
43
43
|
import { MODULE_FLAGS_PATH, PAID_MCP_TOOLS_PATH, PAID_SECTIONS_PATH, writePaidSections, } from "./paid-sections.js";
|
|
44
44
|
import { ParseError, parseModules } from "./parse-args.js";
|
|
45
|
-
import {
|
|
46
|
-
import { SITE_ROSTER_PATH, readSiteRoster } from "./site-roster.js";
|
|
47
|
-
import { HUB_KEPT_ROUTE_DIRS, MODULE_SURFACES, ROUTE_ROOT, resolveSurfaces, } from "./surfaces.js";
|
|
45
|
+
import { isGenerated, isRecordedRoute } from "./routes.js";
|
|
46
|
+
import { SITE_ROSTER_PATH, readSiteRoster, webDependencies } from "./site-roster.js";
|
|
47
|
+
import { HUB_KEPT_ROUTE_DIRS, MODULE_SURFACES, PAGE_PACKAGE_ROUTES, ROUTE_ROOT, resolveSurfaces, } from "./surfaces.js";
|
|
48
48
|
import { BASE_LAYER_DIR, templateTreeDir } from "./template-manifest.js";
|
|
49
49
|
import { TEMPLATE_RECORD_PATH, isRecordable, parseTemplateRecord, serializeTemplateRecord, sha256Hex, } from "./template-record.js";
|
|
50
50
|
import { readSiteTopology } from "./topology.js";
|
|
@@ -191,15 +191,6 @@ export function removalSet(targetDir, moduleName) {
|
|
|
191
191
|
// ── Edited-file classification (D5) ─────────────────────────────────────────
|
|
192
192
|
/** The `request` a removed generated route's `customizations.yaml` entry names. */
|
|
193
193
|
const REMOVED_ROUTE_REQUEST = "working-theory-labs/ai-launch-kit-internal#11251";
|
|
194
|
-
/**
|
|
195
|
-
* Whether a file opens with the `create-ailk routes --write` header — on
|
|
196
|
-
* line 1, or on line 2 behind the `// oss: false` marker (#11252).
|
|
197
|
-
*/
|
|
198
|
-
function isGeneratedRoute(bytes) {
|
|
199
|
-
const text = Buffer.from(bytes).toString("utf8");
|
|
200
|
-
const marker = `${OSS_FALSE_MARKER}\n`;
|
|
201
|
-
return (text.startsWith(marker) ? text.slice(marker.length) : text).startsWith(GENERATED_ROUTE_HEADER);
|
|
202
|
-
}
|
|
203
194
|
/**
|
|
204
195
|
* Append one `customizations.yaml` entry per removed generated route file
|
|
205
196
|
* (#11251 D12): `id: removed-<route>`, its one path, the decision that the
|
|
@@ -285,7 +276,7 @@ function isEdited(layers, targetDir, path) {
|
|
|
285
276
|
// #11251 D12 — a route file `create-ailk routes --write` generated is the
|
|
286
277
|
// page package's code, never the site's edit (`routes --check` holds it to
|
|
287
278
|
// the manifest).
|
|
288
|
-
if (
|
|
279
|
+
if (isGenerated(disk.toString("utf8")))
|
|
289
280
|
return false;
|
|
290
281
|
// A carried module's own sample seeds are placeholders by contract (the
|
|
291
282
|
// starter-template contract R2); no shipped layer holds their bytes to
|
|
@@ -438,7 +429,7 @@ export function removeModuleFromScaffold(opts) {
|
|
|
438
429
|
].join("\n"));
|
|
439
430
|
}
|
|
440
431
|
// ── Delete, then prune the directories the deletions emptied ────────────
|
|
441
|
-
const generatedRoutes = paths.filter((p) =>
|
|
432
|
+
const generatedRoutes = paths.filter((p) => isGenerated(readFileSync(join(targetDir, ...p.split("/")), "utf8")));
|
|
442
433
|
for (const p of paths)
|
|
443
434
|
rmSync(join(targetDir, ...p.split("/")));
|
|
444
435
|
// #11251 D12 (ADR 0040 rule 2) — a deleted generated route is recorded as
|
|
@@ -511,6 +502,19 @@ export function removeModuleFromScaffold(opts) {
|
|
|
511
502
|
keptSegments.add(dir);
|
|
512
503
|
}
|
|
513
504
|
}
|
|
505
|
+
// #11259 D6 — a carried page package's pages under a kept group are kept
|
|
506
|
+
// too: the snapshot holds none of its generated route files, so a site
|
|
507
|
+
// whose routes are not yet written has no `(auth)/sign-in` on disk.
|
|
508
|
+
const carried = webDependencies(targetDir);
|
|
509
|
+
for (const row of PAGE_PACKAGE_ROUTES) {
|
|
510
|
+
if (!carried.has(row.package))
|
|
511
|
+
continue;
|
|
512
|
+
for (const page of row.pages) {
|
|
513
|
+
const [group, segment] = page.split("/");
|
|
514
|
+
if (segment !== undefined && HUB_KEPT_ROUTE_DIRS.includes(group ?? ""))
|
|
515
|
+
keptSegments.add(segment);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
514
518
|
const dropRoutes = moduleName === "marketing"
|
|
515
519
|
? (route) => !keptSegments.has(route.split("/")[1] ?? "")
|
|
516
520
|
: (route) => (MODULE_SLICES[moduleName].pageContributions ?? []).some((c) => c.route === route);
|
package/dist/routes.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/** The app a page package's routes mount in, relative to the site root. */
|
|
2
2
|
export declare const ROUTES_APP_DIR = "apps/web";
|
|
3
|
+
/**
|
|
4
|
+
* The site's own handler trees under `app/api/`, which no page package may
|
|
5
|
+
* declare as an app prefix (#11257 D10, SEC-11257-3): the Offerings buy route,
|
|
6
|
+
* the revalidate hook, the webhook routes and the legacy checkout.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SITE_HANDLER_PREFIXES: readonly string[];
|
|
9
|
+
/** The routing file names the generator writes (`ROUTING_FILES`), for the snapshot build (#11259 D6). */
|
|
10
|
+
export declare const ROUTING_FILE_NAMES: ReadonlySet<string>;
|
|
3
11
|
export type RouteKind = "page" | "layout" | "route";
|
|
4
12
|
export interface RouteEntry {
|
|
5
13
|
/** The routing file under `app/[locale]/`, POSIX, e.g. `(authed)/account/general/page.tsx`. */
|
|
@@ -15,12 +23,25 @@ export interface RouteEntry {
|
|
|
15
23
|
config: boolean;
|
|
16
24
|
/** Whether `generateMetadata` takes it too (#11253) — only with `config` and a `generateMetadata` export. */
|
|
17
25
|
metadataConfig: boolean;
|
|
26
|
+
/** Where `path` is relative to: `app/[locale]/` (the default) or `app/` (#11257 D10). */
|
|
27
|
+
mount: RouteMount;
|
|
28
|
+
/** An ADR 0020 inline waiver the generated handler carries after its header (#11257 D10). */
|
|
29
|
+
waiver: string | undefined;
|
|
18
30
|
}
|
|
31
|
+
export type RouteMount = "locale" | "app";
|
|
19
32
|
export interface RouteManifest {
|
|
20
33
|
package: string;
|
|
21
34
|
version: string;
|
|
22
35
|
/** The package's route prefixes under `app/[locale]/` — the stray check's scope; a manifest's single string is wrapped. */
|
|
23
36
|
prefix: string[];
|
|
37
|
+
/** Whether the package ships the locale-root `page.tsx` — the manifest's `"root": true` (#11259 D5). */
|
|
38
|
+
localeRoot: boolean;
|
|
39
|
+
/** Whether the site's surfaces and public tree gate the package's entries (#11259 D5). */
|
|
40
|
+
siteGated: boolean;
|
|
41
|
+
/** The package's prefixes under `app/` for its `app`-mounted entries — their stray check's scope (#11257 D10). */
|
|
42
|
+
appPrefixes: string[];
|
|
43
|
+
/** Whether the package reads the site through `<package>/site`, which the site must alias (#11257 D4). */
|
|
44
|
+
siteSeam: boolean;
|
|
24
45
|
/** The site's config file at the app root, without extension (`account.config`). */
|
|
25
46
|
config: string | undefined;
|
|
26
47
|
/** Routing files under the prefix that stay the site's own pages, never generated. */
|
|
@@ -58,6 +79,8 @@ export declare const GENERATED_ROUTE_HEADER = "// Generated by create-ailk route
|
|
|
58
79
|
export declare const OSS_FALSE_MARKER = "// oss: false";
|
|
59
80
|
/** The generated file's text for one entry. Every statement is one line; the config wrapper is in prettier's shape. */
|
|
60
81
|
export declare function renderRouteFile(manifest: RouteManifest, entry: RouteEntry): string;
|
|
82
|
+
/** Whether `text` is a file this generator wrote: its first line (after an `oss: false` marker) is the header. */
|
|
83
|
+
export declare function isGenerated(text: string): boolean;
|
|
61
84
|
/** Whether `<siteDir>/customizations.yaml` records `sitePath` — any entry, any path form or glob (the generator's own reading). */
|
|
62
85
|
export declare function isRecordedRoute(siteDir: string, sitePath: string): boolean;
|
|
63
86
|
export interface RecordedRoute {
|
|
@@ -76,10 +99,12 @@ export interface RoutesDrift {
|
|
|
76
99
|
siteKept: string[];
|
|
77
100
|
/** Site message keys under a package's namespace that its catalog no longer has: `<file>: <key>`. */
|
|
78
101
|
orphanedOverrides: string[];
|
|
102
|
+
/** A site file missing the alias line a `siteSeam` package needs: `<file>: <alias>` (#11257 D4). */
|
|
103
|
+
seamAliasMissing: string[];
|
|
79
104
|
/** The manifest entries in force — recorded ones included, not-carried ones not. */
|
|
80
105
|
generated: number;
|
|
81
106
|
}
|
|
82
|
-
/** The count check mode fails on: missing, stale and stray route files and
|
|
107
|
+
/** The count check mode fails on: missing, stale and stray route files, orphaned overrides and missing seam aliases. */
|
|
83
108
|
export declare function routesFailing(drift: RoutesDrift): number;
|
|
84
109
|
/** How the site's route files and message overrides differ from the installed page packages. `routesFailing` zero means in sync. */
|
|
85
110
|
export declare function checkRoutes(siteDir: string): RoutesDrift;
|
|
@@ -87,6 +112,8 @@ export interface WriteRoutesResult {
|
|
|
87
112
|
written: string[];
|
|
88
113
|
current: string[];
|
|
89
114
|
recorded: RecordedRoute[];
|
|
115
|
+
/** Routing files at an entry's path that the generator did not write — a site's own handler — left as they are (#11257 D10). */
|
|
116
|
+
kept: string[];
|
|
90
117
|
}
|
|
91
118
|
/** Write every generated file that is missing or stale; a recorded route is left exactly as it is. */
|
|
92
119
|
export declare function writeRoutes(siteDir: string): WriteRoutesResult;
|
|
@@ -96,7 +123,7 @@ export interface RoutesArgs {
|
|
|
96
123
|
check: boolean;
|
|
97
124
|
help: boolean;
|
|
98
125
|
}
|
|
99
|
-
export declare const ROUTES_HELP = "create-ailk routes \u2014 generate the route files for the pages a site's packages ship.\n\nUsage:\n create-ailk routes --write [<target-dir>]\n create-ailk routes --check [<target-dir>]\n\nArguments:\n <target-dir> The site root (holds apps/web). Defaults to the\n current dir.\n\nOptions:\n --write Write one generated file per route the installed\n page packages declare, under apps/web/app/[locale]/.\n A file already current is left alone.\n --check Write nothing; exit 1 naming each generated file\n that is missing, stale (differs from what --write\n would write) or stray (a page.tsx, layout.tsx or\n route.ts under a package's route prefix that is\n neither generated, recorded, nor one the package\n leaves to the site). It also names each orphaned\n override: a key in apps/web/messages/<locale>.json\n under a namespace a package's catalog ships that\n the catalog no longer has.\n --help, -h Print this message.\n\nA page package is an installed @working-theory/* dependency of apps/web whose\npackage.json declares \"ailk\": { \"routes\": \"<manifest>\" }. A generated file\nre-exports the package's page and copies its route-segment config; when the\npage takes the site's config it imports the manifest's config file from the\napp root (apps/web/account.config.tsx, say) and passes it in. Replace or remove a shipped route by recording it in\ncustomizations.yaml (an entry whose paths match the route file): a recorded\nroute is reported as replaced or removed, never failed, and --write never\ntouches it. Run --write after `pnpm install` (the manifests are read from the\ninstalled packages); the scaffold's preflight runs --check as `pnpm routes:check`.\n";
|
|
126
|
+
export declare const ROUTES_HELP = "create-ailk routes \u2014 generate the route files for the pages a site's packages ship.\n\nUsage:\n create-ailk routes --write [<target-dir>]\n create-ailk routes --check [<target-dir>]\n\nArguments:\n <target-dir> The site root (holds apps/web). Defaults to the\n current dir.\n\nOptions:\n --write Write one generated file per route the installed\n page packages declare, under apps/web/app/[locale]/.\n A file already current is left alone.\n --check Write nothing; exit 1 naming each generated file\n that is missing, stale (differs from what --write\n would write) or stray (a page.tsx, layout.tsx or\n route.ts under a package's route prefix that is\n neither generated, recorded, nor one the package\n leaves to the site). It also names each orphaned\n override: a key in apps/web/messages/<locale>.json\n under a namespace a package's catalog ships that\n the catalog no longer has.\n --help, -h Print this message.\n\nA page package is an installed @working-theory/* dependency of apps/web whose\npackage.json declares \"ailk\": { \"routes\": \"<manifest>\" }. A generated file\nre-exports the package's page and copies its route-segment config; when the\npage takes the site's config it imports the manifest's config file from the\napp root (apps/web/account.config.tsx, say) and passes it in. Replace or remove a shipped route by recording it in\ncustomizations.yaml (an entry whose paths match the route file): a recorded\nroute is reported as replaced or removed, never failed, and --write never\ntouches it. A manifest may list several prefixes, and one manifest with\n\"root\": true may ship the locale-root page.tsx. A manifest with\n\"siteGated\": true ships only the routes the site selected: its public pages\nare not carried when .ailk-site-manifest.json lists no marketing module, and\nneither is any page under a surface the architecture.yaml \"# Surfaces:\" header\nleaves out. Run --write after `pnpm install` (the manifests are read from the\ninstalled packages); the scaffold's preflight runs --check as `pnpm routes:check`.\n";
|
|
100
127
|
/** Parse the argv AFTER the `routes` word. Strict `node:util` parseArgs, like `parseSyncRoutesArgs`. */
|
|
101
128
|
export declare function parseRoutesArgs(argv: string[]): RoutesArgs;
|
|
102
129
|
/** The printed report: one line per file, grouped by state; the recorded routes last, under their decision. */
|
package/dist/routes.js
CHANGED
|
@@ -63,20 +63,91 @@
|
|
|
63
63
|
* that site: neither written, nor missing, nor stray; the check names it as
|
|
64
64
|
* not carried.
|
|
65
65
|
*
|
|
66
|
+
* The app mount (#11257 D10). A route handler a page package ships outside
|
|
67
|
+
* the locale segment — `/api/auth/**`, `/api/hub-session/**` — is an entry
|
|
68
|
+
* with `"mount": "app"`, its `path` relative to `apps/web/app/`, under one of
|
|
69
|
+
* the manifest's `appPrefixes`. The trust model is the same in both mounts: an
|
|
70
|
+
* installed `@working-theory/*` page package authors the routing files under
|
|
71
|
+
* the prefixes it declares, and nothing else. So an app prefix must start
|
|
72
|
+
* `api/`, may not be `api` itself or one of the site's own handler trees
|
|
73
|
+
* (`SITE_HANDLER_PREFIXES`), and may not equal, contain or sit under another
|
|
74
|
+
* installed manifest's; an app entry never takes the config (a route handler
|
|
75
|
+
* cannot). In both mounts `--write` never overwrites a routing file whose
|
|
76
|
+
* first line is not the generator header — a site's own handler, or a
|
|
77
|
+
* recorded replacement — it reports it as `kept`. An entry's `waiver` (one
|
|
78
|
+
* line — no newline or control character; non-ASCII text such as an em
|
|
79
|
+
* dash is allowed) is written as the ADR 0020 marker on the line
|
|
80
|
+
* after the header, and every `module` is held to a fixed character set, so
|
|
81
|
+
* no manifest text can inject source into a generated file.
|
|
82
|
+
*
|
|
83
|
+
* A manifest that sets `"siteSeam": true` names a package whose modules read
|
|
84
|
+
* the site through `<package>/site`, which the site aliases to its config
|
|
85
|
+
* file in `next.config.mjs` and `jest.config.cjs`; check mode names either
|
|
86
|
+
* file when its alias line is missing, so a build bound to the package's
|
|
87
|
+
* stub fails before any request (SEC-11257-1).
|
|
88
|
+
*
|
|
89
|
+
* The locale root (#11259 D5). A manifest that sets `"root": true` may list
|
|
90
|
+
* the entry `page.tsx` — the home page at `app/[locale]/page.tsx`; its stray
|
|
91
|
+
* scope there is that one file, never the tree beneath it. One installed
|
|
92
|
+
* manifest at most may claim the root, and no two may claim overlapping
|
|
93
|
+
* prefixes: each refusal names both packages.
|
|
94
|
+
*
|
|
95
|
+
* The site's surfaces (#11259 D5). A manifest that sets `"siteGated": true`
|
|
96
|
+
* ships routes a site carries only when it selected them. On a site whose
|
|
97
|
+
* `.ailk-site-manifest.json` lists no `marketing` module, an entry inside the
|
|
98
|
+
* public route tree (`isRemovedPublicRoutePath`) is not carried; and an entry
|
|
99
|
+
* whose top directory is a `GATEABLE_SURFACES` route of a surface the site's
|
|
100
|
+
* `architecture.yaml` `# Surfaces:` header does not list (aliases
|
|
101
|
+
* canonicalized) is not carried either. A site with no readable header
|
|
102
|
+
* carries every entry. A manifest without the flag is never gated.
|
|
103
|
+
*
|
|
66
104
|
* Pure module: no `import.meta.url`, so jest imports it directly.
|
|
67
105
|
*/
|
|
68
106
|
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
69
107
|
import { dirname, join, posix, relative, resolve, sep } from "node:path";
|
|
70
108
|
import { parseArgs } from "node:util";
|
|
109
|
+
import { AddModuleRefusedError, readArchitectureHeader } from "./add-module-core.js";
|
|
110
|
+
import { publicTreeRemoved } from "./lib/site-modules.js";
|
|
111
|
+
import { GATEABLE_SURFACES, ROUTE_ROOT, canonicalizeSurface, isRemovedPublicRoutePath } from "./surfaces.js";
|
|
71
112
|
import { isSpokeExcluded, readSpokeShape } from "./topology.js";
|
|
72
113
|
/** The app a page package's routes mount in, relative to the site root. */
|
|
73
114
|
export const ROUTES_APP_DIR = "apps/web";
|
|
74
115
|
/** The locale segment every shipped route sits under. */
|
|
75
116
|
const LOCALE_DIR = "app/[locale]";
|
|
117
|
+
/** The locale-root page, the one entry a `"root": true` manifest may list outside its prefixes (#11259 D5). */
|
|
118
|
+
const ROOT_PAGE = "page.tsx";
|
|
119
|
+
/** The app root an `app`-mounted entry's path is relative to (#11257 D10). */
|
|
120
|
+
const APP_DIR = "app";
|
|
121
|
+
/**
|
|
122
|
+
* The site's own handler trees under `app/api/`, which no page package may
|
|
123
|
+
* declare as an app prefix (#11257 D10, SEC-11257-3): the Offerings buy route,
|
|
124
|
+
* the revalidate hook, the webhook routes and the legacy checkout.
|
|
125
|
+
*/
|
|
126
|
+
export const SITE_HANDLER_PREFIXES = ["api/offerings", "api/revalidate", "api/webhooks", "api/checkout"];
|
|
127
|
+
/** A `module` value: the characters both shipped manifests use, so no quote or backtick reaches generated source. */
|
|
128
|
+
const MODULE_RE = /^[A-Za-z0-9_\-./()[\]]+$/;
|
|
129
|
+
/**
|
|
130
|
+
* A `waiver`: one line of text — no control character (C0, DEL or C1) and no
|
|
131
|
+
* Unicode line or paragraph separator, so nothing can end the comment line it
|
|
132
|
+
* is written into. Not ASCII-only: the shipped waivers carry an em dash, the
|
|
133
|
+
* ADR 0020 marker's own form.
|
|
134
|
+
*/
|
|
135
|
+
function isOneLineText(value) {
|
|
136
|
+
if (value === "")
|
|
137
|
+
return false;
|
|
138
|
+
for (const char of value) {
|
|
139
|
+
const code = char.codePointAt(0) ?? 0;
|
|
140
|
+
if (code < 0x20 || (code >= 0x7f && code <= 0x9f) || code === 0x2028 || code === 0x2029)
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
76
145
|
/** The `package.json` key a page package declares its manifest under. */
|
|
77
146
|
const MANIFEST_KEY = "ailk";
|
|
78
147
|
const PACKAGE_SCOPE = "@working-theory/";
|
|
79
148
|
const ROUTING_FILES = new Set(["page.tsx", "layout.tsx", "route.ts"]);
|
|
149
|
+
/** The routing file names the generator writes (`ROUTING_FILES`), for the snapshot build (#11259 D6). */
|
|
150
|
+
export const ROUTING_FILE_NAMES = ROUTING_FILES;
|
|
80
151
|
const SKIPPED_DIRS = new Set(["__tests__", "node_modules"]);
|
|
81
152
|
const HTTP_METHODS = new Set(["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]);
|
|
82
153
|
const KIND_OF_FILE = { "page.tsx": "page", "layout.tsx": "layout", "route.ts": "route" };
|
|
@@ -108,6 +179,10 @@ function stringList(value, where) {
|
|
|
108
179
|
}
|
|
109
180
|
return value;
|
|
110
181
|
}
|
|
182
|
+
/** Whether one of two plain paths equals the other or sits under it. */
|
|
183
|
+
function overlaps(a, b) {
|
|
184
|
+
return a === b || a.startsWith(`${b}/`) || b.startsWith(`${a}/`);
|
|
185
|
+
}
|
|
111
186
|
/** Parse and validate one manifest; every refusal names the package and the entry. */
|
|
112
187
|
export function parseRouteManifest(pkg, version, raw) {
|
|
113
188
|
const at = `${pkg}'s route manifest`;
|
|
@@ -129,6 +204,25 @@ export function parseRouteManifest(pkg, version, raw) {
|
|
|
129
204
|
}
|
|
130
205
|
if (!Array.isArray(raw.routes))
|
|
131
206
|
throw new RoutesRefusedError(`${at}: routes must be a list`);
|
|
207
|
+
for (const key of ["siteSeam", "root", "siteGated"]) {
|
|
208
|
+
if (raw[key] !== undefined && typeof raw[key] !== "boolean") {
|
|
209
|
+
throw new RoutesRefusedError(`${at}: ${key} must be a boolean when set`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const root = raw.root === true;
|
|
213
|
+
const appPrefixes = stringList(raw.appPrefixes, `${at}: appPrefixes`);
|
|
214
|
+
if (new Set(appPrefixes).size !== appPrefixes.length) {
|
|
215
|
+
throw new RoutesRefusedError(`${at}: appPrefixes must be distinct`);
|
|
216
|
+
}
|
|
217
|
+
for (const appPrefix of appPrefixes) {
|
|
218
|
+
if (!isPlainPath(appPrefix) || !appPrefix.startsWith("api/")) {
|
|
219
|
+
throw new RoutesRefusedError(`${at}: appPrefixes ${JSON.stringify(appPrefix)} must be a plain path under app/api/ (no leading or trailing slash, no . or .. segment)`);
|
|
220
|
+
}
|
|
221
|
+
const site = SITE_HANDLER_PREFIXES.find((own) => overlaps(own, appPrefix));
|
|
222
|
+
if (site !== undefined) {
|
|
223
|
+
throw new RoutesRefusedError(`${at}: appPrefixes ${JSON.stringify(appPrefix)} overlaps the site's own ${site}/ handlers`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
132
226
|
const prefix = prefixes;
|
|
133
227
|
const underPrefix = (path) => prefix.some((p) => path.startsWith(`${p}/`));
|
|
134
228
|
const prefixNamed = prefix.length === 1 ? `prefix ${prefix[0]}/` : `prefixes ${prefix.join(", ")}`;
|
|
@@ -160,7 +254,26 @@ export function parseRouteManifest(pkg, version, raw) {
|
|
|
160
254
|
if (!isPlainPath(path) || !ROUTING_FILES.has(posix.basename(path))) {
|
|
161
255
|
throw new RoutesRefusedError(`${where}: path must be a plain path ending in page.tsx, layout.tsx or route.ts`);
|
|
162
256
|
}
|
|
163
|
-
if (
|
|
257
|
+
if (entry.mount !== undefined && entry.mount !== "locale" && entry.mount !== "app") {
|
|
258
|
+
throw new RoutesRefusedError(`${where}: mount must be "locale" or "app"`);
|
|
259
|
+
}
|
|
260
|
+
const mount = entry.mount === "app" ? "app" : "locale";
|
|
261
|
+
if (mount === "app") {
|
|
262
|
+
if (appPrefixes.length === 0) {
|
|
263
|
+
throw new RoutesRefusedError(`${where}: ${path} is mounted under app/, but the manifest names no appPrefixes`);
|
|
264
|
+
}
|
|
265
|
+
if (!appPrefixes.some((p) => path.startsWith(`${p}/`))) {
|
|
266
|
+
throw new RoutesRefusedError(`${where}: ${path} is outside the manifest's appPrefixes ${appPrefixes.join(", ")}`);
|
|
267
|
+
}
|
|
268
|
+
if (entry.config === true) {
|
|
269
|
+
throw new RoutesRefusedError(`${where}: an app-mounted entry (${path}) cannot take the site config`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else if (path === ROOT_PAGE) {
|
|
273
|
+
if (!root)
|
|
274
|
+
throw new RoutesRefusedError(`${where}: ${path} is the locale root, which only a manifest with "root": true ships`);
|
|
275
|
+
}
|
|
276
|
+
else if (!underPrefix(path)) {
|
|
164
277
|
throw new RoutesRefusedError(`${where}: ${path} is outside the manifest's ${prefixNamed}`);
|
|
165
278
|
}
|
|
166
279
|
if (seen.has(path) || siteOwned.includes(path)) {
|
|
@@ -170,8 +283,17 @@ export function parseRouteManifest(pkg, version, raw) {
|
|
|
170
283
|
const kind = KIND_OF_FILE[posix.basename(path)];
|
|
171
284
|
if (entry.kind !== kind)
|
|
172
285
|
throw new RoutesRefusedError(`${where}: kind must be ${JSON.stringify(kind)} for ${path}`);
|
|
173
|
-
if (!isPlainPath(entry.module)) {
|
|
174
|
-
throw new RoutesRefusedError(`${where}: module must name the package subpath to re-export from, as a plain path`);
|
|
286
|
+
if (!isPlainPath(entry.module) || !MODULE_RE.test(entry.module)) {
|
|
287
|
+
throw new RoutesRefusedError(`${where}: module must name the package subpath to re-export from, as a plain path of letters, digits and _ - . / ( ) [ ]`);
|
|
288
|
+
}
|
|
289
|
+
let waiver;
|
|
290
|
+
if (entry.waiver !== undefined) {
|
|
291
|
+
if (typeof entry.waiver !== "string" || !isOneLineText(entry.waiver)) {
|
|
292
|
+
throw new RoutesRefusedError(`${where}: waiver must be one line of text, with no control or line-separator character`);
|
|
293
|
+
}
|
|
294
|
+
if (kind !== "route")
|
|
295
|
+
throw new RoutesRefusedError(`${where}: only a route handler carries a waiver`);
|
|
296
|
+
waiver = entry.waiver;
|
|
175
297
|
}
|
|
176
298
|
const exports = stringList(entry.exports, `${where}: exports`);
|
|
177
299
|
if (exports.length === 0)
|
|
@@ -210,10 +332,23 @@ export function parseRouteManifest(pkg, version, raw) {
|
|
|
210
332
|
throw new RoutesRefusedError(`${where}: ${JSON.stringify(line)} is not a route-segment-config line`);
|
|
211
333
|
}
|
|
212
334
|
}
|
|
213
|
-
return { path, kind, module: entry.module, exports, segmentConfig, config, metadataConfig };
|
|
335
|
+
return { path, kind, module: entry.module, exports, segmentConfig, config, metadataConfig, mount, waiver };
|
|
214
336
|
});
|
|
215
337
|
const oss = raw.oss === false ? false : undefined;
|
|
216
|
-
return {
|
|
338
|
+
return {
|
|
339
|
+
package: pkg,
|
|
340
|
+
version,
|
|
341
|
+
prefix,
|
|
342
|
+
localeRoot: root,
|
|
343
|
+
siteGated: raw.siteGated === true,
|
|
344
|
+
appPrefixes,
|
|
345
|
+
siteSeam: raw.siteSeam === true,
|
|
346
|
+
config: raw.config,
|
|
347
|
+
siteOwned,
|
|
348
|
+
messages,
|
|
349
|
+
oss,
|
|
350
|
+
routes,
|
|
351
|
+
};
|
|
217
352
|
}
|
|
218
353
|
/**
|
|
219
354
|
* The route manifests of the installed page packages, in package-name
|
|
@@ -272,6 +407,23 @@ export function readRouteManifests(siteDir) {
|
|
|
272
407
|
throw new RoutesRefusedError(`${name}'s route manifest does not parse: ${err.message}`);
|
|
273
408
|
}
|
|
274
409
|
const manifest = parseRouteManifest(name, typeof meta.version === "string" ? meta.version : "0.0.0", raw);
|
|
410
|
+
for (const other of manifests) {
|
|
411
|
+
if (manifest.localeRoot && other.localeRoot) {
|
|
412
|
+
throw new RoutesRefusedError(`${name}'s route manifest claims the locale root, which ${other.package}'s already does`);
|
|
413
|
+
}
|
|
414
|
+
for (const mine of manifest.prefix) {
|
|
415
|
+
const clash = other.prefix.find((theirs) => overlaps(mine, theirs));
|
|
416
|
+
if (clash !== undefined) {
|
|
417
|
+
throw new RoutesRefusedError(`${name}'s route manifest: prefix ${JSON.stringify(mine)} overlaps ${other.package}'s ${JSON.stringify(clash)}`);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
for (const mine of manifest.appPrefixes) {
|
|
421
|
+
const clash = other.appPrefixes.find((theirs) => overlaps(mine, theirs));
|
|
422
|
+
if (clash !== undefined) {
|
|
423
|
+
throw new RoutesRefusedError(`${name}'s route manifest: appPrefixes ${JSON.stringify(mine)} overlaps ${other.package}'s ${JSON.stringify(clash)}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
275
427
|
manifests.push({ ...manifest, root: dirname(installed) });
|
|
276
428
|
}
|
|
277
429
|
return manifests;
|
|
@@ -286,13 +438,15 @@ export function renderRouteFile(manifest, entry) {
|
|
|
286
438
|
const lines = [`${GENERATED_ROUTE_HEADER}${manifest.package} ${manifest.version} — do not edit.`];
|
|
287
439
|
if (manifest.oss === false)
|
|
288
440
|
lines.unshift(OSS_FALSE_MARKER);
|
|
441
|
+
if (entry.waiver !== undefined)
|
|
442
|
+
lines.push(`// platform-decisions-waiver: ${entry.waiver}`);
|
|
289
443
|
if (entry.config) {
|
|
290
444
|
// The wrapper calls the page as the async function it is and returns its
|
|
291
445
|
// tree — no element boundary of its own — so the route module keeps the
|
|
292
446
|
// page's own contract (`(props) => Promise<ReactElement>`): what Next
|
|
293
447
|
// mounts, and what a test that renders `await Page(props)` renders.
|
|
294
448
|
// `app/[locale]/<path>` → the file's directory depth from the app root.
|
|
295
|
-
const depth = posix.dirname(posix.join(
|
|
449
|
+
const depth = posix.dirname(posix.join(mountDir(entry.mount), entry.path)).split("/").length;
|
|
296
450
|
// #11253 — a `metadataConfig` entry's `generateMetadata` reads the config
|
|
297
451
|
// too (the checkout pages answer notFound() off a spoke before any
|
|
298
452
|
// translation), so it is imported beside `Page` and wrapped, never
|
|
@@ -322,6 +476,16 @@ export function renderRouteFile(manifest, entry) {
|
|
|
322
476
|
}
|
|
323
477
|
return `${lines.join("\n")}\n`;
|
|
324
478
|
}
|
|
479
|
+
/** The directory under the app an entry's `path` is relative to. */
|
|
480
|
+
function mountDir(mount) {
|
|
481
|
+
return mount === "app" ? APP_DIR : LOCALE_DIR;
|
|
482
|
+
}
|
|
483
|
+
/** Whether `text` is a file this generator wrote: its first line (after an `oss: false` marker) is the header. */
|
|
484
|
+
export function isGenerated(text) {
|
|
485
|
+
const lines = text.split("\n", 2);
|
|
486
|
+
const first = lines[0] === OSS_FALSE_MARKER ? (lines[1] ?? "") : (lines[0] ?? "");
|
|
487
|
+
return first.startsWith(GENERATED_ROUTE_HEADER);
|
|
488
|
+
}
|
|
325
489
|
/** The scaffold lint's own glob (`template-overlay/tools/lint-architecture.ts`): `**` is zero or more whole segments, `*` stays inside one. */
|
|
326
490
|
function globToRegExp(glob) {
|
|
327
491
|
const segments = glob.split("/");
|
|
@@ -412,8 +576,8 @@ function recordFor(recorded, sitePath) {
|
|
|
412
576
|
export function isRecordedRoute(siteDir, sitePath) {
|
|
413
577
|
return recordFor(readRecorded(resolve(siteDir)), sitePath) !== undefined;
|
|
414
578
|
}
|
|
415
|
-
/** Routing files under `<web
|
|
416
|
-
function routingFilesUnder(web, siteDir, prefix) {
|
|
579
|
+
/** Routing files under `<web>/<mount dir>/<prefix>`, as site-relative POSIX paths, sorted. */
|
|
580
|
+
function routingFilesUnder(web, siteDir, prefix, mount = "locale") {
|
|
417
581
|
const out = [];
|
|
418
582
|
const walk = (dir) => {
|
|
419
583
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
@@ -427,7 +591,7 @@ function routingFilesUnder(web, siteDir, prefix) {
|
|
|
427
591
|
}
|
|
428
592
|
}
|
|
429
593
|
};
|
|
430
|
-
const root = join(web,
|
|
594
|
+
const root = join(web, mountDir(mount), prefix);
|
|
431
595
|
if (existsSync(root))
|
|
432
596
|
walk(root);
|
|
433
597
|
return out.sort();
|
|
@@ -440,13 +604,12 @@ function plan(siteDir) {
|
|
|
440
604
|
// The site's topology (`.ailk-site-manifest.json`): on a spoke, the paths
|
|
441
605
|
// it does not carry are not its routes. A hub, or no manifest, carries all.
|
|
442
606
|
const spoke = readSpokeShape(root);
|
|
607
|
+
const gate = siteGate(root);
|
|
608
|
+
const carries = (manifest, sitePath) => (spoke === undefined || !isSpokeExcluded(sitePath, spoke)) && (!manifest.siteGated || gate(sitePath));
|
|
443
609
|
const planned = [];
|
|
444
610
|
const notCarried = [];
|
|
445
611
|
for (const manifest of manifests) {
|
|
446
|
-
const carried = manifest.routes.filter((entry) =>
|
|
447
|
-
const sitePath = relative(root, join(web, LOCALE_DIR, entry.path)).split(sep).join("/");
|
|
448
|
-
return spoke === undefined || !isSpokeExcluded(sitePath, spoke);
|
|
449
|
-
});
|
|
612
|
+
const carried = manifest.routes.filter((entry) => carries(manifest, relative(root, join(web, mountDir(entry.mount), entry.path)).split(sep).join("/")));
|
|
450
613
|
if (manifest.config !== undefined && carried.some((entry) => entry.config)) {
|
|
451
614
|
const configPath = join(web, `${manifest.config}.tsx`);
|
|
452
615
|
if (!existsSync(configPath)) {
|
|
@@ -454,9 +617,9 @@ function plan(siteDir) {
|
|
|
454
617
|
}
|
|
455
618
|
}
|
|
456
619
|
for (const entry of manifest.routes) {
|
|
457
|
-
const absPath = join(web,
|
|
620
|
+
const absPath = join(web, mountDir(entry.mount), entry.path);
|
|
458
621
|
const sitePath = relative(root, absPath).split(sep).join("/");
|
|
459
|
-
if (
|
|
622
|
+
if (!carries(manifest, sitePath)) {
|
|
460
623
|
notCarried.push(sitePath);
|
|
461
624
|
continue;
|
|
462
625
|
}
|
|
@@ -465,9 +628,70 @@ function plan(siteDir) {
|
|
|
465
628
|
}
|
|
466
629
|
return { root, web, manifests, planned, recorded, notCarried };
|
|
467
630
|
}
|
|
468
|
-
/**
|
|
631
|
+
/**
|
|
632
|
+
* Whether a `siteGated` manifest's entry at `sitePath` is a route of the site
|
|
633
|
+
* (#11259 D5): not inside the public tree on a site without `marketing`, and
|
|
634
|
+
* not under a gateable surface the site's `# Surfaces:` header leaves out. A
|
|
635
|
+
* site with no readable header carries every surface.
|
|
636
|
+
*/
|
|
637
|
+
function siteGate(siteDir) {
|
|
638
|
+
const noPublicTree = publicTreeRemoved(siteDir);
|
|
639
|
+
let surfaces;
|
|
640
|
+
const archPath = join(siteDir, "architecture.yaml");
|
|
641
|
+
if (existsSync(archPath)) {
|
|
642
|
+
const text = readFileSync(archPath, "utf8");
|
|
643
|
+
try {
|
|
644
|
+
surfaces = new Set(readArchitectureHeader(text).surfaces.map(canonicalizeSurface));
|
|
645
|
+
}
|
|
646
|
+
catch (err) {
|
|
647
|
+
// Only a missing or malformed header means "no header": a read error throws.
|
|
648
|
+
if (!(err instanceof AddModuleRefusedError))
|
|
649
|
+
throw err;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return (sitePath) => {
|
|
653
|
+
if (noPublicTree && isRemovedPublicRoutePath(sitePath))
|
|
654
|
+
return false;
|
|
655
|
+
if (surfaces === undefined || !sitePath.startsWith(`${ROUTE_ROOT}/`))
|
|
656
|
+
return true;
|
|
657
|
+
const top = `${ROUTE_ROOT}/${sitePath.slice(ROUTE_ROOT.length + 1).split("/")[0]}`;
|
|
658
|
+
const surface = GATEABLE_SURFACES.find((s) => s.routes.includes(top));
|
|
659
|
+
return surface === undefined || surfaces.has(surface.id);
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
/** The count check mode fails on: missing, stale and stray route files, orphaned overrides and missing seam aliases. */
|
|
469
663
|
export function routesFailing(drift) {
|
|
470
|
-
return drift.missing.length +
|
|
664
|
+
return (drift.missing.length +
|
|
665
|
+
drift.stale.length +
|
|
666
|
+
drift.stray.length +
|
|
667
|
+
drift.orphanedOverrides.length +
|
|
668
|
+
drift.seamAliasMissing.length);
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* The two site files that bind a `siteSeam` package's `<package>/site` to
|
|
672
|
+
* the site's config (#11257 D4, SEC-11257-1): `next.config.mjs`'s
|
|
673
|
+
* `resolve.alias` key and `jest.config.cjs`'s `moduleNameMapper` key, read as
|
|
674
|
+
* text. A missing line means a build or a suite would bind the package's
|
|
675
|
+
* stub, so check mode fails naming the file; a file the site does not have
|
|
676
|
+
* is named too.
|
|
677
|
+
*/
|
|
678
|
+
function seamAliasMissing(web, siteDir, manifests) {
|
|
679
|
+
const out = [];
|
|
680
|
+
for (const manifest of manifests) {
|
|
681
|
+
if (!manifest.siteSeam || manifest.routes.length === 0)
|
|
682
|
+
continue;
|
|
683
|
+
const wants = [
|
|
684
|
+
["next.config.mjs", `"${manifest.package}/site$"`],
|
|
685
|
+
["jest.config.cjs", `"^${manifest.package}/site$"`],
|
|
686
|
+
];
|
|
687
|
+
for (const [file, alias] of wants) {
|
|
688
|
+
const path = join(web, file);
|
|
689
|
+
const text = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
690
|
+
if (!text.includes(alias))
|
|
691
|
+
out.push(`${relative(siteDir, path).split(sep).join("/")}: ${alias}`);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return out;
|
|
471
695
|
}
|
|
472
696
|
/** How the site's route files and message overrides differ from the installed page packages. `routesFailing` zero means in sync. */
|
|
473
697
|
export function checkRoutes(siteDir) {
|
|
@@ -480,6 +704,7 @@ export function checkRoutes(siteDir) {
|
|
|
480
704
|
notCarried,
|
|
481
705
|
siteKept: [],
|
|
482
706
|
orphanedOverrides: orphanedOverrides(web, root, manifests),
|
|
707
|
+
seamAliasMissing: seamAliasMissing(web, root, manifests),
|
|
483
708
|
generated: planned.length,
|
|
484
709
|
};
|
|
485
710
|
const known = new Set();
|
|
@@ -502,7 +727,13 @@ export function checkRoutes(siteDir) {
|
|
|
502
727
|
if (manifest.routes.length === 0)
|
|
503
728
|
continue;
|
|
504
729
|
const kept = new Set(manifest.siteOwned.map((path) => relative(root, join(web, LOCALE_DIR, path)).split(sep).join("/")));
|
|
505
|
-
|
|
730
|
+
const rootPage = join(web, LOCALE_DIR, ROOT_PAGE);
|
|
731
|
+
const underPrefixes = [
|
|
732
|
+
...(manifest.localeRoot && existsSync(rootPage) ? [relative(root, rootPage).split(sep).join("/")] : []),
|
|
733
|
+
...manifest.prefix.flatMap((prefix) => routingFilesUnder(web, root, prefix)),
|
|
734
|
+
...manifest.appPrefixes.flatMap((prefix) => routingFilesUnder(web, root, prefix, "app")),
|
|
735
|
+
];
|
|
736
|
+
for (const sitePath of underPrefixes) {
|
|
506
737
|
if (known.has(sitePath))
|
|
507
738
|
continue;
|
|
508
739
|
known.add(sitePath);
|
|
@@ -594,16 +825,23 @@ function orphanedOverrides(web, siteDir, manifests) {
|
|
|
594
825
|
/** Write every generated file that is missing or stale; a recorded route is left exactly as it is. */
|
|
595
826
|
export function writeRoutes(siteDir) {
|
|
596
827
|
const { planned } = plan(siteDir);
|
|
597
|
-
const result = { written: [], current: [], recorded: [] };
|
|
828
|
+
const result = { written: [], current: [], recorded: [], kept: [] };
|
|
598
829
|
for (const p of planned) {
|
|
599
830
|
const exists = existsSync(p.absPath);
|
|
600
831
|
if (p.record) {
|
|
601
832
|
result.recorded.push({ path: p.sitePath, state: exists ? "replaced" : "removed", id: p.record.id });
|
|
602
833
|
continue;
|
|
603
834
|
}
|
|
604
|
-
if (exists
|
|
605
|
-
|
|
606
|
-
|
|
835
|
+
if (exists) {
|
|
836
|
+
const text = readFileSync(p.absPath, "utf8");
|
|
837
|
+
if (text === p.text) {
|
|
838
|
+
result.current.push(p.sitePath);
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
if (!isGenerated(text)) {
|
|
842
|
+
result.kept.push(p.sitePath);
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
607
845
|
}
|
|
608
846
|
mkdirSync(dirname(p.absPath), { recursive: true });
|
|
609
847
|
writeFileSync(p.absPath, p.text);
|
|
@@ -643,7 +881,12 @@ page takes the site's config it imports the manifest's config file from the
|
|
|
643
881
|
app root (apps/web/account.config.tsx, say) and passes it in. Replace or remove a shipped route by recording it in
|
|
644
882
|
customizations.yaml (an entry whose paths match the route file): a recorded
|
|
645
883
|
route is reported as replaced or removed, never failed, and --write never
|
|
646
|
-
touches it.
|
|
884
|
+
touches it. A manifest may list several prefixes, and one manifest with
|
|
885
|
+
"root": true may ship the locale-root page.tsx. A manifest with
|
|
886
|
+
"siteGated": true ships only the routes the site selected: its public pages
|
|
887
|
+
are not carried when .ailk-site-manifest.json lists no marketing module, and
|
|
888
|
+
neither is any page under a surface the architecture.yaml "# Surfaces:" header
|
|
889
|
+
leaves out. Run --write after \`pnpm install\` (the manifests are read from the
|
|
647
890
|
installed packages); the scaffold's preflight runs --check as \`pnpm routes:check\`.
|
|
648
891
|
`;
|
|
649
892
|
/** Parse the argv AFTER the `routes` word. Strict `node:util` parseArgs, like `parseSyncRoutesArgs`. */
|
|
@@ -682,6 +925,7 @@ export function formatRoutesReport(result, mode) {
|
|
|
682
925
|
...drift.stale.map((p) => ` stale: ${p}`),
|
|
683
926
|
...drift.stray.map((p) => ` stray: ${p}`),
|
|
684
927
|
...drift.orphanedOverrides.map((p) => ` orphaned override: ${p}`),
|
|
928
|
+
...drift.seamAliasMissing.map((p) => ` missing site seam alias: ${p}`),
|
|
685
929
|
];
|
|
686
930
|
if (failing.length === 0) {
|
|
687
931
|
lines.push(`[create-ailk] routes: OK — ${drift.generated} generated route file(s) in sync`);
|
|
@@ -695,6 +939,8 @@ export function formatRoutesReport(result, mode) {
|
|
|
695
939
|
lines.push(`[create-ailk] routes: wrote ${write.written.length} route file(s), ${write.current.length} already current`);
|
|
696
940
|
for (const p of write.written)
|
|
697
941
|
lines.push(` wrote: ${p}`);
|
|
942
|
+
for (const p of write.kept)
|
|
943
|
+
lines.push(` kept (not a generated file, never overwritten): ${p}`);
|
|
698
944
|
}
|
|
699
945
|
for (const r of result.recorded)
|
|
700
946
|
lines.push(` ${r.state} (recorded): ${r.path} — customizations.yaml "${r.id}"`);
|