diff --git a/assets/config/webpack-plugins/fix-webpack-stats-format-plugin.js b/assets/config/webpack-plugins/fix-webpack-stats-format-plugin.js deleted file mode 100644 --- a/assets/config/webpack-plugins/fix-webpack-stats-format-plugin.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (C) 2020 The Software Heritage developers - * See the AUTHORS file at the top-level directory of this distribution - * License: GNU Affero General Public License version 3, or any later version - * See top-level LICENSE file for more information - */ - -'use strict'; - -// Simple webpack plugin that processes the webpack-stats.json file produced by -// the latest version of webpack-bundle-tracker [1] in order to modify the JSON -// schema to the one expected by django-webpack-loader [2]. -// TODO: Remove that plugin once a new version of django-webpack-loader -// is released. -// [1] https://github.com/owais/webpack-bundle-tracker -// [2] https://github.com/owais/django-webpack-loader - -const fs = require('fs'); -const path = require('path'); - -class FixWebpackStatsFormatPlugin { - - apply(compiler) { - compiler.hooks.done.tap('FixWebpackStatsFormatPlugin', statsObj => { - const outputPath = statsObj.compilation.compiler.outputPath; - const statsFile = path.join(outputPath, 'webpack-stats.json'); - const statsJson = fs.readFileSync(statsFile).toString('utf8'); - const stats = JSON.parse(statsJson); - const statsFixed = { - status: stats.status, - publicPath: stats.publicPath, - chunks: {} - }; - Object.keys(stats.chunks).forEach((chunkName) => { - const chunkAssets = []; - for (let asset of stats.chunks[chunkName]) { - const publicPath = stats.assets[asset].publicPath; - chunkAssets.push({ - name: asset, - publicPath: publicPath, - path: path.join(outputPath, asset) - }); - } - statsFixed.chunks[chunkName] = chunkAssets; - }); - fs.writeFileSync(statsFile, JSON.stringify(statsFixed)); - }); - } - -}; - -module.exports = FixWebpackStatsFormatPlugin; diff --git a/assets/config/webpack.config.development.js b/assets/config/webpack.config.development.js --- a/assets/config/webpack.config.development.js +++ b/assets/config/webpack.config.development.js @@ -20,7 +20,6 @@ const CopyWebpackPlugin = require('copy-webpack-plugin'); const GenerateWebLabelsPlugin = require('./webpack-plugins/generate-weblabels-webpack-plugin'); const ProgressBarPlugin = require('progress-bar-webpack-plugin'); -const FixWebpackStatsFormatPlugin = require('./webpack-plugins/fix-webpack-stats-format-plugin'); const DumpHighlightjsLanguagesDataPlugin = require('./webpack-plugins/dump-highlightjs-languages-data-plugin'); // are we running webpack-dev-server ? @@ -359,8 +358,7 @@ }), // needed in order to use django_webpack_loader new BundleTracker({ - path: path.resolve('./static/'), - filename: 'webpack-stats.json' + filename: './static/webpack-stats.json' }), // for generating the robots.txt file new RobotstxtPlugin({ @@ -459,7 +457,6 @@ format: chalk.cyan.bold('webpack build of swh-web assets') + ' [:bar] ' + chalk.green.bold(':percent') + ' (:elapsed seconds)', width: 50 }), - new FixWebpackStatsFormatPlugin(), new DumpHighlightjsLanguagesDataPlugin() ], // webpack optimizations diff --git a/package.json b/package.json --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "terser-webpack-plugin": "^5.1.1", "url-loader": "^4.1.1", "webpack": "^5.36.2", - "webpack-bundle-tracker": "^1.0.0-alpha.1", + "webpack-bundle-tracker": "^1.0.0", "webpack-cli": "^4.7.0", "webpack-dev-server": "^3.11.2" }, @@ -132,4 +132,4 @@ "engines": { "node": ">=12.0.0" } -} \ No newline at end of file +} diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ iso8601 lxml prometheus-client -pybadges +pybadges >= 2.2.1 pygments python-magic >= 0.4.0 python-memcached diff --git a/swh/web/tests/conftest.py b/swh/web/tests/conftest.py --- a/swh/web/tests/conftest.py +++ b/swh/web/tests/conftest.py @@ -95,16 +95,19 @@ _, bundles, _ = next(os.walk(bundles_dir)) - mock_webpack_stats = {"status": "done", "publicPath": "/static", "chunks": {}} + mock_webpack_stats = { + "status": "done", + "publicPath": "/static", + "chunks": {}, + "assets": {}, + } for bundle in bundles: - asset = "js/%s.js" % bundle - mock_webpack_stats["chunks"][bundle] = [ - { - "name": asset, - "publicPath": "/static/%s" % asset, - "path": os.path.join(static_dir, asset), - } - ] + asset = f"js/{bundle}.js" + mock_webpack_stats["chunks"][bundle] = [asset] + mock_webpack_stats["assets"][asset] = { + "name": asset, + "publicPath": f"/static/{asset}", + } with open(webpack_stats, "w") as outfile: json.dump(mock_webpack_stats, outfile) diff --git a/yarn.lock b/yarn.lock --- a/yarn.lock +++ b/yarn.lock @@ -2142,7 +2142,7 @@ resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4= -"@types/lodash.foreach@^4.4.6": +"@types/lodash.foreach@^4.5.6": version "4.5.6" resolved "https://registry.yarnpkg.com/@types/lodash.foreach/-/lodash.foreach-4.5.6.tgz#24735299139a739e436ab4fb8a6a31ca3d54bbb3" integrity sha512-A8+157A+27zwJSstmW/eWPc9lHLJNEer4jiMlsyxWieBxEx0arwB9vgQm+iai6DEDYYQuufHrzVhQOiapCalQQ== @@ -8774,7 +8774,7 @@ resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2" integrity sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI= -lodash.foreach@^4.2.0: +lodash.foreach@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.foreach/-/lodash.foreach-4.5.0.tgz#1a6a35eace401280c7f06dddec35165ab27e3e53" integrity sha1-Gmo16s5AEoDH8G3d7DUWWrJ+PlM= @@ -13512,16 +13512,16 @@ resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-6.1.0.tgz#9111b4d7ea80acd40f5270d666621afa78b69514" integrity sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w== -webpack-bundle-tracker@^1.0.0-alpha.1: - version "1.0.0-alpha.1" - resolved "https://registry.yarnpkg.com/webpack-bundle-tracker/-/webpack-bundle-tracker-1.0.0-alpha.1.tgz#17b4f41df147d53989f3542b035bcde8c7c2dc00" - integrity sha512-kyLrwD0ZeINe76pevIsAQY49lRrSfw01iCM6kbMi/Fb9m2LYJBv3up3ALcqf3ugiydy4vbaZ8NYTi4F2MxojVw== +webpack-bundle-tracker@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/webpack-bundle-tracker/-/webpack-bundle-tracker-1.0.0.tgz#46428b91d106c3729b7211474cd888b62c8ca4ba" + integrity sha512-uO787xNxxq2+D+P4FPsnX7D+yDY4qmjopenkxxq2kT6e4QjMe2uPJ6R03mv9KT74YkWKKt/gBC+x+ZFGjb2URQ== dependencies: - "@types/lodash.foreach" "^4.4.6" + "@types/lodash.foreach" "^4.5.6" "@types/lodash.get" "^4.4.6" lodash.assign "^4.2.0" lodash.defaults "^4.2.0" - lodash.foreach "^4.2.0" + lodash.foreach "^4.5.0" lodash.get "^4.4.2" strip-ansi "^6.0.0"