mikser-io 7.10.0 → 7.10.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": "mikser-io",
3
- "version": "7.10.0",
3
+ "version": "7.10.2",
4
4
  "description": "<p align=\"center\"> <img src=\"mikser-lockup-stacked.svg\" alt=\"mikser\" width=\"198\" /> </p>",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,21 +13,71 @@ export async function setup({ config, logger }) {
13
13
  return
14
14
  }
15
15
 
16
- const { default: puppeteer } = await import('puppeteer').catch(() => {
17
- throw new Error('Puppeteer is required for the pdf postprocessor run: npm install puppeteer')
18
- })
16
+ // Resolve which chrome to use, in precedence order:
17
+ // 1. config.launch.executablePath explicit, wins
18
+ // 2. config.executable — friendly top-level alias
19
+ // 3. PUPPETEER_EXECUTABLE_PATH — puppeteer's standard env var
20
+ // (useful for prod servers where
21
+ // the path differs from dev)
22
+ // 4. undefined → puppeteer's bundled download (the brittle path
23
+ // that fails when ~/.cache/puppeteer is half-populated)
24
+ //
25
+ // For headless production servers, pointing at a system chromium
26
+ // installed via apt skips puppeteer's postinstall download entirely.
27
+ const executablePath =
28
+ config?.launch?.executablePath
29
+ ?? config?.executable
30
+ ?? process.env.PUPPETEER_EXECUTABLE_PATH
31
+ ?? undefined
32
+
33
+ // Driver library: try `puppeteer` first (most common, bundles chrome),
34
+ // then `puppeteer-core` (same API without the chrome auto-download —
35
+ // the right choice when you've configured an external `executable`).
36
+ // Either is fine; either can drive any chrome binary you point at.
37
+ const puppeteer =
38
+ await import('puppeteer').then(m => m.default).catch(() => null)
39
+ ?? await import('puppeteer-core').then(m => m.default).catch(() => null)
40
+
41
+ if (!puppeteer) {
42
+ // Context-aware install instructions. If the user already configured
43
+ // an executable, they almost certainly want puppeteer-core (lean,
44
+ // no chrome download). Otherwise either works.
45
+ if (executablePath) {
46
+ throw new Error(
47
+ `post-pdf needs the puppeteer driver library to talk to chrome at ${executablePath}.\n` +
48
+ `Since you've configured an external executable, install the lean driver (no bundled chrome):\n` +
49
+ ` npm install puppeteer-core`
50
+ )
51
+ }
52
+ throw new Error(
53
+ 'post-pdf needs a puppeteer driver to render PDFs.\n' +
54
+ 'Two options:\n' +
55
+ ' - Quickest: npm install puppeteer (bundles chrome ~500MB)\n' +
56
+ ' - Headless: sudo apt install google-chrome-stable\n' +
57
+ ' npm install puppeteer-core (no chrome download)\n' +
58
+ ' # then in mikser.config.js:\n' +
59
+ " 'post-pdf': { executable: '/usr/bin/google-chrome-stable' }"
60
+ )
61
+ }
62
+
19
63
  // --no-sandbox / --disable-setuid-sandbox are required on most
20
64
  // headless Linux servers and Docker images where Chrome's sandbox
21
65
  // can't be set up. Applied by default and merged (deduped) with any
22
66
  // user-supplied launch.args so callers can add flags without losing
23
67
  // these. To run WITH the sandbox, override launch.args explicitly.
24
68
  const defaultArgs = ['--no-sandbox', '--disable-setuid-sandbox']
69
+
25
70
  browser = await puppeteer.launch({
26
71
  headless: true,
27
72
  ...config?.launch,
73
+ ...(executablePath ? { executablePath } : {}),
28
74
  args: [...new Set([...defaultArgs, ...(config?.launch?.args ?? [])])],
29
75
  })
30
- logger.debug('Puppeteer browser launched')
76
+ if (executablePath) {
77
+ logger.debug('Puppeteer browser launched (executable: %s)', executablePath)
78
+ } else {
79
+ logger.debug('Puppeteer browser launched (bundled chrome)')
80
+ }
31
81
  }
32
82
 
33
83
  export async function postprocess({ entity, options, config, logger }) {