-
-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaking: Use transformSync option for sync transform #209
Conversation
Codecov Report
@@ Coverage Diff @@
## master #209 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 7 7
Lines 231 231
Branches 51 51
=====================================
Hits 231 231
Continue to review full report at Codecov.
|
I don't think this is ideal, but also don't think it makes things worse. The core problem, I think, is that it's possible to configure things in a way that produces surprising results: Before this change, you could pass an async function to There's a similar problem with the way Turns out providing both sync and async APIs is kind of a nightmare. As long as we're considering breaking changes, here's a wild idea, if we want to be ambitious: What if we make the sync/async split at the very top level of the API? When you initialize cosmiconfig, you need to initialize a sync or async instance: |
I like that idea and think it will fit the common use-case nicely. then again I don't remember seeing any issues with this so maybe it's not a problem in practice ? |
I can't think of any downsides to this. Seems the easiest, least complicated, and smallest API solution.
I personally don't think this is necessary. I think it is pretty clear/can be made more clear by the user if needed via variable names, but I don't have a strong opinion of this at all.
I found the potential issues with Very possible this is not an issue for anyone. My guess is the majority of people use cosmiconfig's sync API and almost always pass sync functions for But that being said, I still think it is better to fix these things now since there is already going to be a breaking release. Just so we are on the same page, this is what I'm understanding the API to look like: import { cosmiconfig, cosmiconfigSync } from 'cosmiconfig';
const explorer = cosmiconfig({
loaders: {
'.js': async () => {},
'.ts': () => {}, // can be sync
},
transform: async (config) => config,
// transform: (config) => config, // can also be sync
});
await explorer.search();
await explorer.load();
const explorerSync = cosmiconfigSync({
loaders: {
'.js': () => {},
'.ts': async () => {}, // can not be async, invalid
},
transform: (config) => config,
// transform: async (config) => config, // can not be async, invalid
});
explorerSync.search();
explorerSync.load(); |
@chrisblossom Yep, that's right. This is quite a bit of work; I don't know how soon I myself would get to it — happy to look at PRs. Meanwhile, I think I'd rather not make other breaking API changes if we think this is the best route. If nobody feels like implementing this change before we release v6, I think that's ok: we'll have minimal breaking changes in v6. But if somebody does feel like implementing this change now, great. |
I started working on this. Should have a PR ready sometime relatively soon. EDIT: I've got this working, just need to figure out how to correctly type a couple functions and update tests / readme. |
Closed in-favor of #211. |
Fixes #197 (comment) via
add transformSync option
.It might be better to have the object only format: