Skip to content

Commit a460fcc

Browse files
authored
feat: Upgrade to Webpack 5 (#1996)
This is a start for upgrading to webpack 5 and webpack-dev-server ^4. With these changes, the basic examples are working ( incl. hot module reloading ). But there are more todo's left * update dev-server config * make StyleguidistOptionsPlugin.ts work with webpack 5 and fix test * fix make-webpack-config.spec.ts tests * upgrade other webpack loader dependencies to latests versions (optional?) * fix type errors * fix deprecation warnings Fixes #1932 BREAKING CHANGE: Webpack 4 is no longer supported.
1 parent 4c55077 commit a460fcc

33 files changed

+30731
-4703
lines changed

package-lock.json

+30,495-4,472
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+23-25
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
"assert": "1.5.0",
3636
"ast-types": "~0.14.2",
3737
"buble": "0.20.0",
38-
"clean-webpack-plugin": "^3.0.0",
38+
"clean-webpack-plugin": "^4.0.0",
3939
"clipboard-copy": "^3.1.0",
4040
"clsx": "^1.0.4",
4141
"common-dir": "^3.0.0",
42-
"copy-webpack-plugin": "^6.1.0",
42+
"copy-webpack-plugin": "^11.0.0",
4343
"core-js": "^3.6.4",
4444
"doctrine": "^3.0.0",
4545
"es6-object-assign": "~1.1.0",
@@ -54,24 +54,23 @@
5454
"glogg": "^1.0.2",
5555
"hash-sum": "^2.0.0",
5656
"javascript-stringify": "^2.0.0",
57-
"jss": "^10.0.0",
58-
"jss-plugin-camel-case": "^10.0.0",
59-
"jss-plugin-compose": "^10.0.0",
60-
"jss-plugin-default-unit": "^10.0.0",
61-
"jss-plugin-global": "^10.0.0",
62-
"jss-plugin-isolate": "^10.0.0",
63-
"jss-plugin-nested": "^10.0.0",
57+
"jss": "^10.9.0",
58+
"jss-plugin-camel-case": "^10.9.0",
59+
"jss-plugin-compose": "^10.9.0",
60+
"jss-plugin-default-unit": "^10.9.0",
61+
"jss-plugin-global": "^10.9.0",
62+
"jss-plugin-isolate": "^10.9.0",
63+
"jss-plugin-nested": "^10.9.0",
6464
"kleur": "^3.0.3",
6565
"listify": "^1.0.0",
66-
"loader-utils": "^2.0.0",
6766
"lodash": "^4.17.15",
6867
"lowercase-keys": "^2.0.0",
6968
"markdown-to-jsx": "^6.11.4",
7069
"mini-html-webpack-plugin": "^3.1.3",
7170
"mri": "^1.1.4",
7271
"ora": "^4.0.2",
7372
"prismjs": "^1.17.1",
74-
"prop-types": "^15.7.2",
73+
"prop-types": "^15.8.1",
7574
"q-i": "^2.0.1",
7675
"qss": "^2.0.3",
7776
"react-dev-utils": "^12.0.0",
@@ -84,11 +83,11 @@
8483
"recast": "~0.18.5",
8584
"remark": "^13.0.0",
8685
"strip-html-comments": "^1.0.0",
87-
"terser-webpack-plugin": "^4.1.0",
86+
"terser-webpack-plugin": "^5.3.3",
8887
"to-ast": "^1.0.0",
8988
"type-detect": "^4.0.8",
9089
"unist-util-visit": "^2.0.0",
91-
"webpack-dev-server": "^3.11.2",
90+
"webpack-dev-server": "^4.9.2",
9291
"webpack-merge": "^4.2.2"
9392
},
9493
"peerDependencies": {
@@ -101,8 +100,8 @@
101100
"@babel/plugin-proposal-class-properties": "^7.8.3",
102101
"@babel/preset-env": "^7.9.0",
103102
"@babel/preset-flow": "^7.9.0",
104-
"@babel/preset-react": "^7.9.4",
105-
"@babel/preset-typescript": "^7.9.0",
103+
"@babel/preset-react": "^7.18.6",
104+
"@babel/preset-typescript": "^7.18.6",
106105
"@testing-library/jest-dom": "^5.11.4",
107106
"@testing-library/react": "^11.1.0",
108107
"@types/buble": "^0.19.2",
@@ -114,15 +113,15 @@
114113
"@types/hash-sum": "^1.0.0",
115114
"@types/jest": "^26.0.14",
116115
"@types/keymirror": "^0.1.1",
117-
"@types/loader-utils": "^1.1.3",
118116
"@types/lodash": "^4.14.144",
119117
"@types/markdown-to-jsx": "^6.9.0",
120118
"@types/node": "^12.12.3",
121119
"@types/prismjs": "^1.16.0",
122120
"@types/react": "^16.9.27",
123121
"@types/react-dom": "^16.9.5",
124-
"@types/terser-webpack-plugin": "^2.2.0",
122+
"@types/terser-webpack-plugin": "^2.2.3",
125123
"@types/type-detect": "^4.0.1",
124+
"@types/webpack": "^5.28.0",
126125
"@types/webpack-dev-server": "^3.11.1",
127126
"@types/webpack-env": "^1.14.1",
128127
"@typescript-eslint/eslint-plugin": "^4.4.1",
@@ -132,7 +131,7 @@
132131
"babel-jest": "^26.6.0",
133132
"babel-loader": "^8.1.0",
134133
"cheerio": "^1.0.0-rc.3",
135-
"css-loader": "^3.2.0",
134+
"css-loader": "^6.7.1",
136135
"danger": "^10.5.3",
137136
"deabsdeep": "^1.0.6",
138137
"deepfreeze": "^2.0.0",
@@ -147,7 +146,7 @@
147146
"eslint-plugin-import": "^2.22.1",
148147
"eslint-plugin-jsx-a11y": "^6.3.1",
149148
"eslint-plugin-react": "^7.21.4",
150-
"file-loader": "^4.2.0",
149+
"file-loader": "^6.2.0",
151150
"fs-extra": "^9.0.0",
152151
"husky": "^4.3.0",
153152
"jest": "^26.6.0",
@@ -161,12 +160,11 @@
161160
"react-dom": "^16.13.1",
162161
"react-test-renderer": "^16.13.1",
163162
"strip-shebang": "^1.0.2",
164-
"style-loader": "^1.0.0",
165-
"tapable": "^1.1.3",
166-
"typescript": "^3.8.3",
167-
"url-loader": "^2.2.0",
168-
"webpack": "^4.46.0",
169-
"webpack-cli": "^3.3.12"
163+
"style-loader": "^3.3.1",
164+
"typescript": "^4.7.4",
165+
"url-loader": "^4.1.1",
166+
"webpack": "^5.72.0",
167+
"webpack-cli": "^4.9.2"
170168
},
171169
"scripts": {
172170
"pretest": "npm run lint && npm run typecheck",

src/client/rsg-components/Arguments/ArgumentsRenderer.tsx

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import Styled, { JssInjectedProps } from 'rsg-components/Styled';
43
import Argument, { ArgumentProps } from 'rsg-components/Argument';
54
import Heading from 'rsg-components/Heading';
@@ -36,23 +35,11 @@ export const ArgumentsRenderer: React.FunctionComponent<ArgumentsProps> = ({
3635
<Heading level={5}>Arguments</Heading>
3736
</div>
3837
)}
39-
{args.map(arg => (
38+
{args.map((arg) => (
4039
<Argument key={arg.name} {...arg} />
4140
))}
4241
</div>
4342
);
4443
};
4544

46-
ArgumentsRenderer.propTypes = {
47-
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired,
48-
args: PropTypes.arrayOf(
49-
PropTypes.shape({
50-
name: PropTypes.string.isRequired,
51-
type: PropTypes.object,
52-
description: PropTypes.string,
53-
}).isRequired
54-
).isRequired,
55-
heading: PropTypes.bool,
56-
};
57-
5845
export default Styled<ArgumentsProps>(styles)(ArgumentsRenderer);

src/client/rsg-components/Editor/Editor.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { highlight as prismHighlight, languages } from 'prismjs';
66
import 'prismjs/components/prism-clike';
77
import 'prismjs/components/prism-markup';
88
import 'prismjs/components/prism-javascript';
9+
import { Styles } from 'jss';
910
import 'prismjs/components/prism-jsx';
1011
import { space } from '../../styles/theme';
1112
import prismTheme from '../../styles/prismTheme';
1213
import * as Rsg from '../../../typings';
1314

1415
const highlight = (code: string) => prismHighlight(code, languages.jsx, 'jsx');
1516

16-
const styles = ({ fontFamily, fontSize, color, borderRadius }: Rsg.Theme) => ({
17+
const styles = ({ fontFamily, fontSize, color, borderRadius }: Rsg.Theme): Styles => ({
1718
root: {
1819
fontFamily: fontFamily.monospace,
1920
fontSize: fontSize.small,

src/client/rsg-components/Markdown/Details/DetailsSummaryRenderer.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { Styles } from 'jss';
34
import Styled, { JssInjectedProps } from 'rsg-components/Styled';
45
import * as Rsg from '../../../../typings';
56

6-
const styles = ({ space, color, fontSize, fontFamily }: Rsg.Theme) => ({
7+
const styles = ({ space, color, fontSize, fontFamily }: Rsg.Theme): Styles => ({
78
summary: {
89
marginBottom: space[1],
910
fontFamily: fontFamily.base,

src/client/rsg-components/Methods/MethodsRenderer.tsx

-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import Markdown from 'rsg-components/Markdown';
43
import Argument from 'rsg-components/Argument';
54
import Arguments from 'rsg-components/Arguments';
@@ -40,16 +39,4 @@ const MethodsRenderer: React.FunctionComponent<{ methods: MethodDescriptor[] }>
4039
<Table columns={columns} rows={methods} getRowKey={getRowKey} />
4140
);
4241

43-
MethodsRenderer.propTypes = {
44-
methods: PropTypes.arrayOf(
45-
PropTypes.shape({
46-
name: PropTypes.string.isRequired,
47-
description: PropTypes.string,
48-
returns: PropTypes.object,
49-
params: PropTypes.array,
50-
tags: PropTypes.object,
51-
}).isRequired
52-
).isRequired,
53-
};
54-
5542
export default MethodsRenderer;

src/client/rsg-components/Preview/Preview.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ export default class Preview extends Component<PreviewProps, PreviewState> {
8888
try {
8989
ReactDOM.render(wrappedComponent, this.mountNode);
9090
} catch (err) {
91-
this.handleError(err);
91+
/* istanbul ignore next: it is near-impossible to trigger a sync error from ReactDOM.render */
92+
if (err instanceof Error) {
93+
/* istanbul ignore next */
94+
this.handleError(err);
95+
}
9296
}
9397
});
9498
}
@@ -107,7 +111,7 @@ export default class Preview extends Component<PreviewProps, PreviewState> {
107111
const { error } = this.state;
108112
return (
109113
<>
110-
<div data-testid="mountNode" ref={ref => (this.mountNode = ref)} />
114+
<div data-testid="mountNode" ref={(ref) => (this.mountNode = ref)} />
111115
{error && <PlaygroundError message={error} />}
112116
</>
113117
);

src/client/rsg-components/TabButton/TabButtonRenderer.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import Styled, { JssInjectedProps } from 'rsg-components/Styled';
4+
import { Styles } from 'jss';
45
import cx from 'clsx';
56
import * as Rsg from '../../../typings';
67

7-
export const styles = ({ space, color, fontFamily, fontSize, buttonTextTransform }: Rsg.Theme) => ({
8+
export const styles = ({
9+
space,
10+
color,
11+
fontFamily,
12+
fontSize,
13+
buttonTextTransform,
14+
}: Rsg.Theme): Styles => ({
815
button: {
916
padding: [[space[1], 0]],
1017
fontFamily: fontFamily.base,

src/client/rsg-components/TableOfContents/TableOfContentsRenderer.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { Styles } from 'jss';
34
import Styled, { JssInjectedProps } from 'rsg-components/Styled';
45
import * as Rsg from '../../../typings';
56

6-
const styles = ({ space, color, fontFamily, fontSize, borderRadius }: Rsg.Theme) => ({
7+
const styles = ({ space, color, fontFamily, fontSize, borderRadius }: Rsg.Theme): Styles => ({
78
root: {
89
fontFamily: fontFamily.base,
910
},
@@ -58,7 +59,7 @@ export const TableOfContentsRenderer: React.FunctionComponent<TableOfContentsRen
5859
className={classes.input}
5960
placeholder="Filter by name"
6061
aria-label="Filter by name"
61-
onChange={event => onSearchTermChange(event.target.value)}
62+
onChange={(event) => onSearchTermChange(event.target.value)}
6263
/>
6364
</div>
6465
{children}

src/client/rsg-components/Usage/Usage.tsx

-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import { MethodDescriptor } from 'react-docgen';
43
import { PropDescriptor } from 'rsg-components/Props/util';
54
import Props from 'rsg-components/Props';
@@ -24,11 +23,4 @@ const Usage: React.FunctionComponent<{
2423
);
2524
};
2625

27-
Usage.propTypes = {
28-
props: PropTypes.shape({
29-
props: PropTypes.array,
30-
methods: PropTypes.array,
31-
}).isRequired,
32-
};
33-
3426
export default Usage;

src/client/utils/compileCode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function compileCode(
2222
const compiledCode = compile(wrappedCode, compilerConfig);
2323
return transpileImports(compiledCode);
2424
} catch (err) {
25-
if (onError) {
25+
if (onError && err instanceof Error) {
2626
onError(err);
2727
}
2828
}

0 commit comments

Comments
 (0)