blueprint-shared-templates 0.6.1 → 0.6.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blueprint-shared-templates",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Templates shared by several products, published on its own",
5
5
  "license": "MIT",
6
6
  "author": "Carlos Space",
@@ -2,7 +2,10 @@
2
2
  # fact-kit check on every facts package, one after the other: the aggregate at facts/, the spec, one
3
3
  # component package per unit, every other aggregate package under facts/ (a shared package published on its
4
4
  # own, facts_roots) with the component packages it lists, and every single-layer package published on its own
5
- # (a facts/*/ with no "aggregate" key). Only the packages' own files are read, never the release-please config. A component package's fact-kit.config.json lists the unit's
5
+ # (a facts/*/ with no "aggregate" key), then every single-layer package that release-please-config.json lists outside
6
+ # facts/ (a unit directory holding a fact-kit.config.json without an "aggregate" key, such as demos/_facts), the same
7
+ # fourth case facts_components pins. Without it such a package is checked only by the workspace `check` script,
8
+ # with no --train, so its pinned rows read as since-ahead on a release branch. A component package's fact-kit.config.json lists the unit's
6
9
  # directory in implDirs, so an implementation that imports the aggregate fails with impl-imports-facts.
7
10
  # Builds the packages first, because some rules read the built indexes.
8
11
  #
@@ -27,6 +30,9 @@ pkgs=("$REPO_ROOT/facts" "$REPO_ROOT"/facts/*/)
27
30
  while IFS= read -r root; do
28
31
  [[ "$root" == "$REPO_ROOT/facts" ]] || pkgs+=("$root"/*/)
29
32
  done < <(facts_roots)
33
+ while IFS=$'\t' read -r p _; do
34
+ jq -e 'has("aggregate")' "$REPO_ROOT/$p/fact-kit.config.json" >/dev/null 2>&1 || pkgs+=("$REPO_ROOT/$p")
35
+ done < <(config_dirs_with fact-kit.config.json)
30
36
  declare -A seen=()
31
37
  for pkg in "${pkgs[@]}"; do
32
38
  pkg="${pkg%/}"
@@ -85,6 +85,45 @@ facts_components() {
85
85
  return 0
86
86
  }
87
87
 
88
+ # facts_package_dirs → every component package directory, one per line: a facts/*/ or a directory under another aggregate
89
+ # (facts_roots) that has a package.json and a fact-kit.config.json or a facts/ directory, or a directory
90
+ # release-please-config.json lists with a fact-kit.config.json. A directory whose fact-kit.config.json has an "aggregate" key
91
+ # is an aggregate, not a component. Unlike facts_components it lists a package whatever its directory is called, so a
92
+ # caller can find the packages that no unit name reaches.
93
+ facts_package_dirs() {
94
+ has_facts || return 0
95
+ local root p c d
96
+ local -A seen=()
97
+ while IFS= read -r d; do
98
+ [[ -n "$d" && -z "${seen[$d]:-}" ]] || continue
99
+ seen[$d]=1
100
+ [[ -f "$d/package.json" && ( -f "$d/fact-kit.config.json" || -d "$d/facts" ) ]] || continue
101
+ jq -e 'has("aggregate")' "$d/fact-kit.config.json" >/dev/null 2>&1 && continue
102
+ printf '%s\n' "$d"
103
+ done < <(
104
+ while IFS= read -r root; do
105
+ for d in "$root"/*/; do [[ -d "$d" ]] && printf '%s\n' "${d%/}"; done
106
+ done < <(facts_roots)
107
+ while IFS=$'\t' read -r p c; do printf '%s\n' "$REPO_ROOT/$p"; done < <(config_dirs_with fact-kit.config.json)
108
+ )
109
+ return 0
110
+ }
111
+
112
+ # facts_component_of <package dir> → the component each built index of the package describes, the way fact-kit check reads it
113
+ # for --train (componentOf): the one key of "describes", else the package name without its scope, "-facts" and publish target
114
+ # suffix. This does not follow the version file: on a unit's first release "describes" is {} and the package name still
115
+ # gives the unit. An index that describes several components gives nothing. Build the package first.
116
+ facts_component_of() {
117
+ local f
118
+ for f in "$1"/dist/*/index.json; do
119
+ [[ -f "$f" ]] || continue
120
+ jq -r '(.describes // {} | keys) as $k
121
+ | if ($k | length) == 1 then $k[0]
122
+ elif ($k | length) > 1 or (.package | type) != "string" then empty
123
+ else .package | sub("^@[^/]+/"; "") | sub("-facts(\\.[a-z0-9]+)?$"; "") end' "$f"
124
+ done | sort -u
125
+ }
126
+
88
127
  # facts_pin <unit> <version>: turn the "next" rows of the unit's component packages into <version>.
89
128
  # Prints nothing; the caller looks at git status.
90
129
  facts_pin() {
@@ -112,24 +151,36 @@ facts_locate_problems() {
112
151
  done < <(sed -nE 's/^[a-z-]+: ([^ :]+): .*/\1/p' <<<"$2")
113
152
  }
114
153
 
115
- # facts_train_check <unit>=<version>... → runs `fact-kit check --train` for the component packages that
116
- # describe those units. Prints the problems (each with its <file>:<line>) and returns 1 on any. A
117
- # repository without facts, or no component package for the units, passes.
154
+ # facts_train_check <unit>=<version>... → runs `fact-kit check --train` for the component packages of those units: the ones
155
+ # facts_components gives the unit, and every other package whose facts describe it (facts_component_of). The second kind was
156
+ # not pinned, because the pin only reaches the first kind, so a "next" row left in it fails the check with its <file>:<line>
157
+ # instead of shipping; the script prints which package that is. Prints the problems (each with its <file>:<line>) and returns 1
158
+ # on any. A repository without facts, or no package that describes the units, passes.
118
159
  facts_train_check() {
119
160
  has_facts || { info "⊘ 沒有 facts/,略過 fact-kit check"; return 0; }
120
161
  local pair unit dir u failed=0 out
121
- local -a train=() dirs=()
122
- local -A seen=()
162
+ local -a train=() dirs=() others=()
163
+ local -A seen=() in_train=()
123
164
  local comps; comps="$(facts_components)"
124
165
  for pair in "$@"; do
125
166
  unit="${pair%%=*}"
167
+ in_train[$unit]=1
168
+ train+=(--train "$pair")
126
169
  while IFS=$'\t' read -r dir u; do
127
170
  [[ "$u" == "$unit" ]] || continue
128
- train+=(--train "$pair")
129
171
  [[ -n "${seen[$dir]:-}" ]] || { seen[$dir]=1; dirs+=("$dir"); }
130
172
  done <<<"$comps"
131
173
  done
132
- (( ${#dirs[@]} )) || { info "⊘ 這次的單元沒有對應的 component 套件,略過 fact-kit check"; return 0; }
174
+ while IFS= read -r dir; do [[ -z "${seen[$dir]:-}" ]] && others+=("$dir"); done < <(facts_package_dirs)
175
+ for dir in "${others[@]+"${others[@]}"}"; do
176
+ out="$(fact_kit build --cwd "$dir" 2>&1)" || { printf '%s\n' "$out" >&2; die "建置 ${dir#"$REPO_ROOT"/} 失敗(facts 的依賴裝了嗎?先在倉庫根目錄執行 pnpm install)"; }
177
+ while IFS= read -r u; do
178
+ [[ -n "$u" && -n "${in_train[$u]:-}" ]] || continue
179
+ warn "${dir#"$REPO_ROOT"/} 的 facts 描述 ${u},但釘版對不到它(釘版只認目錄名稱或 release-please-config.json 給的單元名),它的 next 不會被釘,留著的 next 會讓下面的 check 失敗"
180
+ [[ -n "${seen[$dir]:-}" ]] || { seen[$dir]=1; dirs+=("$dir"); }
181
+ done < <(facts_component_of "$dir")
182
+ done
183
+ (( ${#dirs[@]} )) || { info "⊘ 沒有描述這次單元的 component 套件,略過 fact-kit check"; return 0; }
133
184
  for dir in "${dirs[@]}"; do
134
185
  if out="$(fact_kit check --cwd "$dir" "${train[@]}" 2>&1)"; then
135
186
  info "✓ fact-kit check ${dir#"$REPO_ROOT"/}(${train[*]})"
@@ -1124,8 +1124,38 @@ Release-Train-Stage: $target"
1124
1124
  # - PyPI:uv_build 只打包模組目錄,不會收進它。換成會收整個目錄的後端(例如 hatchling)時,
1125
1125
  # sdist 要排除它。
1126
1126
  # 核對方式:cargo package --list、npm pack --dry-run、解開 uv build 的產物,都不該出現 .release-marker。
1127
+ # train_bring_commit <branch> <sha>: cherry-pick <sha> from main onto the release branch that is checked out, for a unit whose
1128
+ # directory the base of the train does not have (cut-release.sh). The files the train manages stay as the branch has them
1129
+ # (RELEASE_REBUILD_PATHS and the manifest: the opening commit wrote the scoped config, the merged manifest and main's
1130
+ # tooling, and a cherry-pick must not undo that), whether the pick conflicts there or merges cleanly. Any other conflict
1131
+ # stops the script with the files listed; the branch is not pushed yet, so the person resolves it or starts over. The
1132
+ # commit keeps the author and message of <sha>, with git's "(cherry picked from commit ...)" line.
1133
+ train_bring_commit() {
1134
+ local branch="$1" c="$2" pre f out
1135
+ local -a managed=() left=()
1136
+ pre="$(git rev-parse HEAD)"
1137
+ out="$(git cherry-pick --no-commit "$c" 2>&1)" || true
1138
+ mapfile -t managed < <(git diff --name-only "$pre" -- "${RELEASE_REBUILD_PATHS[@]}" "$MANIFEST"; git diff --name-only --diff-filter=U -- "${RELEASE_REBUILD_PATHS[@]}" "$MANIFEST")
1139
+ for f in "${managed[@]+"${managed[@]}"}"; do
1140
+ [[ -n "$f" ]] || continue
1141
+ if git cat-file -e "$pre:$f" 2>/dev/null; then git checkout -q "$pre" -- "$f"; else git rm -q -f --ignore-unmatch -- "$f"; fi
1142
+ done
1143
+ mapfile -t left < <(git diff --name-only --diff-filter=U)
1144
+ if (( ${#left[@]} )); then
1145
+ printf '%s\n' "$out" >&2
1146
+ die "cherry-pick ${c:0:7} 到 ${branch} 時,這些檔衝突:${left[*]}。${branch} 還沒推送:解完衝突後 git add 並 git commit -C ${c:0:7},再推送 ${branch};或 git cherry-pick --abort、切回原本的分支、刪掉本機的 ${branch} 後重開"
1147
+ fi
1148
+ git commit -q --allow-empty --author="$(git log -1 --format='%an <%ae>' "$c")" --date="$(git log -1 --format=%aI "$c")" \
1149
+ --cleanup=whitespace -F - <<<"$(git log -1 --format=%B "$c")
1150
+
1151
+ (cherry picked from commit $c)"
1152
+ git cherry-pick --quit 2>/dev/null || true
1153
+ }
1154
+
1127
1155
  release_as_commit() { # release_as_commit <branch> <unit> <path> <version>
1128
1156
  local branch="$1" u="$2" p="$3" v="$4"
1157
+ # a unit that boarded a train rebuilt from a tag older than the unit has no directory on the branch yet
1158
+ mkdir -p "$p"
1129
1159
  {
1130
1160
  printf '%s\n' "$v"
1131
1161
  printf '%s\n' "#"
@@ -209,9 +209,15 @@ if all_independent && [[ -n "$(aggregate_unit)" ]]; then
209
209
  fi
210
210
  # A unit the line has not reached yet is deferred: it stays out of the config, so release-please does not
211
211
  # release it, and advance-release.sh brings it in when the line gets to its first stage.
212
+ # The path of each unit is resolved here, in the tree the script started in, and kept: a train rebuilt from a product tag
213
+ # switches to that tag below, and a unit that has never shipped may have no directory there yet.
212
214
  declare -a paths active=() deferred=()
215
+ declare -A path_of=()
213
216
  for u in "${units[@]}"; do
214
- if [[ -n "${stage_of[$u]}" ]]; then active+=("$u"); paths+=("$(unit_path "$u")"); else deferred+=("$u"); fi
217
+ if [[ -n "${stage_of[$u]}" ]]; then
218
+ p="$(unit_path "$u")" || die "${u} 在 $(current_branch) 上找不到目錄($CONFIG 或 apps/、packages/、libs/)"
219
+ active+=("$u"); paths+=("$p"); path_of[$u]="$p"
220
+ else deferred+=("$u"); fi
215
221
  done
216
222
  stage="$line_stage"
217
223
 
@@ -244,8 +250,16 @@ stagemap="{}"
244
250
  for u in "${deferred[@]:-}"; do
245
251
  [[ -n "$u" ]] && info "${u}:發布線還沒到它的第一個階段($(policy_unit_stages "$u" | head -1)),先不發,推進到那個階段才入版"
246
252
  done
253
+ # A unit whose directory the base does not have (a train rebuilt from a tag older than the unit) still boards: its config
254
+ # entry comes from main, and the commits of main that touch its directory are cherry-picked onto the branch after the
255
+ # opening commit (train_bring_commit), so release-please has the directory and the commits to release it from.
256
+ declare -a absent=()
247
257
  for u in "${active[@]}"; do
248
- p="$(unit_path "$u")"; ust="${stage_of[$u]}"
258
+ p="${path_of[$u]}"; ust="${stage_of[$u]}"
259
+ if ! git cat-file -e "${base}^{commit}:$p" 2>/dev/null; then
260
+ absent+=("$u")
261
+ info "${u}:起點 ${base} 沒有 ${p},照 main 的設定入版,開線後把 main 上改到 ${p} 的 commit cherry-pick 進 ${branch}"
262
+ fi
249
263
  stagemap="$(jq -c --arg p "$p" --arg s "$ust" '. + {($p): $s}' <<<"$stagemap")"
250
264
  initial="$(stage_initial_version "$(unit_base_version "$p" "$line")" "$ust")"
251
265
  case "$(policy_unit_kind "$u")" in
@@ -320,6 +334,26 @@ Release-Plan: $plan
320
334
  Release-Train-Units: ${units[*]}
321
335
  Release-Train-Stage: $stage"
322
336
 
337
+ # Bring the directories the base does not have: every commit of main since the base that touches one of those units,
338
+ # oldest first, each once. A commit also brings what else it changed (its facts, the lock file); the files the train
339
+ # manages stay as the opening commit wrote them.
340
+ declare -a picks=() picked=()
341
+ for u in "${absent[@]+"${absent[@]}"}"; do
342
+ p="${path_of[$u]}"
343
+ mapfile -t picks < <(git log --reverse --format=%H "${base}..origin/main" -- "$p")
344
+ if (( ${#picks[@]} == 0 )); then
345
+ warn "${u}:main 上找不到 ${base} 之後改到 ${p} 的 commit。${branch} 帶入這個目錄之前,release-please 不會發它"
346
+ continue
347
+ fi
348
+ for c in "${picks[@]}"; do
349
+ in_array "$c" "${picked[@]+"${picked[@]}"}" && continue
350
+ picked+=("$c")
351
+ if (( DRY_RUN )); then info "[dry-run] ${u}:會 cherry-pick $(git log -1 --format='%h %s' "$c")"; continue; fi
352
+ train_bring_commit "$branch" "$c"
353
+ info "${u}:已 cherry-pick $(git log -1 --format='%h %s' "$c")"
354
+ done
355
+ done
356
+
323
357
  # release-please's python and rust strategies start a unit that has no release at 0.1.0 and never read
324
358
  # initial-version, so the first version of those units is pinned by Release-As commits on top of the opening commit.
325
359
  if (( DRY_RUN )); then