-
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
Prevents importing of public code into server #67149
Prevents importing of public code into server #67149
Conversation
We should not be allowing importing of public into server. Any shared code should reside in a common directory. After elastic#66506, this will not even be possible as we will no longer be transpiling public code into commonjs. Blocks elastic#66506 Signed-off-by: Tyler Smalley <[email protected]>
Pinging @elastic/apm-ui (Team:apm) |
Signed-off-by: Tyler Smalley <[email protected]>
.eslintrc.js
Outdated
@@ -197,6 +197,11 @@ module.exports = { | |||
from: ['src/core/utils/**/*'], | |||
errorMessage: `Plugins may only import from src/core/server and src/core/public.`, | |||
}, | |||
{ | |||
target: ['(src|x-pack)/plugins/*/server/**/*', '!x-pack/plugins/apm/**/*'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APM is a less than straightforward update and I would rather not make assumptions for their desired organization. I will follow-up with an issue for the team to resolve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what you are hitting is caused by the server side types consumed by the client.
Types are inferred from server-side routes and can therefore not be moved to common.
I expect we can resolve this when typescript is updated to 3.8 and we can use type only imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @dgieselaar
Introduced in elastic#66432 and I have a more thorough PR to prevent imports in server from public in elastic#67149 Signed-off-by: Tyler Smalley <[email protected]>
Pinging @elastic/kibana-operations (Team:Operations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alerting code LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SIEM and endpoint changes LGTM 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tylersmalley 👍 I'm onboard with the intention behind this change. However, one of ES UI's organizing principles is to organize code inside of __packages_do_not_import__
and then re-export from public
, server
, and common
directories. Can we make a couple adjustments that will both follow this principle and fulfill the goal of preventing public code from being imported into server code?
Here's what I think will work:
- Moving all the authorization code back into its original state inside of
__packages_do_not_import__
. - Changing the exports from
public/authorization
to be explicit. None of these modules are usable on the server, socommon
isn't the best place for them.
export {
WithPrivileges,
NotAuthorizedSection,
AuthorizationProvider,
AuthorizationContext,
SectionError,
Error,
useAuthorizationContext,
} from '../../__packages_do_not_import__/authorization';
- Changing the exports from
common/index.ts
to consist of the types only, since they're the only things that are usable on both client and server:
export {
Privileges,
MissingPrivileges,
} from '../../__packages_do_not_import__/authorization';
Signed-off-by: Tyler Smalley <[email protected]>
Signed-off-by: Tyler Smalley <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM! Didn't test locally. Thanks for making the change I suggested!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maps changes LGTM
code review
Signed-off-by: Tyler Smalley <[email protected]>
@elasticmachine merge upstream |
@elasticmachine merge upstream |
Signed-off-by: Tyler Smalley <[email protected]>
Signed-off-by: Tyler Smalley <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage collection changes (src/plugins/usage_collection/server/report/store_report.test.ts
) LGTM!
@elastic/kibana-app and @elastic/siem - can I get a codeowners review here? |
pinging @elastic/endpoint-app-team as they own the conflicting files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elastic/kibana-app-arch LGTM
Signed-off-by: Tyler Smalley <[email protected]>
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
We should not be allowing importing of public into server. Any shared code should reside in a common directory. After elastic#66506, this will not even be possible as we will no longer be transpiling public code into commonjs. Blocks elastic#66506 Signed-off-by: Tyler Smalley <[email protected]>
We should not be allowing importing of public into server. Any shared code should reside in a common directory. After #66506, this will not even be possible as we will no longer be transpiling public code into commonjs. Blocks #66506 Signed-off-by: Tyler Smalley <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
We should not be allowing importing of public into server. Any shared code should reside in a common directory. After #66506, this will not even be possible as we will no longer be transpiling public code into commonjs.
Relates to #66506