|
159 | 159 | * this gate read nothing -- never that it found nothing. |
160 | 160 | */ |
161 | 161 |
|
162 | | -import { readFileSync } from 'node:fs'; |
| 162 | +import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; |
| 163 | +import { tmpdir } from 'node:os'; |
163 | 164 | import { join } from 'node:path'; |
164 | 165 | import { fileURLToPath } from 'node:url'; |
165 | 166 |
|
@@ -224,6 +225,36 @@ export const DECLARED_WATCH_HINTS = [ |
224 | 225 | 'examples/*/package.json', |
225 | 226 | ]; |
226 | 227 |
|
| 228 | +/** |
| 229 | + * Generic keys that are declared AHEAD of the packages that hold them: the |
| 230 | + * objectui tree is imported under `ui/` (objectstack#25677), and its packages |
| 231 | + * spell these task names, which no package of this workspace declares. The |
| 232 | + * root turbo.json carries their definitions from the wiring PR onwards so the |
| 233 | + * CI jobs for `ui/` are written once and run on the import commit. |
| 234 | + * |
| 235 | + * This is a hold, not an exemption from the rule above, and it has three limits: |
| 236 | + * |
| 237 | + * - it applies ONLY while `UI_IMPORT_MARKER` is absent from the checkout. Once |
| 238 | + * `ui/package.json` exists the hold is void and every key below is judged |
| 239 | + * like any other generic key, so a key the imported tree does not hold reds |
| 240 | + * on the import commit itself; |
| 241 | + * - no root script wraps any of these keys, so the shape this limb was written |
| 242 | + * for (`pnpm <task>` exiting 0 over nothing, #12373) is not reachable here. |
| 243 | + * The only callers are the `ui/` jobs in ci.yml, which skip while the tree |
| 244 | + * is absent; |
| 245 | + * - a listed key that turbo.json does not carry is itself a finding, so the |
| 246 | + * list cannot outlive the entries it holds. |
| 247 | + * |
| 248 | + * Retire the whole map, and `UI_IMPORT_MARKER` with it, once the import has |
| 249 | + * landed: from then on the hold can never apply. |
| 250 | + */ |
| 251 | +export const UI_IMPORT_MARKER = 'ui/package.json'; |
| 252 | +export const GENERIC_TASKS_AWAITING_UI_IMPORT = Object.freeze({ |
| 253 | + 'type-check': "objectui's per-package tsc script (`type-check`, hyphenated); run by the Type Check UI job", |
| 254 | + lint: "objectui's per-package eslint script; run by the Lint UI job", |
| 255 | + 'test:dist': "objectui's built-dist suite of @object-ui/components (dependsOn build)", |
| 256 | +}); |
| 257 | + |
227 | 258 | /** The file this gate judges, as the reader spells it on disk. */ |
228 | 259 | const TURBO_CONFIG_FILE = 'turbo.json'; |
229 | 260 |
|
@@ -347,17 +378,32 @@ export function holdersOf(task, scriptsByPackage) { |
347 | 378 | * @param {Record<string, unknown>} tasks turbo.json's `tasks` table |
348 | 379 | * @param {Map<string, Set<string>>} scriptsByPackage package name -> script names |
349 | 380 | * @param {Set<string>} rootScripts the ROOT manifest's script names, for `//#<task>` |
350 | | - * @returns {{ problems: string[], judged: number, genericJudged: number, rootJudged: number }} |
| 381 | + * @param {Set<string>} [held] generic keys under the `GENERIC_TASKS_AWAITING_UI_IMPORT` |
| 382 | + * hold for THIS checkout -- empty once the import marker exists (see `heldGenericTasks`) |
| 383 | + * @returns {{ problems: string[], judged: number, genericJudged: number, rootJudged: number, heldJudged: number }} |
351 | 384 | */ |
352 | | -export function verdict(tasks, scriptsByPackage, rootScripts) { |
| 385 | +export function verdict(tasks, scriptsByPackage, rootScripts, held = new Set()) { |
353 | 386 | const problems = []; |
354 | 387 | let judged = 0; |
355 | 388 | let genericJudged = 0; |
356 | 389 | let rootJudged = 0; |
| 390 | + let heldJudged = 0; |
| 391 | + for (const key of held) { |
| 392 | + if (!Object.hasOwn(tasks, key)) { |
| 393 | + problems.push( |
| 394 | + `"${key}" is held as awaiting the ui/ import, but ${TURBO_CONFIG_FILE} declares no such key.\n` + |
| 395 | + ` Delete it from GENERIC_TASKS_AWAITING_UI_IMPORT: a hold over nothing is a leftover.`, |
| 396 | + ); |
| 397 | + } |
| 398 | + } |
357 | 399 | for (const key of Object.keys(tasks)) { |
358 | 400 | const split = splitTaskKey(key); |
359 | 401 | if (!split) { |
360 | 402 | genericJudged += 1; |
| 403 | + if (holdersOf(key, scriptsByPackage).length === 0 && held.has(key)) { |
| 404 | + heldJudged += 1; |
| 405 | + continue; |
| 406 | + } |
361 | 407 | if (holdersOf(key, scriptsByPackage).length === 0) { |
362 | 408 | const declaredAnywhere = new Set(); |
363 | 409 | for (const scripts of scriptsByPackage.values()) for (const name of scripts) declaredAnywhere.add(name); |
@@ -434,7 +480,20 @@ export function verdict(tasks, scriptsByPackage, rootScripts) { |
434 | 480 | ); |
435 | 481 | } |
436 | 482 | } |
437 | | - return { problems, judged, genericJudged, rootJudged }; |
| 483 | + return { problems, judged, genericJudged, rootJudged, heldJudged }; |
| 484 | +} |
| 485 | + |
| 486 | +/** |
| 487 | + * The generic keys the ui/ import hold covers on the checkout at `root`: every |
| 488 | + * key of `GENERIC_TASKS_AWAITING_UI_IMPORT` while `UI_IMPORT_MARKER` is absent, |
| 489 | + * and none at all once it exists. |
| 490 | + * |
| 491 | + * @param {string} root |
| 492 | + * @returns {Set<string>} |
| 493 | + */ |
| 494 | +export function heldGenericTasks(root) { |
| 495 | + if (existsSync(join(root, UI_IMPORT_MARKER))) return new Set(); |
| 496 | + return new Set(Object.keys(GENERIC_TASKS_AWAITING_UI_IMPORT)); |
438 | 497 | } |
439 | 498 |
|
440 | 499 | /** |
@@ -563,7 +622,13 @@ function main() { |
563 | 622 | throw err; |
564 | 623 | } |
565 | 624 |
|
566 | | - const { problems, judged, genericJudged, rootJudged } = verdict(tasks, scriptsByPackage, rootScripts); |
| 625 | + const held = heldGenericTasks(ROOT); |
| 626 | + const { problems, judged, genericJudged, rootJudged, heldJudged } = verdict( |
| 627 | + tasks, |
| 628 | + scriptsByPackage, |
| 629 | + rootScripts, |
| 630 | + held, |
| 631 | + ); |
567 | 632 |
|
568 | 633 | if (genericJudged === 0) { |
569 | 634 | console.error( |
@@ -615,7 +680,12 @@ function main() { |
615 | 680 | : '') + |
616 | 681 | ` — every package-scoped one names a package that exists (or the root token ` + |
617 | 682 | `"${ROOT_PACKAGE_TOKEN}") and a script it declares, and every generic one is declared by at ` + |
618 | | - `least one member.`, |
| 683 | + `least one member` + |
| 684 | + (heldJudged |
| 685 | + ? `, except ${heldJudged} held for the ui/ import while ${UI_IMPORT_MARKER} is absent ` + |
| 686 | + `(${[...held].sort().join(', ')})` |
| 687 | + : '') + |
| 688 | + `.`, |
619 | 689 | ); |
620 | 690 | } |
621 | 691 |
|
@@ -659,7 +729,7 @@ function main() { |
659 | 729 | // not red. A battery BELOW its floor means cases stopped running; the remedy is |
660 | 730 | // to find what stopped registering. |
661 | 731 | const SELF_TEST_BATTERIES = Object.freeze({ |
662 | | - 'check-turbo-task-graph self-test': 49, |
| 732 | + 'check-turbo-task-graph self-test': 56, |
663 | 733 | }); |
664 | 734 |
|
665 | 735 | // DELETING an entry silences that battery's floor exactly as effectively as |
@@ -869,6 +939,36 @@ export function selfTest() { |
869 | 939 | t('a near-miss of the root token is still an unknown package', notRoot.problems.length === 1); |
870 | 940 | t('a near-miss of the root token is not in the root population', notRoot.rootJudged === 0); |
871 | 941 |
|
| 942 | + // ── The ui/ import hold, both directions ── |
| 943 | + // Held: a generic key nobody declares is NOT a finding while it is held. |
| 944 | + const heldGeneric = verdict({ 'type-check': {} }, workspace, rootScripts, new Set(['type-check'])); |
| 945 | + t('a generic key held for the ui/ import is not a finding', heldGeneric.problems.length === 0); |
| 946 | + t('a held generic key is counted in the held population', heldGeneric.heldJudged === 1); |
| 947 | + t('a held generic key is still counted in the generic population', heldGeneric.genericJudged === 1); |
| 948 | + // Not held (the marker exists, so the hold set is empty): the same key reds. |
| 949 | + const unheldGeneric = verdict({ 'type-check': {} }, workspace, rootScripts, new Set()); |
| 950 | + t('the same key without the hold is a finding again', unheldGeneric.problems.length === 1); |
| 951 | + // The hold names keys, not a shape: an unlisted inert key beside a held one still reds. |
| 952 | + const heldBeside = verdict({ 'type-check': {}, 'test:e2e': {} }, workspace, rootScripts, new Set(['type-check'])); |
| 953 | + t('an inert key the hold does not list still reds beside a held one', heldBeside.problems.length === 1 |
| 954 | + && heldBeside.problems[0]?.includes('"test:e2e"')); |
| 955 | + // A hold over a key turbo.json does not carry is a leftover. |
| 956 | + const heldNothing = verdict({ build: {} }, workspace, rootScripts, new Set(['type-check'])); |
| 957 | + t('a held key turbo.json does not declare is a finding', heldNothing.problems.length === 1 |
| 958 | + && heldNothing.problems[0]?.includes('a hold over nothing')); |
| 959 | + // The marker decides: an existing marker empties the hold, an absent one fills it. |
| 960 | + t('the hold is void on a checkout carrying the import marker', (() => { |
| 961 | + const dir = mkdtempSync(join(tmpdir(), 'turbo-task-graph-ui-hold-')); |
| 962 | + try { |
| 963 | + const without = heldGenericTasks(dir).size; |
| 964 | + mkdirSync(join(dir, 'ui')); |
| 965 | + writeFileSync(join(dir, UI_IMPORT_MARKER), '{}'); |
| 966 | + return without === Object.keys(GENERIC_TASKS_AWAITING_UI_IMPORT).length && heldGenericTasks(dir).size === 0; |
| 967 | + } finally { |
| 968 | + rmSync(dir, { recursive: true, force: true }); |
| 969 | + } |
| 970 | + })()); |
| 971 | + |
872 | 972 | // ── Direction 2: the rule must stay GREEN on every legitimate shape ── |
873 | 973 | // `gen:schema` stands where `test:e2e` used to: a generic key held by exactly |
874 | 974 | // ONE package is legitimate, and this case is what keeps the limb above from |
|
0 commit comments