From 4c1710551e6f4fa2326fb1aa7341dc1437bf8577 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Wed, 28 Feb 2024 17:02:14 -0500 Subject: [PATCH] Opt-in config to Prettier --- .prettierignore | 1 + config/formatjs-formatter.js | 4 +++- config/webpack/configuration.js | 4 +++- config/webpack/development.js | 2 +- config/webpack/production.js | 34 +++++++++++++++++++++------------ config/webpack/rules/babel.js | 11 ++++------- config/webpack/shared.js | 28 ++++++++++++--------------- 7 files changed, 46 insertions(+), 38 deletions(-) diff --git a/.prettierignore b/.prettierignore index 6b2f0c18894..631b3a02296 100644 --- a/.prettierignore +++ b/.prettierignore @@ -83,3 +83,4 @@ AUTHORS.md # Process a few selected JS files !lint-staged.config.js +!/config/**/*.js diff --git a/config/formatjs-formatter.js b/config/formatjs-formatter.js index adb5e82ef73..bf8342d3e35 100644 --- a/config/formatjs-formatter.js +++ b/config/formatjs-formatter.js @@ -1,6 +1,8 @@ const path = require('path'); -const currentTranslations = require(path.join(__dirname, "../app/javascript/mastodon/locales/en.json")); +const currentTranslations = require( + path.join(__dirname, '../app/javascript/mastodon/locales/en.json'), +); exports.format = (msgs) => { const results = {}; diff --git a/config/webpack/configuration.js b/config/webpack/configuration.js index a647b45992b..9d36abe9ba1 100644 --- a/config/webpack/configuration.js +++ b/config/webpack/configuration.js @@ -7,7 +7,9 @@ const { env } = require('process'); const { load } = require('js-yaml'); const configPath = resolve('config', 'webpacker.yml'); -const settings = load(readFileSync(configPath), 'utf8')[env.RAILS_ENV || env.NODE_ENV]; +const settings = load(readFileSync(configPath), 'utf8')[ + env.RAILS_ENV || env.NODE_ENV +]; const themePath = resolve('config', 'themes.yml'); const themes = load(readFileSync(themePath), 'utf8'); diff --git a/config/webpack/development.js b/config/webpack/development.js index e3fbfe4b9d5..363a6a53ad5 100644 --- a/config/webpack/development.js +++ b/config/webpack/development.js @@ -57,6 +57,6 @@ module.exports = merge(sharedConfig, { settings.dev_server.watch_options, watchOptions, ), - writeToDisk: filePath => /ocr/.test(filePath), + writeToDisk: (filePath) => /ocr/.test(filePath), }, }); diff --git a/config/webpack/production.js b/config/webpack/production.js index 7f1ee4a8f9e..3ed4e7baef1 100644 --- a/config/webpack/production.js +++ b/config/webpack/production.js @@ -42,24 +42,27 @@ module.exports = merge(sharedConfig, { cache: true, test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/, }), - new BundleAnalyzerPlugin({ // generates report.html + new BundleAnalyzerPlugin({ + // generates report.html analyzerMode: 'static', openAnalyzer: false, logLevel: 'silent', // do not bother Webpacker, who runs with --json and parses stdout }), new InjectManifest({ - additionalManifestEntries: ['1f602.svg', 'sheet_13.png'].map((filename) => { - const path = resolve(root, 'public', 'emoji', filename); - const body = readFileSync(path); - const md5 = createHash('md5'); + additionalManifestEntries: ['1f602.svg', 'sheet_13.png'].map( + (filename) => { + const path = resolve(root, 'public', 'emoji', filename); + const body = readFileSync(path); + const md5 = createHash('md5'); - md5.update(body); + md5.update(body); - return { - revision: md5.digest('hex'), - url: `/emoji/${filename}`, - }; - }), + return { + revision: md5.digest('hex'), + url: `/emoji/${filename}`, + }; + }, + ), exclude: [ /(?:base|extra)_polyfills-.*\.js$/, /locale_.*\.js$/, @@ -68,7 +71,14 @@ module.exports = merge(sharedConfig, { include: [/\.js$/, /\.css$/], maximumFileSizeToCacheInBytes: 2 * 1_024 * 1_024, // 2 MiB swDest: resolve(root, 'public', 'packs', 'sw.js'), - swSrc: resolve(root, 'app', 'javascript', 'mastodon', 'service_worker', 'entry.js'), + swSrc: resolve( + root, + 'app', + 'javascript', + 'mastodon', + 'service_worker', + 'entry.js', + ), }), ], }); diff --git a/config/webpack/rules/babel.js b/config/webpack/rules/babel.js index c7bf886e795..8770b5bbcf2 100644 --- a/config/webpack/rules/babel.js +++ b/config/webpack/rules/babel.js @@ -7,13 +7,10 @@ module.exports = { include: [ settings.source_path, ...settings.resolved_paths, - 'node_modules/@reduxjs' - ].map(p => resolve(p)), - exclude: function(modulePath) { - return ( - /node_modules/.test(modulePath) && - !/@reduxjs/.test(modulePath) - ); + 'node_modules/@reduxjs', + ].map((p) => resolve(p)), + exclude: function (modulePath) { + return /node_modules/.test(modulePath) && !/@reduxjs/.test(modulePath); }, use: [ { diff --git a/config/webpack/shared.js b/config/webpack/shared.js index 8e77a840a51..2870f7f83a1 100644 --- a/config/webpack/shared.js +++ b/config/webpack/shared.js @@ -21,7 +21,8 @@ module.exports = { packPaths.reduce((map, entry) => { const localMap = map; const namespace = relative(join(entryPath), dirname(entry)); - localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry); + localMap[join(namespace, basename(entry, extname(entry)))] = + resolve(entry); return localMap; }, {}), Object.keys(themes).reduce((themePaths, name) => { @@ -61,19 +62,17 @@ module.exports = { }, module: { - rules: Object.keys(rules).map(key => rules[key]), + rules: Object.keys(rules).map((key) => rules[key]), strictExportPresence: true, }, plugins: [ new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))), - new webpack.NormalModuleReplacementPlugin( - /^history\//, (resource) => { - // temporary fix for https://github.com/ReactTraining/react-router/issues/5576 - // to reduce bundle size - resource.request = resource.request.replace(/^history/, 'history/es'); - }, - ), + new webpack.NormalModuleReplacementPlugin(/^history\//, (resource) => { + // temporary fix for https://github.com/ReactTraining/react-router/issues/5576 + // to reduce bundle size + resource.request = resource.request.replace(/^history/, 'history/es'); + }), new MiniCssExtractPlugin({ filename: 'css/[name]-[contenthash:8].css', chunkFilename: 'css/[name]-[contenthash:8].chunk.css', @@ -87,18 +86,15 @@ module.exports = { }), new CircularDependencyPlugin({ failOnError: true, - }) + }), ], resolve: { extensions: settings.extensions, - modules: [ - resolve(settings.source_path), - 'node_modules', - ], + modules: [resolve(settings.source_path), 'node_modules'], alias: { - "@": resolve(settings.source_path), - } + '@': resolve(settings.source_path), + }, }, resolveLoader: {