From 609df20aa0ae718eb943c3e41865d48d522a4ca5 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Sun, 23 Nov 2025 19:44:25 -0700 Subject: [PATCH] resolves #126 log warning if specified config file cannot be resolved --- CHANGELOG.adoc | 1 + packages/assembler/lib/assemble-content.js | 4 +-- packages/assembler/lib/load-config.js | 31 ++++++++++++++------- packages/assembler/test/load-config-test.js | 14 ++++++++++ 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 89642f2..25007fb 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -9,6 +9,7 @@ For a detailed view of what's changed, refer to the {url-repo}/commits[commit hi === Changed * Allow assembly.link_reference_style to be relative when export filetype is pdf (#134) +* Log warning if specified config file cannot be resolved (#126) == 1.0.0-beta.13 (2025-10-25) diff --git a/packages/assembler/lib/assemble-content.js b/packages/assembler/lib/assemble-content.js index 09f269f..90347b8 100644 --- a/packages/assembler/lib/assemble-content.js +++ b/packages/assembler/lib/assemble-content.js @@ -16,8 +16,6 @@ const PACKAGE_NAME = require('../package.json').name const NEWLINE_RX = /(?:\r?\n)+/ async function assembleContent (playbook, contentCatalog, converter, { configSource, navigationCatalog }) { - const assemblerConfig = await loadConfig(playbook, configSource) - if (assemblerConfig.enabled === false) return [] const context = isBound(this) ? this : { @@ -25,6 +23,8 @@ async function assembleContent (playbook, contentCatalog, converter, { configSou getLogger: invariably.void, getVariables: invariably.new, } + const assemblerConfig = await loadConfig.call(context, playbook, configSource) + if (assemblerConfig.enabled === false) return [] const generatorFunctions = context.getFunctions() const { loadAsciiDoc = require('@antora/asciidoc-loader') } = generatorFunctions const { diff --git a/packages/assembler/lib/load-config.js b/packages/assembler/lib/load-config.js index 98adc01..2075a3c 100644 --- a/packages/assembler/lib/load-config.js +++ b/packages/assembler/lib/load-config.js @@ -5,6 +5,8 @@ const fsp = require('node:fs/promises') const os = require('node:os') const yaml = require('js-yaml') +const PACKAGE_NAME = require('../package.json').name + const ASSEMBLY_KEYS = [ 'rootLevel', 'insertStartPage', @@ -13,23 +15,32 @@ const ASSEMBLY_KEYS = [ 'dropExplicitXrefText', ] -function loadConfig (playbook, configSource = './antora-assembler.yml') { +function loadConfig (playbook, configSource) { + let resolvedConfigSource return ( - configSource.constructor === Object + configSource?.constructor === Object ? Promise.resolve(configSource) : fsp - .access((configSource = expandPath(configSource, { dot: playbook.dir }))) + .access((resolvedConfigSource = expandPath(configSource ?? './antora-assembler.yml', { dot: playbook.dir }))) .then( () => true, () => false ) - .then((exists) => - exists - ? fsp - .readFile(configSource) - .then((data) => Object.assign(camelCaseKeys(yaml.load(data), ['asciidoc']), { file: configSource })) - : {} - ) + .then((exists) => { + if (!exists) { + let logger + if (configSource && (logger = this?.getLogger?.(PACKAGE_NAME))) { + const ctx = { file: { path: configSource } } + logger.warn(ctx, 'Could not resolve config file; reverting to default settings') + } + return {} + } + return fsp + .readFile(resolvedConfigSource) + .then((data) => + Object.assign(camelCaseKeys(yaml.load(data), ['asciidoc']), { file: resolvedConfigSource }) + ) + }) ).then((config) => { if (config.enabled === false) return config let asciidocAttrs diff --git a/packages/assembler/test/load-config-test.js b/packages/assembler/test/load-config-test.js index da39fc2..11b4f20 100644 --- a/packages/assembler/test/load-config-test.js +++ b/packages/assembler/test/load-config-test.js @@ -108,6 +108,20 @@ describe('loadConfig()', () => { assert(actual.build.processLimit > 0) }) + it('should log warning if custom config file is not found', async () => { + const actualWarnCalls = [] + const logger = { + warn () { + actualWarnCalls.push(arguments) + }, + } + const actual = await loadConfig.call({ getLogger: () => logger }, playbook, './does-not-exist.yml') + assertx.instanceOf(actual, Object) + assert.equal(actualWarnCalls.length, 1) + assert.deepEqual(actualWarnCalls[0][0], { file: { path: './does-not-exist.yml' } }) + assert.match(actualWarnCalls[0][1], /Could not resolve config file/) + }) + it('should accept custom config source', async () => { const input = { componentVersions: '**', sectionMergeStrategy: 'enclose' } const actual = await loadConfig(playbook, input) -- GitLab