diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 743e61b3a92d87c329e3ede6685fb235cc2aa905..bb743d078038b89ededfd85266e2ea49948df958 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -4,6 +4,12 @@ This document provides a summary of all notable changes to Antora Assembler by release. For a detailed view of what's changed, refer to the {url-repo}/commits[commit history] of this project. +== Unreleased + +=== Fixed + +* integrate Asciidoctor log messages properly when jsonl formatter is not enabled (#133) + == 1.0.0-beta.10 (2025-10-17) === Added diff --git a/packages/assembler/lib/assemble-content.js b/packages/assembler/lib/assemble-content.js index 3534117bdaad3614d85eedf8a32df2db8b1a4cc7..6eae90c7ad572959bd1585864b39e326f002735d 100644 --- a/packages/assembler/lib/assemble-content.js +++ b/packages/assembler/lib/assemble-content.js @@ -267,10 +267,15 @@ function resolveFileOrContents (convertResult, convertAttributes, buildConfig, l if (entry.name) ctx.program = entry.name if (entry.file?.line) ctx.line = entry.file.line logger[entry.level](ctx, entry.msg) - } else if ((match = /^(.+):(\d+): warning: (.+)/.exec(line))) { + } else if ((match = /^([^:]+):(\d+): warning: (.+)/.exec(line))) { const [, scriptPath, lineno, msg] = match ctx.stack = [{ file: { path: scriptPath }, line: parseInt(lineno, 10) }] logger.warn(ctx, msg) + } else if ((match = /^asciidoctor: ([A-Z]+): (?:[^:]+: line (\d+): )?(.+)/.exec(line))) { + // NOTE we don't care about the filename in the message since it can only be docfile + const [, level, lineno, msg] = match + if (lineno) ctx.line = parseInt(lineno, 10) + logger[level === 'WARNING' ? 'warn' : level.toLowerCase()](ctx, msg) } else { logger.info(ctx, line) } diff --git a/packages/assembler/test/assemble-content-test.js b/packages/assembler/test/assemble-content-test.js index 4c4d3894cd83c2cb0710ff3644437c5cd64977fd..715d91eadf635a141331b730b52e8809401af7a3 100644 --- a/packages/assembler/test/assemble-content-test.js +++ b/packages/assembler/test/assemble-content-test.js @@ -338,7 +338,7 @@ describe('assembleContent()', () => { assert.equal(messages.error[0][1], 'section title out of sequence') }) - it('should route non-jsonl lines on stderr to Antora logger', async () => { + it('should route Ruby warnings to Antora logger', async () => { const scenario = 'insert-page' const { playbook, contentCatalog, assemblerConfig: configSource } = await loadScenario(scenario, __dirname) configSource.build.publish = false @@ -394,6 +394,67 @@ describe('assembleContent()', () => { assertx.empty(messages.error) }) + it('should route non-json Asciidoctor log messages on stderr to Antora logger', async () => { + const scenario = 'insert-page' + const { playbook, contentCatalog, assemblerConfig: configSource } = await loadScenario(scenario, __dirname) + configSource.build.publish = false + configSource.build.stderr = 'log' + configSource.build.command = 'asciidoctor-pdf' + let docfile + const convert = async (...args) => { + docfile = args[1].docfile + const contents = Readable.from('converted contents') + const stderrLines = [ + `asciidoctor: WARNING: skipping references to missing attribute: foobar`, + `asciidoctor: ERROR: ${ospath.basename(docfile)}: line 3: level 0 sections can only be used when doctype is book`, + ] + return { status: 0, stderr: stderrLines.join('\n'), contents } + } + const converter = { convert, extname: '.pdf', mediaType: 'application/pdf' } + const messages = { info: [], warn: [], error: [] } + const logger = { + info () { + messages.info.push(Array.from(arguments)) + }, + warn () { + messages.warn.push(Array.from(arguments)) + }, + error () { + messages.error.push(Array.from(arguments)) + }, + } + const actualLoggerNames = [] + const context = { + getFunctions: () => ({}), + getLogger: (name) => { + actualLoggerNames.push(name) + return logger + }, + getVariables: () => ({}), + } + const actual = await assembleContent.call(context, playbook, contentCatalog, converter, { configSource }) + assert.equal(actual.length, 1) + assert.deepEqual(actualLoggerNames, ['@antora/assembler', '@antora/assembler']) + assertx.empty(messages.info) + assert.equal(messages.warn.length, 1) + assert.deepEqual(messages.warn[0], [ + { + command: 'asciidoctor-pdf', + file: { path: docfile }, + }, + 'skipping references to missing attribute: foobar', + ]) + assert.equal(messages.error.length, 1) + assert.deepEqual(messages.error[0], [ + { + command: 'asciidoctor-pdf', + file: { path: docfile }, + line: 3, + }, + 'level 0 sections can only be used when doctype is book', + ]) + }) + it('should use file as is if already coerced to output identity', async () => { const scenario = 'insert-page' const { playbook, contentCatalog, assemblerConfig: configSource } = await loadScenario(scenario, __dirname)