cosmiconfig
cosmiconfig copied to clipboard
Support ECMAScript modules (ESM)
This PR intends to close https://github.com/davidtheclark/cosmiconfig/issues/224. I don't have more time to work on this today so I'll get what I have up as a draft — feedback welcome! I'd especially appreciate help testing this from people interested in using ESM, both ensuring that it works as expected and ensuring that the expectations are the right ones.
Some notes:
- ESM is only supported by the asynchronous API, because it is enabled by the asynchronous
import()
function. - So
.mjs
is only added to the defaultsearchPlaces
of the asynchronous API. - I turned off the selective branches in CI configuration because I wasn't seeing tests run. It may be that Travis and Appveyor needed to catch up with the main branch name change (from
master
tomain
). We'll see. - I was having some trouble early on with Jest, so tried using the
jest-circus
test runner. Turns out that wasn't the problem at all, but I left in that update. - This PR is set to merge into a
v8
branch, in case there's anything else in the issue queue that anybody wants to get into v8.
Codecov Report
Merging #251 (7c28c3e) into v8 (1834605) will not change coverage. The diff coverage is
100.00%
.
@@ Coverage Diff @@
## v8 #251 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 9 9
Lines 227 235 +8
Branches 46 47 +1
=========================================
+ Hits 227 235 +8
Impacted Files | Coverage Δ | |
---|---|---|
src/ExplorerBase.ts | 100.00% <ø> (ø) |
|
src/index.ts | 100.00% <100.00%> (ø) |
|
src/loaders.ts | 100.00% <100.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 1834605...7c28c3e. Read the comment docs.
Known to-dos:
- [ ] Document change to
defaultLoaders
(loadJs
is async) and exposure ofdefaultLoadersSync
. Or consider changing this. And maybe we want to address https://github.com/davidtheclark/cosmiconfig/issues/226. - [ ] Write new tests that find ESM configs.
By using the --experimental-vm-modules
flag and some workarounds for the inability to clear the ESM loader cache, the tests are now passing for me locally. But on Travis, they are not, with segmentation faults in Node 10 and 14 and something else in Node 12 I don't understand yet.
The segfault issue is probably caused by https://github.com/nodejs/node/issues/35889
Just posted this note at the top of the README:
MAINTAINERS WANTED! If you're interested in taking over and maintaining Cosmiconfig, please let @davidtheclark know (with an issue or email). I'd like to hand over the keys completely, so I'm looking for owners, not people who just want to merge a PR or two! You can make the decisions about what happens in v8 and subsequent versions, how the package balances stability and opinionated features, and so on. Take a look at open issues and PRs to learn about possibilities that have been on people's minds over the years.
If you're interested in taking ownership of the package and moving this feature forward, let me know!
This was superseded by #304, which is now merged.