fix: try require first for custom formatters so transpiled ones work #1985
+59
−50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🤔 What's changed?
Tweak the loading of custom formatters and snippet syntaxes so we try
require()
first and then tryimport()
if it turns out the target file is a module (ESM).This mirrors how we are also now loading the configuration file.
⚡️ What's your motivation?
https://cucumberbdd.slack.com/archives/C6QJ6N695/p1649071066867509
An edge case arguably, but some users in the wild have formatters in their project written in TypeScript (or something else that transpiles) and take advantage of the fact that
--require-module
means their transpiler has registered by the time the formatter is loaded.This is quite cool and something we should avoid breaking if possible. We broke it with earlier RCs because we switched to exclusively using
import()
to load custom formatters, which doesn't yet account for just-in-time transpiled code.In 1 or 2 major releases (when loader hooks are a solved problem) we'll ditch the
require()
bit and just useimport()
which will simplify things a lot but for now this works reliably and is well covered by tests.🏷️ What kind of change is this?
📋 Checklist:
This text was originally generated from a template, then edited by hand. You can modify the template here.