mikser-io 7.10.2 → 7.11.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mikser-io",
3
- "version": "7.10.2",
3
+ "version": "7.11.0",
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": {
@@ -53,18 +53,19 @@
53
53
  "yaml": "^2.9.0"
54
54
  },
55
55
  "optionalDependencies": {
56
- "express": "^5.2.1",
57
- "puppeteer": "^25.1.0"
56
+ "express": "^5.2.1"
58
57
  },
59
58
  "devDependencies": {
60
59
  "fluent-ffmpeg": "^2.1.3",
61
60
  "mikser-io-decap": "file:../mikser-io-decap",
62
61
  "mikser-io-post-mjml": "file:../mikser-io-post-mjml",
62
+ "mikser-io-post-pdf": "file:../mikser-io-post-pdf",
63
63
  "mikser-io-render-eta": "file:../mikser-io-render-eta",
64
64
  "mikser-io-render-liquid": "file:../mikser-io-render-liquid",
65
65
  "mikser-io-render-markdown": "file:../mikser-io-render-markdown",
66
66
  "mikser-io-schemas": "file:../mikser-io-schemas",
67
67
  "mikser-io-vector": "file:../mikser-io-vector",
68
+ "puppeteer": "^25.1.0",
68
69
  "sharp": "^0.34.5",
69
70
  "zod": "^4.4.3"
70
71
  },
@@ -1,117 +0,0 @@
1
- import path from 'node:path'
2
-
3
- const TEARDOWN_DELAY = 60_000
4
-
5
- let browser
6
- let teardownTimer
7
-
8
- export async function setup({ config, logger }) {
9
- if (teardownTimer) {
10
- clearTimeout(teardownTimer)
11
- teardownTimer = undefined
12
- logger.debug('Puppeteer browser reused')
13
- return
14
- }
15
-
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
-
63
- // --no-sandbox / --disable-setuid-sandbox are required on most
64
- // headless Linux servers and Docker images where Chrome's sandbox
65
- // can't be set up. Applied by default and merged (deduped) with any
66
- // user-supplied launch.args so callers can add flags without losing
67
- // these. To run WITH the sandbox, override launch.args explicitly.
68
- const defaultArgs = ['--no-sandbox', '--disable-setuid-sandbox']
69
-
70
- browser = await puppeteer.launch({
71
- headless: true,
72
- ...config?.launch,
73
- ...(executablePath ? { executablePath } : {}),
74
- args: [...new Set([...defaultArgs, ...(config?.launch?.args ?? [])])],
75
- })
76
- if (executablePath) {
77
- logger.debug('Puppeteer browser launched (executable: %s)', executablePath)
78
- } else {
79
- logger.debug('Puppeteer browser launched (bundled chrome)')
80
- }
81
- }
82
-
83
- export async function postprocess({ entity, options, config, logger }) {
84
- const sourcePath = path.join(options.outputFolder, entity.origin)
85
-
86
- const page = await browser.newPage()
87
- try {
88
- await page.goto(`file://${sourcePath}`, {
89
- waitUntil: 'networkidle0',
90
- ...config?.navigation
91
- })
92
- return await page.pdf({
93
- format: 'A4',
94
- printBackground: true,
95
- ...config?.pdf
96
- })
97
- } finally {
98
- await page.close()
99
- }
100
- }
101
-
102
- export async function teardown({ options, config, logger }) {
103
- if (!options?.watch) {
104
- await browser?.close()
105
- browser = undefined
106
- logger.debug('Puppeteer browser closed')
107
- return
108
- }
109
- const delay = config?.teardownDelay ?? TEARDOWN_DELAY
110
- teardownTimer = setTimeout(async () => {
111
- teardownTimer = undefined
112
- await browser?.close()
113
- browser = undefined
114
- logger.debug('Puppeteer browser closed')
115
- }, delay)
116
- logger.debug('Puppeteer browser teardown scheduled in %dms', delay)
117
- }