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

[CCI] Update webpack to v5 #770

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

andreymyssak
Copy link
Collaborator

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:

  • yarn build
  • yarn build-docs
  • yarn start
  • yarn test-unit
  • yarn lint

Issues Resolved

#584

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • All tests pass
    • yarn lint
    • yarn test-unit
  • Commits are signed per the DCO using --signoff

By 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.

Comment on lines -127 to -143
"@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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These plugins are included in @babel/preset-env

"axe-core": "^4.1.1",
"babel-core": "7.0.0-bridge.0",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed in favor of @babel/core

"babel-plugin-pegjs-inline-precompile": "^0.1.1",
"babel-template": "^6.26.0",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed in favor of @babel/template

@@ -190,28 +182,28 @@
"eslint-plugin-react": "^7.21.3",
"eslint-plugin-react-hooks": "^4.1.2",
"expose-gc": "^1.0.0",
"file-loader": "^6.1.0",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"pre-commit": "^1.2.2",
"prettier": "^2.1.2",
"prop-types": "^15.6.0",
"puppeteer": "^5.5.0",
"raw-loader": "^4.0.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"webpack-dev-server": "^3.11.0",
"style-loader": "^3.3.2",
"terser-webpack-plugin": "^5.3.9",
"typescript": "4.1.6",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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.

@@ -137,10 +137,10 @@ function resolveOmitToPropTypes(node, state) {
// extract the string values of keys to remove
const keysToRemove = new Set(
toRemovePropTypes.arguments[0].elements
.map(keyToRemove =>
.map((keyToRemove) =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

prettier added parentheses, @BSFishy can you check if they were supposed to be added? If they shouldn't, I'll revert the prettier changes

Copy link
Contributor

Choose a reason for hiding this comment

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

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 :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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.

Screenshot 2023-05-29 at 09 36 46

Copy link
Collaborator

Choose a reason for hiding this comment

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

i am glad to see you are using a real IDE... unlike some people... 😉 at Ashwin.

@@ -30,7 +30,7 @@

import React, { Component, Fragment, ReactElement } from 'react';
import { createFilter, SearchFilterConfig } from './filters';
import { Query } from './query';
import { Query } from './query/query';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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

Comment on lines +252 to +253
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Copy link
Collaborator Author

@andreymyssak andreymyssak May 20, 2023

Choose a reason for hiding this comment

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

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'.

Copy link
Contributor

Choose a reason for hiding this comment

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

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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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

@andreymyssak andreymyssak force-pushed the 584-update-webpack branch 2 times, most recently from 14ab77c to 029a8dd Compare May 21, 2023 07:47

const isDevelopment = WEBPACK_DEV_SERVER === 'true' && CI == null;
const isDevelopment = WEBPACK_SERVE === 'true' && CI == null;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

WEBPACK_DEV_SERVER was changed to WEBPACK_SERVE (webpack/webpack-cli#2027)

Comment on lines -163 to -186
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;
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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
@@ -108,6 +108,7 @@ module.exports = {
plugins: ['jsx-a11y', 'prettier', 'local', 'react-hooks'],
rules: {
'prefer-template': 'error',
'import/no-unresolved': 'off',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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?

Copy link
Member

Choose a reason for hiding this comment

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

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?

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.

Copy link
Contributor

@BSFishy BSFishy left a comment

Choose a reason for hiding this comment

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

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

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`

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can any of you help me with why we need any polyfills?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked the code of babel/preset-env and @BSFishy's solution is a valid one.

@@ -137,10 +137,10 @@ function resolveOmitToPropTypes(node, state) {
// extract the string values of keys to remove
const keysToRemove = new Set(
toRemovePropTypes.arguments[0].elements
.map(keyToRemove =>
.map((keyToRemove) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

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 :)

@@ -14,7 +14,7 @@ import React from 'react';
import { OuiMarkdownFormat } from '../../../../src';
import { GuidePage } from '../../components/guide_page';

const changelogSource = require('!!raw-loader!../../../../CHANGELOG.md').default.replace(
const changelogSource = require('../../../../CHANGELOG.md?raw').replace(
/## \[`master`\].+?##/s, // remove the `master` heading & contents
Copy link
Contributor

Choose a reason for hiding this comment

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

Just saw this, maybe since we renamed our default branch to main, we can update it here? Can create a followup issue for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines 157 to 166
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,
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Collaborator Author

@andreymyssak andreymyssak May 29, 2023

Choose a reason for hiding this comment

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

  1. the contentBase, ..., watchOptions were removed in favor of the static option (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)
  2. the disableHostCheck and allowedHosts options were removed in favor of the firewall option (https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md#400-beta0-2020-11-27)
  3. rename firewall option to allowedHosts option (https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md#400-rc0-2021-07-19)

The other fields have not changed

@@ -60,7 +60,7 @@ function testIcon(props: PropsOf<OuiIcon>) {
const onIconLoad = () => {
component.update();
expect(prettyHtml(component.html())).toMatchSnapshot();
resolve();
resolve(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

What prompted this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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

@@ -37,7 +37,7 @@ import { OuiFilterButton, OuiFilterSelectItem } from '../../filter_group';
import { OuiLoadingChart } from '../../loading';
import { OuiSpacer } from '../../spacer';
import { OuiIcon } from '../../icon';
import { Query } from '../query';
import { Query } from '../query/query';
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we already export Query for ../query? If not, it seems like that might be desirable. Even more so for backwards compatibility reasons?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have index.ts, but it doesn't work for class imports and that's weird

export { Query } from './query';
export { AST } from './ast';

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

Comment on lines +252 to +253
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

We can create a followup issue to dive deeper into this

Comment on lines 124 to 128
optimization: {
minimize: isProduction,
minimizer: [terserPlugin],
noEmitOnErrors: true,
emitOnErrors: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

In my testing, I had to add usedExports: false to disable some aggressive tree shaking. Did you run into the same thing at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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
@@ -108,6 +108,7 @@ module.exports = {
plugins: ['jsx-a11y', 'prettier', 'local', 'react-hooks'],
rules: {
'prefer-template': 'error',
'import/no-unresolved': 'off',
Copy link
Contributor

Choose a reason for hiding this comment

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

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

@BSFishy
Copy link
Contributor

BSFishy commented May 22, 2023

Also 2086980 and e9a63af need to be reverted, as we want to backport this to 1.x :)

@jmetev1 jmetev1 mentioned this pull request May 22, 2023
6 tasks
@andreymyssak
Copy link
Collaborator Author

Also 2086980 and e9a63af need to be reverted, as we want to backport this to 1.x :)

If I revet these commits, then my changes won't go into main. Should I create another PR where I just do the cherry-pick and the necessary changes for 1.x?

andreymyssak and others added 7 commits July 13, 2023 09:50
Co-authored-by: Sergey Myssak <[email protected]>
Signed-off-by: Andrey Myssak <[email protected]>
Co-authored-by: Sergey Myssak <[email protected]>
Signed-off-by: Andrey Myssak <[email protected]>
Co-authored-by: Sergey Myssak <[email protected]>
Signed-off-by: Andrey Myssak <[email protected]>
andreymyssak and others added 2 commits July 13, 2023 20:22
@andreymyssak
Copy link
Collaborator Author

andreymyssak commented Jul 13, 2023

Summary of Work Done

Dependencies

  • Bumped webpack from v4 to v5
  • Bumped postcss from v7 to v8
  • Bumped babel minor version
  • Bumped typescript from v4.0.5 to v4.1.6 ([CCI] Update webpack to v5 #770 (comment))
  • Removed some of the resolutions that were covered by a dependency update

Formatting

Prettier was not applied to some files in the script folder before, so the changes can be found in the following files (#770 (comment))

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

Questions Requiring Further Discussion

  1. Can we directly use port 8030 instead of utilizing getPortSync and getPort.makeRange?

During our migration to webpack v5, we ran into a problem with deasync, as it stopped working. Previously, it was used to convert our webpack.config.js from asynchronous to synchronous. However, since webpack supports asynchronous configurations, I've converted our config file accordingly. However, this change introduced a bottleneck.

As part of our adherence to best practices, the legacy !!raw-loader! syntax has been replaced with ?raw, such as:

const basicSource = require('!!raw-loader!./basic_window_event');
// is now
const basicSource = require('./basic_window_event?raw');

You can read more about this transition in the Webpack documentation.

However, we ran into a problem: eslint does not recognize resourceQuery. This is because eslint-import-resolver-webpack only supports synchronous webpack configurations (see here), while we are using an asynchronous one. Since deasync is no longer working in webpack.config.js, we can't go back to it.

To address this, we could potentially switch back to a synchronous configuration in our webpack.config.js. This could be accomplished by eliminating the use of getPortSync and using port 8030 directly. Would it be possible to simply use port 8030 instead of getPortSync and getPort.makeRange?

  1. TypeScript refuses to export the Query class from index.ts for reasons that remain unclear. See the specific issue in the [code here].

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-47

For now, the issue has been resolved by importing the Query class from query/query.ts, instead of from query/index.ts.

There is a chance that a future update of the `TypeScript' version may have a fix for this problem.

  1. Running into a complex type conflict with searchProps in OuiSelectable

We've encountered a type conflict problem with searchProps in the OuiSelectable component that is proving difficult to resolve. Details about the specific type error can be found here.

This problem is currently solved by using the @ts-ignore. There is a chance that a future update of the `TypeScript' version may have a fix for this problem.

  1. Build process displays WARNING (@babel/preset-env): The corejs option only has an effect when the useBuiltIns option is not false.

Please note that the current warning does not cause a functional failure. For more details, please refer to the discussion in this thread.

  1. Including usedExports in webpack.config.js. For more details, please refer to the discussion in this thread

@andreymyssak andreymyssak requested a review from BSFishy July 14, 2023 05:13
@AMoo-Miki
Copy link
Collaborator

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.

@BSFishy
Copy link
Contributor

BSFishy commented Jul 20, 2023

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)

@joshuarrrr
Copy link
Member

@andreymyssak I took a shot at resolving the conflicts, but take a look at 22fb706 to see if they make sense.

@BSFishy
Copy link
Contributor

BSFishy commented Sep 18, 2023

Thinking about this more, could it be possible that the sass-vars-to-js-loader loader is using some sort of Webpack 4 structure and the reason why the charts module doesn't export anything?

@AMoo-Miki
Copy link
Collaborator

AMoo-Miki commented Sep 28, 2023

A few observations, after rebasing and resolving conflicts:

  1. The updated autoprefixer causes duplicate CSS. I am not worried about this because i will be porting some changes from OSD that will eliminate the need for autoprefixer.
  2. *.min.css files are no longer minified. postcss and cssnano have both been bumped but I didn't dig to see which portion is breaking the logic.
  3. oui.js is 1.5MB larger; doesn't sound right and more investigation is needed.
  4. oui.min.js, oui.min.js.LICENSE.txt, oui.min.js.map fail to generate.
  5. *ui_charts_theme.js are generated as folders and not files.

I have pushed the rebased code to AMoo-Miki@ddf16ef.

@AMoo-Miki
Copy link
Collaborator

Fixed the minification:

  • Had to disable cssDeclarationSorter because it could have been unsafe.
  • The new cssnano merges back-to-back media queries and removes the media queries for the lower boundary; verified that it was safe.
  • The new cssnano also doesn't break and combine neighboring definitions.
  • rgba is converted to hsla; shouldn't be a big deal.
  • svgo produces slightly longer assets.

@BSFishy
Copy link
Contributor

BSFishy commented Sep 30, 2023

  • svgo produces slightly longer assets.

But the assets generated by svgo should all be in separate files right? All OUI icons are loaded in async, and won't be in the main bundle, right?

@AMoo-Miki
Copy link
Collaborator

AMoo-Miki commented Oct 1, 2023

But the assets generated by svgo should all be in separate files right? All OUI icons are loaded in async, and won't be in the main bundle, right?

OUI inlines them :/

postcss.config.js has postcss-inline-svg defined in it. However, the ones I saw elongated are those that it finds in imported deps.

@AMoo-Miki
Copy link
Collaborator

AMoo-Miki commented Oct 1, 2023

In an attempt to dig deeper into why the JS files were larger with webpack5, i split the eui_charts_theme.js files, before (260KB) and after (363KB). I see a lot more imports from corjs included with webpack5; 57 files totaling 100KB. These include stuff like:

../node_modules/core-js/internals/array-from.js
../node_modules/core-js/internals/iterator-define.js
../node_modules/core-js/internals/regexp-exec.js
../node_modules/core-js/modules/es.symbol.constructor.js

Also, one almost 5KB is wasted due to two indented copyright headers!

I suspect the same is happening with oui.js too.

My latest stuff can be found at https://github.com/AMoo-Miki/oui/tree/updated-webpack-5.

@AMoo-Miki
Copy link
Collaborator

With oui.js:

  • 1.5MB was added.
  • 197 imports of 461KB are removed.
    • some removed imports are index.ts and types.ts files that only re-exported stuff:
      ./components/delay_hide/index.ts
      ./services/color_picker/index.ts
      ./services/popover/index.ts
      
  • 62 imports of 214KB are added.
    • imports from assert make up 114KB of that.
    • 15 are from corejs worth 20KB.
  • 1919 files have some kind of change in them, resulting in the 1.7MB delta:
    • Numerous files (i stopped counting at 50 of the first 100) have gained 5KB-10KB, all because of lines like:
    /* harmony import */ var core_js_modules_es_array_slice_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! core-js/modules/es.array.slice.js */ "../node_modules/core-js/modules/es.array.slice.js");
    /* harmony import */ var core_js_modules_es_array_slice_js__WEBPACK_IMPORTED_MODULE_21___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_slice_js__WEBPACK_IMPORTED_MODULE_21__);
    

@AMoo-Miki
Copy link
Collaborator

by the way, i couldn't get the docs to work. yarn start shows a blank page.

@BSFishy
Copy link
Contributor

BSFishy commented Oct 3, 2023

by the way, i couldn't get the docs to work. yarn start shows a blank page.

From CI, it looks like there's still reference to raw-loader: https://github.com/opensearch-project/oui/actions/runs/6177159690/job/16767685139?pr=770#step:5:31

@BSFishy BSFishy mentioned this pull request Oct 16, 2023
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CCI College Contributor Initiative valued-contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants