Skip to content

Commit

Permalink
Fix TypeScript error
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Sep 15, 2024
1 parent fe90d85 commit bf16916
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
36 changes: 19 additions & 17 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,23 +296,25 @@ export class Converter {

let outlineData: OutlineData | undefined

ret.buffer = await this.usePuppeteer(html, async (page, { render }) => {
await render()

if (tpl.rendered.outline) {
outlineData = await page.evaluate(
pptrOutlinePositionResolver,
tpl.rendered.outline.flatMap((o) => o.headings),
pdfOutlineAttr
)
}
ret.buffer = Buffer.from(
await this.usePuppeteer(html, async (page, { render }) => {
await render()

if (tpl.rendered.outline) {
outlineData = await page.evaluate(
pptrOutlinePositionResolver,
tpl.rendered.outline.flatMap((o) => o.headings),
pdfOutlineAttr
)
}

return await page.pdf({
printBackground: true,
preferCSSPageSize: true,
timeout: this.puppeteerTimeout,
return await page.pdf({
printBackground: true,
preferCSSPageSize: true,
timeout: this.puppeteerTimeout,
})
})
})
)

// Apply PDF metadata and annotations
const creationDate = new Date()
Expand Down Expand Up @@ -426,14 +428,14 @@ export class Converter {
page,
extension: opts.type,
})
ret.buffer = await screenshot(page)
ret.buffer = Buffer.from(await screenshot(page))

files.push(ret)
}
} else {
// Title image
const ret = file.convert(this.options.output, { extension: opts.type })
ret.buffer = await screenshot()
ret.buffer = Buffer.from(await screenshot())

files.push(ret)
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { isWSL, resolveWindowsEnv } from './wsl'
let executablePath: string | undefined | false = false
let wslTmp: string | undefined

export const enableHeadless = (): true | 'new' =>
process.env.PUPPETEER_HEADLESS_MODE?.toLowerCase() === 'new' ? 'new' : true
export const enableHeadless = (): 'shell' | true =>
process.env.PUPPETEER_HEADLESS_MODE?.toLowerCase() === 'new' ? true : 'shell'

const isShebang = (path: string) => {
let fd: number | null = null
Expand Down
6 changes: 3 additions & 3 deletions src/watcher.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable @typescript-eslint/no-namespace */
import crypto from 'crypto'
import path from 'path'
import chokidar from 'chokidar'
import chokidar, { type FSWatcher } from 'chokidar'
import { getPortPromise } from 'portfinder'
import { Server as WSServer, ServerOptions } from 'ws'
import { Converter, ConvertedCallback } from './converter'
import { isError } from './error'
import { File, FileType } from './file'

export class Watcher {
chokidar: chokidar.FSWatcher
chokidar: FSWatcher

readonly converter: Converter
readonly events: Watcher.Events
Expand All @@ -23,7 +23,7 @@ export class Watcher {
this.mode = opts.mode

this.chokidar = chokidar
.watch(watchPath, { disableGlobbing: true, ignoreInitial: true })
.watch(watchPath, { ignoreInitial: true })
.on('change', (f) => this.convert(f))
.on('add', (f) => this.convert(f))
.on('unlink', (f) => this.delete(f))
Expand Down

0 comments on commit bf16916

Please sign in to comment.