Skip to content

Commit c61543e

Browse files
authored
fix: load CLI configs with top-level await (#4100)
1 parent ef0704c commit c61543e

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎bin/main.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export async function main(nodeProcess) {
180180
// try require for json
181181
markedConfig = require(configFile);
182182
} catch(err) {
183-
if (err.code !== 'ERR_REQUIRE_ESM') {
183+
if (err.code !== 'ERR_REQUIRE_ESM' && err.code !== 'ERR_REQUIRE_ASYNC_MODULE') {
184184
throw err;
185185
}
186186
// must import esm

‎test/unit/bin.test.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ describe('bin/marked', () => {
116116
stdout: '<p>line1<br>line2</p>',
117117
}));
118118

119+
it('config with top-level await', testInput({
120+
args: ['--config', fixturePath('bin-config-await.mjs'), '-s', 'line1\nline2'],
121+
stdout: '<p>line1<br>line2</p>',
122+
}));
123+
119124
it('config not found', testInput({
120125
args: ['--config', fixturePath('does-not-exist.js'), '-s', 'line1\nline2'],
121126
stderr: `Cannot load config file '${fixturePath('does-not-exist.js')}'`,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default await Promise.resolve({
2+
breaks: true,
3+
});

0 commit comments

Comments
 (0)