Skip to content

Commit 7a92a4c

Browse files
authoredJan 19, 2024
Update yarn from version 1.22.21 to 3.4.1 and webpack-dev-server from 3.11.1 to 4.0.0 (#895)
We need to be able to conditionally set headers for pyodideWorker.js in pull request #893 but this feature isn’t supported in webpack-dev-server 3.x.x. We therefore need to upgrade to version 4.0.0 which allows a function to be provided in the headers option. When attempting this upgrade, I ran into [this issue](storybookjs/storybook#22431) and only managed to resolve it by also updating yarn to version 3. I’ve tried to follow the migration guide here: https://github.com/webpack/webpack-dev-server/blob/master/migration-v4.md
1 parent 6f20db3 commit 7a92a4c

12 files changed

+37484
-26739
lines changed
 

‎.github/workflows/ci-cd.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
scope: '@RaspberryPiFoundation'
2525

2626
- name: Install code
27-
run: yarn install --frozen-lock-file
27+
run: yarn install --immutable
2828
env:
2929
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3030

@@ -50,7 +50,7 @@ jobs:
5050
scope: '@RaspberryPiFoundation'
5151

5252
- name: Install code
53-
run: yarn install --frozen-lock-file
53+
run: yarn install --immutable
5454
env:
5555
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5656

@@ -80,7 +80,7 @@ jobs:
8080
scope: '@RaspberryPiFoundation'
8181

8282
- name: Install code
83-
run: yarn install --frozen-lock-file
83+
run: yarn install --immutable
8484
env:
8585
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8686

‎.github/workflows/deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
scope: '@RaspberryPiFoundation'
118118

119119
- name: Install code
120-
run: yarn install --frozen-lock-file
120+
run: yarn install --immutable
121121
env:
122122
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123123

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ node_modules
2727
npm-debug.log*
2828
yarn-debug.log*
2929
yarn-error.log*
30+
.yarn/cache
31+
.yarn/install-state.gz
3032

3133
.vscode/settings.json

‎.yarn/releases/yarn-3.4.1.cjs

+873
Large diffs are not rendered by default.

‎.yarnrc.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
nodeLinker: node-modules
2+
3+
yarnPath: .yarn/releases/yarn-3.4.1.cjs
4+
5+
checksumBehavior: "update"

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1010

1111
- Minor copy changes to HTML add file modal
1212
- Toggle errors sent via apiCallHandler off (#890)
13+
- Upgrade webpack-dev-server to 4.0.0 to support conditional headers
14+
- Upgrade yarn to 3.4.1 to workaround a string-width issue
1315

1416
## [0.21.1] - 2024-01-11
1517

‎config/webpackDevServer.config.js

+53-70
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,11 @@ const sockHost = process.env.WDS_SOCKET_HOST;
1414
const sockPath = process.env.WDS_SOCKET_PATH; // default: '/sockjs-node'
1515
const sockPort = process.env.WDS_SOCKET_PORT;
1616

17-
module.exports = function (proxy, allowedHost) {
17+
module.exports = function (proxy, _allowedHost) {
1818
return {
19-
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
20-
// websites from potentially accessing local content through DNS rebinding:
21-
// https://github.com/webpack/webpack-dev-server/issues/887
22-
// https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
23-
// However, it made several existing use cases such as development in cloud
24-
// environment or subdomains in development significantly more complicated:
25-
// https://github.com/facebook/create-react-app/issues/2271
26-
// https://github.com/facebook/create-react-app/issues/2233
27-
// While we're investigating better solutions, for now we will take a
28-
// compromise. Since our WDS configuration only serves files in the `public`
29-
// folder we won't consider accessing them a vulnerability. However, if you
30-
// use the `proxy` feature, it gets more dangerous because it can expose
31-
// remote code execution vulnerabilities in backends like Django and Rails.
32-
// So we will disable the host check normally, but enable it if you have
33-
// specified the `proxy` setting. Finally, we let you override it if you
34-
// really know what you're doing with a special environment variable.
35-
disableHostCheck:
36-
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
19+
allowedHosts: "all",
3720
// Enable gzip compression of generated files.
3821
compress: true,
39-
// Silence WebpackDevServer's own logs since they're generally not useful.
40-
// It will still show compile warnings and errors with this setting.
41-
clientLogLevel: 'none',
42-
// By default WebpackDevServer serves physical files from current directory
43-
// in addition to all the virtual build products that it serves from memory.
44-
// This is confusing because those files won’t automatically be available in
45-
// production build folder unless we copy them. However, copying the whole
46-
// project directory is dangerous because we may expose sensitive files.
47-
// Instead, we establish a convention that only files in `public` directory
48-
// get served. Our build script will copy `public` into the `build` folder.
49-
// In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
50-
// <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
51-
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
52-
// Note that we only recommend to use `public` folder as an escape hatch
53-
// for files like `favicon.ico`, `manifest.json`, and libraries that are
54-
// for some reason broken when imported through webpack. If you just want to
55-
// use an image, put it in `src` and `import` it from JavaScript instead.
56-
contentBase: paths.appPublic,
57-
contentBasePublicPath: paths.publicUrlOrPath,
58-
// By default files from `contentBase` will not trigger a page reload.
59-
watchContentBase: true,
6022
// Enable hot reloading server. It will provide WDS_SOCKET_PATH endpoint
6123
// for the WebpackDevServer client so it can learn when the files were
6224
// updated. The WebpackDevServer client is included as an entry point
@@ -65,71 +27,92 @@ module.exports = function (proxy, allowedHost) {
6527
hot: true,
6628
// Use 'ws' instead of 'sockjs-node' on server since we're using native
6729
// websockets in `webpackHotDevClient`.
68-
transportMode: 'ws',
69-
// Prevent a WS client from getting injected as we're already including
70-
// `webpackHotDevClient`.
71-
injectClient: false,
72-
// Enable custom sockjs pathname for websocket connection to hot reloading server.
73-
// Enable custom sockjs hostname, pathname and port for websocket connection
74-
// to hot reloading server.
75-
sockHost,
76-
sockPath,
77-
sockPort,
30+
webSocketServer: 'ws',
7831
// It is important to tell WebpackDevServer to use the same "publicPath" path as
7932
// we specified in the webpack config. When homepage is '.', default to serving
8033
// from the root.
8134
// remove last slash so user can land on `/test` instead of `/test/`
82-
publicPath: paths.publicUrlOrPath.slice(0, -1),
83-
// WebpackDevServer is noisy by default so we emit custom message instead
84-
// by listening to the compiler events with `compiler.hooks[...].tap` calls above.
85-
quiet: true,
86-
// Reportedly, this avoids CPU overload on some systems.
87-
// https://github.com/facebook/create-react-app/issues/293
88-
// src/node_modules is not ignored to support absolute imports
89-
// https://github.com/facebook/create-react-app/issues/1065
90-
watchOptions: {
91-
ignored: ignoredFiles(paths.appSrc),
35+
devMiddleware: {
36+
publicPath: paths.publicUrlOrPath.slice(0, -1),
37+
},
38+
static: {
39+
// By default WebpackDevServer serves physical files from current directory
40+
// in addition to all the virtual build products that it serves from memory.
41+
// This is confusing because those files won’t automatically be available in
42+
// production build folder unless we copy them. However, copying the whole
43+
// project directory is dangerous because we may expose sensitive files.
44+
// Instead, we establish a convention that only files in `public` directory
45+
// get served. Our build script will copy `public` into the `build` folder.
46+
// In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
47+
// <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
48+
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
49+
// Note that we only recommend to use `public` folder as an escape hatch
50+
// for files like `favicon.ico`, `manifest.json`, and libraries that are
51+
// for some reason broken when imported through webpack. If you just want to
52+
// use an image, put it in `src` and `import` it from JavaScript instead.
53+
directory: paths.appPublic,
54+
publicPath: paths.publicUrlOrPath,
55+
// By default files from `directory` will not trigger a page reload.
56+
// Reportedly, this avoids CPU overload on some systems.
57+
// https://github.com/facebook/create-react-app/issues/293
58+
// src/node_modules is not ignored to support absolute imports
59+
// https://github.com/facebook/create-react-app/issues/1065
60+
watch: {
61+
ignored: ignoredFiles(paths.appSrc),
62+
},
9263
},
9364
https: getHttpsConfig(),
9465
host,
95-
overlay: false,
9666
historyApiFallback: {
9767
// Paths with dots should still use the history fallback.
9868
// See https://github.com/facebook/create-react-app/issues/387.
9969
disableDotRule: true,
10070
index: paths.publicUrlOrPath,
10171
},
102-
headers: {
72+
headers: {
10373
"Access-Control-Allow-Origin": "*",
10474
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
10575
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
10676
},
107-
public: allowedHost,
77+
client: {
78+
// Silence WebpackDevServer's own logs since they're generally not useful.
79+
// It will still show compile warnings and errors with this setting.
80+
logging: 'none',
81+
overlay: false,
82+
webSocketURL: {
83+
// Enable custom sockjs pathname for websocket connection to hot reloading server.
84+
// Enable custom sockjs hostname, pathname and port for websocket connection
85+
// to hot reloading server.
86+
hostname: sockHost,
87+
pathname: sockPath,
88+
port: sockPort,
89+
},
90+
},
10891
// `proxy` is run between `before` and `after` `webpack-dev-server` hooks
10992
proxy,
110-
before(app, server) {
93+
onBeforeSetupMiddleware(devServer) {
11194
// Keep `evalSourceMapMiddleware` and `errorOverlayMiddleware`
11295
// middlewares before `redirectServedPath` otherwise will not have any effect
11396
// This lets us fetch source contents from webpack for the error overlay
114-
app.use(evalSourceMapMiddleware(server));
97+
devServer.app.use(evalSourceMapMiddleware(devServer));
11598
// This lets us open files from the runtime error overlay.
116-
app.use(errorOverlayMiddleware());
99+
devServer.app.use(errorOverlayMiddleware());
117100

118101
if (fs.existsSync(paths.proxySetup)) {
119102
// This registers user provided middleware for proxy reasons
120-
require(paths.proxySetup)(app);
103+
require(paths.proxySetup)(devServer.app);
121104
}
122105
},
123-
after(app) {
106+
onAfterSetupMiddleware(devServer) {
124107
// Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
125-
app.use(redirectServedPath(paths.publicUrlOrPath));
108+
devServer.app.use(redirectServedPath(paths.publicUrlOrPath));
126109

127110
// This service worker file is effectively a 'no-op' that will reset any
128111
// previous service worker registered for the same host:port combination.
129112
// We do this in development to avoid hitting the production cache if
130113
// it used the same host and port.
131114
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
132-
app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
115+
devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
133116
},
134117
};
135118
};

‎package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"scripts": {
8181
"start": "node scripts/start.js",
8282
"build": "node scripts/build.js",
83-
"build:dev": "yarn install --force && yarn run build-storybook && node scripts/build.js",
83+
"build:dev": "yarn install --check-cache && yarn run build-storybook && node scripts/build.js",
8484
"build-storybook": "cd ./storybook && yarn install && yarn run build-storybook -- -o ../public/storybook --loglevel warn",
8585
"lint": "eslint \"src/**/*.{js,jsx,json}\"",
8686
"lint:fix": "eslint --fix \"src/**/*.{js,jsx,json}\"",
@@ -186,7 +186,7 @@
186186
"webgl-mock-threejs": "^0.0.1",
187187
"webpack": "4.44.2",
188188
"webpack-cli": "^4.9.2",
189-
"webpack-dev-server": "3.11.1",
189+
"webpack-dev-server": "4.0.0",
190190
"webpack-manifest-plugin": "2.2.0",
191191
"workbox-webpack-plugin": "5.1.4"
192192
},
@@ -246,5 +246,6 @@
246246
"jest-watch-typeahead/testname"
247247
],
248248
"resetMocks": true
249-
}
249+
},
250+
"packageManager": "yarn@3.4.1"
250251
}

‎storybook/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
"@storybook/addon-actions": "6.5.10",
1212
"@storybook/addon-essentials": "6.5.10",
1313
"@storybook/addon-interactions": "6.5.10",
14-
"@storybook/builder-webpack4": "6.5.10",
15-
"@storybook/manager-webpack4": "6.5.10",
16-
"@storybook/mdx2-csf": "0.0.3",
17-
"@storybook/preset-scss": "^1.0.3",
18-
"@storybook/react": "6.5.10",
1914
"@storybook/blocks": "^7.5.3",
15+
"@storybook/builder-webpack4": "6.5.10",
2016
"@storybook/channels": "^7.5.3",
2117
"@storybook/components": "^7.5.3",
2218
"@storybook/core-events": "^7.5.3",
19+
"@storybook/manager-webpack4": "6.5.10",
20+
"@storybook/mdx2-csf": "0.0.3",
21+
"@storybook/preset-scss": "^1.0.3",
2322
"@storybook/preview-api": "^7.5.3",
23+
"@storybook/react": "6.5.10",
2424
"@storybook/theming": "^7.5.3",
2525
"css-loader": "^5.2.6",
2626
"i18next": "^23.7.6",

‎storybook/yarn.lock

+16,774-12,148
Large diffs are not rendered by default.

‎webpack.component.config.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,16 @@ module.exports = {
7070
},
7171
devServer: {
7272
allowedHosts: ["react-ui-test-wc"],
73-
contentBase: path.join(__dirname, "public"),
74-
index: "web-component.html",
7573
host: "0.0.0.0",
76-
disableHostCheck: true,
74+
allowedHosts: "all",
7775
port: 3001,
78-
writeToDisk: true,
76+
devMiddleware: {
77+
index: "web-component.html",
78+
writeToDisk: true,
79+
},
80+
static: {
81+
directory: path.join(__dirname, "public"),
82+
},
7983
},
8084
plugins: [
8185
new Dotenv({

‎yarn.lock

+19,754-14,505
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.