From 0609ebc430fe9a5df5edffb4f545298aa0866947 Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Tue, 27 Jul 2021 14:45:51 +0530 Subject: [PATCH 1/3] Add raw-loader to moduleNameMapper --- package.json | 5 ++++- yarn.lock | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0043362eb8..d6c43f8888 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,7 @@ "html-webpack-plugin": "^4.5.2", "jest": "^26.6.3", "jest-environment-jsdom-sixteen": "^1.0.3", + "jest-raw-loader": "^1.0.1", "json-loader": "^0.5.7", "loader-utils": "^1.4.0", "matrix-mock-request": "^1.2.3", @@ -138,6 +139,7 @@ "postcss-scss": "^2.1.1", "postcss-simple-vars": "^5.0.2", "postcss-strip-inline-comments": "^0.1.5", + "raw-loader": "^4.0.2", "rimraf": "^3.0.2", "shell-escape": "^0.2.0", "simple-proxy-agent": "^1.1.0", @@ -173,7 +175,8 @@ "waveWorker\\.min\\.js": "/node_modules/matrix-react-sdk/__mocks__/empty.js", "context-filter-polyfill": "/node_modules/matrix-react-sdk/__mocks__/empty.js", "FontManager.ts": "/node_modules/matrix-react-sdk/__mocks__/FontManager.js", - "workers/(.+)\\.worker\\.ts": "/node_modules/matrix-react-sdk/__mocks__/workerMock.js" + "workers/(.+)\\.worker\\.ts": "/node_modules/matrix-react-sdk/__mocks__/workerMock.js", + "^!!raw-loader!.*": "jest-raw-loader" }, "transformIgnorePatterns": [ "/node_modules/(?!matrix-js-sdk).+$", diff --git a/yarn.lock b/yarn.lock index e85f75b40d..2b83ea0320 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1454,7 +1454,7 @@ dependencies: "@types/istanbul-lib-report" "*" -"@types/json-schema@^7.0.5", "@types/json-schema@^7.0.7": +"@types/json-schema@^7.0.5", "@types/json-schema@^7.0.7", "@types/json-schema@^7.0.8": version "7.0.8" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.8.tgz#edf1bf1dbf4e04413ca8e5b17b3b7d7d54b59818" integrity sha512-YSBPTLTVm2e2OoQIDYx8HaeWJ5tTToLH67kXR7zYNGupXMEHa2++G8k+DczX2cFVgalypqtyZIcU19AFcmOpmg== @@ -1919,7 +1919,7 @@ ajv-keywords@^3.1.0, ajv-keywords@^3.4.1, ajv-keywords@^3.5.2: resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d" integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ== -ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.3, ajv@^6.12.4: +ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.3, ajv@^6.12.4, ajv@^6.12.5: version "6.12.6" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== @@ -6666,6 +6666,11 @@ jest-pnp-resolver@^1.2.2: resolved "https://registry.yarnpkg.com/jest-pnp-resolver/-/jest-pnp-resolver-1.2.2.tgz#b704ac0ae028a89108a4d040b3f919dfddc8e33c" integrity sha512-olV41bKSMm8BdnuMsewT4jqlZ8+3TCARAXjZGT9jcoSnrfUnRCqnMoF9XEeoWjbzObpqF9dRhHQj0Xb9QdF6/w== +jest-raw-loader@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/jest-raw-loader/-/jest-raw-loader-1.0.1.tgz#ce9f56d54650f157c4a7d16d224ba5d613bcd626" + integrity sha1-zp9W1UZQ8VfEp9FtIkul1hO81iY= + jest-regex-util@^26.0.0: version "26.0.0" resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-26.0.0.tgz#d25e7184b36e39fd466c3bc41be0971e821fee28" @@ -7130,6 +7135,15 @@ loader-utils@^1.0.0, loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4 emojis-list "^3.0.0" json5 "^1.0.1" +loader-utils@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.0.tgz#e4cace5b816d425a166b5f097e10cd12b36064b0" + integrity sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ== + dependencies: + big.js "^5.2.2" + emojis-list "^3.0.0" + json5 "^2.1.2" + locate-path@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e" @@ -9566,6 +9580,14 @@ raw-body@2.4.0: iconv-lite "0.4.24" unpipe "1.0.0" +raw-loader@^4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/raw-loader/-/raw-loader-4.0.2.tgz#1aac6b7d1ad1501e66efdac1522c73e59a584eb6" + integrity sha512-ZnScIV3ag9A4wPX/ZayxL/jZH+euYb6FcUinPcgiQW0+UBtEv0O6Q3lGd3cqJ+GHH+rksEv3Pj99oxJ3u3VIKA== + dependencies: + loader-utils "^2.0.0" + schema-utils "^3.0.0" + re-resizable@^6.9.0: version "6.9.0" resolved "https://registry.yarnpkg.com/re-resizable/-/re-resizable-6.9.0.tgz#9c3059b389ced6ade602234cc5bb1e12d231cd47" @@ -10196,6 +10218,15 @@ schema-utils@^2.5.0, schema-utils@^2.6.5, schema-utils@^2.6.6, schema-utils@^2.7 ajv "^6.12.4" ajv-keywords "^3.5.2" +schema-utils@^3.0.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.1.1.tgz#bc74c4b6b6995c1d88f76a8b77bea7219e0c8281" + integrity sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw== + dependencies: + "@types/json-schema" "^7.0.8" + ajv "^6.12.5" + ajv-keywords "^3.5.2" + select-hose@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca" @@ -11692,8 +11723,10 @@ watchpack@^1.7.4: resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.7.5.tgz#1267e6c55e0b9b5be44c2023aed5437a2c26c453" integrity sha512-9P3MWk6SrKjHsGkLT2KHXdQ/9SNkyoJbabxnKOoJepsvJjJG8uYTR3yTPxPQvNDI3w4Nz1xnE0TLHK4RIVe/MQ== dependencies: + chokidar "^3.4.1" graceful-fs "^4.1.2" neo-async "^2.5.0" + watchpack-chokidar2 "^2.0.1" optionalDependencies: chokidar "^3.4.1" watchpack-chokidar2 "^2.0.1" From 714d03524c0a39dd17efed121c73614f60f40e5a Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Tue, 27 Jul 2021 17:18:17 +0530 Subject: [PATCH 2/3] Add declaration file --- src/@types/raw-loader.d.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/@types/raw-loader.d.ts diff --git a/src/@types/raw-loader.d.ts b/src/@types/raw-loader.d.ts new file mode 100644 index 0000000000..ea3df880f6 --- /dev/null +++ b/src/@types/raw-loader.d.ts @@ -0,0 +1,4 @@ +declare module '!!raw-loader!*' { + const contents: string; + export default contents; +} From 42e3fd02821fd0258c917472297b2cbe10b846c7 Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Wed, 4 Aug 2021 12:45:10 +0530 Subject: [PATCH 3/3] Add extendedAPI plugin to access globals --- webpack.config.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index bb1d5d9ff5..e6fa9bb0ea 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,6 +6,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const TerserPlugin = require('terser-webpack-plugin'); const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); const HtmlWebpackInjectPreload = require('@principalstudio/html-webpack-inject-preload'); +const { ExtendedAPIPlugin } = require('webpack'); let ogImageUrl = process.env.RIOT_OG_IMAGE_URL; if (!ogImageUrl) ogImageUrl = 'https://app.element.io/themes/element/img/logos/opengraph.png'; @@ -219,7 +220,7 @@ module.exports = (env, argv) => { // It's important that this plugin is last otherwise we end // up with broken CSS. - require('postcss-preset-env')({stage: 3, browsers: 'last 2 versions'}), + require('postcss-preset-env')({ stage: 3, browsers: 'last 2 versions' }), ], parser: "postcss-scss", "local-plugins": true, @@ -257,7 +258,7 @@ module.exports = (env, argv) => { // It's important that this plugin is last otherwise we end // up with broken CSS. - require('postcss-preset-env')({stage: 3, browsers: 'last 2 versions'}), + require('postcss-preset-env')({ stage: 3, browsers: 'last 2 versions' }), ], parser: "postcss-scss", "local-plugins": true, @@ -437,6 +438,8 @@ module.exports = (env, argv) => { files: [{ match: /.*Inter.*\.woff2$/ }], }), + new ExtendedAPIPlugin(), + ...additionalPlugins, ],