-
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
[build/ts] transpile public code with webpack-specific ts config #21865
[build/ts] transpile public code with webpack-specific ts config #21865
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
return { | ||
...jestConfig, | ||
globals: { | ||
...(jestConfig.globals || {}), | ||
'ts-jest': { | ||
skipBabel: true, | ||
tsConfigFile: getTsProjectForAbsolutePath(filePath).tsConfigPath, | ||
tsConfigFile, |
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.
for whatever reason I thought we were using the browser env. any ideas if jest still includes jsdom even in node?
in any case that might explain https://github.com/elastic/kibana/pull/21811/files. I had to manually include the fetch mock browser client because it kept using node-fetch instead of window.fetch. should we not be setting anything on window there?
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.
Yeah, we have jest configured to include jsdom, but that only mocks out some things, mostly the document/DOM related stuff. Things like fetch()
are not supported. This change is specifically necessary because our browser based config is assuming that the code will be run through webpack before being executed by a browser, which would transpile ESM into webpack requires, but when running the code in jest it is run in node right out of TypeScript, so we need to use the node config to get commonJS
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.
An alternative option would be to use a light webpack-like transform on these files after then are put through typescript with our browser-based config, but I don't see any reason for the additional work that would take.
This comment has been minimized.
This comment has been minimized.
💚 Build Succeeded |
…stic#21865) Right now the build process is running TypeScript code through a single transpilation process which produces the JS code that ships with the distributable. This process causes problems because when running the optimizer from source we use a slightly different config https://github.com/elastic/kibana/blob/33c6ade75631fb3f56816bc134dff83d08f4f387/src/optimize/base_optimizer.js#L312-L313, which instructs typescript to build modules using ESM, which webpack understands, but in the build we transpile this TypeScript to commonjs, which does not support features that are important to the strategy we are using to maintain BWC with the legacy platform as we migrate to the new platform. This implements a `tsconfig.browser.json` file at the root of the repository that extends the default `tsconfig.json` file and includes a `src/**/public/**/*` code, which the root `tsconfig.json` file now excludes. This new config file is added to the list of projects that we lint, is shared with webpack, and is built along with the default project in the build process to create JS code that uses esm for webpack to consume.
6.5/6.x: 835ed85 |
In elastic#21865 we tried to make a separate config file that would be used for browser TS files by excluding them from the default config file and adding a second that included them. This works fine in the build, but IDE integrations rely on being able to automatically discover a `tsconfig.json` file in a parent directory of the file being edited, which doesn't work when the tsconfig.json file is found, but excludes the file being edited. In this situation IDE integrations silently fallback to the default TSConfig settings, which don't show the types of compiler errors that will become issues in CI, like implicit any warnings. This implements the original strategy we tried in elastic#21865 of mutating the tsconfig.json file before we run the tsc in the build so that the config files select the right files at build time.
* [typescript] continue to use the default config in development In #21865 we tried to make a separate config file that would be used for browser TS files by excluding them from the default config file and adding a second that included them. This works fine in the build, but IDE integrations rely on being able to automatically discover a `tsconfig.json` file in a parent directory of the file being edited, which doesn't work when the tsconfig.json file is found, but excludes the file being edited. In this situation IDE integrations silently fallback to the default TSConfig settings, which don't show the types of compiler errors that will become issues in CI, like implicit any warnings. This implements the original strategy we tried in #21865 of mutating the tsconfig.json file before we run the tsc in the build so that the config files select the right files at build time. * [tslint] remove browser config from default projects list since it is empty * [build/ts] fix typo
…ic#21966) * [typescript] continue to use the default config in development In elastic#21865 we tried to make a separate config file that would be used for browser TS files by excluding them from the default config file and adding a second that included them. This works fine in the build, but IDE integrations rely on being able to automatically discover a `tsconfig.json` file in a parent directory of the file being edited, which doesn't work when the tsconfig.json file is found, but excludes the file being edited. In this situation IDE integrations silently fallback to the default TSConfig settings, which don't show the types of compiler errors that will become issues in CI, like implicit any warnings. This implements the original strategy we tried in elastic#21865 of mutating the tsconfig.json file before we run the tsc in the build so that the config files select the right files at build time. * [tslint] remove browser config from default projects list since it is empty * [build/ts] fix typo
… (#21973) * [typescript] continue to use the default config in development In #21865 we tried to make a separate config file that would be used for browser TS files by excluding them from the default config file and adding a second that included them. This works fine in the build, but IDE integrations rely on being able to automatically discover a `tsconfig.json` file in a parent directory of the file being edited, which doesn't work when the tsconfig.json file is found, but excludes the file being edited. In this situation IDE integrations silently fallback to the default TSConfig settings, which don't show the types of compiler errors that will become issues in CI, like implicit any warnings. This implements the original strategy we tried in #21865 of mutating the tsconfig.json file before we run the tsc in the build so that the config files select the right files at build time. * [tslint] remove browser config from default projects list since it is empty * [build/ts] fix typo
Right now the build process is running TypeScript code through a single transpilation process which produces the JS code that ships with the distributable. This process causes problems because when running the optimizer from source we use a slightly different config
kibana/src/optimize/base_optimizer.js
Lines 312 to 313 in 33c6ade
This implements a
tsconfig.browser.json
file at the root of the repository that extends the defaulttsconfig.json
file and includes asrc/**/public/**/*
code, which the roottsconfig.json
file now excludes. This new config file is added to the list of projects that we lint, is shared with webpack, and is built along with the default project in the build process to create JS code that uses esm for webpack to consume.