[CCI] Update webpack to v5#770
[CCI] Update webpack to v5#770andreymyssak wants to merge 12 commits intoopensearch-project:mainfrom
Conversation
| "@babel/plugin-proposal-class-properties": "^7.10.4", | ||
| "@babel/plugin-proposal-object-rest-spread": "^7.11.0", | ||
| "@babel/plugin-syntax-dynamic-import": "^7.8.3", | ||
| "@babel/plugin-transform-async-to-generator": "^7.10.4", |
There was a problem hiding this comment.
These plugins are included in @babel/preset-env
| "autoprefixer": "^9.8.6", | ||
| "autoprefixer": "^10.4.14", | ||
| "axe-core": "^4.1.1", | ||
| "babel-core": "7.0.0-bridge.0", |
There was a problem hiding this comment.
Removed in favor of @babel/core
| "babel-plugin-inline-react-svg": "^1.1.1", | ||
| "babel-plugin-inline-react-svg": "^2.0.2", | ||
| "babel-plugin-pegjs-inline-precompile": "^0.1.1", | ||
| "babel-template": "^6.26.0", |
There was a problem hiding this comment.
Removed in favor of @babel/template
| "eslint-plugin-react": "^7.21.3", | ||
| "eslint-plugin-react-hooks": "^4.1.2", | ||
| "expose-gc": "^1.0.0", | ||
| "file-loader": "^6.1.0", |
There was a problem hiding this comment.
DEPRECATED for v5 (https://v4.webpack.js.org/loaders/file-loader/)
| "prettier": "^2.1.2", | ||
| "prop-types": "^15.6.0", | ||
| "puppeteer": "^5.5.0", | ||
| "raw-loader": "^4.0.1", |
There was a problem hiding this comment.
DEPRECATED for v5 (https://v4.webpack.js.org/loaders/file-loader/). It was replaced with asset/source type (https://webpack.js.org/guides/asset-modules/#replacing-inline-loader-syntax)
| "webpack-dev-server": "^3.11.0", | ||
| "style-loader": "^3.3.2", | ||
| "terser-webpack-plugin": "^5.3.9", | ||
| "typescript": "4.1.6", |
There was a problem hiding this comment.
Typescript v4.0.5 gives an error below because @types/express-serve-static-core uses TypeScript v4.1 syntax, so I had to update it
node_modules/@types/express-serve-static-core/index.d.ts:104:68 - error TS1110: Type expected.
| const keysToRemove = new Set( | ||
| toRemovePropTypes.arguments[0].elements | ||
| .map(keyToRemove => | ||
| .map((keyToRemove) => |
There was a problem hiding this comment.
prettier added parentheses, @BSFishy can you check if they were supposed to be added? If they shouldn't, I'll revert the prettier changes
There was a problem hiding this comment.
What caused this change? I don't see any changes to anything related to Prettier. Is the file just not included in linting checks?
I don't see any issue with adding this change. It will keep our code style more consistent. I just want to know what caused it :)
There was a problem hiding this comment.
I just enabled Prettier in the settings of my IDE, it seems that Prettier was not applied to some files in the script folder before, f.e.
scripts/babel/fetch-i18n-strings.js
scripts/babel/react-docgen-typescript.js
scripts/eslint-plugin/forward_ref_display_name.js
scripts/eslint-plugin/i18n.js
and etc.
There was a problem hiding this comment.
i am glad to see you are using a real IDE... unlike some people... 😉 at Ashwin.
| import React, { Component, Fragment, ReactElement } from 'react'; | ||
| import { createFilter, SearchFilterConfig } from './filters'; | ||
| import { Query } from './query'; | ||
| import { Query } from './query/query'; |
There was a problem hiding this comment.
Typescript doesn't want to export the Query class from the index.ts for reasons I don't understand, so I had to adjust the imports
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore |
There was a problem hiding this comment.
Typescript is great, but nowhere without pain 😭, I couldn't fix it, so I had to come up with a not-so-good solution - @ts-ignore
TS2322: Type '{ onFocus: (e: React.FocusEvent) => void; onBlur: (e: React.FocusEvent) => void; onInput: (e: React.FormEvent<...>) => void; ... 295 more ...; isPreFiltered?: boolean | undefined; }' is not assignable to type 'Partial<OuiSelectableSearchProps<{ className: string; prepend: {} | null | undefined; append: {} | null | undefined; icon?: OuiIconProps | undefined; avatar?: (Pick<HTMLAttributes, "children" | ... 251 more ... | "onTransitionEndCapture"> & CommonProps & DisambiguateSet<...> & { ...; } & { ...; }) | ...'. Types of property 'options' are incompatible. Type '((DisambiguateSet<OuiSelectableGroupLabelOption<{ [key: string]: any; }>, OuiSelectableLIOption<{ [key: string]: any; }>> & CommonProps & { ...; } & HTMLAttributes<...> & { ...; }) | (DisambiguateSet<...> & ... 3 more ... & { ...; }))[] | undefined' is not assignable to type '((DisambiguateSet<Pick<OuiSelectableOptionBase, "className" | "id" | "aria-label" | "data-test-subj" | "label" | "searchableLabel" | "key" | "checked" | "disabled" | "prepend" | "append" | "ref"> & HTMLAttributes<...> & { ...; } & { ...; }, CommonProps & ... 2 more ... & { ...; }> & CommonProps & { ...; } & HTMLAttr...'. Type '((DisambiguateSet<OuiSelectableGroupLabelOption<{ [key: string]: any; }>, OuiSelectableLIOption<{ [key: string]: any; }>> & CommonProps & { ...; } & HTMLAttributes<...> & { ...; }) | (DisambiguateSet<...> & ... 3 more ... & { ...; }))[]' is not assignable to type '((DisambiguateSet<Pick<OuiSelectableOptionBase, "className" | "id" | "aria-label" | "data-test-subj" | "label" | "searchableLabel" | "key" | "checked" | "disabled" | "prepend" | "append" | "ref"> & HTMLAttributes<...> & { ...; } & { ...; }, CommonProps & ... 2 more ... & { ...; }> & CommonProps & { ...; } & HTMLAttr...'. Type '(DisambiguateSet<OuiSelectableGroupLabelOption<{ [key: string]: any; }>, OuiSelectableLIOption<{ [key: string]: any; }>> & CommonProps & { ...; } & HTMLAttributes<...> & { ...; }) | (DisambiguateSet<...> & ... 3 more ... & { ...; })' is not assignable to type '(DisambiguateSet<Pick<OuiSelectableOptionBase, "className" | "id" | "aria-label" | "data-test-subj" | "label" | "searchableLabel" | "key" | "checked" | "disabled" | "prepend" | "append" | "ref"> & HTMLAttributes<...> & { ...; } & { ...; }, CommonProps & ... 2 more ... & { ...; }> & CommonProps & { ...; } & HTMLAttri...'. Type 'DisambiguateSet<OuiSelectableGroupLabelOption<{ [key: string]: any; }>, OuiSelectableLIOption<{ [key: string]: any; }>> & CommonProps & { ...; } & HTMLAttributes<...> & { ...; }' is not assignable to type '(DisambiguateSet<Pick<OuiSelectableOptionBase, "className" | "id" | "aria-label" | "data-test-subj" | "label" | "searchableLabel" | "key" | "checked" | "disabled" | "prepend" | "append" | "ref"> & HTMLAttributes<...> & { ...; } & { ...; }, CommonProps & ... 2 more ... & { ...; }> & CommonProps & { ...; } & HTMLAttri...'. Type 'DisambiguateSet<OuiSelectableGroupLabelOption<{ [key: string]: any; }>, OuiSelectableLIOption<{ [key: string]: any; }>> & CommonProps & { ...; } & HTMLAttributes<...> & { ...; }' is not assignable to type 'DisambiguateSet<Pick<OuiSelectableOptionBase, "className" | "id" | "aria-label" | "data-test-subj" | "label" | "searchableLabel" | "key" | "checked" | "disabled" | "prepend" | "append" | "ref"> & HTMLAttributes<...> & { ...; } & { ...; }, CommonProps & ... 2 more ... & { ...; }> & CommonProps & { ...; } & HTMLAttrib...'. Type 'DisambiguateSet<OuiSelectableGroupLabelOption<{ [key: string]: any; }>, OuiSelectableLIOption<{ [key: string]: any; }>> & CommonProps & { ...; } & HTMLAttributes<...> & { ...; }' is not assignable to type '{ className: string; prepend: {} | null | undefined; append: {} | null | undefined; icon?: OuiIconProps | undefined; avatar?: (Pick<React.HTMLAttributes, "children" | ... 251 more ... | "onTransitionEndCapture"> & CommonProps & DisambiguateSet<...> & { ...; } & { ...; }) | (Pick<...> & ... 4 more ......'. Types of property 'className' are incompatible. Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.
There was a problem hiding this comment.
We can create a followup issue to dive deeper into this
| "@babel/plugin-proposal-object-rest-spread": "^7.11.0", | ||
| "@babel/plugin-syntax-dynamic-import": "^7.8.3", | ||
| "@babel/plugin-transform-async-to-generator": "^7.10.4", | ||
| "@babel/plugin-transform-runtime": "^7.11.0", |
There was a problem hiding this comment.
It's not strictly necessary to use @babel/plugin-transform-runtime if we are already using core-js with useBuiltIns: 'usage' in @babel/preset-env
14ab77c to
029a8dd
Compare
| const { NODE_ENV, CI, WEBPACK_SERVE } = process.env; | ||
|
|
||
| const isDevelopment = WEBPACK_DEV_SERVER === 'true' && CI == null; | ||
| const isDevelopment = WEBPACK_SERVE === 'true' && CI == null; |
There was a problem hiding this comment.
WEBPACK_DEV_SERVER was changed to WEBPACK_SERVE (webpack/webpack-cli#2027)
| function getPortSync(options) { | ||
| let isDone = false; | ||
| let freeport = null; | ||
| let error = null; | ||
|
|
||
| getPort(options) | ||
| .then((port) => { | ||
| isDone = true; | ||
| freeport = port; | ||
| }) | ||
| .catch((err) => { | ||
| isDone = true; | ||
| error = err; | ||
| }); | ||
|
|
||
| // wait until we're done' | ||
| deasync.loopWhile(() => !isDone); | ||
|
|
||
| if (error) { | ||
| throw error; | ||
| } else { | ||
| return freeport; | ||
| } | ||
| } |
There was a problem hiding this comment.
getPort was not running for reasons I do not know, so I made webpack.config.js as a function and removed deasync
.eslintrc.js
Outdated
| plugins: ['jsx-a11y', 'prettier', 'local', 'react-hooks'], | ||
| rules: { | ||
| 'prefer-template': 'error', | ||
| 'import/no-unresolved': 'off', |
There was a problem hiding this comment.
Eslint started not passing due to the detection of errors like the following
68:30 error Unable to resolve path to module './search?raw' import/no-unresolved
This may be due to the fact that these files were indexed, but I'm not sure. If you go into the code locally in another branch, IDE will also show the same error. I haven't found a more elegant solution to fix this error, so I turned off the rule.
There was a problem hiding this comment.
Is there an option to ignore query params? Maybe we could raise this to the ESLint team? Otherwise we could create a follow up issue to dive deeper into this
There was a problem hiding this comment.
As it turned out, eslint-import-resolver-webpack only supports "synchronous" Webpack configs (https://github.com/import-js/eslint-plugin-import/tree/main/resolvers/webpack). How critical is it to use getPort? Is it possible to just put port 8030?
There was a problem hiding this comment.
As it turned out,
eslint-import-resolver-webpackonly supports "synchronous" Webpack configs (https://github.com/import-js/eslint-plugin-import/tree/main/resolvers/webpack). How critical is it to usegetPort? Is it possible to just put port8030?
I'm pretty sure the reason for getPort is that you can actually have multiple instances of OUI running on different ports - you can replicate by doing yarn start in multiple terminal tabs/windows, and the port will auto increment without collisions.
BSFishy
left a comment
There was a problem hiding this comment.
Looks pretty good, just had a few questions. Running integration tests now to verify compatibility with Dashboards
| { | ||
| // `targets` property set via `.browserslistrc` | ||
| useBuiltIns: process.env.NO_COREJS_POLYFILL ? false : 'usage', | ||
| corejs: 3, |
There was a problem hiding this comment.
In my testing, this line needed to be changed to
corejs: process.env.NO_COREJS_POLYFILL ? undefined : 3,I think because it doesn't want the corejs version unless 'usage' is specified for useBuiltIns. Did you run into the same thing at all?
There was a problem hiding this comment.
Just confirmed, a warning pops up when this line isn't changed:
WARNING (@babel/preset-env): The `corejs` option only has an effect when the `useBuiltIns` option is not `false`
There was a problem hiding this comment.
corejs: process.env.NO_COREJS_POLYFILL ? undefined : 3,
I'm not sure about changing false to undefined because there is no difference between them. According to the documentation, the default value for useBuiltIns is false (https://babeljs.io/docs/babel-preset-env#usebuiltins). I guess it is worth leaving false because using values that are expected by the field will help avoid surprise issues in the future.
I think because it doesn't want the corejs version unless 'usage' is specified for useBuiltIns. Did you run into the same thing at all?
Yes, I get the same warning message. The reason for this is that we purposely do not include polyfill imports in our build (see https://github.com/opensearch-project/oui/blob/main/scripts/compile-oui.js#L190-L219). As far as I understand, this solution was inherited from here elastic/eui#1982.
There was a problem hiding this comment.
Can any of you help me with why we need any polyfills?
There was a problem hiding this comment.
I checked the code of babel/preset-env and @BSFishy's solution is a valid one.
| const keysToRemove = new Set( | ||
| toRemovePropTypes.arguments[0].elements | ||
| .map(keyToRemove => | ||
| .map((keyToRemove) => |
There was a problem hiding this comment.
What caused this change? I don't see any changes to anything related to Prettier. Is the file just not included in linting checks?
I don't see any issue with adding this change. It will keep our code style more consistent. I just want to know what caused it :)
|
|
||
| const changelogSource = require('!!raw-loader!../../../../CHANGELOG.md').default.replace( | ||
| const changelogSource = require('../../../../CHANGELOG.md?raw').replace( | ||
| /## \[`master`\].+?##/s, // remove the `master` heading & contents |
There was a problem hiding this comment.
Just saw this, maybe since we renamed our default branch to main, we can update it here? Can create a followup issue for that.
src-docs/webpack.config.js
Outdated
| static: { | ||
| directory: path.resolve(__dirname, 'build'), | ||
| // prevent file watching while running on CI | ||
| // /app/ represents the entire docker environment | ||
| watch: isPuppeteer ? { ignored: '**/*' } : undefined, | ||
| }, | ||
| host: '0.0.0.0', | ||
| }), | ||
| disableHostCheck: true, | ||
| historyApiFallback: true, | ||
| // prevent file watching while running on CI | ||
| // /app/ represents the entire docker environment | ||
| watchOptions: isPuppeteer | ||
| ? { | ||
| ignored: '**/*', | ||
| } | ||
| : undefined, | ||
| } | ||
| : undefined, | ||
| node: { | ||
| fs: 'empty', | ||
| }, | ||
| port, | ||
| allowedHosts: 'all', | ||
| historyApiFallback: true, |
There was a problem hiding this comment.
Why has the devServer setting changed so much? Did the API just change significantly? And do all the previous settings have an equivalent in the new settings?
There was a problem hiding this comment.
- the
contentBase, ...,watchOptionswere removed in favor of thestaticoption (https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md#400-beta0-2020-11-27, https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md#static) - the
disableHostCheckandallowedHostsoptions were removed in favor of thefirewalloption (https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md#400-beta0-2020-11-27) - rename
firewalloption toallowedHostsoption (https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md#400-rc0-2021-07-19)
The other fields have not changed
src/components/icon/icon.test.tsx
Outdated
| component.update(); | ||
| expect(prettyHtml(component.html())).toMatchSnapshot(); | ||
| resolve(); | ||
| resolve(null); |
There was a problem hiding this comment.
What prompted this change?
There was a problem hiding this comment.
Updating Typescript to v4.1.6 prompted this change (see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#resolves-parameters-are-no-longer-optional-in-promises), but I can use Promise<void> instead of resolve(null), thanks for catching this
| import { OuiSpacer } from '../../spacer'; | ||
| import { OuiIcon } from '../../icon'; | ||
| import { Query } from '../query'; | ||
| import { Query } from '../query/query'; |
There was a problem hiding this comment.
Do we already export Query for ../query? If not, it seems like that might be desirable. Even more so for backwards compatibility reasons?
There was a problem hiding this comment.
We have index.ts, but it doesn't work for class imports and that's weird
oui/src/components/search_bar/query/index.ts
Lines 31 to 32 in ce8acf4
WARNING in ../../src/components/search_bar/search_bar.tsx 256:39-44
export 'Query' (imported as 'Query') was not found in './query' (possible exports: AST)
@ ../../src/components/search_bar/index.ts 31:0-49 31:0-49 31:0-49
@ ../../src/components/index.js 94:0-49 94:0-49 94:0-49
@ ./routes.js 56:0-56 205:44-60
@ ./index.js 42:0-30 58:28-47| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore |
There was a problem hiding this comment.
We can create a followup issue to dive deeper into this
| optimization: { | ||
| minimize: isProduction, | ||
| minimizer: [terserPlugin], | ||
| noEmitOnErrors: true, | ||
| emitOnErrors: true, | ||
| }, |
There was a problem hiding this comment.
In my testing, I had to add usedExports: false to disable some aggressive tree shaking. Did you run into the same thing at all?
There was a problem hiding this comment.
In the webpack v5 migration, nothing was written about usedExports. If I'm not mistaken, it was also included by default for productions in version 4 (https://v4.webpack.js.org/configuration/optimization/#optimizationusedexports), so I'm not sure if we should turn it off.
.eslintrc.js
Outdated
| plugins: ['jsx-a11y', 'prettier', 'local', 'react-hooks'], | ||
| rules: { | ||
| 'prefer-template': 'error', | ||
| 'import/no-unresolved': 'off', |
There was a problem hiding this comment.
Is there an option to ignore query params? Maybe we could raise this to the ESLint team? Otherwise we could create a follow up issue to dive deeper into this
47c290e to
b0c56f3
Compare
Co-authored-by: Sergey Myssak <sergey.myssak@gmail.com> Signed-off-by: Andrey Myssak <andreymyssak@gmail.com>
Co-authored-by: Sergey Myssak <sergey.myssak@gmail.com> Signed-off-by: Andrey Myssak <andreymyssak@gmail.com>
Co-authored-by: Sergey Myssak <sergey.myssak@gmail.com> Signed-off-by: Andrey Myssak <andreymyssak@gmail.com>
Co-authored-by: Sergey Myssak <sergey.myssak@gmail.com> Signed-off-by: Andrey Myssak <andreymyssak@gmail.com>
Co-authored-by: Sergey Myssak <sergey.myssak@gmail.com> Signed-off-by: Andrey Myssak <andreymyssak@gmail.com>
Co-authored-by: Sergey Myssak <sergey.myssak@gmail.com> Signed-off-by: Andrey Myssak <andreymyssak@gmail.com>
Co-authored-by: Sergey Myssak <sergey.myssak@gmail.com> Signed-off-by: Andrey Myssak <andreymyssak@gmail.com>
b0c56f3 to
0f07baf
Compare
…ch-project#584) Co-authored-by: Sergey Myssak <sergey.myssak@gmail.com> Signed-off-by: Andrey Myssak <andreymyssak@gmail.com>
Co-authored-by: Sergey Myssak <sergey.myssak@gmail.com> Signed-off-by: Andrey Myssak <andreymyssak@gmail.com>
Summary of Work DoneDependencies
Formatting
Questions Requiring Further Discussion
During our migration to As part of our adherence to best practices, the legacy You can read more about this transition in the Webpack documentation. However, we ran into a problem: To address this, we could potentially switch back to a synchronous configuration in our
The system throws the following warning message: WARNING in ../../src/components/search_bar/search_bar.tsx 256:39-44
export 'Query' (imported as 'Query') was not found in './query' (possible exports: AST)
@ ../../src/components/search_bar/index.ts 31:0-49 31:0-49 31:0-49
@ ../../src/components/index.js 94:0-49 94:0-49 94:0-49
@ ./routes.js 56:0-56 205:44-60
@ ./index.js 42:0-30 58:28-47For now, the issue has been resolved by importing the There is a chance that a future update of the `TypeScript' version may have a fix for this problem.
We've encountered a type conflict problem with This problem is currently solved by using the
Please note that the current warning does not cause a functional failure. For more details, please refer to the discussion in this thread.
|
|
Thanks guys; this is a big deal and what you have done is awesome. I will pull this down and play with it a bit. |
Additionally, make sure to test with Dashboards. I was running into issues where one of the auxiliary bundles wasn't exporting anything, causing issues in Dashboards. More info here: #765 (comment) |
Signed-off-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: Josh Romero <rmerqg@amazon.com>
|
@andreymyssak I took a shot at resolving the conflicts, but take a look at 22fb706 to see if they make sense. |
|
Thinking about this more, could it be possible that the |
|
A few observations, after rebasing and resolving conflicts:
I have pushed the rebased code to AMoo-Miki@ddf16ef. |
|
Fixed the minification:
|
But the assets generated by |
OUI inlines them :/
|
|
In an attempt to dig deeper into why the JS files were larger with webpack5, i split the Also, one almost 5KB is wasted due to two indented copyright headers! I suspect the same is happening with My latest stuff can be found at https://github.com/AMoo-Miki/oui/tree/updated-webpack-5. |
|
With
|
|
by the way, i couldn't get the docs to work. |
From CI, it looks like there's still reference to |
Description
Improved version of #765. It would take a long time to address all the potential improvements, so I created a new PR where I applied them.
Run the following commands again to see if there are any errors:
Issues Resolved
#584
Check List
yarn lintyarn test-unitBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.