@se-studio/project-build 1.7.0 → 1.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @se-studio/project-build
2
2
 
3
+ ## 1.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 621653a: marketing-routes.json gains `peopleTypeSlug` (CMS custom type slug for people when it differs from the `peopleSlug` URL; written as `PEOPLE_TYPE_SLUG`, kept by `--from-cms --write`) and `segmentConfig` (path-keyed literal `dynamic`, `revalidate`, `dynamicParams`, `fetchCache`, `runtime`, `preferredRegion` exports on generated pages; illegal keys, values and paths are rejected). Bugfix: `enableArticleTypeIndex` is now true only when `articlesSlug` is a non-empty string, so a site with article types and no `articlesSlug` no longer gets a phantom `/articles/` index (regenerate `marketing-flags.ts`). `check-marketing-routes` accepts `route-build-policy.json` entries for pages on `allowHandWrittenPages`. `generate-marketing-routes --write` keeps hand-added `route-build-policy.json` entries for `allowHandWrittenPages` pages, `check-marketing-routes` now fails on an illegal `segmentConfig` instead of swallowing the render error, `enableArticleTypeTagIndex` is documented as intentionally independent of `articlesSlug`, and the README notes that `dynamic: 'force-dynamic'` and `runtime: 'edge'` opt out of static rendering for that route.
8
+
3
9
  ## 1.7.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -182,6 +182,19 @@ An index that is off writes no page (so it 404s) and the matching `enable…Inde
182
182
 
183
183
  That serves `/people/` and `/person/{slug}/`, and `/tag/{slug}/` with no `/tags/`. The generated person and tag pages pass their own served path to the handlers, so the canonical is always the URL that served the page. A config that declares any of the four keys also writes `PERSON_DETAIL_BASE` / `PERSON_DETAIL_SLUG` and `TAG_DETAIL_BASE` / `TAG_DETAIL_SLUG` into `src/generated/marketing-slugs.ts`. Build person and tag links (`section-urls.ts`, `urlCalculators`, sitemap sources) from those constants, not from `PEOPLE_BASE` / `TAGS_BASE`, or internal links point at the index segment while the page lives at the detail segment.
184
184
 
185
+ ##### People custom type slug, segment config, and the article-type index flag
186
+
187
+ | Key | Meaning | Default |
188
+ |-----|---------|---------|
189
+ | `peopleTypeSlug` | CMS custom type slug backing the people section, when it differs from the URL (`/people/` and `/person/{slug}/`, custom type `person`). Written as `PEOPLE_TYPE_SLUG` in `marketing-slugs.ts` and used for `getCustomType`, the person `customType` lookup and the sitemap people backing type. `peopleSlug` / `personSlug` stay the URL segments. `--from-cms --write` keeps it | the value of `peopleSlug` (no constant is written) |
190
+ | `segmentConfig` | `{ "<generated page path>": { "dynamic": "force-static" } }`. Each key is written as `export const key = <literal>;` at the end of that generated page. Allowed keys: `dynamic`, `revalidate`, `dynamicParams`, `fetchCache`, `runtime`, `preferredRegion`, each with a literal value Next.js accepts. An unknown key, a non-literal value, a path that is not a generated page, or a path on `allowHandWrittenPages` is an error. The checker flags a page edited away from it. `--from-cms --write` keeps it | none: no extra exports |
191
+
192
+ `enableArticleTypeIndex` (bugfix, not an opt-in) is `true` only when `articlesSlug` is a non-empty string. It used to be `true` for a site with article types and `articlesSlug: null`, which could add a phantom `/articles/` sitemap entry. Article type index pages at their `indexSlug` are unaffected. `enableArticleTypeTagIndex` is deliberately **not** tied to `articlesSlug`: it stays `tagInPath && (articlesSlug || articleTypes)` because tag-in-path indexes live on article-type routes such as `/resources/events/{tag}/` and need no parent hub. A site with `tagInPath: true`, `articlesSlug: null` and `articleTypes` keeps `enableArticleTypeTagIndex = true` (and `enableArticleTypeIndex = false`), so its tag URLs stay in the sitemap. A site that kept `enableArticleTypeIndex = false` by hand can drop that after regenerating; a site with `articlesSlug` set sees no change.
193
+
194
+ **`segmentConfig` trades away static rendering.** `dynamic: 'force-dynamic'` and `runtime: 'edge'` are accepted by design, as opt-ins. Each one removes static rendering (SSG/ISR, and the R5 `mustBeSsgOrStatic` guarantee for that route) from that generated CMS route: the page renders per request, or on the edge runtime with its limits. Use them only on a page that really needs it. `force-static`, `revalidate` and `dynamicParams` keep the route static. `check-marketing-routes` fails when `segmentConfig` is illegal (unknown key, non-literal value, a path that is not a generated page or is on `allowHandWrittenPages`), the same error `generate-marketing-routes` reports.
195
+
196
+ **Hand-added build policy for allowlisted pages.** `generate-marketing-routes --write` regenerates the generated-route entries of `mustBeSsgOrStatic` but keeps hand-added entries that match an `allowHandWrittenPages` entry by URL shape; other unknown routes are dropped. `check-marketing-routes` accepts a `route-build-policy.json` `mustBeSsgOrStatic` entry whose route matches an `allowHandWrittenPages` entry (by URL shape), so a hand-written page keeps the SSG guard. A route that is neither generated nor allowlisted still fails.
197
+
185
198
  **Keep a custom tag listing or filter.** Pass `renderTagListing` to `createRouteHandlers` in `src/lib/route-handlers.ts`. `generateTagPage` calls it after the tag's own content and renders the result inside the layout, so the generated `tag/[tag]` page keeps the site's filter tabs and article list with no hand-written route and no generator fork:
