mikser-io 7.10.1 → 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 +4 -3
- package/src/plugins/post/pdf.js +0 -93
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mikser-io",
|
|
3
|
-
"version": "7.
|
|
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
|
},
|
package/src/plugins/post/pdf.js
DELETED
|
@@ -1,93 +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
|
-
const { default: puppeteer } = await import('puppeteer').catch(() => {
|
|
17
|
-
throw new Error('Puppeteer is required for the pdf postprocessor — run: npm install puppeteer')
|
|
18
|
-
})
|
|
19
|
-
// --no-sandbox / --disable-setuid-sandbox are required on most
|
|
20
|
-
// headless Linux servers and Docker images where Chrome's sandbox
|
|
21
|
-
// can't be set up. Applied by default and merged (deduped) with any
|
|
22
|
-
// user-supplied launch.args so callers can add flags without losing
|
|
23
|
-
// these. To run WITH the sandbox, override launch.args explicitly.
|
|
24
|
-
const defaultArgs = ['--no-sandbox', '--disable-setuid-sandbox']
|
|
25
|
-
|
|
26
|
-
// Resolve which chrome to use, in precedence order:
|
|
27
|
-
// 1. config.launch.executablePath — explicit, wins
|
|
28
|
-
// 2. config.executable — friendly top-level alias
|
|
29
|
-
// 3. PUPPETEER_EXECUTABLE_PATH — puppeteer's standard env var
|
|
30
|
-
// (useful for prod servers where
|
|
31
|
-
// the path differs from dev)
|
|
32
|
-
// 4. undefined → puppeteer's bundled download (the brittle path
|
|
33
|
-
// that fails when ~/.cache/puppeteer is half-populated)
|
|
34
|
-
//
|
|
35
|
-
// For headless production servers, pointing at a system chromium
|
|
36
|
-
// installed via apt (executable: '/usr/bin/chromium') skips
|
|
37
|
-
// puppeteer's postinstall download entirely. Set
|
|
38
|
-
// PUPPETEER_SKIP_DOWNLOAD=true at npm install time to keep it from
|
|
39
|
-
// even trying.
|
|
40
|
-
const executablePath =
|
|
41
|
-
config?.launch?.executablePath
|
|
42
|
-
?? config?.executable
|
|
43
|
-
?? process.env.PUPPETEER_EXECUTABLE_PATH
|
|
44
|
-
?? undefined
|
|
45
|
-
|
|
46
|
-
browser = await puppeteer.launch({
|
|
47
|
-
headless: true,
|
|
48
|
-
...config?.launch,
|
|
49
|
-
...(executablePath ? { executablePath } : {}),
|
|
50
|
-
args: [...new Set([...defaultArgs, ...(config?.launch?.args ?? [])])],
|
|
51
|
-
})
|
|
52
|
-
if (executablePath) {
|
|
53
|
-
logger.debug('Puppeteer browser launched (executable: %s)', executablePath)
|
|
54
|
-
} else {
|
|
55
|
-
logger.debug('Puppeteer browser launched (bundled chrome)')
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export async function postprocess({ entity, options, config, logger }) {
|
|
60
|
-
const sourcePath = path.join(options.outputFolder, entity.origin)
|
|
61
|
-
|
|
62
|
-
const page = await browser.newPage()
|
|
63
|
-
try {
|
|
64
|
-
await page.goto(`file://${sourcePath}`, {
|
|
65
|
-
waitUntil: 'networkidle0',
|
|
66
|
-
...config?.navigation
|
|
67
|
-
})
|
|
68
|
-
return await page.pdf({
|
|
69
|
-
format: 'A4',
|
|
70
|
-
printBackground: true,
|
|
71
|
-
...config?.pdf
|
|
72
|
-
})
|
|
73
|
-
} finally {
|
|
74
|
-
await page.close()
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export async function teardown({ options, config, logger }) {
|
|
79
|
-
if (!options?.watch) {
|
|
80
|
-
await browser?.close()
|
|
81
|
-
browser = undefined
|
|
82
|
-
logger.debug('Puppeteer browser closed')
|
|
83
|
-
return
|
|
84
|
-
}
|
|
85
|
-
const delay = config?.teardownDelay ?? TEARDOWN_DELAY
|
|
86
|
-
teardownTimer = setTimeout(async () => {
|
|
87
|
-
teardownTimer = undefined
|
|
88
|
-
await browser?.close()
|
|
89
|
-
browser = undefined
|
|
90
|
-
logger.debug('Puppeteer browser closed')
|
|
91
|
-
}, delay)
|
|
92
|
-
logger.debug('Puppeteer browser teardown scheduled in %dms', delay)
|
|
93
|
-
}
|