@miragon/slidev-speaker-profiles 0.2.0 → 0.2.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/README.md CHANGED
@@ -12,9 +12,12 @@ accident.
12
12
  ## Install
13
13
 
14
14
  ```bash
15
- npm i -D @miragon/slidev-speaker-profiles
15
+ npm i @miragon/slidev-speaker-profiles
16
16
  ```
17
17
 
18
+ A dependency, not a devDependency: Slidev compiles the addon into the deck, so
19
+ a build needs it the same way it needs the theme.
20
+
18
21
  Register it as an addon in your deck's headmatter:
19
22
 
20
23
  ```yaml
package/bin/slide-ids.mjs CHANGED
@@ -104,14 +104,16 @@ const where = row => `${rel(row.file)}:${row.start + 1}`
104
104
  const name = row => row.title || '(untitled)'
105
105
 
106
106
  if (options.mode === 'stamp') {
107
- const { stamped, unwritable, total, skipped, files } = await stampSlides({ entry, also })
107
+ const { stamped, unwritable, total, skipped, reason, files } = await stampSlides({ entry, also })
108
108
  if (unwritable.length) {
109
109
  for (const row of unwritable)
110
110
  console.error(`FAIL: ${where(row)} has no writable frontmatter block (style: ${row.style})`)
111
111
  process.exit(1)
112
112
  }
113
113
  if (skipped) {
114
- console.error('slide ids: another stamping run holds the lock, nothing written')
114
+ console.error(reason === 'busy'
115
+ ? 'slide ids: another stamping run holds the lock, nothing written'
116
+ : `slide ids: could not take the stamping lock (${reason}), nothing written`)
115
117
  process.exit(1)
116
118
  }
117
119
  if (!stamped.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miragon/slidev-speaker-profiles",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "description": "Per-speaker slide selection for a Slidev deck several people present. Each speaker keeps their own profile file, nobody overwrites anybody, and main never changes. Slides are addressed by a stable id the shipped slide-ids CLI stamps into their frontmatter, so a selection survives retitling, reordering and renumbered chapters.",
6
6
  "keywords": [
package/stamp.mjs CHANGED
@@ -13,7 +13,7 @@
13
13
  * would be forgotten once.
14
14
  */
15
15
  import { randomBytes } from 'node:crypto'
16
- import { closeSync, existsSync, openSync, readFileSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
16
+ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
17
17
  import path from 'node:path'
18
18
  import { injectPreparserExtensionLoader, load } from '@slidev/parser/fs'
19
19
  import { walkMarkdownFiles } from './identity.mjs'
@@ -180,12 +180,24 @@ const LOCK_STALE_MS = 60_000
180
180
  * matters the other run has written the ids, and stamping is idempotent anyway.
181
181
  */
182
182
  function withLock(profilesRoot, fn) {
183
- const lock = path.join(profilesRoot, PROFILE_DIR, LOCK_NAME)
183
+ const dir = path.join(profilesRoot, PROFILE_DIR)
184
+ const lock = path.join(dir, LOCK_NAME)
185
+ // The very first stamp of a deck runs before anyone has made a profile, so
186
+ // the directory the lock lives in may not exist yet. Creating it is not a
187
+ // side effect: stamping IS the deck opting in, and the profiles land here.
188
+ try {
189
+ mkdirSync(dir, { recursive: true })
190
+ }
191
+ catch {
192
+ // read-only, or a file in the way. The open below reports it properly.
193
+ }
184
194
  let handle
185
195
  try {
186
196
  handle = openSync(lock, 'wx')
187
197
  }
188
- catch {
198
+ catch (error) {
199
+ if (error?.code !== 'EEXIST')
200
+ return { skipped: true, reason: error?.code ?? 'unknown', stamped: [], total: 0 }
189
201
  // A lock left behind by a killed process must not block the deck forever.
190
202
  try {
191
203
  if (Date.now() - statSync(lock).mtimeMs > LOCK_STALE_MS)
@@ -193,7 +205,7 @@ function withLock(profilesRoot, fn) {
193
205
  handle = openSync(lock, 'wx')
194
206
  }
195
207
  catch {
196
- return { skipped: true, stamped: [], total: 0 }
208
+ return { skipped: true, reason: 'busy', stamped: [], total: 0 }
197
209
  }
198
210
  }
199
211
  try {
package/state.ts CHANGED
@@ -118,6 +118,15 @@ export function drift(currentIds: string[]) {
118
118
  * So whenever the endpoint answers, its profile wins over the frontmatter.
119
119
  */
120
120
  export async function loadServerState() {
121
+ // A built deck has no dev server and therefore no endpoint. Asking anyway
122
+ // costs every viewer a 404 on every load, and any tool that treats a failed
123
+ // request as a defect reports it - the BPM training's hub check flagged all
124
+ // 14 of its decks. The selection is baked into the frontmatter at build time,
125
+ // which is all a built deck needs.
126
+ if (!import.meta.env.DEV) {
127
+ ready.value = true
128
+ return
129
+ }
121
130
  try {
122
131
  const res = await fetch('/@speaker-profiles/state')
123
132
  if (!res.ok)