Skip to content

Commit

Permalink
Merge pull request #172 from marp-team/v0.15.0-develop
Browse files Browse the repository at this point in the history
Support Marp Core v0.14.0
  • Loading branch information
yhatt committed Oct 20, 2019
2 parents 69ed0f9 + b1dc79a commit 20789b4
Show file tree
Hide file tree
Showing 12 changed files with 402 additions and 394 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

### Changed

- Upgrade dependent packages to the latest version ([#164](https://github.com/marp-team/marp-cli/pull/164))
- Upgrade [Marpit v1.4.1](https://github.com/marp-team/marpit/releases/tag/v1.4.1) and [Marp Core v0.14.0](https://github.com/marp-team/marp-core/releases/tag/v0.14.0) ([#169](https://github.com/marp-team/marp-cli/pull/169))
- Upgrade dependent packages to the latest version ([#164](https://github.com/marp-team/marp-cli/pull/164), [#169](https://github.com/marp-team/marp-cli/pull/169))

### Removed

- Remove the detection of helper script from resolved engine ([#171](https://github.com/marp-team/marp-cli/pull/171))

## v0.14.1 - 2019-09-15

Expand Down
42 changes: 23 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,33 @@
"@types/cheerio": "^0.22.13",
"@types/cosmiconfig": "^5.0.3",
"@types/express": "^4.17.1",
"@types/jest": "^24.0.18",
"@types/jest": "^24.0.19",
"@types/jest-plugin-context": "^2.9.2",
"@types/node": "^12.7.7",
"@types/node": "^12.11.1",
"@types/pug": "^2.0.4",
"@types/puppeteer": "^1.19.1",
"@types/puppeteer": "^1.20.2",
"@types/supertest": "^2.0.8",
"@types/ws": "^6.0.3",
"@types/yargs": "^13.0.2",
"autoprefixer": "^9.6.1",
"@types/yargs": "^13.0.3",
"autoprefixer": "^9.6.5",
"bespoke": "bespokejs/bespoke",
"bespoke-forms": "^1.0.0",
"builtin-modules": "^3.1.0",
"cheerio": "^1.0.0-rc.3",
"codecov": "^3.6.1",
"cssnano": "^4.1.10",
"image-size": "^0.8.2",
"image-size": "^0.8.3",
"jest": "^24.9.0",
"jest-junit": "^8.0.0",
"jest-plugin-context": "^2.9.0",
"nanoid": "^2.1.1",
"nanoid": "^2.1.4",
"npm-run-all": "^4.1.5",
"pkg": "^4.4.0",
"postcss-url": "^8.0.0",
"prettier": "^1.18.2",
"pug": "^2.0.4",
"rimraf": "^3.0.0",
"rollup": "^1.21.4",
"rollup": "^1.25.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
Expand All @@ -101,10 +101,10 @@
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^5.1.2",
"rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-url": "^2.2.2",
"sass": "^1.22.12",
"rollup-plugin-url": "^2.2.4",
"sass": "^1.23.0",
"screenfull": "^5.0.0",
"stylelint": "^11.0.0",
"stylelint": "^11.1.1",
"stylelint-config-prettier": "^6.0.0",
"stylelint-config-standard": "^19.0.0",
"stylelint-scss": "^3.11.1",
Expand All @@ -116,17 +116,17 @@
"tslint": "^5.20.0",
"tslint-config-airbnb": "^5.11.2",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.6.3",
"typescript": "^3.6.4",
"yauzl": "^2.10.0",
"zip-stream": "^2.1.2"
},
"dependencies": {
"@marp-team/marp-core": "^0.13.1",
"@marp-team/marpit": "^1.4.0",
"@marp-team/marp-core": "^0.14.0",
"@marp-team/marpit": "^1.4.1",
"@marp-team/pptx": "^0.1.0",
"carlo": "^0.9.46",
"chalk": "^2.4.2",
"chokidar": "^3.1.1",
"chokidar": "^3.2.2",
"chrome-launcher": "^0.11.2",
"cosmiconfig": "^5.2.1",
"express": "^4.17.1",
Expand All @@ -138,15 +138,19 @@
"mkdirp": "^0.5.1",
"os-locale": "^4.0.0",
"pkg-up": "^3.1.0",
"portfinder": "^1.0.24",
"puppeteer-core": "~1.17.0",
"portfinder": "^1.0.25",
"puppeteer-core": "~1.20.0",
"serve-index": "^1.9.1",
"strip-ansi": "^5.2.0",
"tmp": "^0.1.0",
"v8-compile-cache": "^2.1.0",
"wrap-ansi": "^6.0.0",
"ws": "^7.1.2",
"yargs": "^14.0.0"
"ws": "^7.2.0",
"yargs": "^14.2.0"
},
"resolutions": {
"https-proxy-agent": "^3.0.0",
"teeny-request": "^5.3.0"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 0 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ export class MarpCLIConfig {
lang: this.conf.lang || (await osLocale()).replace(/@/g, '-'),
options: this.conf.options || {},
pages: !!(this.args.images || this.conf.images),
readyScript: this.engine.browserScript
? `<script>${this.engine.browserScript}</script>`
: undefined,
watch:
pick(this.args.watch, this.conf.watch) || preview || server || false,
}
Expand Down
4 changes: 1 addition & 3 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export interface ConverterOption {
pages?: boolean | number[]
preview?: boolean
jpegQuality?: number
readyScript?: string
server?: boolean
template: string
templateOption?: TemplateOption
Expand Down Expand Up @@ -91,7 +90,7 @@ export class Converter {
}

async convert(markdown: string, file?: File): Promise<TemplateResult> {
const { lang, readyScript, globalDirectives, type } = this.options
const { lang, globalDirectives, type } = this.options
const isFile = file && file.type === FileType.File

let additionals = ''
Expand All @@ -107,7 +106,6 @@ export class Converter {
return await this.template({
...(this.options.templateOption || {}),
lang,
readyScript,
base:
isFile && type !== ConvertType.html
? file!.absoluteFileScheme
Expand Down
19 changes: 3 additions & 16 deletions src/engine.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import { Marpit } from '@marp-team/marpit'
import fs from 'fs'
import path from 'path'
import pkgUp from 'pkg-up'
import { promisify } from 'util'
import importFrom from 'import-from'
import { CLIError } from './error'

const readFile = promisify(fs.readFile)

export type Engine = typeof Marpit
export type ResolvableEngine = Engine | string

export class ResolvedEngine {
browserScript?: string
klass: Engine
package?: { [key: string]: any }

private static browserScriptKey = 'marpBrowser'
package?: Record<string, any>

static async resolve(
engine: ResolvableEngine | ResolvableEngine[],
Expand All @@ -26,7 +19,7 @@ export class ResolvedEngine {
ResolvedEngine.resolveModule(engine, from)
)

await resolvedEngine.resolveBrowserScript()
await resolvedEngine.resolvePackage()
return resolvedEngine
}

Expand Down Expand Up @@ -56,20 +49,14 @@ export class ResolvedEngine {
this.klass = klass
}

private async resolveBrowserScript(): Promise<void> {
private async resolvePackage(): Promise<void> {
const classPath = this.findClassPath(this.klass)
if (!classPath) return

const pkgPath = await pkgUp({ cwd: path.dirname(classPath) })
if (!pkgPath) return

this.package = require(pkgPath)
const scriptPath = this.package![ResolvedEngine.browserScriptKey]
if (!scriptPath) return undefined

this.browserScript = (await readFile(
path.resolve(path.dirname(pkgPath), scriptPath)
)).toString()
}

// NOTE: It cannot test because of overriding `require` in Jest context.
Expand Down
8 changes: 0 additions & 8 deletions src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface TemplateCoreOption {
base?: string
lang: string
notifyWS?: string
readyScript?: string
renderer: (tplOpts: MarpitOptions) => RendererResult
}

Expand Down Expand Up @@ -89,13 +88,6 @@ export const bespoke: Template<TemplateBespokeOption> = async opts => {
osc: opts.osc === undefined ? true : opts.osc,
progress: opts.progress,
},
readyScript:
opts.readyScript ||
`<script>${await libJs(
require.resolve(
'@marp-team/marpit-svg-polyfill/lib/polyfill.browser.js'
)
)}</script>`,
watchJs: await watchJs(opts.notifyWS),
}),
}
Expand Down
1 change: 0 additions & 1 deletion src/templates/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ html(lang=lang)
body
block deck
!= html
!= readyScript

block script

Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function outputVersion(config: MarpCLIConfig): Promise<0> {
const { engine } = config

if (isMarpCore(engine.klass)) {
engineVer = `bundled @marp-team/marp-core v${bundledCoreVer}`
engineVer = `@marp-team/marp-core v${bundledCoreVer}`

if (engine.package && engine.package.version !== bundledCoreVer) {
engineVer = `user-installed @marp-team/marp-core v${engine.package.version}`
Expand Down
7 changes: 1 addition & 6 deletions test/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,11 @@ describe('Converter', () => {

it('returns the result of template', async () => {
const options: any = { html: true }
const readyScript = '<b>ready</b>'
const { result, rendered } = await instance({
options,
readyScript,
}).convert(md)
const { result, rendered } = await instance({ options }).convert(md)

expect(result).toMatch(/^<!DOCTYPE html>[\s\S]+<\/html>$/)
expect(result).toContain(rendered.html)
expect(result).toContain(rendered.css)
expect(result).toContain(readyScript)
expect(result).not.toContain('<base')
expect(rendered.css).toContain('@theme default')
})
Expand Down
21 changes: 2 additions & 19 deletions test/engine.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
import Marp from '@marp-team/marp-core'
import resolve, { ResolvedEngine } from '../src/engine'
import resolve from '../src/engine'

describe('Engine', () => {
const coreModule = '@marp-team/marp-core'
const marpitModule = '@marp-team/marpit'

describe('.resolve', () => {
it('returns ResolvedEngine class with resolved class', async () => {
expect((await resolve(Marp)).klass).toBe(Marp)
expect((await resolve(coreModule)).klass.name).toBe('Marp')
expect((await resolve('@marp-team/marp-core')).klass.name).toBe('Marp')

// Return with the first resolved class
expect((await resolve(['__invalid_module__', Marp])).klass).toBe(Marp)
})

it("loads browser script from defined in module's marpBrowser section", async () => {
const finder = jest.spyOn(<any>ResolvedEngine.prototype, 'findClassPath')

// Core (defined marpBrowser)
finder.mockImplementation(() => require.resolve(coreModule))

expect((await resolve(Marp)).browserScript).toBeTruthy()
expect((await resolve(coreModule)).browserScript).toBeTruthy()

// Marpit (not defined marpBrowser)
finder.mockImplementation(() => require.resolve(marpitModule))
expect((await resolve(marpitModule)).browserScript).toBeUndefined()
})
})
})
4 changes: 1 addition & 3 deletions test/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ describe('Marp CLI', () => {
expect.stringContaining(`@marp-team/marp-cli v${cliVersion}`)
)
expect(log).toBeCalledWith(
expect.stringContaining(
`bundled @marp-team/marp-core v${coreVersion}`
)
expect.stringContaining(`@marp-team/marp-core v${coreVersion}`)
)
})

Expand Down
Loading

0 comments on commit 20789b4

Please sign in to comment.