Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependent packages to the latest version #319

Merged
merged 7 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
### Changed

- Use Noto CJK font instead of broken font-ipa in Docker image ([#318](https://github.com/marp-team/marp-cli/pull/318))
- Upgrade [Marpit v1.6.4](https://github.com/marp-team/marpit/releases/tag/v1.6.4) and [Marp Core v1.4.1](https://github.com/marp-team/marp-core/releases/tag/v1.4.1) ([#319](https://github.com/marp-team/marp-cli/pull/319))
- Upgrade dependent packages to the latest version ([#319](https://github.com/marp-team/marp-cli/pull/319))

## v0.23.0 - 2020-12-05

Expand Down
63 changes: 31 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,31 @@
"watch": "rollup -w -c"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-node-resolve": "^11.1.1",
"@rollup/plugin-replace": "^2.3.4",
"@rollup/plugin-typescript": "^8.0.0",
"@rollup/plugin-typescript": "^8.1.1",
"@rollup/plugin-url": "^6.0.0",
"@types/cheerio": "^0.22.22",
"@types/express": "^4.17.9",
"@types/jest": "^26.0.16",
"@types/node": "~14.14.10",
"@types/cheerio": "^0.22.23",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.20",
"@types/node": "~14.14.25",
"@types/pug": "^2.0.4",
"@types/puppeteer": "^5.4.1",
"@types/supertest": "^2.0.10",
"@types/ws": "^7.4.0",
"@types/yargs": "^15.0.11",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"@types/yargs": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"autoprefixer": "^9.8.6",
"bespoke": "bespokejs/bespoke",
"builtin-modules": "^3.1.0",
"builtin-modules": "^3.2.0",
"chalk": "^4.1.0",
"cheerio": "^1.0.0-rc.3",
"cheerio": "^1.0.0-rc.5",
"codecov": "^3.8.1",
"cssnano": "^4.1.10",
"eslint": "^7.15.0",
"eslint-config-prettier": "^6.15.0",
"eslint": "^7.19.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.3",
"file-url": "^3.0.0",
Expand All @@ -108,44 +107,44 @@
"prettier": "^2.2.1",
"pug": "^3.0.0",
"rimraf": "^3.0.2",
"rollup": "^2.34.1",
"rollup": "^2.38.5",
"rollup-plugin-postcss": "^3.1.8",
"rollup-plugin-pug": "^1.1.1",
"rollup-plugin-terser": "^7.0.2",
"sass": "^1.30.0",
"screenfull": "^5.0.2",
"sass": "^1.32.6",
"screenfull": "^5.1.0",
"strip-ansi": "^6.0.0",
"stylelint": "^13.8.0",
"stylelint": "^13.9.0",
"stylelint-config-prettier": "^8.0.2",
"stylelint-config-standard": "^20.0.0",
"stylelint-scss": "^3.18.0",
"supertest": "^6.0.1",
"tar-stream": "^2.1.4",
"ts-jest": "^26.4.4",
"supertest": "^6.1.3",
"tar-stream": "^2.2.0",
"ts-jest": "^26.5.0",
"ts-keycode-enum": "^1.0.6",
"tslib": "^2.0.3",
"typescript": "^4.1.2",
"tslib": "^2.1.0",
"typescript": "^4.1.3",
"vhtml": "^2.2.0",
"wrap-ansi": "^7.0.0",
"yauzl": "^2.10.0",
"zip-stream": "^4.0.4"
},
"dependencies": {
"@marp-team/marp-core": "^1.4.0",
"@marp-team/marpit": "^1.6.3",
"chokidar": "^3.4.3",
"@marp-team/marp-core": "^1.4.1",
"@marp-team/marpit": "^1.6.4",
"chokidar": "^3.5.1",
"chrome-launcher": "^0.13.4",
"cosmiconfig": "^7.0.0",
"express": "^4.17.1",
"globby": "^11.0.1",
"globby": "^11.0.2",
"import-from": "^3.0.0",
"pptxgenjs": "^3.3.1",
"puppeteer-core": "~5.5.0",
"pptxgenjs": "^3.4.0",
"puppeteer-core": "~7.0.1",
"serve-index": "^1.9.1",
"tmp": "^0.2.1",
"v8-compile-cache": "^2.2.0",
"ws": "^7.4.1",
"yargs": "^16.1.1"
"ws": "^7.4.3",
"yargs": "^16.2.0"
},
"publishConfig": {
"access": "public"
Expand Down
21 changes: 13 additions & 8 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { URL } from 'url'
import { MarpOptions } from '@marp-team/marp-core'
import { Marpit, Options as MarpitOptions } from '@marp-team/marpit'
import chalk from 'chalk'
import puppeteer from 'puppeteer-core'
import { silence, warn } from './cli'
import { Engine } from './engine'
import infoPlugin, { engineInfo, EngineInfo } from './engine/info-plugin'
Expand All @@ -22,6 +21,9 @@ import {
generatePuppeteerDataDirPath,
generatePuppeteerLaunchArgs,
launchPuppeteer,
PuppeteerBrowser,
PuppeteerPage,
PuppeteerRequest,
} from './utils/puppeteer'
import { isChromeInWSLHost, resolveWSLPathToHost } from './utils/wsl'
import { notifier } from './watcher'
Expand Down Expand Up @@ -267,9 +269,12 @@ export class Converter {
)

if (opts.type === ConvertType.jpeg)
return await page.screenshot({ quality: opts.quality, type: 'jpeg' })
return (await page.screenshot({
quality: opts.quality,
type: 'jpeg',
})) as Buffer

return await page.screenshot({ type: 'png' })
return (await page.screenshot({ type: 'png' })) as Buffer
}

if (opts.pages) {
Expand Down Expand Up @@ -362,7 +367,7 @@ export class Converter {

private async usePuppeteer<T>(
baseFile: File,
processer: (page: puppeteer.Page, uri: string) => Promise<T>
processer: (page: PuppeteerPage, uri: string) => Promise<T>
) {
const tmpFile: File.TmpFileInterface | undefined = await (() => {
if (!this.options.allowLocalFiles) return undefined
Expand All @@ -384,7 +389,7 @@ export class Converter {

const uri = await (async () => {
if (tmpFile) {
if (isChromeInWSLHost(browser.process().spawnfile)) {
if (isChromeInWSLHost(browser.process()?.spawnfile)) {
// Windows Chrome should read file from WSL environment
return `file:${await resolveWSLPathToHost(tmpFile.path)}`
}
Expand Down Expand Up @@ -429,12 +434,12 @@ export class Converter {
}

private trackFailedLocalFileAccess(
page: puppeteer.Page
page: PuppeteerPage
): { missingFileSet: Set<string>; failedFileSet: Set<string> } {
const missingFileSet = new Set<string>()
const failedFileSet = new Set<string>()

page.on('requestfailed', (req: puppeteer.Request) => {
page.on('requestfailed', (req: PuppeteerRequest) => {
try {
const url = new URL(req.url())
if (url.protocol === 'file:') {
Expand All @@ -456,7 +461,7 @@ export class Converter {
if (Converter.browser) await Converter.browser.close()
}

private static browser?: puppeteer.Browser
private static browser?: PuppeteerBrowser

private static async runBrowser() {
if (!Converter.browser) {
Expand Down
20 changes: 11 additions & 9 deletions src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable import/export, @typescript-eslint/no-namespace */
import { EventEmitter } from 'events'
import { nanoid } from 'nanoid'
import puppeteer from 'puppeteer-core'
import favicon from './assets/favicon.png'
import { ConvertType, mimeTypes } from './converter'
import { error } from './error'
Expand All @@ -10,6 +9,9 @@ import {
generatePuppeteerDataDirPath,
generatePuppeteerLaunchArgs,
launchPuppeteer,
PuppeteerBrowser,
PuppeteerPage,
PuppeteerTarget,
} from './utils/puppeteer'
import TypedEventEmitter from './utils/typed-event-emitter'
import { isChromeInWSLHost } from './utils/wsl'
Expand All @@ -32,7 +34,7 @@ export namespace Preview {
export class Preview extends TypedEventEmitter<Preview.Events> {
readonly options: Preview.Options

private puppeteerInternal: puppeteer.Browser | undefined
private puppeteerInternal: PuppeteerBrowser | undefined

constructor(opts: Partial<Preview.Options> = {}) {
super()
Expand All @@ -42,7 +44,7 @@ export class Preview extends TypedEventEmitter<Preview.Events> {
}
}

get puppeteer(): puppeteer.Browser | undefined {
get puppeteer(): PuppeteerBrowser | undefined {
return this.puppeteerInternal
}

Expand All @@ -67,7 +69,7 @@ export class Preview extends TypedEventEmitter<Preview.Events> {
}
}

private createWindowObject(page: puppeteer.Page) {
private createWindowObject(page: PuppeteerPage) {
const window = new EventEmitter()

page.on('close', async () => window.emit('close'))
Expand Down Expand Up @@ -100,17 +102,17 @@ export class Preview extends TypedEventEmitter<Preview.Events> {
private async createWindow() {
try {
return this.createWindowObject(
await new Promise<puppeteer.Page>((res, rej) => {
await new Promise<PuppeteerPage>((res, rej) => {
const pptr = this.puppeteer
if (!pptr) return rej(false)

const id = nanoid()
const idMatcher = (target: puppeteer.Target) => {
const idMatcher = (target: PuppeteerTarget) => {
const url = new URL(target.url())

if (url.searchParams.get('__marp_cli_id') === id) {
pptr.removeListener('targetcreated', idMatcher)
res(target.page())
pptr.off('targetcreated', idMatcher)
;(async () => res((await target.page())!))() // eslint-disable-line @typescript-eslint/no-non-null-assertion
}
}

Expand Down Expand Up @@ -143,7 +145,7 @@ export class Preview extends TypedEventEmitter<Preview.Events> {
`--app=data:text/html,<title>${encodeURIComponent('Marp CLI')}</title>`,
`--window-size=${this.options.width},${this.options.height}`,
],
defaultViewport: null,
defaultViewport: null as any,
headless: process.env.NODE_ENV === 'test',
userDataDir: await generatePuppeteerDataDirPath('marp-cli-preview', {
wslHost: isChromeInWSLHost(baseArgs.executablePath),
Expand Down
3 changes: 1 addition & 2 deletions src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ declare module '*.scss' {
}

declare module 'puppeteer-core' {
// eslint-disable-next-line import/no-unresolved
import * as puppeteer from 'puppeteer'
import * as puppeteer from 'puppeteer-core/cjs-entry'
export = puppeteer
}
24 changes: 13 additions & 11 deletions src/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ import { CLIErrorCode, error } from '../error'
import { findEdgeInstallation } from './edge-finder'
import { isWSL, resolveWindowsEnv } from './wsl'

type UnwrapPromise<T> = T extends Promise<infer U> ? U : never

export type PuppeteerBrowser = UnwrapPromise<
ReturnType<typeof puppeteer['launch']>
>
export type PuppeteerPage = UnwrapPromise<
ReturnType<PuppeteerBrowser['newPage']>
>
export type PuppeteerRequest = UnwrapPromise<
ReturnType<PuppeteerPage['waitForRequest']>
>
export type PuppeteerTarget = ReturnType<PuppeteerBrowser['target']>

let executablePath: string | undefined | false = false
let wslTmp: string | undefined

Expand Down Expand Up @@ -81,16 +94,7 @@ export const generatePuppeteerLaunchArgs = () => {
export const launchPuppeteer = async (
...[options]: Parameters<typeof puppeteer['launch']>
) => {
const { arch } = os

try {
os.arch = () => {
// Patch for Apple M1 (arm64)
// @see https://github.com/puppeteer/puppeteer/issues/6634
if (process.platform === 'darwin' && arch() === 'arm64') return 'x64'
return arch()
}

return await puppeteer.launch(options)
} catch (e) {
if (e instanceof Error) {
Expand All @@ -107,8 +111,6 @@ export const launchPuppeteer = async (
}

throw e
} finally {
os.arch = arch
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ describe('Converter', () => {
const coreProps = $('cp\\:coreProperties')

coreProps.children().each((_, elm) => {
meta[elm.tagName] = $(elm).text()
meta[elm['tagName']] = $(elm).text()
})

zip.readEntry()
Expand Down
Loading