-
Notifications
You must be signed in to change notification settings - Fork 2
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
Programmatic Interface #9
Comments
Hey, @moltar. That's an interesting idea. Do you have some imaginary API in mind that we could expose to help you implement this? Internally, this library just maps a single declaration file to multiple sources (jest, webpack, etc.). All mapping functions can be described as: function map(config: AliasConfig): any But as I understand, you want to use some sort of API so that I've looked at projen, and it looks like higher-level tooling. You should be able to use |
The original API is almost fine, I think. The only issue is that it will throw if it can't find the source paths. Lines 10 to 12 in 45d6f43
So, maybe
Right, almost there. The only thing is that projen does not commit the config files to the filesystem, until all configs are synth'ed in memory. We can access the config in memory ( I am proposing that |
Thanks for the examples! It's much more clear now. I think we can create a new
import { config } from 'dotalias'
const alias = config({
server: '../packages/server/'
})
alias.jest
alias.WebpackPlugin It's important we keep the actual usage identical to the one you get with using One question I have is how should the |
IMO in programmatic use case everything should be explicit without any side effects, e.g. no reading from disk. |
Yeap, in favor with you on that 👍 Nice, I think we have the API worked out. Would you be interested in opening a pull request with the draft implementation? I could use your help with this. |
Certainly can try. One thing I am not sure of, is how to handle this part: Lines 10 to 12 in 45d6f43
Since this is in the global scope, this will always throw in the programmatic use case, and it's kind of impossible to hide it now, since index exports |
We can start by moving what's currently in
This won't solve the global-scope configuration check just yet. We have two options: Make
|
Sure, I was considering all these options too, but wasn't sure if breaking change was an option. Not a huge fan of: import { config } from 'dotalias/config' But I think that might be the best option in this case. Similar patterns exist already, e.g. see: |
Another thought... Might be beneficial to expose programmatic API for each converter independently. The downside is to that approach is that it exposes (right now) internal API, and then makes it harder to move away from it later. But the benefit is that if you only need one converter, then you don't need to call all other converters to get the full alias object back. Thoughts? |
So basically make |
Yeah. Because, for example, for our use case, we have no use for Webpack, so it's just extra CPU cycles to create an instance. |
Then I suppose it's a replacement for I can see both APIs being useful but I'd start with the one that immediately covers your use case. I'm all hands for the following thing: import { toRollup, toJest } from 'alias/config'
const config = { foo: '../bar/foo' }
const aliasOptions = toRollup(config)
const jestMapperOptions = toJest(config) Would that be the functionality you're looking for?
|
import { toRollup, toJest } from 'alias/config' Yup, that's what we are looking for! |
Would be great to have a programmatic interface to integrate into other projects.
I'd like to use it with projen.
The text was updated successfully, but these errors were encountered: