Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Close the lifeline start-up window and run i18n drift on a copy (#6334)
Nick Gomezedb1a690fad1
diff --git a/packages/app/package.json b/packages/app/package.jsonindex 2f3d4d733..b1bd4eab7 100644--- a/packages/app/package.json+++ b/packages/app/package.json@@ -18,9 +18,10 @@"build": "node scripts/copy-excalidraw-assets.mjs && tsc --noEmit && vite build && pnpm run check:no-dev-harness","check:no-dev-harness": "node scripts/check-dev-harness-absent.mjs","typecheck": "tsc --noEmit",- "i18n": "lingui extract --clean && pnpm run i18n:compile",+ "i18n": "pnpm run i18n:extract && pnpm run i18n:compile","i18n:extract": "lingui extract --clean",- "i18n:compile": "lingui compile --namespace json && biome format --write src/locales/*/messages.json",+ "i18n:compile": "pnpm run i18n:compile:catalogs && biome format --write src/locales/*/messages.json",+ "i18n:compile:catalogs": "lingui compile --namespace json","lint": "biome check .","format": "biome check --write .","test": "vitest run --config vitest.config.ts src/ tests/free-port.test.ts tests/temp-dir.test.ts tests/perf/fixtures/ tests/perf/lib/ tests/perf/profile.test.ts tests/perf/scenarios/sweep-cache-regime.smoke.test.ts tests/perf/scenarios/sweep-convention-cap-graduation.smoke.test.ts tests/stress/oracle-e-expectations.test.ts",diff --git a/scripts/check-i18n-drift.sh b/scripts/check-i18n-drift.shindex e035073df..0611ecbc9 100755--- a/scripts/check-i18n-drift.sh+++ b/scripts/check-i18n-drift.sh@@ -6,68 +6,124 @@ unset GIT_DIR GIT_WORK_TREE GIT_COMMON_DIR GIT_INDEX_FILE \SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"+APP_DIR="$REPO_ROOT/packages/app"LOCALES_DIR="packages/app/src/locales"-SNAPSHOT_ROOT="$(mktemp -d)"-SNAPSHOT_READY=0-CATALOGS_SETTLED=0+WORK_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/check-i18n-drift.XXXXXX")"+CATALOGS="$WORK_ROOT/locales"EXTRACTING=0-STAGED_RESTORE="$REPO_ROOT/$LOCALES_DIR.restore.$$"-restore_catalogs() {+finish() {set +eif [ "$EXTRACTING" -eq 1 ]; thenkill -TERM %1 2>/dev/nullwait %1 2>/dev/nullfi- if [ "$SNAPSHOT_READY" -eq 1 ] && [ "$CATALOGS_SETTLED" -eq 0 ]; then- rm -rf "${STAGED_RESTORE:?}"- if ! { cp -Rp "$SNAPSHOT_ROOT/locales" "${STAGED_RESTORE:?}" &&- rm -rf "${REPO_ROOT:?}/$LOCALES_DIR" &&- mv "${STAGED_RESTORE:?}" "${REPO_ROOT:?}/$LOCALES_DIR"; }; then- echo "FATAL: could not restore $LOCALES_DIR. The pre-run catalogs are kept at" >&2- echo " $SNAPSHOT_ROOT/locales" >&2- echo "Copy them back before running anything else." >&2- rm -rf "${STAGED_RESTORE:?}"- return- fi- fi- rm -rf "$SNAPSHOT_ROOT"+ rm -rf "$WORK_ROOT"}-trap restore_catalogs EXIT-cp -Rp "$REPO_ROOT/$LOCALES_DIR" "$SNAPSHOT_ROOT/locales"-SNAPSHOT_READY=1+trap finish EXIT+cp -Rp "$REPO_ROOT/$LOCALES_DIR" "$CATALOGS"+SEEDED="$(cd "$CATALOGS" && find . -type f | LC_ALL=C sort)"-cd "$REPO_ROOT"-UNTRACKED_BEFORE="$(git ls-files --others --exclude-standard -- "$LOCALES_DIR")"+node -e '+const { writeFileSync } = require("node:fs");+const [config, app, catalogs, out] = process.argv.slice(1);+const from = "<rootDir>/src/locales/";+writeFileSync(out, [+ `import config from ${JSON.stringify(config)};`,+ `const from = ${JSON.stringify(from)};`,+ "export default {",+ " ...config,",+ ` rootDir: ${JSON.stringify(app)},`,+ " catalogs: config.catalogs.map((catalog) => {",+ " if (!catalog.path.startsWith(from)) throw new Error(`check-i18n-drift.sh can only redirect catalogs under ${from}, not ${catalog.path}`);",+ ` return { ...catalog, path: ${JSON.stringify(`${catalogs}/`)} + catalog.path.slice(from.length) };`,+ " }),",+ "};",+ "",+].join("\n"));+' "$APP_DIR/lingui.config.ts" "$APP_DIR" "$CATALOGS" "$WORK_ROOT/lingui.config.mjs"-cd "$REPO_ROOT/packages/app"-node "$SCRIPT_DIR/run-in-own-process-group.mjs" pnpm run --silent i18n >/dev/null &-EXTRACTING=1-extract_status=0-wait %1 || extract_status=$?-EXTRACTING=0-[ "$extract_status" -eq 0 ] || exit "$extract_status"+cd "$APP_DIR"+in_copy() {+ LINGUI_CONFIG="$WORK_ROOT/lingui.config.mjs" node "$SCRIPT_DIR/run-in-own-process-group.mjs" "$@" >/dev/null &+ EXTRACTING=1+ local status=0+ wait %1 || status=$?+ EXTRACTING=0+ return "$status"+}+in_copy pnpm run --silent i18n:extract || exit $?+in_copy pnpm run --silent i18n:compile:catalogs || exit $?cd "$REPO_ROOT"-UNTRACKED_AFTER="$(git ls-files --others --exclude-standard -- "$LOCALES_DIR")"-if ! git diff --quiet -- "$LOCALES_DIR" || [ "$UNTRACKED_BEFORE" != "$UNTRACKED_AFTER" ]; then+git ls-files -z -- "$LOCALES_DIR" >"$WORK_ROOT/tracked"+COMPARED=0+DIFFERING=""+while IFS= read -r -d '' tracked; do+ case "$tracked" in+ */messages.po | */messages.json) ;;+ *) continue ;;+ esac+ COMPARED=$((COMPARED + 1))+ copy="$CATALOGS/${tracked#"$LOCALES_DIR"/}"+ if [ ! -f "$copy" ]; then+ DIFFERING="$DIFFERING$tracked"$'\n'+ continue+ fi+ case "$tracked" in+ *.json)+ git cat-file blob ":./$tracked" >"$WORK_ROOT/indexed"+ compared=0+ node -e '+const { readFileSync } = require("node:fs");+const [indexedFile, copyFile, tracked] = process.argv.slice(1);+const parsed = (file, side) => {+ try {+ return JSON.stringify(JSON.parse(readFileSync(file, "utf8")));+ } catch (error) {+ process.stderr.write(`ERROR: the i18n drift check could not parse ${side} of ${tracked}, so it stopped: ${error.message}\n`);+ process.exit(2);+ }+};+process.exit(parsed(indexedFile, "the index entry") === parsed(copyFile, "the regenerated copy") ? 0 : 1);+' "$WORK_ROOT/indexed" "$copy" "$tracked" || compared=$?+ case "$compared" in+ 0) ;;+ 1) DIFFERING="$DIFFERING$tracked"$'\n' ;;+ *) exit "$compared" ;;+ esac+ ;;+ *)+ indexed_id="$(git rev-parse ":./$tracked")"+ copy_id="$(git hash-object --path="$tracked" "$copy")"+ [ "$copy_id" = "$indexed_id" ] || DIFFERING="$DIFFERING$tracked"$'\n'+ ;;+ esac+done <"$WORK_ROOT/tracked"+if [ "$COMPARED" -eq 0 ]; then+ echo "ERROR: git lists no tracked catalog under $LOCALES_DIR, so the i18n drift check has nothing to compare." >&2+ exit 1+fi+CREATED="$(comm -13 <(printf '%s\n' "$SEEDED") <(cd "$CATALOGS" && find . -type f | LC_ALL=C sort) | sed "s|^\./|$LOCALES_DIR/|")"+if [ -n "$DIFFERING" ] || [ -n "$CREATED" ]; thenecho "ERROR: i18n catalog drift detected." >&2echo "" >&2echo " <Trans> or t\`...\` macros under packages/app/src have changed without" >&2- echo " regenerating the Lingui catalogs. Re-running the extractor produced a" >&2- echo " diff under $LOCALES_DIR." >&2+ echo " regenerating the Lingui catalogs. Running the extractor on a copy of" >&2+ echo " $LOCALES_DIR produced catalogs that differ from the index." >&2echo "" >&2echo " Fix:" >&2echo " cd public/open-knowledge/packages/app && pnpm run i18n" >&2echo " then commit the updated catalog files." >&2- echo "" >&2- echo " Drift summary:" >&2- git --no-pager diff --stat -- "$LOCALES_DIR" >&2- if [ "$UNTRACKED_BEFORE" != "$UNTRACKED_AFTER" ]; then+ if [ -n "$DIFFERING" ]; then+ echo "" >&2+ echo " Catalog files that differ from the index:" >&2+ printf '%s' "$DIFFERING" | sed 's/^/ /' >&2+ fi+ if [ -n "$CREATED" ]; then+ echo "" >&2echo " Catalog files the extractor created:" >&2- comm -13 <(printf '%s\n' "$UNTRACKED_BEFORE" | sed '/^$/d' | sort -u) \- <(printf '%s\n' "$UNTRACKED_AFTER" | sed '/^$/d' | sort -u) >&2+ printf '%s\n' "$CREATED" | sed 's/^/ /' >&2fiexit 1fi-CATALOGS_SETTLED=1