Skip to content
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

[Fleet] Use type-only imports where possible #92979

Merged
merged 5 commits into from
Mar 2, 2021

Conversation

jfsiii
Copy link
Contributor

@jfsiii jfsiii commented Feb 26, 2021

Summary

Use type-only import to differentiate between runtime values and (erasable) TS types.

Screen Shot 2021-02-27 at 6 34 46 PM

Allows Babel and tsc to make some optimizations since it can be sure what can be erased.

It can also be helpful in situations like below which highlights that even though KibanaAssetType and KibanaSavedObjectType are named a certain way and from common/types, they are JS values not TS types. They are enums which means they are JS objects at runtime; not eliminated at runtime.

/*
Enum mapping of a saved object asset type to how it would appear in a package file path (snake cased)
*/
export enum KibanaAssetType {
dashboard = 'dashboard',
visualization = 'visualization',
search = 'search',
indexPattern = 'index_pattern',
map = 'map',
lens = 'lens',
}
/*
Enum of saved object types that are allowed to be installed
*/
export enum KibanaSavedObjectType {
dashboard = 'dashboard',
visualization = 'visualization',
search = 'search',
indexPattern = 'index-pattern',
map = 'map',
lens = 'lens',
}

@jfsiii
Copy link
Contributor Author

jfsiii commented Feb 26, 2021

@elasticmachine merge upstream

@jfsiii jfsiii changed the title [Fleet] Use 'import type' in where possible [Fleet] Use 'import type' where possible Feb 27, 2021
@jfsiii jfsiii changed the title [Fleet] Use 'import type' where possible [Fleet] Use type-onlt imports where possible Feb 27, 2021
@jfsiii jfsiii changed the title [Fleet] Use type-onlt imports where possible [Fleet] Use type-only imports where possible Mar 1, 2021
@jfsiii jfsiii added release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.13.0 v8.0.0 labels Mar 1, 2021
@jfsiii jfsiii self-assigned this Mar 1, 2021
@jfsiii jfsiii requested a review from a team March 1, 2021 14:45
@jfsiii jfsiii marked this pull request as ready for review March 1, 2021 16:40
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@jen-huang jen-huang added the chore label Mar 1, 2021
Copy link
Contributor

@jen-huang jen-huang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement 👍🏻 Spot checked the files but not all of them.

@jfsiii
Copy link
Contributor Author

jfsiii commented Mar 2, 2021

@elasticmachine merge upstream

@jfsiii jfsiii enabled auto-merge (squash) March 2, 2021 02:00
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
triggersActionsUi 1.6MB 1.5MB -23.9KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
triggersActionsUi 104.0KB 104.1KB +82.0B
Unknown metric groups

async chunk count

id before after diff
triggersActionsUi 41 42 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @jfsiii

@jfsiii jfsiii merged commit 1702cf9 into elastic:master Mar 2, 2021
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 2, 2021
* master: (199 commits)
  Convert Canvas docs to MDX for use in Elastic Docs (elastic#91969)
  [Bazel] More resilient Workspace Status (elastic#93244)
  [Discover] Change icon of saved search in open search panel and embeddable selection (elastic#93001)
  [Workplace Search] Role Mappings to Kibana (elastic#93123)
  [Fleet] Use type-only imports where possible (elastic#92979)
  [Lens] Set pie chart slices sorted clockwise (elastic#92617)
  Remove ms label from CPU load on status page (elastic#92836)
  [App Search] Migrate Create Meta Engine View (elastic#92127)
  [Time to Visualize] Disable Visualize URL Tracker When Linked to OriginatingApp (elastic#92917)
  [ILM] Allow multiple searchable snapshot actions (elastic#92789)
  Improve consistency for display of management items (elastic#92694)
  skip flaky suite (elastic#93152)
  skip flaky suite (elastic#93152)
  [ILM] Refactor edit_policy client integration tests into separate feature files (elastic#92826)
  Add developer documentation about the building blocks we offer plugin developers (elastic#92743)
  [Security Solution] Case ui enhancement (elastic#91863)
  [Security Solution] [Detections] Updates warning message when no indices match provided index patterns (elastic#93094)
  Collect agent telemetry even when fleet server is disabled. (elastic#93198)
  [Lens] Fix runtime validation error message (elastic#93195)
  [Lens] Remove warning about ordinal x-domain (elastic#93049)
  ...
jfsiii pushed a commit that referenced this pull request Mar 2, 2021
## Summary

Use [type-only `import`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) to differentiate between runtime values and (erasable) TS types.

<img width="1499" alt="Screen Shot 2021-02-27 at 6 34 46 PM" src="https://user-images.githubusercontent.com/57655/109403323-84e32c80-792a-11eb-94b7-854d0e5c3e99.png">

Allows Babel and `tsc` to make some optimizations since it can be sure what can be erased.

It can also be helpful in situations like below which highlights that even though `KibanaAssetType` and `KibanaSavedObjectType` are named a certain way and from `common/types`, they are JS values _not_ TS types. They are `enum`s which means they are JS objects at runtime; not eliminated at runtime.

https://github.com/elastic/kibana/blob/d92a1a08d89accc2fa303b1355a9e222f9b6d090/x-pack/plugins/fleet/common/types/models/epm.ts#L41-L63

# Conflicts:
#	x-pack/plugins/fleet/server/services/index.ts
jfsiii pushed a commit that referenced this pull request Mar 15, 2021
…94464)

## Summary

Use the [`consistent-type-imports` lint rule ](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-imports.md) to use `import type ...` where possible

Code-only changes like this were recently added in #92979, but it was a more manual process.  This PR adds an autofixable lint rule which will keep the changes up-to-date and Just Work ™️
jfsiii pushed a commit that referenced this pull request Mar 17, 2021
…94464) (#94868)

## Summary

Use the [`consistent-type-imports` lint rule ](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-imports.md) to use `import type ...` where possible

Code-only changes like this were recently added in #92979, but it was a more manual process.  This PR adds an autofixable lint rule which will keep the changes up-to-date and Just Work ™️
# Conflicts:
#	x-pack/plugins/fleet/server/services/agents/crud.ts
#	x-pack/plugins/fleet/server/services/artifacts/artifacts.ts
#	x-pack/plugins/fleet/server/services/artifacts/mappings.ts
#	x-pack/plugins/fleet/server/services/artifacts/mocks.ts
#	x-pack/plugins/fleet/server/services/index.ts
@jfsiii jfsiii deleted the fleet-ts-import-types branch April 6, 2021 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants