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

Update to webpack 5 #26229

Merged
merged 33 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
af3659a
Update to webpack 5
Johennes Sep 23, 2023
c844d80
Merge branch 'johannes/webpack-cli-4.10.0' into johannes/webpack-5
Johennes Sep 29, 2023
9b8d6e7
Set context manually in NormalModuleReplacementPlugin to fix relative…
Johennes Sep 29, 2023
2984c3b
Remove . since path is already relative
Johennes Sep 30, 2023
0b706bb
Merge branch 'johannes/webpack-cli-4.10.0' into johannes/webpack-5
Johennes Oct 16, 2023
88666ee
Also polyfill buffer and process/browser
Johennes Oct 16, 2023
98c27c8
Merge branch 'johannes/webpack-cli-4.10.0' into johannes/webpack-5
Johennes Oct 24, 2023
3a73f6b
Merge branch 'develop' into johannes/webpack-5
Johennes Oct 25, 2023
d8f46ab
Appease the linter
Johennes Oct 25, 2023
17147ad
Merge branch 'develop' into johannes/webpack-5
Johennes Nov 6, 2023
4ffac57
Merge branch 'develop' into johannes/webpack-5
Johennes Nov 8, 2023
e271f2c
Upgrade webpack to 5.89.0
Johennes Nov 8, 2023
fe46b05
Remove unused extract-text-webpack-plugin
Johennes Nov 8, 2023
25bb2ae
Replace optimize-css-assets-webpack-plugin with css-minimizer-webpack…
Johennes Nov 8, 2023
0a36934
Eliminate use of loader-utils
Johennes Nov 8, 2023
f0c5ed8
Appease the linter
Johennes Nov 8, 2023
e6ba36d
Merge branch 'develop' into johannes/webpack-5
Johennes Nov 9, 2023
ae1d21f
Remove obsolete comment
Johennes Nov 9, 2023
42da986
Only show overlay on build errors
Johennes Nov 9, 2023
37632d8
Eliminate worklet-loader
Johennes Nov 9, 2023
3e03b2e
Appease the linter
Johennes Nov 9, 2023
0584c39
Add defaults and fix comment
Johennes Nov 11, 2023
91f46cc
Disable automatic publicPath to unbreak worklets
Johennes Nov 12, 2023
bbd449f
Merge branch 'develop' into johannes/webpack-5
Johennes Nov 13, 2023
432c1d6
Squashed commit of the following:
Johennes Nov 13, 2023
5e9763e
Update mocks for workers / worklets
Johennes Nov 14, 2023
a56a226
Merge branch 'develop' into johannes/webpack-5
Johennes Nov 16, 2023
4e32b6f
Update copy-webpack-plugin to latest
Johennes Nov 16, 2023
8dbefcc
Undo auto public path disablement as it doesn't work with workers
Johennes Nov 16, 2023
e2fddda
Add custom loader for recorder worklet
Johennes Nov 18, 2023
6093cd8
Move worklet rule up to where it used to be
Johennes Nov 18, 2023
f46cdd0
Merge branch 'develop' into johannes/webpack-5
Johennes Nov 18, 2023
37c1c4e
Set es2022 globally but force CommonJS when using ts-node for scripts
Johennes Nov 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const config: Config = {
"waveWorker\\.min\\.js": "<rootDir>/node_modules/matrix-react-sdk/__mocks__/empty.js",
"context-filter-polyfill": "<rootDir>/node_modules/matrix-react-sdk/__mocks__/empty.js",
"FontManager.ts": "<rootDir>/node_modules/matrix-react-sdk/__mocks__/FontManager.js",
"workers/(.+)\\.worker\\.ts": "<rootDir>/node_modules/matrix-react-sdk/__mocks__/workerMock.js",
"workers/(.+)Factory": "<rootDir>/node_modules/matrix-react-sdk/__mocks__/workerFactoryMock.js",
"^!!raw-loader!.*": "jest-raw-loader",
"RecorderWorklet": "<rootDir>/node_modules/matrix-react-sdk/__mocks__/empty.js",
"recorderWorkletFactory": "<rootDir>/node_modules/matrix-react-sdk/__mocks__/empty.js",
"^fetch-mock$": "<rootDir>/node_modules/fetch-mock",
},
transformIgnorePatterns: ["/node_modules/(?!matrix-js-sdk).+$", "/node_modules/(?!matrix-react-sdk).+$"],
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
"build:modernizr": "modernizr -c .modernizr.json -d src/vector/modernizr.js",
"build:bundle": "webpack --progress --mode production",
"build:bundle-stats": "webpack --progress --mode production --json > webpack-stats.json",
"build:module_system": "tsc --project ./tsconfig.module_system.json && node ./lib/module_system/scripts/install.js",
"build:module_system": "ts-node --project ./tsconfig.module_system.json module_system/scripts/install.ts",
"dist": "scripts/package.sh",
"start": "concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n modules,res,jitsi \"yarn build:module_system\" \"yarn build:res\" \"yarn build:jitsi\" && concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n res,element-js \"yarn start:res\" \"yarn start:js\"",
"start:https": "concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n res,element-js \"yarn start:res\" \"yarn start:js --https\"",
"start:res": "ts-node scripts/copy-res.ts -w",
"start:js": "webpack serve --output-path webapp --mode development",
"start:js": "webpack serve --output-path webapp --output-filename=bundles/_dev_/[name].js --output-chunk-filename=bundles/_dev_/[name].js --mode development",
"lint": "yarn lint:types && yarn lint:js && yarn lint:style",
"lint:js": "yarn lint:js:src && yarn lint:js:module_system",
"lint:js:src": "eslint --max-warnings 0 src test && prettier --check .",
Expand Down Expand Up @@ -103,13 +103,12 @@
"@babel/runtime": "^7.12.5",
"@casualbot/jest-sonar-reporter": "2.2.7",
"@principalstudio/html-webpack-inject-preload": "^1.2.7",
"@sentry/webpack-plugin": "^2.0.0",
"@sentry/webpack-plugin": "^2.7.1",
"@svgr/webpack": "^5.5.0",
"@testing-library/react": "^12.1.5",
"@types/jest": "^29.0.0",
"@types/jitsi-meet": "^2.0.2",
"@types/jsrsasign": "^10.5.4",
"@types/loader-utils": "^2.0.4",
"@types/lodash": "^4.14.197",
"@types/node": "^16",
"@types/node-fetch": "^2.6.4",
Expand All @@ -121,11 +120,13 @@
"allchange": "^1.0.6",
"babel-jest": "^29.0.0",
"babel-loader": "^8.2.2",
"buffer": "^6.0.3",
"chokidar": "^3.5.1",
"concurrently": "^8.0.0",
"copy-webpack-plugin": "^6.0.0",
"copy-webpack-plugin": "^11.0.0",
"cronstrue": "^2.41.0",
"css-loader": "^4",
"css-minimizer-webpack-plugin": "^5.0.1",
"dotenv": "^16.0.2",
"eslint": "8.53.0",
"eslint-config-google": "^0.14.0",
Expand All @@ -140,21 +141,19 @@
"fetch-mock": "9.11.0",
"fetch-mock-jest": "^1.5.1",
"file-loader": "^6.0.0",
"html-webpack-plugin": "^4.5.2",
"html-webpack-plugin": "^5.5.3",
"jest": "^29.0.0",
"jest-canvas-mock": "2.5.2",
"jest-environment-jsdom": "^29.0.0",
"jest-mock": "^29.0.0",
"jest-raw-loader": "^1.0.1",
"loader-utils": "^3.0.0",
"matrix-mock-request": "^2.5.0",
"matrix-web-i18n": "^3.1.3",
"mini-css-extract-plugin": "^1",
"mini-css-extract-plugin": "^2.7.6",
"minimist": "^1.2.6",
"mkdirp": "^3.0.0",
"modernizr": "^3.12.0",
"node-fetch": "^2.6.7",
"optimize-css-assets-webpack-plugin": "^6.0.0",
"postcss": "^8.4.31",
"postcss-easings": "^2.0.0",
"postcss-hexrgba": "2.0.1",
Expand All @@ -166,25 +165,26 @@
"postcss-scss": "^4.0.4",
"postcss-simple-vars": "^5.0.2",
"prettier": "2.8.8",
"process": "^0.11.10",
"proxy-agent": "^6.3.0",
"raw-loader": "^4.0.2",
"rimraf": "^5.0.0",
"semver": "^7.5.2",
"setimmediate": "^1.0.5",
"string-replace-loader": "3",
"style-loader": "2",
"stylelint": "^15.10.1",
"stylelint-config-standard": "^34.0.0",
"stylelint-scss": "^5.0.0",
"terser-webpack-plugin": "^4.0.0",
"terser-webpack-plugin": "^5.3.9",
"ts-node": "^10.9.1",
"ts-prune": "^0.10.3",
"typescript": "5.2.2",
"webpack": "^4.47.0",
"util": "^0.12.5",
"webpack": "^5.89.0",
"webpack-bundle-analyzer": "^4.8.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.15.1",
"worker-loader": "^3.0.0",
"worklet-loader": "^2.0.0",
"yaml": "^2.3.3"
},
"@casualbot/jest-sonar-reporter": {
Expand Down
45 changes: 45 additions & 0 deletions recorder-worklet-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2023 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Inspired by https://github.com/reklawnos/worklet-loader which doesn't
// formally support Webpack 5

const SingleEntryPlugin = require("webpack/lib/SingleEntryPlugin");

module.exports = function () {};

module.exports.pitch = function pitch(request) {
const cb = this.async();
const filename = "recorder.worklet.js";

const compiler = this._compilation.createChildCompiler("worker", {
filename,
chunkFilename: `[id].${filename}`,
namedChunkFilename: null,
});

new SingleEntryPlugin(this.context, `!!${request}`, "main").apply(compiler);

compiler.runAsChild((err, entries, compilation) => {
if (err) {
return cb(err);
}
if (entries[0]) {
return cb(null, `module.exports = __webpack_public_path__ + ${JSON.stringify(entries[0].files[0])};`);
}
return cb(null, null);
});
};
4 changes: 2 additions & 2 deletions scripts/copy-res.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import parseArgs from "minimist";
import * as chokidar from "chokidar";
import * as fs from "node:fs";
import _ from "lodash";
import * as loaderUtils from "loader-utils";
import { util } from "webpack";
import { Translations } from "matrix-web-i18n";

const REACT_I18N_BASE_PATH = "node_modules/matrix-react-sdk/src/i18n/strings/";
Expand Down Expand Up @@ -60,7 +60,7 @@ function prepareLangFile(lang: string, dest: string): [filename: string, json: s

const json = JSON.stringify(translations, null, 4);
const jsonBuffer = Buffer.from(json);
const digest = loaderUtils.getHashDigest(jsonBuffer, null, "hex", 7);
const digest = util.createHash("xxhash64").update(jsonBuffer).digest("hex").slice(0, 7);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

const filename = `${lang}.${digest}.json`;

return [filename, json];
Expand Down
26 changes: 0 additions & 26 deletions src/@types/loader-utils.d.ts

This file was deleted.

9 changes: 4 additions & 5 deletions src/vector/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@
<% }
} %>

<% for (var i=0; i < htmlWebpackPlugin.tags.headTags.length; i++) {
var tag = htmlWebpackPlugin.tags.headTags[i];
var path = tag.attributes && tag.attributes.href;
if (path.includes("/Inter/")) { %>
<link rel="preload" as="font" href=".<%= path %>" crossorigin="anonymous"/>
<% for (const tag of htmlWebpackPlugin.tags.headTags) {
let path = tag.attributes && tag.attributes.href;
if (path && path.includes("/Inter/")) { %>
<link rel="preload" as="font" href="<%= path %>" crossorigin="anonymous"/>
<% }
} %>

Expand Down
3 changes: 3 additions & 0 deletions src/vector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import { extractErrorMessageFromError } from "matrix-react-sdk/src/components/vi
import { parseQsFromFragment } from "./url_utils";
import "./modernizr";

// Make setImmediate available in bundle
import "setimmediate";

// Require common CSS here; this will make webpack process it into bundle.css.
// Our own CSS (which is themed) is imported via separate webpack entry points
// in webpack.config.js
Expand Down
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"emitDecoratorMetadata": false,
"resolveJsonModule": true,
"esModuleInterop": true,
"module": "commonjs",
"module": "es2022",
"moduleResolution": "node",
"target": "es2016",
"noUnusedLocals": true,
Expand All @@ -28,6 +28,9 @@
"./scripts/*.ts"
],
"ts-node": {
"files": true
"files": true,
"moduleTypes": {
"*": "cjs"
}
}
}
Loading
Loading