diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b7b4264..9833df41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Improve version output when using user-installed Marp Core ([#105](https://github.com/marp-team/marp-cli/pull/105)) + ## v0.10.1 - 2019-06-19 ### Fixed diff --git a/README.md b/README.md index c1f53083..fa1c9ae2 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,9 @@ npm install -g @marp-team/marp-cli ### Standalone binary _(EXPERIMENTAL)_ -Do you never want to install any dependent tools? we also provide executable binaries for Linux, macOS, and Windows. [:fast_forward: Download the latest standalone binary for your OS from release page.](https://github.com/marp-team/marp-cli/releases) +Do you never want to install any dependent tools? we also provide executable binaries for Linux, macOS, and Windows. + +**[:fast_forward: Download the latest standalone binary for your OS from release page.](https://github.com/marp-team/marp-cli/releases)** ## Basic usage @@ -326,10 +328,10 @@ By using `--version` (`-v`) option, you may confirm the version of engine that i ```console $ marp --version -@marp-team/marp-cli v0.x.x (/w bundled @marp-team/marp-core v0.x.x) +@marp-team/marp-cli v0.x.x (w/ bundled @marp-team/marp-core v0.x.x) ``` -Marp CLI prefers to use _an installed core by user_ than the bundled. If the current project has installed `@marp-team/marp-core` individually, it would show its version and the annotation "/w customized engine". +Marp CLI prefers to use _an installed core by user_ than the bundled. If the current project has installed `@marp-team/marp-core` individually, it would show its version and the annotation: `w/ user-installed @marp-team/marp-core vX.X.X` or `w/ customized engine`. ## Configuration file diff --git a/src/version.ts b/src/version.ts index 51edb1ad..54ccd071 100644 --- a/src/version.ts +++ b/src/version.ts @@ -4,17 +4,21 @@ import { MarpCLIConfig } from './config' import { name, version } from '../package.json' export default async function outputVersion(config: MarpCLIConfig): Promise<0> { - let message = `${name} v${version} ` + let engineVer = '' const { engine } = config if (engine.klass === Marp) { - message += `(/w bundled @marp-team/marp-core v${bundledCoreVer})` + engineVer = `bundled @marp-team/marp-core v${bundledCoreVer}` + + if (engine.package && engine.package.version !== bundledCoreVer) { + engineVer = `user-installed @marp-team/marp-core v${engine.package.version}` + } } else if (engine.package && engine.package.name && engine.package.version) { - message += `(/w customized engine in ${engine.package.name} v${engine.package.version})` + engineVer = `customized engine in ${engine.package.name} v${engine.package.version}` } else { - message += `(/w customized engine)` + engineVer = `customized engine` } - console.log(message) + console.log(`${name} v${version}${engineVer ? ` (w/ ${engineVer})` : ''}`) return 0 } diff --git a/test/marp-cli.ts b/test/marp-cli.ts index 4ced8e79..1604481d 100644 --- a/test/marp-cli.ts +++ b/test/marp-cli.ts @@ -43,12 +43,12 @@ describe('Marp CLI', () => { for (const cmd of ['--version', '-v']) context(`with ${cmd} option`, () => { let log: jest.SpyInstance - let findClassPath: jest.SpyInstance + let findClassPath: jest.SpyInstance beforeEach(() => { log = jest.spyOn(console, 'log').mockImplementation() findClassPath = jest - .spyOn(ResolvedEngine.prototype, 'findClassPath') + .spyOn(ResolvedEngine.prototype as any, 'findClassPath') .mockImplementation() }) @@ -67,6 +67,33 @@ describe('Marp CLI', () => { ) }) + context( + 'when resolved core has unexpected version against bundled', + () => { + const pkgJson = { name: '@marp-team/marp-core', version: '0.0.0' } + const pkgPath = '../node_modules/@marp-team/marp-core/package.json' + + beforeEach(() => { + findClassPath.mockImplementation(() => + assetFn('../node_modules/@marp-team/marp-core/lib/marp.js') + ) + + jest.doMock(pkgPath, () => pkgJson) + }) + + afterEach(() => jest.unmock(pkgPath)) + + it('outputs resolved version as user-installed core', async () => { + expect(await marpCli([cmd])).toBe(0) + expect(log).toBeCalledWith( + expect.stringContaining( + 'user-installed @marp-team/marp-core v0.0.0' + ) + ) + }) + } + ) + context('with specified Marpit engine', () => { const cmds = [cmd, '--engine', '@marp-team/marpit']