-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[discuss] Allow imports from plugin common
directories
#59710
Comments
Would like to suggest to export "common" code from
instead of
with the idea that we can still keep as a convention to internally use |
In this approach, would we still have exports from public and server as well? One benefit of the "common" convention is that it's a bit more clear that code shared from there is compatible with both server and client environments. We also would like to have linting rules to prevent the common module from importing server-only or client-only code. It's kind of strange that with the top-level index idea, this module couldn't imoort from server or public. That said, one thing I like the top-level index approach is that it side-steps the problem of having to refactor existing common directories. |
The top level
One reason for suggesting this and also the impression I got from discussing this during our team sync, was that it is very clear that top level
Internally—inside the plugin—we can still keep the convention to use
Yes, that is one of the benefits. Another benefit is that you can import common code without needing to add import { FILTERS } from 'src/plugins/data'; Similar how you do not import React from import React from 'react'; E.g. if our plugins were published to NPM, one could import isomorphic code easily: import { ExpressionsService } from '@kbn/plugin-expressions'; |
Makes sense, we can easily add a rule to ensure that the index does not import any values from |
The Platform currently enforces (via lint rule) that plugins can only import code from other plugins from the
public/index
andserver/index
. Due to our other linting rules that prevent plugins from importing server code into client code, there is no way for a plugin to "publish" code that is safe to use on both the server and client.There has been a proposal that we formalize the "common" directory that many plugins are already using, allowing other plugins to import code from this directory.
Plugins that are currently using the "common" pattern will need to evaluate the exports from these modules and ensure that they are all intended to be "public" to other plugins. Given that challenge, I propose we roll this out in phases:
common
directoriescommon
directories entirely so they are not considered part of the plugin's public API. I think 1 month would be enough.common
directoriescommon
directoriesThe text was updated successfully, but these errors were encountered: