@bridgebrew/project 0.0.9 → 0.0.12

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/branches.ts CHANGED
@@ -23,6 +23,7 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameS
23
23
  import { basename, dirname, join, sep } from 'node:path';
24
24
  import { isRecord } from '@bridge/kernel/json';
25
25
  import type { GitService } from '@bridgebrew/git/contract.ts';
26
+ import { foldLetters } from './names.ts';
26
27
 
27
28
  /** What the host says Bridge loads from a repository (`bridgeNodes.codeFrom`). */
28
29
  export interface CodeFrom {
@@ -139,10 +140,7 @@ const folderName = (name: string) => name.replaceAll('/', '-');
139
140
  /** A branch name from a title: its letters without their accents (`Café crème` is `cafe-creme`, bridge#552), lowercase,
140
141
  * joined by `-`. */
141
142
  export const branchName = (title: string) =>
142
- title
143
- .toLowerCase()
144
- .normalize('NFKD')
145
- .replace(/[\u0300-\u036f]/g, '')
143
+ foldLetters(title)
146
144
  .replace(/[^a-z0-9/]+/g, '-')
147
145
  .replace(/^-+|-+$/g, '')
148
146
  .slice(0, 50);
@@ -455,7 +453,7 @@ export function createBranches(host: BranchesHost, settings: Settings = {}) {
455
453
  ...(job && { job, jobs: recent! }),
456
454
  };
457
455
  try {
458
- const status = await git.branchStatus(path, { exclude: [BRIDGE_YML] });
456
+ const status = await git.branchStatus(path, { exclude: [BRIDGE_YML], base });
459
457
  return {
460
458
  ...known,
461
459
  // A merge resolved to HEAD's own tree changes no file, yet waits for its commit (bridge#522): one change.
@@ -294,6 +294,8 @@ export function Branches({
294
294
  const [installing, setInstalling] = React.useState(false);
295
295
  const [gitMissing, setGitMissing] = React.useState(false);
296
296
  const [reads, setReads] = React.useState(0);
297
+ /** Counts the reads that ended, read or failed: the poll's next timer starts from there (plugins#272). */
298
+ const [settled, setSettled] = React.useState(0);
297
299
  React.useEffect(() => {
298
300
  let gone = false;
299
301
  fetch(projectBranchesRoute(slug, node), { cache: 'no-store' })
@@ -301,25 +303,39 @@ export function Branches({
301
303
  .then((body: unknown) => {
302
304
  if (gone) return;
303
305
  // A project that is not a git repository of its own has no branches: that state, in place of the list.
304
- if (isRecord(body) && body.repository === false && isRecord(body.project))
306
+ // These three answers end the polling: no job of a list they replace runs on.
307
+ if (isRecord(body) && body.repository === false && isRecord(body.project)) {
308
+ setView(undefined);
305
309
  return setError(`${String(body.project.title)} is not a git repository`);
310
+ }
306
311
  // A node no bridge.yml lists as a project (one made before projects had one): no branches either.
307
- if (isRecord(body) && body.project === null)
312
+ if (isRecord(body) && body.project === null) {
313
+ setView(undefined);
308
314
  return setError('No bridge.yml lists this project: Bridge shows no branches for it');
315
+ }
316
+ // A read that failed before (a poll while the project plugin reloaded) is over.
317
+ setError('');
309
318
  // No Git plugin: nothing to list; its install offered.
310
- if (isRecord(body) && body.git === 'missing') return setGitMissing(true);
319
+ if (isRecord(body) && body.git === 'missing') {
320
+ setView(undefined);
321
+ return setGitMissing(true);
322
+ }
311
323
  setGitMissing(false);
312
324
  // The host's own answer: typed once where it is read.
313
325
  setView(body as View);
314
326
  })
315
327
  .catch((cause: unknown) => {
316
328
  if (!gone) setError(cause instanceof Error ? cause.message : String(cause));
329
+ })
330
+ .finally(() => {
331
+ if (!gone) setSettled((count) => count + 1);
317
332
  });
318
333
  return () => {
319
334
  gone = true;
320
335
  };
321
336
  }, [slug, node, reads]);
322
- // While an action runs on past its route, the branches are read again until it ends.
337
+ // While an action runs on past its route, the branches are read again until it ends: each read once the one before
338
+ // it ended, read or failed (a failed one keeps the last list's jobs, so the polling goes on).
323
339
  const runsOn =
324
340
  !!view?.refreshing ||
325
341
  !!view?.branches.some((branch) => branch.job?.running) ||
@@ -328,7 +344,7 @@ export function Branches({
328
344
  if (!runsOn) return;
329
345
  const timer = setTimeout(() => setReads((count) => count + 1), POLL_MS);
330
346
  return () => clearTimeout(timer);
331
- }, [runsOn, view]);
347
+ }, [runsOn, settled]);
332
348
  /** Installs a plugin in this workspace (the Plugins screen's own install), then reads the branches again. */
333
349
  const install = async (source: string, title: string) => {
334
350
  setInstalling(true);
@@ -365,6 +381,8 @@ export function Branches({
365
381
  )) as View & {
366
382
  result?: { name?: string; running?: string; left?: { plugin: string; reason: string }[] };
367
383
  };
384
+ // A list read: an error a poll met meanwhile is over.
385
+ setError('');
368
386
  setView(answer);
369
387
  if (action === 'new') {
370
388
  setTitle('');
package/names.ts CHANGED
@@ -14,13 +14,24 @@ export const nameOfUrl = (url: string) =>
14
14
  .replace(/[^\w.-]/g, '-')
15
15
  .replace(/^[.-]+/, '');
16
16
 
17
+ /** The letters NFKD leaves whole (no base letter and mark to split them into), spelled in plain Latin (plugins#217). */
18
+ const LETTERS: Record<string, string> = { ß: 'ss', æ: 'ae', œ: 'oe', ø: 'o', ł: 'l', đ: 'd', ð: 'd', þ: 'th', ı: 'i' };
19
+ /** `text` lowercase in plain Latin letters where it has them: those letters spelled out, then accents dropped
20
+ * (`Straße Łódź` → `strasse lodz`). */
21
+ export const foldLetters = (text: string) =>
22
+ text
23
+ // ʼn first: NFKD splits it into an apostrophe and `n`, which would split the word.
24
+ .replace(/ʼn/g, 'n')
25
+ // NFKD before the rest: it reveals letters (`Ǽ` → `Æ` + accent, `𝐒` → `S`) the table and the lowercase then see.
26
+ .normalize('NFKD')
27
+ .toLowerCase()
28
+ .replace(/[ßæœøłđðþı]/g, (letter) => LETTERS[letter] ?? letter)
29
+ .replace(/[\u0300-\u036f]/g, '');
30
+
17
31
  /** A project's folder name from its title, which may be anything: `Test git` → `test-git`, `Café` → `cafe`. Empty
18
32
  * when nothing of it fits a folder name (letters, digits, `_ - .`, at most 100). */
19
33
  export const folderOf = (title: string) =>
20
- title
21
- .normalize('NFKD')
22
- .replace(/[̀-ͯ]/g, '')
23
- .toLowerCase()
34
+ foldLetters(title)
24
35
  .replace(/[^\w.-]+/g, '-')
25
36
  .replace(/-{2,}/g, '-')
26
37
  .replace(/^[.-]+|-+$/g, '')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bridgebrew/project",
3
- "version": "0.0.9",
3
+ "version": "0.0.12",
4
4
  "license": "MIT",
5
5
  "description": "A project is a folder of work with its bridge.yml, and a node with its own sessions: code, documents, anything; Bridge plugins can be made there too.",
6
6
  "keywords": [
@@ -137,6 +137,6 @@
137
137
  "typecheck": "bridge plugin check ."
138
138
  },
139
139
  "engines": {
140
- "bridge": ">=0.0.1-nightly.20261120.1"
140
+ "bridge": ">=0.0.1-nightly.20261123.1"
141
141
  }
142
142
  }