-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Extract src/core in a separate TS project #76785
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
Conversation
| if (this.coreContext.env.cliArgs.repl && process.env.kbnWorkerType === 'server') { | ||
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
| require('../../../cli/repl').startRepl(kbnServer); | ||
| require('./cli').startRepl(kbnServer); |
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.
a temporary hack to remove type dependencies between the core and cli. I'm going to enforce strict separation
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.
created issue #76935
| // eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
| import { UiPlugins } from '../../core/server/plugins'; | ||
| import { CallClusterWithRequest, ElasticsearchPlugin } from '../core_plugins/elasticsearch'; | ||
| import { UsageCollectionSetup } from '../../plugins/usage_collection/server'; |
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.
removed dependency on plugin types
| * under the License. | ||
| */ | ||
|
|
||
| declare module 'query-string' { |
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 didn't want to include global typings in every package.
It seems there are no reason not to update query-string to the version shipped with type definitions. We had to roll back to the old version due to compatibility issues with IE11 #59633
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.
Can't we have a ts project for /typings and import the reference?
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.
we already have @kbn/utility-types for standard types, I'd rather avoid creating another utility package until it's unavoidable
| (createInternalClientMock() as unknown) as ElasticsearchClientMock; | ||
|
|
||
| interface ScopedClusterClientMock { | ||
| export interface ScopedClusterClientMock { |
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.
required for TS to be able to reference the type in a declaration file
This reverts commit 79cec57.
| "@types/jsdom": "^16.2.3", | ||
| "@types/json-stable-stringify": "^1.0.32", | ||
| "@types/jsonwebtoken": "^7.2.8", | ||
| "@types/lodash": "^4.14.159", |
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.
got @types/lodash/ts3.1 error TS2300: Duplicate identifier error since both oss & x-pack types were included. I'd remove lodash from x-pack/package.json completely to rely on oss/package.json, but some plugins use import/no-extraneous-dependencies @elastic/kibana-operations
d62e1f3 to
c9b2342
Compare
| export function extract(str: string): string; | ||
| } | ||
|
|
||
| type DeeplyMockedKeys<T> = { |
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.
Unfortunately, I didn't find a way to import MockInstance & Mocked interfaces from jest package. It didn't allow me to move DeeplyMockedKeys & MockedKeys interfaces to @kbn/utility-types, since global defined jest types conflict with mocha types when importing @kbn/utility-types in /test/ folder.
| "exclude": [] | ||
| "exclude": [], | ||
| "references": [ | ||
| { "path": "../../src/core/tsconfig.json" } |
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.
not a hard requirement, but it reduced the number of processed files
node --max-old-space-size=6144 ./node_modules/.bin/tsc -p examples/bfetch_explorer/tsconfig.json --extendedDiagnostics --noEmit
with references
Files: 876
Lines: 219410
Nodes: 789781
Identifiers: 286371
without references
Files: 1203
Lines: 272257
Nodes: 930313
Identifiers: 333766
|
Pinging @elastic/kibana-platform (Team:Platform) |
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.
AppArch 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.
LGTM for platform changes
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
| const pkg = require('../../../../../package.json'); |
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.
The package file is also considered as an external dependency?
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.
if you import, yes. it should gone when @kbn/utils is merged.
| * under the License. | ||
| */ | ||
|
|
||
| declare module 'query-string' { |
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.
Can't we have a ts project for /typings and import the reference?
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, checked operations specific changes and ran it locally, all seems well
💚 Build SucceededBuild metricsdistributable file count
History
To update your PR or re-run it, just comment with: |
* break dependency on data plugin TS code * move global typings to @kbn/utility-types * import types from @kbn/utility-types * remove type dependency on plugins * add intermediate js files to break dependency on outter TS code * temp type declaration for query-string * declare src/core project * export types to reference in the built d.ts files * reference core project * move jest types out of kbn/utility-types due to a clash with mocha types * fix wrong es_kuery path and ts project paths * reference core from packages consuming it * x-pack & oss should use the same lodash version * Revert "x-pack & oss should use the same lodash version" This reverts commit 79cec57. * use the same lodash version * fix @types/lodash TS2300: Duplicate identifier error * fix wrong imports * update docs * update docs * add a comment why file is needed # Conflicts: # packages/kbn-utility-types/index.ts # src/core/public/application/capabilities/capabilities_service.mock.ts # src/core/public/chrome/chrome_service.mock.ts
* break dependency on data plugin TS code * move global typings to @kbn/utility-types * import types from @kbn/utility-types * remove type dependency on plugins * add intermediate js files to break dependency on outter TS code * temp type declaration for query-string * declare src/core project * export types to reference in the built d.ts files * reference core project * move jest types out of kbn/utility-types due to a clash with mocha types * fix wrong es_kuery path and ts project paths * reference core from packages consuming it * x-pack & oss should use the same lodash version * Revert "x-pack & oss should use the same lodash version" This reverts commit 79cec57. * use the same lodash version * fix @types/lodash TS2300: Duplicate identifier error * fix wrong imports * update docs * update docs * add a comment why file is needed # Conflicts: # packages/kbn-utility-types/index.ts # src/core/public/application/capabilities/capabilities_service.mock.ts # src/core/public/chrome/chrome_service.mock.ts
Summary
This PR moves
src/coreinto a separate TS project. To do so, I had to make a few adjustments:MethodKeysOfto@kbn/utility-typesto able to use it in any packagecoretypescript dependency ondata plugin&cli. These dependencies still exist in runtime. Dependency on data plugin should be removed in [core.savedObjects] Update esKuery imports to pull from new package instead of data plugin #55485An issue to remove the dependency on CLI: Remove circular dependencies between CLI & core #76935
Measurements
TypeScript
node --max-old-space-size=6144 ./node_modules/.bin/tsc -p tsconfig.json --extendedDiagnostics --noEmit
branch
master
VSCode
Improved responsiveness when working in the
src/coreproject.Test case:
src/core/server/index.tsfileCoreIdtypebranch
navigation takes ~5s
gif: https://recordit.co/7wd2wtuSIt
master
navigation takes ~ 30sec.
gif: https://recordit.co/zFkNd1mGd6
Follow-ups:
query-stringversion to get rid of manually maintained types https://github.com/elastic/kibana/pull/76785/files#r483710091jesttypes to moveDeeplyMockedKeys&MockedKeysto @kbn/utility-types