@10stars/config 17.0.0 → 17.0.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": "@10stars/config",
3
- "version": "17.0.0",
3
+ "version": "17.0.2",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "config": "./src/index.ts"
@@ -125,20 +125,59 @@ const bfsSiblings = async (cwd: string, visit: (sib: string) => Promise<void>):
125
125
  }
126
126
  }
127
127
 
128
- const branchExists = (url: string, ref: string): boolean =>
129
- Boolean(tryGit([`ls-remote`, `--heads`, url, ref]))
128
+ /**
129
+ * The first of `candidates` (priority order) that exists as a branch on the remote, else null.
130
+ * Queries only those specific refs in one `ls-remote` — no full head listing. A non-zero exit means
131
+ * the repo is unreadable (private + missing/unauthorized clone token → "Repository not found") —
132
+ * surfaced immediately rather than masquerading as a missing branch.
133
+ */
134
+ const matchRemoteBranch = (url: string, candidates: string[]): string | null => {
135
+ let out: string
136
+ try {
137
+ out = git([`ls-remote`, url, ...candidates.map((c) => `refs/heads/${c}`)])
138
+ } catch (err) {
139
+ const stderr = (err as { stderr?: string | Buffer })?.stderr
140
+ throw new Error(
141
+ `Cannot read ${url}: repo is unreachable — if private, the clone token is missing or ` +
142
+ `unauthorized. Pass app-key to setup-siblings and install the GitHub App on this repo ` +
143
+ `with contents:read.\n${(stderr ?? (err as Error)?.message ?? ``).toString().trim()}`,
144
+ )
145
+ }
146
+ // Lines are "<sha>\trefs/heads/<branch>"; a branch may itself contain slashes (e.g. alice/x).
147
+ const present = new Set(
148
+ out
149
+ .split(`\n`)
150
+ .map((line) => line.split(`refs/heads/`)[1])
151
+ .filter(Boolean),
152
+ )
153
+ return candidates.find((c) => present.has(c)) ?? null
154
+ }
130
155
 
131
- /** Branch-first: current PR branch, then push branch, then `develop`, then `production`. */
132
- const resolveRef = (url: string, repo: string): string => {
133
- const candidates = [
156
+ /**
157
+ * Clone a missing sibling as a flat peer, returning the branch it landed on. Prefers a branch
158
+ * matching the consumer's coordinated branch (PR head, then push branch) when the sibling has one;
159
+ * otherwise clones the sibling's own default branch directly. A default-branch clone needs no
160
+ * `--branch`, so the `ls-remote` probe is skipped entirely when no coordinated branch is set — one
161
+ * fewer round-trip for local/manual runs (in GitHub Actions GITHUB_REF_NAME is always set).
162
+ */
163
+ const cloneSibling = (url: string, repo: string, sib: string, dest: string): string | null => {
164
+ const coordinated = [
134
165
  process.env.GITHUB_HEAD_REF, // pull_request events
135
166
  process.env.GITHUB_REF_NAME, // push events
136
- `develop`,
137
- `production`,
138
167
  ].filter((v): v is string => Boolean(v))
139
-
140
- for (const ref of candidates) if (branchExists(url, ref)) return ref
141
- throw new Error(`No branch found for ${repo}; tried: ${candidates.join(`, `)}`)
168
+ const ref = coordinated.length ? matchRemoteBranch(url, coordinated) : null
169
+
170
+ console.info(`linkRemote: cloning ${repo}@${ref ?? `(default)`} -> ${dest}`)
171
+ gitInherit([
172
+ `clone`,
173
+ `--depth`,
174
+ `1`,
175
+ `--single-branch`,
176
+ ...(ref ? [`--branch`, ref] : []),
177
+ url,
178
+ sib,
179
+ ])
180
+ return ref ?? currentRef(sib)
142
181
  }
143
182
 
144
183
  const headSha = (dir: string): string | null => tryGit([`rev-parse`, `HEAD`], dir)
@@ -170,10 +209,7 @@ const cloneClosureBranchFirst = async (cwd: string): Promise<Sibling[]> => {
170
209
  ref = currentRef(sib)
171
210
  } else {
172
211
  const repo = path.basename(sib)
173
- const url = repoUrl(repo)
174
- ref = resolveRef(url, repo)
175
- console.info(`linkRemote: cloning ${repo}@${ref} -> ${path.relative(cwd, sib)}`)
176
- gitInherit([`clone`, `--depth`, `1`, `--single-branch`, `--branch`, ref, url, sib])
212
+ ref = cloneSibling(repoUrl(repo), repo, sib, path.relative(cwd, sib))
177
213
  }
178
214
  order.push({ abs: sib, ref })
179
215
  })
@@ -22,15 +22,29 @@ const PATCHED = String.raw`/(?:^|[/\\])css\.(js|cjs|mjs|jsx|ts|tsx)(\?used)?$/`
22
22
  */
23
23
  export const patchVanillaExtract = async (cwd: string): Promise<boolean> => {
24
24
  const nodeModules = path.join(cwd, `node_modules`)
25
- const glob = new Bun.Glob(`**/@vanilla-extract/integration/dist/*.js`)
25
+
26
+ // Recursively collect `@vanilla-extract/integration/dist/*.js` WITHOUT following directory
27
+ // symlinks. A `file:` self-dep (e.g. frontend-toolkit's `frontend-toolkit: file:.` creates
28
+ // node_modules/frontend-toolkit -> .) makes symlink-following recurse forever — Bun.Glob does,
29
+ // even with `followSymlinks: false`. A linked sibling patches its own VE during its own install,
30
+ // and this repo's own copy is hoisted as a real dir, so real-dir-only recursion is sufficient.
31
+ const integrationDist = /[/\\]@vanilla-extract[/\\]integration[/\\]dist[/\\][^/\\]+\.js$/
32
+ const findFiles = async (dir: string, out: string[] = []): Promise<string[]> => {
33
+ for (const entry of await fs.readdir(dir, { withFileTypes: true }).catch(() => [])) {
34
+ if (entry.isSymbolicLink()) continue
35
+ const full = path.join(dir, entry.name)
36
+ if (entry.isDirectory()) await findFiles(full, out)
37
+ else if (entry.isFile() && integrationDist.test(full)) out.push(full)
38
+ }
39
+ return out
40
+ }
26
41
 
27
42
  let integrationFound = false
28
43
  let definitionFound = false
29
44
  const patched: string[] = []
30
45
 
31
- for await (const rel of glob.scan({ cwd: nodeModules, onlyFiles: true })) {
46
+ for (const file of await findFiles(nodeModules)) {
32
47
  integrationFound = true
33
- const file = path.join(nodeModules, rel)
34
48
  const content = await fs.readFile(file, `utf8`)
35
49
 
36
50
  if (content.includes(PATCHED)) {
@@ -41,7 +55,7 @@ export const patchVanillaExtract = async (cwd: string): Promise<boolean> => {
41
55
 
42
56
  definitionFound = true
43
57
  await fs.writeFile(file, content.replaceAll(ORIGINAL, PATCHED))
44
- patched.push(rel)
58
+ patched.push(path.relative(nodeModules, file))
45
59
  }
46
60
 
47
61
  if (!integrationFound) return false // VE not installed here