issue-map 0.3.1 → 0.4.0

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.
@@ -6,26 +6,28 @@
6
6
  * 這是 package.json 的預設 bin,所以在**要看的那個 repo** 裡直接跑就會畫那個 repo:
7
7
  * bunx issue-map@latest
8
8
  *
9
- * 起來之後直接開瀏覽器。不要的話設 `ISSUE_MAP_OPEN=0`——`bun --watch` 的開發模式就是這樣關掉
10
- * 的,否則每存一次檔就多一個分頁。
9
+ * 起來之後直接開瀏覽器,`ISSUE_MAP_OPEN=0` 可以關掉(`--watch` 的開發模式靠它,否則每存一次
10
+ * 檔就多一個分頁)。
11
+ *
12
+ * 預設不綁固定 port(`port: 0`,交給 OS 挑),所以在好幾個 repo 裡同時跑不會互相撞;實際網址
13
+ * 跟正在畫的目錄一起印在啟動訊息裡。設 `ISSUE_MAP_PORT` 可以固定,那時撞到就直接失敗而不偷
14
+ * 偷換一個——指定了還被換掉,書籤和反向代理都會對不上。
11
15
  *
12
16
  * 在這個 repo 裡開發時:
13
- * bun run issue-map:serve # http://localhost:4747,不自動開
14
- * ISSUE_MAP_PORT=5000 bun run issue-map:serve
17
+ * bun run issue-map:serve # 隨機 port,不自動開
18
+ * ISSUE_MAP_PORT=4747 bun run issue-map:serve # 固定網址,--watch 重啟後還是同一個
15
19
  */
16
20
 
17
21
  import { spawnSync } from 'bun'
18
22
 
19
- import { describe, renderFragment, takeSnapshot } from './issue-map.ts'
23
+ import { describe, renderDocument, takeSnapshot } from './issue-map.ts'
20
24
 
21
- // `PORT` 是 Claude 桌面 app 的 launch.json 在 autoPort 換 port 時塞進來的。
22
- const PORT = Number(process.env.ISSUE_MAP_PORT ?? process.env.PORT ?? 4747)
25
+ // `PORT` 是 Claude 桌面 app 的 launch.json 在 autoPort 換 port 時塞進來的。都沒設就是 0:
26
+ // OS 指派,`server.port` 才是真的在聽的那個。
27
+ const PORT = Number(process.env.ISSUE_MAP_PORT ?? process.env.PORT ?? 0)
23
28
  const OPEN = process.env.ISSUE_MAP_OPEN !== '0'
24
29
 
25
- /**
26
- * 開系統預設瀏覽器。**打不開不算失敗**:server 已經起來了,印出網址讓人自己開就好——把它
27
- * 當錯誤收掉會讓「地圖其實好好地跑著」這件事被一個無關的問題蓋掉。
28
- */
30
+ /** 開系統預設瀏覽器。**打不開不算失敗**:server 已經起來了,印出網址讓人自己開就好。 */
29
31
  function openInBrowser(url: string): void {
30
32
  const command =
31
33
  process.platform === 'darwin'
@@ -44,11 +46,7 @@ function openInBrowser(url: string): void {
44
46
  async function page(): Promise<string> {
45
47
  const snapshot = takeSnapshot()
46
48
  console.log(describe(snapshot))
47
- // 樣板是 artifact 用的片段;本機直接看要補上完整文件與 charset。
48
- const head =
49
- '<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">'
50
- // `lang` 是預設語言;頁面上換語言時畫面那一支會改掉 `documentElement.lang`。
51
- return `<!doctype html><html lang="en"><head>${head}</head><body>${await renderFragment(snapshot)}</body></html>`
49
+ return renderDocument(snapshot)
52
50
  }
53
51
 
54
52
  const server = Bun.serve({
@@ -72,5 +70,6 @@ const server = Bun.serve({
72
70
  })
73
71
 
74
72
  const url = `http://localhost:${server.port}`
75
- console.log(`Dev map: ${url} (every refresh re-fetches from GitHub)`)
73
+ console.log(`Dev map for ${process.cwd()}`)
74
+ console.log(` ${url} (every refresh re-fetches from GitHub)`)
76
75
  if (OPEN) openInBrowser(url)