From 739748fab24e0da8e26eabc1d4a3cbf2c5243d8c Mon Sep 17 00:00:00 2001 From: pengboyu-dev <203494526+pengboyu-dev@users.noreply.github.com> Date: Sun, 20 Sep 2026 05:21:13 +0800 Subject: [PATCH] fix: load CLI configs with top-level await --- bin/main.js | 2 +- test/unit/bin.test.js | 5 +++++ test/unit/fixtures/bin-config-await.mjs | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/unit/fixtures/bin-config-await.mjs diff --git a/bin/main.js b/bin/main.js index 3c6585776f..76fa6c0783 100644 --- a/bin/main.js +++ b/bin/main.js @@ -180,7 +180,7 @@ export async function main(nodeProcess) { // try require for json markedConfig = require(configFile); } catch(err) { - if (err.code !== 'ERR_REQUIRE_ESM') { + if (err.code !== 'ERR_REQUIRE_ESM' && err.code !== 'ERR_REQUIRE_ASYNC_MODULE') { throw err; } // must import esm diff --git a/test/unit/bin.test.js b/test/unit/bin.test.js index 30fa726674..e0b2bf718b 100644 --- a/test/unit/bin.test.js +++ b/test/unit/bin.test.js @@ -116,6 +116,11 @@ describe('bin/marked', () => { stdout: '

line1
line2

', })); + it('config with top-level await', testInput({ + args: ['--config', fixturePath('bin-config-await.mjs'), '-s', 'line1\nline2'], + stdout: '

line1
line2

', + })); + it('config not found', testInput({ args: ['--config', fixturePath('does-not-exist.js'), '-s', 'line1\nline2'], stderr: `Cannot load config file '${fixturePath('does-not-exist.js')}'`, diff --git a/test/unit/fixtures/bin-config-await.mjs b/test/unit/fixtures/bin-config-await.mjs new file mode 100644 index 0000000000..00291ad103 --- /dev/null +++ b/test/unit/fixtures/bin-config-await.mjs @@ -0,0 +1,3 @@ +export default await Promise.resolve({ + breaks: true, +});