@@ -399,6 +399,10 @@ import { readClause2Line, readMetadataProtocolLine } from './pm/clause2-line.mjs
399399// this gate into a sandbox (`objectui-changeset-digest.mjs`), because two hand
400400// lists for one graph is how one of them goes stale unnoticed.
401401import { stageFirstPartyClosure } from './first-party-closure.mjs';
402+ // #26220 — the workspace's package globs, through the repo's ONE parse of
403+ // `pnpm-workspace.yaml` rather than a hand-kept list of roots (see
404+ // `workspaceGlobsAt`).
405+ import { WORKSPACE_FILE, WorkspaceEnumerationError, isExclusionGlob, parseWorkspaceGlobs } from './workspace-enumerator.mjs';
402406
403407// ── The self-test's own battery roster and floor (#13489) ──────────────────
404408//
@@ -533,8 +537,6 @@ export const MIGRATION_LEDGER_ENTRY_DIRS = [
533537const WITNESS_GENERATOR = 'packages/spec/scripts/build-spec-changes.ts';
534538const WITNESS_INPUTS = ['packages/spec/src', 'packages/spec/scripts', 'packages/spec/package.json'];
535539
536- /** Package roots holding workspace manifests, for the `unpublished` precondition. */
537- const PACKAGE_ROOTS = ['packages', 'apps', 'examples'];
538540
539541/**
540542 * The closed disposition vocabulary. Adding a category is a deliberate act.
@@ -2663,21 +2665,82 @@ export function assertInputs({ cwd, head, witness = generatedWitness }) {
26632665// Workspace manifests -- the `unpublished` precondition
26642666// ---------------------------------------------------------------------------
26652667
2668+ /**
2669+ * The workspace's package globs at a rev -- `pnpm-workspace.yaml` read from git and
2670+ * parsed by `workspace-enumerator.mjs`, the repo's one parse of it (#26220).
2671+ *
2672+ * This gate used to carry its own `PACKAGE_ROOTS = ['packages', 'apps', 'examples']`.
2673+ * That list predates the objectui import, so every `@object-ui/*` package (the
2674+ * `ui/packages/*`, `ui/apps/*` and `ui/examples/*` globs) had no workspace manifest
2675+ * here, and every disposition that reads one -- `unpublished`, `type-surface-only`
2676+ * predicate 1, `runtime-export-retired` predicate 1 -- refused a true claim about
2677+ * them. A hand-kept copy of the workspace's membership is the same drift #14378
2678+ * found in a different file; the workspace's own declaration cannot drift from
2679+ * itself. Read at the REV being judged, never from the working tree, so the gate
2680+ * stays a pure function of its two revs.
2681+ *
2682+ * A missing file, an empty or duplicate `packages:` block and a glob richer than
2683+ * `<dir>` / `<dir>/*` are REFUSED with `WorkspaceEnumerationError`, never read as an
2684+ * empty workspace: every disposition above would then answer "no workspace
2685+ * manifest" about a package that has one.
2686+ *
2687+ * @returns {string[]} the inclusion globs; an exclusion (`!pattern`) enumerates nothing
2688+ */
2689+ export function workspaceGlobsAt(rev, cwd) {
2690+ const source = `${WORKSPACE_FILE} at ${rev.slice(0, 12)}`;
2691+ const text = showOrNull(rev, WORKSPACE_FILE, cwd);
2692+ if (text === null) {
2693+ throw new WorkspaceEnumerationError(
2694+ `${source} is missing -- the workspace's package globs cannot be read, so no package can be\n` +
2695+ ' matched to its manifest. Refused rather than read as an empty workspace (#4690).',
2696+ );
2697+ }
2698+ const globs = parseWorkspaceGlobs(text, { source }).filter((g) => !isExclusionGlob(g));
2699+ for (const g of globs) {
2700+ if (g.replace(/\/\*$/, '').includes('*')) {
2701+ throw new WorkspaceEnumerationError(
2702+ `${source}: pattern ${JSON.stringify(g)} is richer than \`<dir>\` or \`<dir>/*\`, the two shapes\n` +
2703+ ' `workspace-enumerator.mjs` expands. Teach both readers the new shape in one edit;\n' +
2704+ ' matching fewer manifests would refuse true claims about the packages left out.',
2705+ );
2706+ }
2707+ }
2708+ return globs;
2709+ }
2710+
2711+ /**
2712+ * Is `manifest` (a repo-relative `<dir>/package.json`) a workspace member's
2713+ * manifest under `globs`? `<dir>` names that directory; `<dir>/*` names each
2714+ * directory directly under it -- the expansion `expandWorkspaceGlob` performs on a
2715+ * working tree, applied here to a path listed from a rev.
2716+ */
2717+ export function isWorkspaceManifest(manifest, globs) {
2718+ if (!manifest.endsWith('/package.json') || manifest.includes('node_modules/')) return false;
2719+ const dir = manifest.slice(0, -'/package.json'.length);
2720+ const parent = posix.dirname(dir);
2721+ const leaf = posix.basename(dir);
2722+ return globs.some((g) => (g.endsWith('/*')
2723+ ? parent === g.slice(0, -2) && !leaf.startsWith('.')
2724+ : dir === g));
2725+ }
2726+
26662727/**
26672728 * name -> { private, file } for every workspace package at a rev.
26682729 *
26692730 * Read from git rather than the working tree so the whole gate is a pure function
26702731 * of two revs, which is what lets the self-test drive the shipping code path with
2671- * real temp repositories instead of an imitation of it.
2732+ * real temp repositories instead of an imitation of it. The members are the ones
2733+ * the rev's own `pnpm-workspace.yaml` declares (`workspaceGlobsAt`).
26722734 */
26732735export function workspacePackagesAt(rev, cwd) {
26742736 const pkgs = new Map();
2737+ const globs = workspaceGlobsAt(rev, cwd);
26752738 let out;
26762739 try { out = git(['ls-tree', '-r', '--name-only', rev], cwd); } catch { return pkgs; }
26772740 const manifests = out
26782741 .split('\n')
26792742 .map((s) => s.trim())
2680- .filter((p) => p.endsWith('/package.json') && !p.includes('node_modules/') && PACKAGE_ROOTS.some((r) => p.startsWith(`${r}/`) ));
2743+ .filter((p) => isWorkspaceManifest(p, globs ));
26812744 for (const [p, raw] of showManyOrNull(rev, manifests, cwd)) {
26822745 try {
26832746 const json = JSON.parse(raw);
@@ -4537,6 +4600,7 @@ function readExportSurface(rev, cwd, pkgName, pkgs, kit) {
45374600 const fromVirtual = (f) => (f.startsWith(VIRTUAL_ROOT) ? f.slice(VIRTUAL_ROOT.length) : null);
45384601 const options = {
45394602 noEmit: true, skipLibCheck: true, types: [], lib: ['lib.es2022.d.ts'],
4603+ jsx: ts.JsxEmit.Preserve,
45404604 target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.Bundler,
45414605 };
45424606 const real = ts.createCompilerHost(options, true);
@@ -5587,7 +5651,16 @@ function selfTest() {
55875651 '# ADR-0087 (fixture)\n\n' +
55885652 cats.map((c) => `<!-- adr-0087: not-required (${c}) ... -->\n`).join('');
55895653
5590- const build = ({ baseIds = ['old-entry-one', 'old-entry-two'], headIds = null, files = {}, baseFiles = {}, pkgs = null }) => {
5654+ // The fixture's `pnpm-workspace.yaml` (#26220): the real file's glob shapes,
5655+ // `ui/packages/*` among them, so a fixture package is a member exactly when it
5656+ // would be one in this repository. `workspace: null` writes none.
5657+ const WORKSPACE_YAML =
5658+ 'packages:\n - packages/*\n - packages/apps/*\n - packages/drivers/*\n - packages/plugins/*\n' +
5659+ ' - packages/qa/*\n - packages/triggers/*\n - packages/services/*\n - packages/adapters/*\n' +
5660+ ' - packages/connectors/*\n - apps/*\n - examples/*\n' +
5661+ ' # the objectui tree\n - ui\n - ui/packages/*\n - ui/apps/*\n - ui/examples/*\n';
5662+
5663+ const build = ({ baseIds = ['old-entry-one', 'old-entry-two'], headIds = null, files = {}, baseFiles = {}, pkgs = null, workspace = WORKSPACE_YAML }) => {
55915664 const dir = mkdtempSync(join(tmpdir(), 'adr0087-'));
55925665 const w = (rel, text) => {
55935666 mkdirSync(dirname(join(dir, rel)), { recursive: true });
@@ -5601,6 +5674,7 @@ function selfTest() {
56015674 w(LEDGER_SOURCES[1], CONV(['a-conversion']));
56025675 w(WITNESS_GENERATOR, WITNESS_GEN());
56035676 w(ADR_0087, ADR_DOC());
5677+ if (workspace !== null) w(WORKSPACE_FILE, workspace);
56045678 // stock: one declared-breaking changeset -- realistic mid-cycle stock for
56055679 // the inherited-changeset cases. (No longer needed to satisfy assertInputs:
56065680 // since #8658 its convention-rot control is synthetic and phase-independent.)
0 commit comments