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

Extract src/core in a separate TS project #76785

Merged
merged 25 commits into from
Sep 15, 2020

Conversation

mshustov
Copy link
Contributor

@mshustov mshustov commented Sep 4, 2020

Summary

This PR moves src/core into a separate TS project. To do so, I had to make a few adjustments:

Measurements

TypeScript

node --max-old-space-size=6144 ./node_modules/.bin/tsc -p tsconfig.json --extendedDiagnostics --noEmit
branch

Files:                        5223
Lines:                      709462
Nodes:                     2346911
Identifiers:                799315

master

Files:                        5801
Lines:                      820489
Nodes:                     2711845
Identifiers:                920910

VSCode

Improved responsiveness when working in the src/core project.
Test case:

  • open src/core/server/index.ts file
  • click on CoreId type

branch
navigation takes ~5s
gif: https://recordit.co/7wd2wtuSIt

[Info  - 14:00:49.498] Starting TS Server 
[Trace  - 14:00:54.441] <syntax> Response received: references (29). Request took 6 ms. Success: true 
Result: {
    "refs": [
        {
            "file": "/Users/mikhailshustov/work/kibana/src/core/server/index.ts",
            "start": {
                "line": 93,
                "offset": 10
            },
            "end": {
                "line": 93,
                "offset": 16
            },
            "contextStart": {
                "line": 93,
                "offset": 1
            },
            "contextEnd": {
                "line": 93,
                "offset": 41
            },
            "lineText": "export { CoreId } from './core_context';",
            "isWriteAccess": true,
            "isDefinition": true
        }
    ],
    "symbolName": "CoreId",
    "symbolStartOffset": 10,
    "symbolDisplayString": "export CoreId"
}

master
navigation takes ~ 30sec.
gif: https://recordit.co/zFkNd1mGd6

[Info  - 13:56:46.789] Starting TS Server 
Trace  - 13:57:13.734] <syntax> Response received: references (60). Request took 5 ms. Success: true 
Result: {
    "refs": [
        {
            "file": "/Users/mikhailshustov/work/kibana-original/src/core/server/index.ts",
            "start": {
                "line": 93,
                "offset": 10
            },
            "end": {
                "line": 93,
                "offset": 16
            },
            "contextStart": {
                "line": 93,
                "offset": 1
            },
            "contextEnd": {
                "line": 93,
                "offset": 41
            },
            "lineText": "export { CoreId } from './core_context';",
            "isWriteAccess": true,
            "isDefinition": true
        }
    ],
    "symbolName": "CoreId",
    "symbolStartOffset": 10,
    "symbolDisplayString": "export CoreId"
}

Follow-ups:

@mshustov mshustov added chore Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes v7.10.0 labels Sep 4, 2020
@@ -371,7 +371,7 @@ export class LegacyService implements CoreService {
// We only want one REPL.
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);
Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

created issue #76935

@@ -44,8 +42,6 @@ import { LegacyConfig, ILegacyService, ILegacyInternals } from '../../core/serve
// 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';
Copy link
Contributor Author

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' {
Copy link
Contributor Author

@mshustov mshustov Sep 4, 2020

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

@@ -75,7 +74,7 @@ export type ElasticsearchClientMock = DeeplyMockedKeys<ElasticsearchClient>;
const createClientMock = (): ElasticsearchClientMock =>
(createInternalClientMock() as unknown) as ElasticsearchClientMock;

interface ScopedClusterClientMock {
export interface ScopedClusterClientMock {
Copy link
Contributor Author

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

@@ -95,7 +95,6 @@
"@types/jsdom": "^16.2.3",
"@types/json-stable-stringify": "^1.0.32",
"@types/jsonwebtoken": "^7.2.8",
"@types/lodash": "^4.14.159",
Copy link
Contributor Author

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

export function extract(str: string): string;
}

type DeeplyMockedKeys<T> = {
Copy link
Contributor Author

@mshustov mshustov Sep 8, 2020

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" }
Copy link
Contributor Author

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

@mshustov mshustov marked this pull request as ready for review September 8, 2020 14:34
@mshustov mshustov requested review from a team as code owners September 8, 2020 14:34
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

Copy link
Contributor

@streamich streamich left a comment

Choose a reason for hiding this comment

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

AppArch changes LGTM.

Copy link
Contributor

@pgayvallet pgayvallet left a 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

Comment on lines +32 to +33
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../../../../../package.json');
Copy link
Contributor

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?

Copy link
Contributor Author

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.

src/core/server/saved_objects/es_query.js Show resolved Hide resolved
* under the License.
*/

declare module 'query-string' {
Copy link
Contributor

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?

Copy link
Contributor

@spalger spalger left a 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

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

distributable file count

id value diff baseline
default 45552 +5 45547
oss 27229 +5 27224
total +10

History

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

@mshustov mshustov merged commit e7d8ea3 into elastic:master Sep 15, 2020
@mshustov mshustov deleted the src-core-ts-project branch September 15, 2020 10:41
mshustov added a commit to mshustov/kibana that referenced this pull request Sep 15, 2020
* 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
mshustov added a commit that referenced this pull request Sep 16, 2020
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported chore release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants