Skip to content

Commit

Permalink
Merge pull request #151 from marp-team/update-dependencies
Browse files Browse the repository at this point in the history
Upgrade development Node and dependent packages to the latest version
  • Loading branch information
yhatt authored Jul 25, 2020
2 parents 704fbbb + 0f7c05a commit c4df74c
Show file tree
Hide file tree
Showing 11 changed files with 892 additions and 959 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.18.0
12.18.2
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## [Unreleased]

### Changed

- Upgrade to [Marp Core v1.2.2](https://github.com/marp-team/marp-core/releases/v1.2.2) and [Marp CLI v0.20.0](https://github.com/marp-team/marp-cli/releases/v0.20.0) ([#151](https://github.com/marp-team/marp-vscode/pull/151))
- Upgrade development Node and dependent packages to the latest version ([#151](https://github.com/marp-team/marp-vscode/pull/151))

## v0.14.0 - 2020-06-14

### Added
Expand Down
37 changes: 18 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,46 +219,45 @@
"watch": "rollup -w -c ./rollup.config.js"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.1",
"@rollup/plugin-commonjs": "^13.0.0",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^8.0.1",
"@rollup/plugin-typescript": "^4.1.2",
"@types/jest": "^26.0.0",
"@rollup/plugin-node-resolve": "^8.4.0",
"@rollup/plugin-typescript": "^5.0.2",
"@types/jest": "^26.0.7",
"@types/lodash.debounce": "^4.0.6",
"@types/markdown-it": "^10.0.1",
"@types/vscode": "~1.40.0",
"@types/yaml": "^1.9.7",
"builtin-modules": "^3.1.0",
"codecov": "^3.7.0",
"codecov": "^3.7.2",
"dedent": "^0.7.0",
"jest": "^26.0.1",
"jest-junit": "^10.0.0",
"jest": "^26.1.0",
"jest-junit": "^11.0.1",
"lodash.debounce": "^4.0.8",
"markdown-it": "^11.0.0",
"nanoid": "^3.1.10",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.5",
"rehype-parse": "^7.0.0",
"remark-parse": "^8.0.2",
"rehype-parse": "^7.0.1",
"remark-parse": "^8.0.3",
"rimraf": "^3.0.2",
"rollup": "^2.16.1",
"rollup": "^2.23.0",
"rollup-plugin-terser": "^6.1.0",
"stylelint": "^13.6.0",
"stylelint-config-prettier": "^8.0.1",
"stylelint": "^13.6.1",
"stylelint-config-prettier": "^8.0.2",
"stylelint-config-standard": "^20.0.0",
"ts-jest": "^26.1.0",
"ts-jest": "^26.1.3",
"tslint": "^6.1.2",
"tslint-config-airbnb": "^5.11.2",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.9.5",
"unified": "^9.0.0",
"unist-util-visit": "^2.0.2",
"typescript": "^3.9.7",
"unified": "^9.1.0",
"unist-util-visit": "^2.0.3",
"yaml": "^1.10.0"
},
"dependencies": {
"@marp-team/marp-cli": "^0.18.1",
"@marp-team/marp-core": "^1.2.0",
"@marp-team/marp-cli": "^0.20.0",
"@marp-team/marp-core": "^1.2.2",
"axios": "^0.19.2"
}
}
27 changes: 12 additions & 15 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path'
import alias from '@rollup/plugin-alias'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import nodeResolve from '@rollup/plugin-node-resolve'
Expand All @@ -8,35 +7,33 @@ import builtinModules from 'builtin-modules'
import { terser } from 'rollup-plugin-terser'
import pkg from './package.json'

const compact = !process.env.ROLLUP_WATCH
const sourcemap = !compact

const plugins = [
alias({
entries: {
// TODO: Remove aliasing if rollup bug was fixed
// @see https://github.com/rollup/plugins/issues/102
'@marp-team/marp-core/browser': require.resolve(
'@marp-team/marp-core/lib/browser.cjs'
),
},
}),
json({ preferConst: true }),
nodeResolve({ mainFields: ['module', 'jsnext:main', 'main'] }),
commonjs(),
typescript(),
!process.env.ROLLUP_WATCH && terser(),
compact && terser(),
]

const sourcemap = !!process.env.ROLLUP_WATCH

export default [
{
external: [...Object.keys(pkg.dependencies), ...builtinModules, 'vscode'],
input: `src/${path.basename(pkg.main, '.js')}.ts`,
output: { exports: 'named', file: pkg.main, format: 'cjs', sourcemap },
output: {
compact,
exports: 'named',
file: pkg.main,
format: 'cjs',
sourcemap,
},
plugins,
},
{
input: 'preview.js',
output: { file: 'lib/preview.js', format: 'iife', sourcemap },
output: { compact, file: 'lib/preview.js', format: 'iife', sourcemap },
plugins,
},
]
2 changes: 1 addition & 1 deletion src/commands/export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('#doExport', () => {

await exportModule.doExport(saveURI, document)
expect(window.showErrorMessage).toBeCalledWith(
expect.stringContaining('Error: ERROR')
expect.stringContaining('[Error] ERROR')
)
})
})
9 changes: 6 additions & 3 deletions src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ export const doExport = async (uri: Uri, document: TextDocument) => {
}
} catch (e) {
window.showErrorMessage(
`Failure to export. ${
e instanceof MarpCLIError ? e.message : e.toString()
}`
`Failure to export${(() => {
if (e instanceof MarpCLIError) return `. ${e.message}`
if (e instanceof Error) return `: [${e.name}] ${e.message}`
return `. ${e.toString()}`
})()}`
)
} finally {
input.cleanup()
Expand Down
29 changes: 16 additions & 13 deletions src/marp-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,29 @@ describe('Marp CLI integration', () => {
jest.spyOn(console, 'log').mockImplementation()
})

it('runs Marp CLI with passed args and --no-stdin option', async () => {
const marpCliSpy = jest.spyOn(marpCliModule, 'default')
it('runs Marp CLI with passed args', async () => {
const marpCliSpy = jest.spyOn(marpCliModule, 'marpCli')
await runMarpCli('--version')

// --no-stdin prevents getting stuck
expect(marpCliSpy).toBeCalledWith(['--no-stdin', '--version'])
expect(marpCliSpy).toBeCalledWith(['--version'])
})

it('throws MarpCLIError when returned error exit code', async () => {
jest.spyOn(marpCliModule, 'default').mockResolvedValue(1)
expect(runMarpCli('--version')).rejects.toThrow(marpCli.MarpCLIError)
jest.spyOn(marpCliModule, 'marpCli').mockResolvedValue(1)
await expect(runMarpCli('--version')).rejects.toThrow(marpCli.MarpCLIError)
})

it('throws error with helpful message when outputed error about Chrome', async () => {
jest.spyOn(marpCliModule, 'default').mockImplementation(() => {
console.error('Chromium revision is not downloaded.')
return Promise.resolve(1)
})

expect(runMarpCli('--version')).rejects.toThrow(/Google Chrome/)
jest
.spyOn(marpCliModule, 'marpCli')
.mockRejectedValue(
new marpCliModule.CLIError(
'mocked error',
marpCliModule.CLIErrorCode.NOT_FOUND_CHROMIUM
)
)

await expect(runMarpCli('--version')).rejects.toThrow(/Google Chrome/)
})

describe('with markdown.marp.chromePath preference', () => {
Expand All @@ -51,7 +54,7 @@ describe('Marp CLI integration', () => {
setConfiguration({ 'markdown.marp.chromePath': __filename })

const marpCliSpy = jest
.spyOn(marpCliModule, 'default')
.spyOn(marpCliModule, 'marpCli')
.mockImplementation(async () => {
expect(process.env.CHROME_PATH).toBe(__filename)
return 0
Expand Down
72 changes: 31 additions & 41 deletions src/marp-cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import marpCli from '@marp-team/marp-cli'
import { unlink, writeFile } from 'fs'
import { nanoid } from 'nanoid'
import { tmpdir } from 'os'
Expand All @@ -8,9 +7,6 @@ import { TextDocument, workspace } from 'vscode'
import { WorkFile, marpCoreOptionForCLI } from './option'
import { marpConfiguration } from './utils'

const marpCliAsync = async (): Promise<typeof marpCli> =>
(await import('@marp-team/marp-cli')).default

const promiseWriteFile = promisify(writeFile)
const promiseUnlink = promisify(unlink)

Expand Down Expand Up @@ -77,52 +73,46 @@ export async function createConfigFile(
}
}

export default async function runMarpCli(...opts: string[]): Promise<void> {
const argv = ['--no-stdin', ...opts]
export default async function runMarpCli(...argv: string[]): Promise<void> {
console.info(`Execute Marp CLI: ${argv.join(' ')}`)

// Track error log to show better feedback
const errors: object[] = []
const { error } = console
const { marpCli, CLIError, CLIErrorCode } = await import(
'@marp-team/marp-cli'
)
const { CHROME_PATH } = process.env

console.error = (...args) => {
errors.push(...args)
return error(...args)
}
let exitCode: number

try {
const marpCliInstance = await marpCliAsync()
const { CHROME_PATH } = process.env

let exitCode: number
process.env.CHROME_PATH =
marpConfiguration().get<string>('chromePath') || CHROME_PATH

exitCode = await marpCli(argv)
} catch (e) {
console.error(e)

if (
e instanceof CLIError &&
e.errorCode === CLIErrorCode.NOT_FOUND_CHROMIUM
) {
const chromium =
process.platform === 'linux'
? ' or [Chromium](https://www.chromium.org/)'
: ''

try {
process.env.CHROME_PATH =
marpConfiguration().get<string>('chromePath') || CHROME_PATH

exitCode = await marpCliInstance(argv)
} finally {
process.env.CHROME_PATH = CHROME_PATH
}

if (exitCode !== 0) {
for (const err of errors) {
if (err.toString().includes('Chromium revision is not downloaded.')) {
const chromium =
process.platform === 'linux'
? ' or [Chromium](https://www.chromium.org/)'
: ''

throw new MarpCLIError(
`It requires to install [Google Chrome](https://www.google.com/chrome/)${chromium} for exporting.`
)
}
}
throw new MarpCLIError(
`Marp CLI throwed unexpected error with exit code ${exitCode}.`
`It requires to install [Google Chrome](https://www.google.com/chrome/)${chromium} for exporting.`
)
}

throw e
} finally {
console.error = error
process.env.CHROME_PATH = CHROME_PATH
}

if (exitCode !== 0) {
throw new MarpCLIError(
`Marp CLI throwed unexpected error with exit code ${exitCode}.`
)
}
}
6 changes: 3 additions & 3 deletions src/preview.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jest-environment jsdom */
import browser from '@marp-team/marp-core/browser'
import { observer } from '@marp-team/marp-core/browser'
import preview from './preview'

jest.mock('@marp-team/marp-core/browser')
Expand All @@ -13,15 +13,15 @@ beforeEach(() => {
describe('Preview HTML', () => {
it('does not call browser context JS when HTML has not Marp slide', () => {
preview()
expect(browser).not.toBeCalled()
expect(observer).not.toBeCalled()
})

it('calls only browser context JS when HTML has Marp slide', () => {
document.body.innerHTML = '<div id="marp-vscode"></div>'

preview()
expect(document.body.classList.contains('marp-vscode')).toBe(true)
expect(browser).toBeCalled()
expect(observer).toBeCalled()
})

it('removes all styles excepted Marp when HTML has Marp slide', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import browser from '@marp-team/marp-core/browser'
import { observer } from '@marp-team/marp-core/browser'

export default function preview() {
const marpVscode = document.getElementById('marp-vscode')
Expand All @@ -17,6 +17,6 @@ export default function preview() {
links.forEach((elm) => elm.remove())

// Run Marp observer
browser()
observer()
}
}
Loading

0 comments on commit c4df74c

Please sign in to comment.