186
199
 
187
200
  ```tsx
@@ -91,6 +91,7 @@ if (fromCms) {
91
91
  articleTypes,
92
92
  tagTypes,
93
93
  peopleSlug: hand.peopleSlug,
94
+ peopleTypeSlug: hand.peopleTypeSlug,
94
95
  tagsSlug: hand.tagsSlug,
95
96
  articlesSlug: hand.articlesSlug,
96
97
  personSlug: hand.personSlug,
@@ -118,10 +118,12 @@ function pathOrNull(slug, label, problems) {
118
118
  * `tags`. Role words still win when the slug is `people`, `tags`, or `articles`.
119
119
  *
120
120
  * @param {string} slug
121
- * @param {{ person?: string | null, tag?: string | null, article?: string | null }} declared
121
+ * @param {{ person?: string | null, personType?: string | null, tag?: string | null, article?: string | null }} declared
122
122
  */
123
123
  function declaredRole(slug, declared) {
124
- if (declared.person && declared.person === slug) return 'person';
124
+ if (declared.person && (declared.person === slug || declared.personType === slug)) {
125
+ return 'person';
126
+ }
125
127
  if (declared.tag && declared.tag === slug) return 'tag';
126
128
  if (declared.article && declared.article === slug) return 'article';
127
129
  return null;
@@ -129,7 +131,7 @@ function declaredRole(slug, declared) {
129
131
 
130
132
  /**
131
133
  * @param {{ slug?: string, name?: string }} entry
132
- * @param {{ person?: string | null, tag?: string | null, article?: string | null }} declared
134
+ * @param {{ person?: string | null, personType?: string | null, tag?: string | null, article?: string | null }} declared
133
135
  * @returns {{ role: string, slug: string } | { error: string }}
134
136
  */
135
137
  function prefixOf(entry, declared) {
@@ -238,6 +240,7 @@ function claimRest(used, rest, label, problems) {
238
240
  * articleTypes?: { slug?: string, name?: string, indexPageSlug?: string }[],
239
241
  * tagTypes?: { slug?: string, name?: string, show?: boolean }[],
240
242
  * peopleSlug?: string | null,
243
+ * peopleTypeSlug?: string | null,
241
244
  * tagsSlug?: string | null,
242
245
  * articlesSlug?: string | null,
243
246
  * personSlug?: string | null,
@@ -259,6 +262,7 @@ export function planFromCms(input) {
259
262
  const options = input.articleTypeOptions ?? {};
260
263
  const declared = {
261
264
  person: handSlug(input, 'peopleSlug', null),
265
+ personType: handSlug(input, 'peopleTypeSlug', null),
262
266
  tag: handSlug(input, 'tagsSlug', null),
263
267
  article: handSlug(input, 'articlesSlug', null),
264
268
  };
@@ -312,6 +316,7 @@ export function planFromCms(input) {
312
316
  }
313
317
  }
314
318
  const peopleSlug = handSlug(input, 'peopleSlug', prefixes.person, problems);
319
+ const peopleTypeSlug = handSlug(input, 'peopleTypeSlug', null, problems);
315
320
  const tagsSlug = handSlug(input, 'tagsSlug', prefixes.tag, problems);
316
321
  const articlesSlug = handSlug(input, 'articlesSlug', prefixes.article, problems);
317
322
  const personBase =
@@ -416,13 +421,14 @@ export function planFromCms(input) {
416
421
  if (problems.length > 0) {
417
422
  return { ok: false, problems };
418
423
  }
419
- const hasArticles = articleTypes.length > 0 || Boolean(articlesSlug);
424
+ const hasArticles = Boolean(articlesSlug);
420
425
  const hasTags = tagTypes.length > 0 || Boolean(tagBase);
421
426
  const hasPeople = personTypes.length > 0 || Boolean(personBase);
422
427
  return {
423
428
  ok: true,
424
429
  warnings,
425
430
  peopleSlug,
431
+ peopleTypeSlug,
426
432
  tagsSlug,
427
433
  articlesSlug,
428
434
  personTypes: [...new Set(personTypes)].sort(),
@@ -474,6 +480,7 @@ export function sectionConfigFromPlan(hand, plan) {
474
480
  tagInPath,
475
481
  peopleSlug: plan.peopleSlug,
476
482
  ...shapeKeys(hand, 'personSlug', 'enablePeopleIndex'),
483
+ ...(plan.peopleTypeSlug ? { peopleTypeSlug: plan.peopleTypeSlug } : {}),
477
484
  tagsSlug: plan.tagsSlug,
478
485
  ...shapeKeys(hand, 'tagSlug', 'enableTagsIndex'),
479
486
  articlesSlug: plan.articlesSlug,
@@ -490,6 +497,9 @@ export function sectionConfigFromPlan(hand, plan) {
490
497
  if (Array.isArray(hand.allowHandWrittenPages) && hand.allowHandWrittenPages.length > 0) {
491
498
  next.allowHandWrittenPages = hand.allowHandWrittenPages;
492
499
  }
500
+ if (hand.segmentConfig && typeof hand.segmentConfig === 'object') {
501
+ next.segmentConfig = hand.segmentConfig;
502
+ }
493
503
  return next;
494
504
  }
495
505
 
@@ -55,6 +55,22 @@ export function isSectionConfig(config) {
55
55
  /** Keys that opt a section config in to separate index and detail segments. */
56
56
  const SHAPE_KEYS = ['personSlug', 'tagSlug', 'enablePeopleIndex', 'enableTagsIndex'];
57
57
 
58
+ /**
59
+ * CMS custom type slug backing the people section. `peopleSlug` is the URL segment and
60
+ * defaults the type slug; `peopleTypeSlug` is set only when the custom type is named
61
+ * differently (URL `/people/`, custom type `person`). Never changes a URL.
62
+ *
63
+ * @param {Record<string, unknown>} config
64
+ * @returns {string} '' when there is no people section
65
+ */
66
+ export function peopleTypeSlug(config) {
67
+ const value = config.peopleTypeSlug;
68
+ if (value === undefined || value === null) {
69
+ return typeof config.peopleSlug === 'string' ? config.peopleSlug : '';
70
+ }
71
+ return requireSegment(value, 'peopleTypeSlug');
72
+ }
73
+
58
74
  /**
59
75
  * URL shape of the people and tag sections. `peopleSlug` / `tagsSlug` name the index
60
76
  * and the type prefix. `personSlug` / `tagSlug` name the singular detail segment and
@@ -102,6 +118,7 @@ export function sectionShape(config) {
102
118
  tagBase: detail('tagSlug', tags),
103
119
  peopleIndex: index('enablePeopleIndex', people, 'peopleSlug'),
104
120
  tagsIndex: index('enableTagsIndex', tags, 'tagsSlug'),
121
+ peopleType: peopleTypeSlug(config),
105
122
  declared: SHAPE_KEYS.some((key) => config[key] !== undefined),
106
123
  };
107
124
  }
@@ -118,8 +135,12 @@ export function sectionFlags(config) {
118
135
  const articles = typeof config.articlesSlug === 'string';
119
136
  const articleTypes = Array.isArray(config.articleTypes) && config.articleTypes.length > 0;
120
137
  const tagInPath = config.tagInPath === true;
138
+ // enableArticleTypeIndex gates only the articlesSlug hub (/articles/ or /resources/ as a section
139
+ // index). enableArticleTypeTagIndex is deliberately NOT tied to it: tag-in-path indexes live on
140
+ // article-type routes (/resources/events/{tag}/) and need no parent hub. Live sites (Pedestal,
141
+ // Headwater) have tagInPath, articlesSlug null and articleTypes, and must keep the flag true.
121
142
  return {
122
- enableArticleTypeIndex: articles || articleTypes,
143
+ enableArticleTypeIndex: articles && config.articlesSlug.length > 0,
123
144
  enableArticleTypeTagIndex: tagInPath && (articles || articleTypes),
124
145
  enableTag: tags || tagTypes,
125
146
  enableTagsIndex: shape.tagsIndex,
@@ -541,7 +562,7 @@ export function checkMarketingRoutes(appRoot) {
541
562
  ...handlerProblems,
542
563
  ...drift,
543
564
  ...supportDrift(appRoot, config),
544
- ...policyProblems(appRoot, allowed),
565
+ ...policyProblems(appRoot, allowed, handWritten),
545
566
  ...proxyMarkdownProblems(appRoot),
546
567
  ];
547
568
  const note = warnings.length > 0 ? ` [warning: ${warnings.join('; ')}]` : '';
@@ -570,6 +591,87 @@ export function checkMarketingRoutes(appRoot) {
570
591
  * @returns {Map<string, string>} rest → file contents
571
592
  */
572
593
  export function renderGeneratedRoutes(config) {
594
+ const files = renderRoutesBase(config);
595
+ applySegmentConfig(config, files);
596
+ return files;
597
+ }
598
+
599
+ /** Next.js route segment config keys a generated page may export, with their literal check. */
600
+ const SEGMENT_CONFIG_KEYS = {
601
+ dynamic: (v) => ['auto', 'force-dynamic', 'error', 'force-static'].includes(v),
602
+ revalidate: (v) => v === false || (Number.isInteger(v) && v >= 0),
603
+ dynamicParams: (v) => typeof v === 'boolean',
604
+ fetchCache: (v) =>
605
+ [
606
+ 'auto',
607
+ 'default-cache',
608
+ 'only-cache',
609
+ 'force-cache',
610
+ 'force-no-store',
611
+ 'default-no-store',
612
+ 'only-no-store',
613
+ ].includes(v),
614
+ runtime: (v) => v === 'nodejs' || v === 'edge',
615
+ preferredRegion: (v) =>
616
+ typeof v === 'string'
617
+ ? /^[a-z0-9-]+$/.test(v)
618
+ : Array.isArray(v) && v.length > 0 && v.every((r) => typeof r === 'string' && /^[a-z0-9-]+$/.test(r)),
619
+ };
620
+
621
+ /**
622
+ * `segmentConfig` is `{ "<generated page rest>": { "dynamic": "force-static" } }`. Each
623
+ * known key is written as `export const key = <literal>;` at the end of that generated
624
+ * page. Unknown keys, non-literal values and paths that are not a generated page throw.
625
+ *
626
+ * @param {unknown} config
627
+ * @param {Map<string, string>} files rest → file contents, updated in place
628
+ */
629
+ function applySegmentConfig(config, files) {
630
+ const raw = config && typeof config === 'object' ? config.segmentConfig : undefined;
631
+ if (raw === undefined || raw === null) {
632
+ return;
633
+ }
634
+ if (typeof raw !== 'object' || Array.isArray(raw)) {
635
+ throw new Error('marketing-routes.json segmentConfig must be an object keyed by page path');
636
+ }
637
+ const allow = handWrittenAllowlist(config);
638
+ for (const [key, entry] of Object.entries(raw)) {
639
+ const rest = key.replace(/^\/+|\/+$/g, '');
640
+ if (!files.has(rest)) {
641
+ throw new Error(`segmentConfig path "${key}" is not a generated marketing page`);
642
+ }
643
+ if (isAllowlisted(allow, rest)) {
644
+ throw new Error(
645
+ `segmentConfig path "${key}" is in allowHandWrittenPages: a hand-written page exports its own config`,
646
+ );
647
+ }
648
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
649
+ throw new Error(`segmentConfig "${key}" must be an object of segment config keys`);
650
+ }
651
+ const lines = [];
652
+ for (const [name, value] of Object.entries(entry)) {
653
+ const valid = Object.hasOwn(SEGMENT_CONFIG_KEYS, name) ? SEGMENT_CONFIG_KEYS[name] : null;
654
+ if (!valid) {
655
+ throw new Error(
656
+ `segmentConfig "${key}": "${name}" is not an allowed key (${Object.keys(SEGMENT_CONFIG_KEYS).join(', ')})`,
657
+ );
658
+ }
659
+ if (!valid(value)) {
660
+ throw new Error(`segmentConfig "${key}": illegal value for ${name}: ${JSON.stringify(value)}`);
661
+ }
662
+ lines.push(`export const ${name} = ${JSON.stringify(value).replace(/"/g, "'")};`);
663
+ }
664
+ if (lines.length > 0) {
665
+ files.set(rest, `${files.get(rest)}\n${lines.join('\n')}\n`);
666
+ }
667
+ }
668
+ }
669
+
670
+ /**
671
+ * @param {unknown} config
672
+ * @returns {Map<string, string>}
673
+ */
674
+ function renderRoutesBase(config) {
573
675
  if (!config || typeof config !== 'object') {
574
676
  throw new Error('marketing-routes.json must be an object');
575
677
  }
@@ -727,6 +829,12 @@ export const ARTICLE_DETAIL_TYPE_SLUGS = ${slugList(
727
829
  `
728
830
  : '';
729
831
  const shape = sectionShape(config);
832
+ const typeLine =
833
+ config.peopleTypeSlug === undefined || config.peopleTypeSlug === null
834
+ ? ''
835
+ : `/** CMS custom type slug for people lookups. PEOPLE_SLUG stays the URL segment. */
836
+ export const PEOPLE_TYPE_SLUG = '${shape.peopleType}';
837
+ `;
730
838
  const detailLines = shape.declared
731
839
  ? `export const PERSON_DETAIL_SLUG = '${shape.personBase}';
732
840
  export const PERSON_DETAIL_BASE = ${base(shape.personBase)};
@@ -737,7 +845,7 @@ export const TAG_DETAIL_BASE = ${base(shape.tagBase)};
737
845
  return `${header()}
738
846
  export const PEOPLE_SLUG = '${people}';
739
847
  export const PEOPLE_BASE = ${base(people)};
740
- export const TAGS_SLUG = '${tags}';
848
+ ${typeLine}export const TAGS_SLUG = '${tags}';
741
849
  export const TAGS_BASE = ${base(tags)};
742
850
  export const ARTICLES_SLUG = '${articles}';
743
851
  export const ARTICLES_BASE = ${base(articles)};
@@ -879,8 +987,10 @@ function generatedDrift(appRoot, config) {
879
987
  let files;
880
988
  try {
881
989
  files = renderGeneratedRoutes(config);
882
- } catch {
883
- return drift;
990
+ } catch (error) {
991
+ // An illegal segmentConfig (or other render error) must fail the checker, as it fails generate.
992
+ const message = error instanceof Error ? error.message : String(error);
993
+ return [`generated routes cannot be rendered: ${message}`];
884
994
  }
885
995
  const requireComplete = fs.existsSync(path.join(appRoot, FLAGS_REL));
886
996
  for (const [rest, expected] of files) {
@@ -1127,6 +1237,11 @@ export function mustBeSsgOrStaticRoutes(config) {
1127
1237
  return routes;
1128
1238
  }
1129
1239
 
1240
+ /** `/llms.txt`, `/site-info.md`: a dotted last segment that is not a `[...catchAll]`. */
1241
+ function isTextRoute(route) {
1242
+ return /\/[^/[\]]+\.[A-Za-z0-9]+$/.test(route);
1243
+ }
1244
+
1130
1245
  /**
1131
1246
  * @param {string} appRoot
1132
1247
  * @param {unknown} config
@@ -1137,7 +1252,23 @@ function syncRouteBuildPolicy(appRoot, config) {
1137
1252
  return;
1138
1253
  }
1139
1254
  const policy = JSON.parse(fs.readFileSync(policyPath, 'utf8'));
1140
- policy.mustBeSsgOrStatic = mustBeSsgOrStaticRoutes(config);
1255
+ const generated = mustBeSsgOrStaticRoutes(config);
1256
+ // Keep hand-added entries for allowHandWrittenPages (same URL-shape match the checker uses).
1257
+ // Unknown, non-allowlisted, non-generated routes are dropped, never invented.
1258
+ const handWritten = handWrittenAllowlist(config);
1259
+ const kept = (Array.isArray(policy.mustBeSsgOrStatic) ? policy.mustBeSsgOrStatic : []).filter(
1260
+ (route) =>
1261
+ typeof route === 'string' &&
1262
+ route.startsWith('/') &&
1263
+ !isTextRoute(route) &&
1264
+ !generated.includes(route) &&
1265
+ isAllowlisted(handWritten, route.slice(1)),
1266
+ );
1267
+ policy.mustBeSsgOrStatic = [
1268
+ ...generated.filter((route) => !isTextRoute(route)),
1269
+ ...kept,
1270
+ ...generated.filter(isTextRoute),
1271
+ ];
1141
1272
  fs.writeFileSync(policyPath, `${JSON.stringify(policy, null, 2)}\n`);
1142
1273
  console.log(`Updated ${path.relative(appRoot, policyPath)}`);
1143
1274
  }
@@ -1215,13 +1346,16 @@ function formatGeneratedPages(appRoot) {
1215
1346
  }
1216
1347
 
1217
1348
  /**
1218
- * Bracket CMS routes in route-build-policy.json must be the generated tree.
1349
+ * Bracket CMS routes in route-build-policy.json must be the generated tree. A route the
1350
+ * site hand-wrote and listed in `allowHandWrittenPages` may also be listed, so it keeps
1351
+ * the SSG guard.
1219
1352
  *
1220
1353
  * @param {string} appRoot
1221
1354
  * @param {Set<string>} allowed
1355
+ * @param {Set<string>} [handWritten] from handWrittenAllowlist
1222
1356
  * @returns {string[]}
1223
1357
  */
1224
- function policyProblems(appRoot, allowed) {
1358
+ function policyProblems(appRoot, allowed, handWritten = new Set()) {
1225
1359
  const policyPath = path.join(appRoot, 'route-build-policy.json');
1226
1360
  if (!fs.existsSync(policyPath)) {
1227
1361
  return [];
@@ -1250,7 +1384,7 @@ function policyProblems(appRoot, allowed) {
1250
1384
  continue;
1251
1385
  }
1252
1386
  const rest = route.slice(1);
1253
- if (!allowed.has(rest)) {
1387
+ if (!allowed.has(rest) && !isAllowlisted(handWritten, rest)) {
1254
1388
  problems.push(`route-build-policy.json lists ${route} outside marketing-routes.json`);
1255
1389
  }
1256
1390
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/project-build",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Build tools and management scripts for SE Studio projects",
5
5
  "repository": {
6
6
  "type": "git",