Extract src/core in a separate TS project#76785
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.
a temporary hack to remove type dependencies between the core and cli. I'm going to enforce strict separation
| // 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.
removed dependency on plugin types
| * under the License. | ||
| */ | ||
|
|
||
| declare module 'query-string' { |
There was a problem hiding this comment.
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.
Can't we have a ts project for /typings and import the reference?
There was a problem hiding this comment.
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.
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.
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.
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.
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) |
pgayvallet
left a comment
There was a problem hiding this comment.
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.
The package file is also considered as an external dependency?
There was a problem hiding this comment.
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.
Can't we have a ts project for /typings and import the reference?
spalger
left a comment
There was a problem hiding this comment.
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