Skip to content

Commit 5cf9941

Browse files
chore(release)!: enter Changesets pre mode (next) so 19.0.0 opens; retire the 18.6.0 i18n keys no code reads (#37230)
Fixes #37223 Clause-②: yes (narrowing) Metadata-protocol: none Skills-docs: none — no file under skills/ or content/docs names any of the 67 retired keys (git grep, each key) ## 维护者速读 - 用户无感:合并后主干进入预发布阶段,下一次出版本得到 19.0.0-next.0;同时把 18.6.0 已发布、现已没有代码读取的 67 条界面文案在新大版本里声明退役。 - 属于「界面文案清理」大卡;按你「下一版是大版本 19.0.0」和「走预发布路线」两次裁决,照上一次开大版本(18)时的同款做法。 - 合并本身不发布任何东西:每一次预发布都要你批准才会发出,普通安装拿到的仍是 18.x;若有部署改写过这些文案,改写不再生效;在切出第一个预发布版之前,删掉三个新文件即可撤回。 - 要你做的两件事(按 7158089101 的裁决 A):① 合并前给本单加上 `allow-major` 标签,作为你对 19.0.0 大版本的人工确认;在加标签之前,「Check Changeset」因级别检查(`Metadata-protocol: none` 旁有 `major`)保持红色,属预期,门禁本身不改。② 由你亲自合并本单(和上次开 18 一样,席位只审不合)。 ## What changes 1. **`.changeset/pre.json`**, written by `pnpm changeset pre enter next` (`@changesets/cli` 3.0.3) and committed as the tool wrote it: `{ "mode": "pre", "tag": "next" }`. ⛔ No `changeset version` output is committed, and nothing was published. 2. **`.changeset/37223-v19-line-opens.md`**, front matter `"@objectstack/spec": major`: the v19 line's opening note (rulings 7153326968 and 7153441862), `Clause-②: no`, and its ADR-0087 `not-required (no-migration-prescription)` disposition, in the form the v18 opening (#22084) used. Why spec: the protocol lockstep admits `PROTOCOL_VERSION` one major ahead only in pre mode WITH a pending `@objectstack/spec` major, and `scripts/sync-protocol-version.mjs` derives the protocol version from spec's major. 3. **`.changeset/37223-i18n-removed-released-keys.md`**, `'@object-ui/i18n': major`: the **BREAKING** banner, its own ADR-0087 disposition, and the 「Removed translation keys」 list (67 keys, each once, with its locales). Two majors in one `fixed` group still give one 19.0.0; the changeset says so. 4. **`ui/packages/i18n/scripts/released-keys-removed.mjs`** (zero third-party deps): reads the package's published catalogues out of git at the tag `@object-ui/i18n@18.6.0` and at a ref (default `origin/main`), and prints every key the tag has that the ref lacks, grouped by namespace, with the locales it was removed from. Which files are catalogues is read from the package: `package.json` `exports`, the all-packs door `src/locales/index.ts`, and each non-pack-shaped namespace's `index.ts` (`studio`). No code change, no key restored, no `PROTOCOL_VERSION` edit, no `allow-major` label, no edit to `.changeset/config.json`, to either changeset guard, or to `release.yml`. ## Reproduction ``` $ node ui/packages/i18n/scripts/released-keys-removed.mjs Keys in @object-ui/i18n@18.6.0 absent at origin/main (d15e439): 67 ## locales (32) every one removed from all 11 locales (ar, de, en, es, fr, ja, ko, pt-BR, ru, zh-Hans, zh-Hant) ## studio (35) every one removed from both locales the namespace ships (en, zh) ``` The 35 Studio keys are the ones the card expected (#36501, #36652). The 32 language-pack keys are extra; some of them are also named in earlier pending `patch` changesets, and this one lists the whole 18.6.0 set once for the major's notes. Keys that the open PRs #37169, #37166 and #37168 remove are still on main, so they are not reported or declared here. No non-test file under `ui/`, `apps/` or `packages/` quotes any of the 67 keys. ## The no-major guard reads `pre.json` from the head checkout | Leg | Reading at `e43e989948` | |---|---| | As committed, `node scripts/check-changeset-no-major.mjs --base origin/main` | exit 0: `Changesets is in pre-release mode (tag: next) — major bumps are the expected product of an RC window; skipping the no-major guard.` | | Control, `.changeset/pre.json` deleted from the working tree only | exit 1: `This PR introduces changeset(s) that declare a major bump.` | | Restored with `git checkout HEAD -- .changeset/pre.json` | `git diff HEAD` empty (0 bytes), blob hash equals the HEAD blob, guard exit 0 again | ## Pins (throwaway detached worktree at `e43e989948`, never committed, removed after) - `pnpm changeset version` exits 0. All 112 `fixed`-group members read `19.0.0-next.0`. `pre.json` is unchanged. `packages/spec/CHANGELOG.md` and `ui/packages/i18n/CHANGELOG.md` each open `## 19.0.0-next.0` / `### Major Changes`. - `node scripts/sync-protocol-version.mjs` (the root `version` script's next step) rewrites `PROTOCOL_VERSION` in `packages/spec/src/kernel/protocol-version.ts`: `PROTOCOL_VERSION 18.0.0 → 19.0.0 (lockstep with @objectstack/spec@19.0.0-next.0)`. - `protocol-version.test.ts` on that tree: `Test Files 1 passed (1)`, `Tests 3 passed (3)`. ## `release.yml` in pre mode: `next` gets the prerelease, `latest` stays 18.x A reading of the files; nothing edited, nothing run. - Job `publish`, step `Publish to npm + push version tags` runs `pnpm run release`, which ends in `scripts/release-publish.sh`, which runs `changeset publish` with no `--tag`. - `@changesets/cli` 3.0.3 `getReleaseTag` (`dist/getPublishPlan.mjs:599-601`): with a pre state and no `--tag`, the tag is `preState.tag` = `next`, unless every published version of a package is already a `next` prerelease. `dist/publish.mjs` refuses a custom tag in pre mode. - `npm view` today: `@objectstack/spec` and `@object-ui/i18n` read `latest` = `18.6.0`, `next` = `0.0.0-next-20261125013212` (a snapshot, whose prerelease id is not `next`), so neither is "only-pre". Each publishes `19.0.0-next.0` to `next`; `latest` stays `18.6.0`. ## Acceptance notes - **Open question: the level axis stays red.** `check-changeset-no-major.mjs`'s level axis refuses `Metadata-protocol: none` beside any entry at `minor` or above (verdict `none-minor`). It runs whatever the pre mode is, and only `allow-major` skips the step. Measured at `e43e989948` with a `pull_request` payload carrying this body's two lines: the no-major guard is exempt (pre mode), and the level axis exits 1. The v18 opening passed because its body had no `Metadata-protocol:` line. This PR changes neither the gate nor the declaration. - **The version-PR lane refuses the protocol move.** `release.yml`'s `version-pr` validation marks a pass that rewrites `packages/spec/src/kernel/protocol-version.ts` as UNVALIDATED and refuses it, because the example apps declare `engines.protocol: '^18'` (`examples/app-crm`, `app-showcase`, `app-todo`) and the ADR-0087 D1 handshake would refuse them under 19. So the version step would sync the constant, but that lane will not carry it: `PROTOCOL_VERSION` → 19.0.0 still needs its own reviewed PR (#37229), which should also move the example apps' `engines.protocol`. With this PR's pre mode and pending spec major, the protocol lockstep admits the constant one major ahead. - `pnpm check:pm-dispatch-gates` is green with `pre.json` tracked (`2313 cases pass`), and the #22084 amendment (`CONSUMED_PRERELEASE_EXCLUDED` in `scripts/check-adr-0087-registration.mjs`) is still on main. No gate script is edited. - Landing: the maintainer merges (precedent #22084); seats review only. The PR stays draft. ## Verification Two-minute check: `node scripts/check-changeset-no-major.mjs --base origin/main` prints the pre-mode exemption line and exits 0; `node ui/packages/i18n/scripts/released-keys-removed.mjs` prints `67` on its first line. Read first: 1. `.changeset/pre.json` and `.changeset/37223-v19-line-opens.md`: the line opening. 2. `.changeset/37223-i18n-removed-released-keys.md`: the list. 3. `ui/packages/i18n/scripts/released-keys-removed.mjs`, `discover()`. <details><summary>Local gates at e43e989: 36 commands, all exit 0</summary> ``` exit 0 :: cd ui && node scripts/check-ui-root-lookups.mjs exit 0 :: node scripts/check-adr-0087-registration.mjs --base origin/main exit 0 :: node scripts/check-adr-0087-registration.mjs --self-test exit 0 :: node scripts/check-changeset-fixed.mjs exit 0 :: node scripts/check-changeset-fixed.mjs --self-test exit 0 :: node scripts/check-changeset-no-major.mjs --base origin/main exit 0 :: node scripts/check-changeset-no-major.mjs --self-test exit 0 :: node scripts/check-closing-keyword-parity.mjs exit 0 :: node scripts/check-closing-keyword-parity.mjs --self-test exit 0 :: node scripts/check-comment-mask-corpus.mjs exit 0 :: node scripts/check-empty-changeset.mjs --base origin/main exit 0 :: node scripts/check-empty-changeset.mjs --self-test exit 0 :: node scripts/check-sdui-manifest.mjs exit 0 :: node scripts/check-sdui-manifest.mjs --self-test exit 0 :: node scripts/ci/snapshot-next.mjs --self-test exit 0 :: node scripts/pm/check-governed-queue-guard.mjs --self-test exit 0 :: node scripts/pm/release-rehearsal-clone.mjs --self-test exit 0 :: node scripts/release-pending-publish.mjs --self-test exit 0 :: pnpm check:adr-anchors exit 0 :: pnpm check:changeset-gate-self-tests exit 0 :: pnpm check:closed-ceremony-text exit 0 :: pnpm check:dispatcher-error-vocabulary exit 0 :: pnpm check:docs-image-tag exit 0 :: pnpm check:driver-memory-census exit 0 :: pnpm check:gitlink-declared exit 0 :: pnpm check:nul-bytes exit 0 :: pnpm check:pm-dispatch-gates exit 0 :: pnpm check:published-files exit 0 :: pnpm check:refd-timer-probe exit 0 :: pnpm check:registry-log-declared exit 0 :: pnpm check:rest-log-spy-declared exit 0 :: pnpm check:skill-identifier-liveness exit 0 :: pnpm check:test-source-alias exit 0 :: pnpm check:tier-file-adoption exit 0 :: pnpm check:undeclared-dep-imports exit 0 :: pnpm check:watch-hint-literal ``` `node scripts/check-governed-merges.mjs --pr 37230`: `0 of 4 path(s) hit the register` · `NOT governed` · `368 changed line(s) ≤ 3000`. Dogfood battery (`!` title): `Test Files 487 passed | 3 skipped (490)`, `Tests 4128 passed | 68 skipped (4196)`, lock VERDICT command-exit 0, measured at `e90f9aa1b9`. The commits after it add `.changeset/` files and rework a script nothing imports. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYkkwuF6UuFtu85Yd5H)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYkkwuF6UuFtu85Yd5H --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4ed453d commit 5cf9941

4 files changed

Lines changed: 368 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
'@object-ui/i18n': major
3+
---
4+
5+
feat(i18n)!: the 67 translation keys `@object-ui/i18n@18.6.0` shipped that no code reads any more are retired in 19.0.0
6+
7+
**BREAKING**: released keys are retired in 19.0.0. `@object-ui/i18n@18.6.0` shipped every key listed below; none of them is in the package any more, in any locale. No code in the platform reads them.
8+
9+
Clause-②: yes (narrowing)
10+
Metadata-protocol: none
11+
12+
<!-- adr-0087: not-required (no-migration-prescription) The retired operands are translation keys in the published i18n catalogues: no packages/spec schema, registered node type, stored metadata row or ADR-0087 conversion surface names them, and nothing a metadata author writes changes, so there is nothing for objectstack migrate meta to rewrite -->
13+
14+
If a deployment overrides one of these keys (in its own i18next resources, or a Studio catalogue it registers), that override no longer applies: nothing in the console or Studio asks for the key, so the overriding text is never shown. Remove the override, or move the text to the key the surface reads now.
15+
16+
`@object-ui/i18n` is in the changesets `fixed` group, so this `major` moves every package in that group to 19, every `@objectstack/*` package included. The line's opening marker is a second `major` (on `@objectstack/spec`) in the same group; two majors in one fixed group still give one 19.0.0. In pre mode under `next` the first version step reads `19.0.0-next.0`.
17+
18+
The list is reproduced by `node ui/packages/i18n/scripts/released-keys-removed.mjs` (the tag against `origin/main`, every locale and namespace the package publishes, nested keys flattened).
19+
20+
## Removed translation keys
21+
22+
### Language packs (`@object-ui/i18n`, `@object-ui/i18n/locales`), 32 keys
23+
24+
Each key below is removed from all eleven locales: ar, de, en, es, fr, ja, ko, pt-BR, ru, zh-Hans, zh-Hant.
25+
26+
- `appDesigner.fieldDesigner.trackHistory`
27+
- `console.firstRunChecklist.confirm`
28+
- `console.firstRunChecklist.currency.saved`
29+
- `console.firstRunChecklist.currency.title`
30+
- `console.firstRunChecklist.currency.todo`
31+
- `console.firstRunChecklist.languageCountry.saved`
32+
- `console.firstRunChecklist.languageCountry.title`
33+
- `console.firstRunChecklist.languageCountry.todo`
34+
- `console.firstRunChecklist.organizationName.action`
35+
- `console.firstRunChecklist.organizationName.title`
36+
- `console.firstRunChecklist.organizationName.todo`
37+
- `console.firstRunChecklist.prefilled`
38+
- `console.firstRunChecklist.timezone.saved`
39+
- `console.firstRunChecklist.timezone.title`
40+
- `console.firstRunChecklist.timezone.todo`
41+
- `console.nav.design`
42+
- `console.nav.phoneBarHint`
43+
- `console.nav.searchMenu`
44+
- `console.objectView.openAsPage`
45+
- `console.objectView.personalizedParts.rowNumbers`
46+
- `dashboard.exportCsv`
47+
- `detail.collapseToDrawer`
48+
- `filterBuilder.where`
49+
- `list.recordOpen`
50+
- `list.recordOpenDeclaredPage`
51+
- `list.recordOpenDrawer`
52+
- `list.recordOpenNote`
53+
- `list.recordOpenPage`
54+
- `list.rowNumbers`
55+
- `sidebar.keepOpen`
56+
- `view.switcher.all`
57+
- `view.switcher.saveAsMyView`
58+
59+
### Studio namespace (`@object-ui/i18n/namespaces/studio`), 35 keys
60+
61+
Each key below is removed from both locales the namespace ships: en, zh.
62+
63+
- `designer.field.relatedList.parentFallback`
64+
- `designer.field.trackHistory`
65+
- `engine.edit.autoSaveOff`
66+
- `engine.edit.autoSaveOn`
67+
- `engine.edit.autoSavingShortly`
68+
- `engine.edit.related`
69+
- `engine.packages.installedApps.description`
70+
- `engine.packages.installedApps.title`
71+
- `engine.studio.autoSaved`
72+
- `engine.studio.data.form.flowCreate`
73+
- `engine.studio.data.form.flowEdit`
74+
- `engine.studio.data.form.flowLabel`
75+
- `engine.studio.data.form.layoutSource.fieldGroups`
76+
- `engine.studio.data.form.layoutSource.fieldGroupsTitle`
77+
- `engine.studio.data.form.layoutSource.formView`
78+
- `engine.studio.data.form.layoutSource.formViewTitle`
79+
- `engine.studio.designer.offForm`
80+
- `engine.studio.designer.sectionDeleteTitle`
81+
- `engine.studio.flowSavedNamed`
82+
- `engine.studio.flowSaveFailed`
83+
- `engine.studio.inspector.listView.kanbanCard.mode.drawer`
84+
- `engine.studio.inspector.listView.kanbanCard.mode.newWindow`
85+
- `engine.studio.inspector.listView.kanbanCard.mode.page`
86+
- `engine.studio.openApp`
87+
- `engine.studio.openAppPick`
88+
- `engine.studio.openAppTitle`
89+
- `engine.studio.owd.save`
90+
- `engine.studio.owd.saved`
91+
- `engine.studio.owd.saveNone`
92+
- `engine.studio.pillar.access`
93+
- `engine.studio.pillar.automations`
94+
- `engine.studio.pillar.data`
95+
- `engine.studio.pillar.interfaces`
96+
- `engine.studio.pillar.metadata`
97+
- `engine.studio.settings.highlightPreview`

‎.changeset/37223-v19-line-opens.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@objectstack/spec": major
3+
---
4+
5+
The v19 line opens (maintainer rulings 7153326968 and 7153441862). Every release from here is a `19.0.0-next.N` prerelease on the npm dist-tag `next`, until 19.0 GA.
6+
7+
Clause-②: no
8+
9+
- **What this marks.** Changesets is in pre mode with the tag `next`. Every package in the `fixed` group versions together, so this `major` takes all of them to 19, and the first version cut is `19.0.0-next.0`. `PROTOCOL_VERSION` follows `@objectstack/spec`'s major at version time. The marker itself changes no code, key, export or stored shape.
10+
- **What the line carries.** Each breaking change on the line says so in its own changeset. The first is `@object-ui/i18n`'s retirement of the translation keys 18.6.0 shipped and no code reads any more; a second `major` in the same `fixed` group still gives one 19.0.0.
11+
- **Who receives it.** A plain install still resolves the dist-tag `latest`, which stays on 18.x until 19.0 GA. A prerelease is installed only on request: `@objectstack/spec@next`, or an exact `19.0.0-next.N`.
12+
- **What ends it.** 19.0 GA exits pre mode and publishes to `latest`.
13+
14+
<!-- adr-0087: not-required (no-migration-prescription) the v19 line's opening marker: Changesets pre mode plus one major on the fixed group, so the train versions 19.0.0-next.N. No authorable key, spelling, export, type or stored shape moves in this changeset, and no stored row is read, rewritten or converted; each breaking change of the line states its own disposition in its own changeset. The other categories are closed on facts: the package publishes (not unpublished); no ADR-0087 id is named or touched (not registered or already-registered); and no TypeScript declaration moves (not runtime-interface-only or type-surface-only). -->

‎.changeset/pre.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"mode": "pre",
3+
"tag": "next"
4+
}
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
#!/usr/bin/env node
2+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
3+
/**
4+
* released-keys-removed.mjs — every translation key a released `@object-ui/i18n`
5+
* shipped that a later tree no longer carries.
6+
*
7+
* Usage (from anywhere inside the repository):
8+
*
9+
* node ui/packages/i18n/scripts/released-keys-removed.mjs \
10+
* [--tag @object-ui/i18n@18.6.0] [--ref origin/main] [--json]
11+
*
12+
* It reads the package's catalogue sources out of git at BOTH refs (never the
13+
* working tree), so it answers the same on any checkout. Zero third-party
14+
* dependencies: git for the blobs, Node's own type stripping to evaluate the
15+
* catalogue modules (they import nothing, so each one evaluates alone).
16+
*
17+
* ## Which files are the published catalogues — read from the package, not listed here
18+
*
19+
* - `package.json` `exports`: every `./namespaces/NAME` subpath is a published
20+
* namespace; `./locales` is the all-packs door.
21+
* - `src/locales/index.ts` (the all-packs door): each DEFAULT import of a
22+
* `./TAG.js` module is a language pack, and each default import of a
23+
* `../namespaces/NAME/TAG.js` module is that language's catalogue in a
24+
* pack-shaped namespace. The door deep-merges them into one catalogue per
25+
* language, and at runtime they all land in i18next's default
26+
* `translation` namespace, so they are ONE key space: a key that moved
27+
* from a pack into a pack-shaped namespace (or back) is not removed.
28+
* - Every other exported namespace (one whose `index.ts` does not build on
29+
* `../packNamespace.js`, today `studio`) is a key space of its own; its
30+
* catalogues are the `./TAG.js` modules its `index.ts` imports, statically
31+
* or through a literal `import()` loader.
32+
*
33+
* A key is the dotted path to a leaf value (strings, plus any non-object
34+
* value, arrays included), so plural forms (`KEY_one`, `KEY_other`, …) are
35+
* separate keys. A key counts as removed in a language when that language's
36+
* catalogue at the tag has it and the same key space at the ref does not.
37+
*/
38+
import { execFileSync } from 'node:child_process';
39+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
40+
import { tmpdir } from 'node:os';
41+
import { dirname, join, posix } from 'node:path';
42+
import { fileURLToPath, pathToFileURL } from 'node:url';
43+
44+
const args = process.argv.slice(2);
45+
const opt = (name, fallback) => {
46+
const i = args.indexOf(name);
47+
if (i === -1) return fallback;
48+
const v = args[i + 1];
49+
if (!v || v.startsWith('--')) {
50+
console.error(`released-keys-removed: ${name} needs a value`);
51+
process.exit(2);
52+
}
53+
return v;
54+
};
55+
const TAG = opt('--tag', '@object-ui/i18n@18.6.0');
56+
const REF = opt('--ref', 'origin/main');
57+
const AS_JSON = args.includes('--json');
58+
59+
// git runs in the package directory and every blob is named in git's own
60+
// cwd-relative form (`REF:./PATH`), so the script needs no repository root and
61+
// reads the same in the standalone and the monorepo layout.
62+
const PKG_DIR = dirname(dirname(fileURLToPath(import.meta.url)));
63+
const git = (...a) => execFileSync('git', a, { cwd: PKG_DIR, encoding: 'utf8', maxBuffer: 1 << 28 });
64+
const PKG = git('rev-parse', '--show-prefix').trim().replace(/\/$/, ''); // for messages only
65+
66+
const show = (ref, path) => git('show', `${ref}:./${path}`);
67+
const exists = (ref, path) => {
68+
try {
69+
git('cat-file', '-e', `${ref}:./${path}`);
70+
return true;
71+
} catch {
72+
return false;
73+
}
74+
};
75+
76+
for (const ref of [TAG, REF]) {
77+
try {
78+
git('rev-parse', '--verify', '--quiet', `${ref}^{commit}`);
79+
} catch {
80+
console.error(`released-keys-removed: ref '${ref}' does not resolve (fetch it first)`);
81+
process.exit(2);
82+
}
83+
}
84+
85+
const tmp = mkdtempSync(join(tmpdir(), 'released-keys-removed-'));
86+
process.on('exit', () => rmSync(tmp, { recursive: true, force: true }));
87+
let seq = 0;
88+
89+
/** Evaluate one catalogue module's default export from its source at `ref`. */
90+
async function loadCatalogue(ref, path) {
91+
const dir = join(tmp, String(seq++));
92+
mkdirSync(dir);
93+
const file = join(dir, posix.basename(path));
94+
writeFileSync(file, show(ref, path));
95+
const mod = await import(pathToFileURL(file).href);
96+
if (!mod.default || typeof mod.default !== 'object') {
97+
throw new Error(`${ref}:${PKG}/${path} has no object default export`);
98+
}
99+
return mod.default;
100+
}
101+
102+
const isPlain = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
103+
function flatten(obj, prefix = '', out = new Set()) {
104+
for (const [k, v] of Object.entries(obj)) {
105+
const key = prefix ? `${prefix}.${k}` : k;
106+
if (isPlain(v)) flatten(v, key, out);
107+
else out.add(key);
108+
}
109+
return out;
110+
}
111+
112+
/** `./x.js` / `../a/b.js` specifiers of default imports and literal `import()` calls. */
113+
function defaultImports(src) {
114+
return [...src.matchAll(/^\s*import\s+[A-Za-z_$][\w$]*\s+from\s+'([^']+)'/gm)].map((m) => m[1]);
115+
}
116+
function dynamicImports(src) {
117+
return [...src.matchAll(/import\(\s*'([^']+)'\s*\)/g)].map((m) => m[1]);
118+
}
119+
const tagOf = (spec) => posix.basename(spec).replace(/\.js$/, '');
120+
const toSrc = (fromDir, spec) => posix.normalize(posix.join(fromDir, spec)).replace(/\.js$/, '.ts');
121+
122+
/**
123+
* The catalogues one ref publishes:
124+
* Map<space, Map<lang, Array<{ module, path }>>>, where `module` names the
125+
* published group the file belongs to (`locales`, or the namespace name).
126+
*/
127+
function discover(ref) {
128+
const pkg = JSON.parse(show(ref, 'package.json'));
129+
const exp = Object.keys(pkg.exports ?? {});
130+
if (!exp.includes('./locales')) throw new Error(`${ref}: package.json exports no ./locales`);
131+
const namespaces = exp
132+
.filter((k) => k.startsWith('./namespaces/'))
133+
.map((k) => k.slice('./namespaces/'.length));
134+
135+
const spaces = new Map();
136+
const add = (space, lang, module, path) => {
137+
if (!spaces.has(space)) spaces.set(space, new Map());
138+
const langs = spaces.get(space);
139+
if (!langs.has(lang)) langs.set(lang, []);
140+
langs.get(lang).push({ module, path });
141+
};
142+
143+
// The all-packs door: packs + pack-shaped namespaces, one `translation` space.
144+
const door = show(ref, 'src/locales/index.ts');
145+
const packShaped = new Set();
146+
for (const spec of defaultImports(door)) {
147+
if (!spec.startsWith('.')) continue;
148+
const path = toSrc('src/locales', spec);
149+
const m = /^src\/namespaces\/([^/]+)\/[^/]+\.ts$/.exec(path);
150+
if (m) {
151+
packShaped.add(m[1]);
152+
add('translation', tagOf(spec), m[1], path);
153+
} else if (/^src\/locales\/[^/]+\.ts$/.test(path)) {
154+
add('translation', tagOf(spec), 'locales', path);
155+
}
156+
}
157+
158+
// Every exported namespace's own catalogue modules.
159+
for (const ns of namespaces) {
160+
const index = `src/namespaces/${ns}/index.ts`;
161+
if (!exists(ref, index)) throw new Error(`${ref}: export ./namespaces/${ns} has no ${index}`);
162+
const src = show(ref, index);
163+
const isPackShaped = /from '\.\.\/packNamespace\.js'/.test(src);
164+
const specs = [...defaultImports(src), ...dynamicImports(src)].filter((s) => /^\.\/[^/]+\.js$/.test(s));
165+
for (const spec of new Set(specs)) {
166+
const path = toSrc(`src/namespaces/${ns}`, spec);
167+
if (isPackShaped) {
168+
// Already in the door; a catalogue the door does not merge would be a
169+
// published file outside every key space this script knows: refuse.
170+
const listed = spaces.get('translation')?.get(tagOf(spec))?.some((e) => e.path === path);
171+
if (!listed) throw new Error(`${ref}: ${path} is loaded by ${index} but not merged by src/locales/index.ts`);
172+
} else {
173+
add(ns, tagOf(spec), ns, path);
174+
}
175+
}
176+
}
177+
return spaces;
178+
}
179+
180+
/** Map<space, Map<lang, Map<key, module>>> for one ref. */
181+
async function keysAt(ref) {
182+
const out = new Map();
183+
for (const [space, langs] of discover(ref)) {
184+
const perLang = new Map();
185+
for (const [lang, entries] of langs) {
186+
const keys = new Map();
187+
for (const { module, path } of entries) {
188+
for (const k of flatten(await loadCatalogue(ref, path))) keys.set(k, module);
189+
}
190+
perLang.set(lang, keys);
191+
}
192+
out.set(space, perLang);
193+
}
194+
return out;
195+
}
196+
197+
const before = await keysAt(TAG);
198+
const after = await keysAt(REF);
199+
200+
// removed: Map<groupName, Map<key, Set<lang>>>; group = space, or the module a
201+
// `translation` key lived in at the tag.
202+
const removed = new Map();
203+
let moved = 0;
204+
for (const [space, langs] of before) {
205+
for (const [lang, keys] of langs) {
206+
const now = after.get(space)?.get(lang) ?? new Map();
207+
for (const [key, module] of keys) {
208+
if (now.has(key)) {
209+
if (now.get(key) !== module) moved++;
210+
continue;
211+
}
212+
const group = space === 'translation' ? module : space;
213+
if (!removed.has(group)) removed.set(group, new Map());
214+
const g = removed.get(group);
215+
if (!g.has(key)) g.set(key, new Set());
216+
g.get(key).add(lang);
217+
}
218+
}
219+
}
220+
221+
const tagLangs = (space) => [...(before.get(space)?.keys() ?? [])];
222+
const total = [...removed.values()].reduce((n, g) => n + g.size, 0);
223+
const groups = [...removed.keys()].sort();
224+
225+
if (AS_JSON) {
226+
const body = {
227+
tag: TAG,
228+
ref: REF,
229+
refSha: git('rev-parse', REF).trim(),
230+
total,
231+
movedBetweenModules: moved,
232+
groups: Object.fromEntries(
233+
groups.map((g) => [
234+
g,
235+
Object.fromEntries([...removed.get(g)].sort(([a], [b]) => a.localeCompare(b)).map(([k, l]) => [k, [...l].sort()])),
236+
]),
237+
),
238+
};
239+
console.log(JSON.stringify(body, null, 2));
240+
} else {
241+
console.log(`Keys in ${TAG} absent at ${REF} (${git('rev-parse', '--short', REF).trim()}): ${total}`);
242+
for (const g of groups) {
243+
const space = before.has(g) ? g : 'translation';
244+
const all = tagLangs(space);
245+
console.log(`\n## ${g} (${removed.get(g).size})`);
246+
for (const [key, langs] of [...removed.get(g)].sort(([a], [b]) => a.localeCompare(b))) {
247+
const l = [...langs].sort();
248+
const which = l.length === all.length ? `all ${all.length} locales (${l.join(', ')})` : l.join(', ');
249+
console.log(`- ${key} — ${which}`);
250+
}
251+
}
252+
if (moved) console.log(`\n(${moved} key×locale rows moved between modules inside one key space; not removals)`);
253+
}

0 commit comments

Comments
 (0)