@writedocs/generator 0.10.11 → 0.10.13

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": "@writedocs/generator",
3
- "version": "0.10.11",
3
+ "version": "0.10.13",
4
4
  "description": "Static site generator for docs — a writedocs.json + MDX folder in, a static site out.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -17,6 +17,7 @@
17
17
  // { type: 'fatal', error } - see serializeError()
18
18
  import path from 'node:path';
19
19
  import { build, dev } from 'astro';
20
+ import { exitWhenFlushed } from './exit-when-flushed.js';
20
21
 
21
22
  const command = process.argv[2];
22
23
  const packageRoot = process.env.WRITEDOCS_PACKAGE_ROOT;
@@ -40,11 +41,11 @@ function serializeError(err) {
40
41
  };
41
42
  }
42
43
 
44
+ // Both ways out go through exitWhenFlushed(): the last message and whatever
45
+ // was printed (a page's console.log goes straight to stdout) have left this
46
+ // process before it exits - see exit-when-flushed.js.
43
47
  async function fail(err) {
44
- send({ type: 'fatal', error: serializeError(err) });
45
- // Let the IPC message leave before exiting.
46
- await new Promise((resolve) => setTimeout(resolve, 50));
47
- process.exit(1);
48
+ await exitWhenFlushed(1, { type: 'fatal', error: serializeError(err) });
48
49
  }
49
50
 
50
51
  process.on('uncaughtException', fail);
@@ -67,9 +68,7 @@ try {
67
68
  send({ type: 'ready', urls: server.resolvedUrls ?? { local: [], network: [] } });
68
69
  } else if (command === 'build') {
69
70
  await build(inlineConfig);
70
- send({ type: 'done' });
71
- await new Promise((resolve) => setTimeout(resolve, 50));
72
- process.exit(0);
71
+ await exitWhenFlushed(0, { type: 'done' });
73
72
  } else {
74
73
  throw new Error(`astro-worker: unknown command "${command}"`);
75
74
  }
@@ -0,0 +1,38 @@
1
+ // Leaving a process without losing what it printed. astro-worker.js ends with
2
+ // process.exit() - Astro leaves handles open, so the process wouldn't end by
3
+ // itself - and on a pipe both stdout/stderr and the IPC channel are
4
+ // asynchronous (on Linux): exit() drops whatever is still queued in the
5
+ // process. A fixed wait isn't enough: a page that prints 1 MiB on a busy
6
+ // machine still had most of it queued after 50 ms, and the CLI got the output
7
+ // cut short with the build exiting 0.
8
+ //
9
+ // Plain JavaScript with no Astro import, so scripts/exit-when-flushed.test.js
10
+ // can run it in a child process of its own.
11
+
12
+ /** How long the wait may take. If the CLI stops reading (alive, but stuck),
13
+ * the worker exits anyway instead of hanging. */
14
+ export const MAX_FLUSH_WAIT_MS = 10_000;
15
+
16
+ /** Resolves once everything written to `stream` so far has left the process. */
17
+ function flushed(stream) {
18
+ return new Promise((resolve) => {
19
+ if (!stream.writable || stream.destroyed) return resolve();
20
+ stream.write('', () => resolve());
21
+ });
22
+ }
23
+
24
+ /** Sends `lastMessage` to the parent (when there is one), waits for it and
25
+ * for stdout and stderr to leave the process, then exits with `code` - or
26
+ * after `maxWaitMs`, whichever comes first. */
27
+ export async function exitWhenFlushed(code, lastMessage, { maxWaitMs = MAX_FLUSH_WAIT_MS } = {}) {
28
+ // unref: the timer alone never keeps the process alive.
29
+ const deadline = setTimeout(() => process.exit(code), maxWaitMs);
30
+ deadline.unref();
31
+ await new Promise((resolve) => {
32
+ if (lastMessage !== undefined && typeof process.send === 'function' && process.connected) {
33
+ process.send(lastMessage, () => resolve());
34
+ } else resolve();
35
+ });
36
+ await Promise.all([flushed(process.stdout), flushed(process.stderr)]);
37
+ process.exit(code);
38
+ }
@@ -58,14 +58,13 @@
58
58
  gap: 0.5rem;
59
59
  font-weight: 600;
60
60
  text-decoration: none;
61
- /* --wd-navbar-foreground, not --wd-text - falls back to var(--wd-text)
62
- when theme.navbar has no `foreground` set (see BaseLayout.astro), so
63
- this is a no-op for the common case; only matters once a site's
64
- navbar background is far enough from the page background that
65
- --wd-text reads poorly against it. Also picked up by
61
+ /* The site's name, when there's no logo: the navbar's strongest color,
62
+ like the current tab - the heading color, or the computed black/white
63
+ on a navbar with its own `styles.navbar` color (see
64
+ --wd-navbar-foreground-strong in BaseLayout.astro). Also picked up by
66
65
  MobileMenu.astro's own copy of this same class in its drawer header -
67
66
  see this file's own top comment. */
68
- color: var(--wd-navbar-foreground);
67
+ color: var(--wd-navbar-foreground-strong);
69
68
  font-size: 1.05rem;
70
69
  /* When the row runs short, a long site name gives way (ending in "..."),
71
70
  not the switchers next to it - their labels would break onto two lines. */
@@ -9,11 +9,12 @@
9
9
  // like Mintlify's - they pick what the sidebar shows
10
10
  // 'topbar' a switcher next to the site name (everything else)
11
11
  // 'none' not shown: the page is inside a hidden item on this level
12
- // (lib/hidden-sections.js)
12
+ // (lib/hidden-sections.js), or it's a 'sidebar' level on a
13
+ // page without a sidebar (below)
13
14
  //
14
- // Without a sidebar on the page (`mode: custom` / `blank`), a 'sidebar'
15
- // switcher goes to the top bar instead. The mobile menu lists every level
16
- // either way.
15
+ // Without a sidebar on the page (`mode: frame` / `custom` / `blank`), a
16
+ // 'sidebar' switcher isn't shown - a hand-built page keeps its top bar to
17
+ // the site's own levels. The mobile menu lists every level either way.
17
18
 
18
19
  export function selectorPlacements(selectors, { sidebar = true } = {}) {
19
20
  const placements = [];
@@ -24,7 +25,7 @@ export function selectorPlacements(selectors, { sidebar = true } = {}) {
24
25
  if (sel.kind === 'tab') return 'tabs';
25
26
  if (sel.kind === 'dropdown' && parent === 'tab') return 'tab-menu';
26
27
  if (sel.kind === 'dropdown' && placements[i - 1] === 'tab-menu') return 'tab-submenu';
27
- if (sel.kind === 'product' && (parent === 'tab' || parent === 'dropdown')) return sidebar ? 'sidebar' : 'topbar';
28
+ if (sel.kind === 'product' && (parent === 'tab' || parent === 'dropdown')) return sidebar ? 'sidebar' : 'none';
28
29
  return 'topbar';
29
30
  })();
30
31
  placements.push(placement);