diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 395b2ab2e..8f3243b54 100755
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -34,3 +34,8 @@ repos:
hooks:
- id: pyupgrade
language_version: python3
+- repo: https://github.com/pre-commit/mirrors-prettier
+ rev: v4.0.0-alpha.8
+ hooks:
+ - id: prettier
+ types_or: [tsx, ts, javascript]
diff --git a/ansible_wisdom_console_react/.eslintrc.js b/ansible_wisdom_console_react/.eslintrc.js
index d2a26af77..85e28f3b8 100644
--- a/ansible_wisdom_console_react/.eslintrc.js
+++ b/ansible_wisdom_console_react/.eslintrc.js
@@ -1,17 +1,17 @@
// See https://youtrack.jetbrains.com/issue/WEB-54170/Allow-specifying-environment-variables-for-ESLint#focus=Comments-27-6031544.0-0
module.exports = {
- 'extends': ['react-app', 'react-app/jest'],
- 'parser': '@typescript-eslint/parser',
- 'parserOptions': {
- 'babelOptions': {
- 'presets': [
- ['babel-preset-react-app', false],
- (process.env.NODE_ENV === 'production')
- ? 'babel-preset-react-app/prod'
- : (process.env.NODE_ENV === 'test')
- ? 'babel-preset-react-app/test'
- : 'babel-preset-react-app/dev',
- ],
- }
- }
-}
+ extends: ["react-app", "react-app/jest"],
+ parser: "@typescript-eslint/parser",
+ parserOptions: {
+ babelOptions: {
+ presets: [
+ ["babel-preset-react-app", false],
+ process.env.NODE_ENV === "production"
+ ? "babel-preset-react-app/prod"
+ : process.env.NODE_ENV === "test"
+ ? "babel-preset-react-app/test"
+ : "babel-preset-react-app/dev",
+ ],
+ },
+ },
+};
diff --git a/ansible_wisdom_console_react/.prettierignore b/ansible_wisdom_console_react/.prettierignore
new file mode 100644
index 000000000..805779273
--- /dev/null
+++ b/ansible_wisdom_console_react/.prettierignore
@@ -0,0 +1,5 @@
+*.css
+*.html
+*.svg
+*.json
+README.md
diff --git a/ansible_wisdom_console_react/__mocks__/monaco-editor.ts b/ansible_wisdom_console_react/__mocks__/monaco-editor.ts
index 650b3384c..0e83a0a04 100644
--- a/ansible_wisdom_console_react/__mocks__/monaco-editor.ts
+++ b/ansible_wisdom_console_react/__mocks__/monaco-editor.ts
@@ -1,3 +1,3 @@
module.exports = {
- // Stub methods as needed (we should not need any for the Admin Portal)
+ // Stub methods as needed (we should not need any for the Admin Portal)
};
diff --git a/ansible_wisdom_console_react/__mocks__/react-i18next.ts b/ansible_wisdom_console_react/__mocks__/react-i18next.ts
index 2b6d1684f..60a567e46 100644
--- a/ansible_wisdom_console_react/__mocks__/react-i18next.ts
+++ b/ansible_wisdom_console_react/__mocks__/react-i18next.ts
@@ -1,8 +1,8 @@
module.exports = {
- // Stub methods as needed...
- useTranslation: () => {
- return {
- t: (str: String) => str,
- };
- },
+ // Stub methods as needed...
+ useTranslation: () => {
+ return {
+ t: (str: String) => str,
+ };
+ },
};
diff --git a/ansible_wisdom_console_react/config/env.js b/ansible_wisdom_console_react/config/env.js
index ffa7e496a..7153edd90 100644
--- a/ansible_wisdom_console_react/config/env.js
+++ b/ansible_wisdom_console_react/config/env.js
@@ -1,16 +1,16 @@
-'use strict';
+"use strict";
-const fs = require('fs');
-const path = require('path');
-const paths = require('./paths');
+const fs = require("fs");
+const path = require("path");
+const paths = require("./paths");
// Make sure that including paths.js after env.js will read .env variables.
-delete require.cache[require.resolve('./paths')];
+delete require.cache[require.resolve("./paths")];
const NODE_ENV = process.env.NODE_ENV;
if (!NODE_ENV) {
throw new Error(
- 'The NODE_ENV environment variable is required but was not specified.'
+ "The NODE_ENV environment variable is required but was not specified.",
);
}
@@ -20,7 +20,7 @@ const dotenvFiles = [
// Don't include `.env.local` for `test` environment
// since normally you expect tests to produce the same
// results for everyone
- NODE_ENV !== 'test' && `${paths.dotenv}.local`,
+ NODE_ENV !== "test" && `${paths.dotenv}.local`,
`${paths.dotenv}.${NODE_ENV}`,
paths.dotenv,
].filter(Boolean);
@@ -30,12 +30,12 @@ const dotenvFiles = [
// that have already been set. Variable expansion is supported in .env files.
// https://github.com/motdotla/dotenv
// https://github.com/motdotla/dotenv-expand
-dotenvFiles.forEach(dotenvFile => {
+dotenvFiles.forEach((dotenvFile) => {
if (fs.existsSync(dotenvFile)) {
- require('dotenv-expand')(
- require('dotenv').config({
+ require("dotenv-expand")(
+ require("dotenv").config({
path: dotenvFile,
- })
+ }),
);
}
});
@@ -50,10 +50,10 @@ dotenvFiles.forEach(dotenvFile => {
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
// We also resolve them to make sure all tools using them work consistently.
const appDirectory = fs.realpathSync(process.cwd());
-process.env.NODE_PATH = (process.env.NODE_PATH || '')
+process.env.NODE_PATH = (process.env.NODE_PATH || "")
.split(path.delimiter)
- .filter(folder => folder && !path.isAbsolute(folder))
- .map(folder => path.resolve(appDirectory, folder))
+ .filter((folder) => folder && !path.isAbsolute(folder))
+ .map((folder) => path.resolve(appDirectory, folder))
.join(path.delimiter);
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
@@ -62,7 +62,7 @@ const REACT_APP = /^REACT_APP_/i;
function getClientEnvironment(publicUrl) {
const raw = Object.keys(process.env)
- .filter(key => REACT_APP.test(key))
+ .filter((key) => REACT_APP.test(key))
.reduce(
(env, key) => {
env[key] = process.env[key];
@@ -71,7 +71,7 @@ function getClientEnvironment(publicUrl) {
{
// Useful for determining whether we’re running in production mode.
// Most importantly, it switches React into the correct mode.
- NODE_ENV: process.env.NODE_ENV || 'development',
+ NODE_ENV: process.env.NODE_ENV || "development",
// Useful for resolving the correct path to static assets in `public`.
// For example,
.
// This should only be used as an escape hatch. Normally you would put
@@ -87,12 +87,12 @@ function getClientEnvironment(publicUrl) {
WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT,
// Whether or not react-refresh is enabled.
// It is defined here so it is available in the webpackHotDevClient.
- FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
- }
+ FAST_REFRESH: process.env.FAST_REFRESH !== "false",
+ },
);
// Stringify all values so we can feed into webpack DefinePlugin
const stringified = {
- 'process.env': Object.keys(raw).reduce((env, key) => {
+ "process.env": Object.keys(raw).reduce((env, key) => {
env[key] = JSON.stringify(raw[key]);
return env;
}, {}),
diff --git a/ansible_wisdom_console_react/config/getHttpsConfig.js b/ansible_wisdom_console_react/config/getHttpsConfig.js
index 013d493c1..eb1c043f1 100644
--- a/ansible_wisdom_console_react/config/getHttpsConfig.js
+++ b/ansible_wisdom_console_react/config/getHttpsConfig.js
@@ -1,10 +1,10 @@
-'use strict';
+"use strict";
-const fs = require('fs');
-const path = require('path');
-const crypto = require('crypto');
-const chalk = require('react-dev-utils/chalk');
-const paths = require('./paths');
+const fs = require("fs");
+const path = require("path");
+const crypto = require("crypto");
+const chalk = require("react-dev-utils/chalk");
+const paths = require("./paths");
// Ensure the certificate and key provided are valid and if not
// throw an easy to debug error
@@ -12,10 +12,10 @@ function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
let encrypted;
try {
// publicEncrypt will throw an error with an invalid cert
- encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
+ encrypted = crypto.publicEncrypt(cert, Buffer.from("test"));
} catch (err) {
throw new Error(
- `The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`
+ `The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`,
);
}
@@ -26,7 +26,7 @@ function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
throw new Error(
`The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
err.message
- }`
+ }`,
);
}
}
@@ -36,8 +36,8 @@ function readEnvFile(file, type) {
if (!fs.existsSync(file)) {
throw new Error(
`You specified ${chalk.cyan(
- type
- )} in your env, but the file "${chalk.yellow(file)}" can't be found.`
+ type,
+ )} in your env, but the file "${chalk.yellow(file)}" can't be found.`,
);
}
return fs.readFileSync(file);
@@ -47,14 +47,14 @@ function readEnvFile(file, type) {
// Return cert files if provided in env, otherwise just true or false
function getHttpsConfig() {
const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
- const isHttps = HTTPS === 'true';
+ const isHttps = HTTPS === "true";
if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE);
const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE);
const config = {
- cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
- key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
+ cert: readEnvFile(crtFile, "SSL_CRT_FILE"),
+ key: readEnvFile(keyFile, "SSL_KEY_FILE"),
};
validateKeyAndCerts({ ...config, keyFile, crtFile });
diff --git a/ansible_wisdom_console_react/config/jest/babelTransform.js b/ansible_wisdom_console_react/config/jest/babelTransform.js
index 5b391e405..7e2179ac4 100644
--- a/ansible_wisdom_console_react/config/jest/babelTransform.js
+++ b/ansible_wisdom_console_react/config/jest/babelTransform.js
@@ -1,14 +1,14 @@
-'use strict';
+"use strict";
-const babelJest = require('babel-jest').default;
+const babelJest = require("babel-jest").default;
const hasJsxRuntime = (() => {
- if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
+ if (process.env.DISABLE_NEW_JSX_TRANSFORM === "true") {
return false;
}
try {
- require.resolve('react/jsx-runtime');
+ require.resolve("react/jsx-runtime");
return true;
} catch (e) {
return false;
@@ -18,9 +18,9 @@ const hasJsxRuntime = (() => {
module.exports = babelJest.createTransformer({
presets: [
[
- require.resolve('babel-preset-react-app'),
+ require.resolve("babel-preset-react-app"),
{
- runtime: hasJsxRuntime ? 'automatic' : 'classic',
+ runtime: hasJsxRuntime ? "automatic" : "classic",
},
],
],
diff --git a/ansible_wisdom_console_react/config/jest/cssTransform.js b/ansible_wisdom_console_react/config/jest/cssTransform.js
index f17fa1025..9b430225d 100644
--- a/ansible_wisdom_console_react/config/jest/cssTransform.js
+++ b/ansible_wisdom_console_react/config/jest/cssTransform.js
@@ -1,16 +1,16 @@
-'use strict';
+"use strict";
// This is a custom Jest transformer turning style imports into empty objects.
// http://facebook.github.io/jest/docs/en/webpack.html
module.exports = {
- process() {
- return {
- code: `module.exports = {};`,
- };
- },
- getCacheKey() {
- // The output is always the same.
- return 'cssTransform';
- },
+ process() {
+ return {
+ code: `module.exports = {};`,
+ };
+ },
+ getCacheKey() {
+ // The output is always the same.
+ return "cssTransform";
+ },
};
diff --git a/ansible_wisdom_console_react/config/jest/fileTransform.js b/ansible_wisdom_console_react/config/jest/fileTransform.js
index 0e81c2b1c..445a2dc7a 100644
--- a/ansible_wisdom_console_react/config/jest/fileTransform.js
+++ b/ansible_wisdom_console_react/config/jest/fileTransform.js
@@ -1,6 +1,6 @@
-'use strict';
+"use strict";
-const path = require('path');
+const path = require("path");
module.exports = {
process(sourceText, sourcePath, options) {
@@ -8,4 +8,4 @@ module.exports = {
code: `module.exports = ${JSON.stringify(path.basename(sourcePath))};`,
};
},
-}
+};
diff --git a/ansible_wisdom_console_react/config/jest/matchMedia.js b/ansible_wisdom_console_react/config/jest/matchMedia.js
index cf2e5822e..b85c9459d 100644
--- a/ansible_wisdom_console_react/config/jest/matchMedia.js
+++ b/ansible_wisdom_console_react/config/jest/matchMedia.js
@@ -1,7 +1,9 @@
-global.matchMedia = global.matchMedia || function() {
+global.matchMedia =
+ global.matchMedia ||
+ function () {
return {
- matches : false,
- addListener : function() {},
- removeListener: function() {}
- }
-}
+ matches: false,
+ addListener: function () {},
+ removeListener: function () {},
+ };
+ };
diff --git a/ansible_wisdom_console_react/config/modules.js b/ansible_wisdom_console_react/config/modules.js
index d63e41d78..1d54f1f10 100644
--- a/ansible_wisdom_console_react/config/modules.js
+++ b/ansible_wisdom_console_react/config/modules.js
@@ -1,10 +1,10 @@
-'use strict';
+"use strict";
-const fs = require('fs');
-const path = require('path');
-const paths = require('./paths');
-const chalk = require('react-dev-utils/chalk');
-const resolve = require('resolve');
+const fs = require("fs");
+const path = require("path");
+const paths = require("./paths");
+const chalk = require("react-dev-utils/chalk");
+const resolve = require("resolve");
/**
* Get additional module paths based on the baseUrl of a compilerOptions object.
@@ -15,19 +15,19 @@ function getAdditionalModulePaths(options = {}) {
const baseUrl = options.baseUrl;
if (!baseUrl) {
- return '';
+ return "";
}
const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
// We don't need to do anything if `baseUrl` is set to `node_modules`. This is
// the default behavior.
- if (path.relative(paths.appNodeModules, baseUrlResolved) === '') {
+ if (path.relative(paths.appNodeModules, baseUrlResolved) === "") {
return null;
}
// Allow the user set the `baseUrl` to `appSrc`.
- if (path.relative(paths.appSrc, baseUrlResolved) === '') {
+ if (path.relative(paths.appSrc, baseUrlResolved) === "") {
return [paths.appSrc];
}
@@ -36,7 +36,7 @@ function getAdditionalModulePaths(options = {}) {
// not transpiled outside of `src`. We do allow importing them with the
// absolute path (e.g. `src/Components/Button.js`) but we set that up with
// an alias.
- if (path.relative(paths.appPath, baseUrlResolved) === '') {
+ if (path.relative(paths.appPath, baseUrlResolved) === "") {
return null;
}
@@ -44,8 +44,8 @@ function getAdditionalModulePaths(options = {}) {
throw new Error(
chalk.red.bold(
"Your project's `baseUrl` can only be set to `src` or `node_modules`." +
- ' Create React App does not support other values at this time.'
- )
+ " Create React App does not support other values at this time.",
+ ),
);
}
@@ -63,7 +63,7 @@ function getWebpackAliases(options = {}) {
const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
- if (path.relative(paths.appPath, baseUrlResolved) === '') {
+ if (path.relative(paths.appPath, baseUrlResolved) === "") {
return {
src: paths.appSrc,
};
@@ -84,9 +84,9 @@ function getJestAliases(options = {}) {
const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
- if (path.relative(paths.appPath, baseUrlResolved) === '') {
+ if (path.relative(paths.appPath, baseUrlResolved) === "") {
return {
- '^src/(.*)$': '/src/$1',
+ "^src/(.*)$": "/src/$1",
};
}
}
@@ -98,7 +98,7 @@ function getModules() {
if (hasTsConfig && hasJsConfig) {
throw new Error(
- 'You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.'
+ "You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.",
);
}
@@ -108,9 +108,11 @@ function getModules() {
// TypeScript project and set up the config
// based on tsconfig.json
if (hasTsConfig) {
- const ts = require(resolve.sync('typescript', {
- basedir: paths.appNodeModules,
- }));
+ const ts = require(
+ resolve.sync("typescript", {
+ basedir: paths.appNodeModules,
+ }),
+ );
config = ts.readConfigFile(paths.appTsConfig, ts.sys.readFile).config;
// Otherwise we'll check if there is jsconfig.json
// for non TS projects.
diff --git a/ansible_wisdom_console_react/config/paths.js b/ansible_wisdom_console_react/config/paths.js
index 142432906..0557fcd2b 100644
--- a/ansible_wisdom_console_react/config/paths.js
+++ b/ansible_wisdom_console_react/config/paths.js
@@ -1,13 +1,13 @@
-'use strict';
+"use strict";
-const path = require('path');
-const fs = require('fs');
-const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath');
+const path = require("path");
+const fs = require("fs");
+const getPublicUrlOrPath = require("react-dev-utils/getPublicUrlOrPath");
// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebook/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd());
-const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
+const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
// "public path" at which the app is served.
@@ -16,31 +16,32 @@ const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
// We can't use a relative path in HTML because we don't want to load something
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
const publicUrlOrPath = getPublicUrlOrPath(
- process.env.NODE_ENV === 'development',
- require(resolveApp('package.json')).homepage,
- process.env.PUBLIC_URL
+ process.env.NODE_ENV === "development",
+ require(resolveApp("package.json")).homepage,
+ process.env.PUBLIC_URL,
);
-const buildPath = process.env.BUILD_PATH || '../ansible_wisdom/main/static/console';
+const buildPath =
+ process.env.BUILD_PATH || "../ansible_wisdom/main/static/console";
const moduleFileExtensions = [
- 'web.mjs',
- 'mjs',
- 'web.js',
- 'js',
- 'web.ts',
- 'ts',
- 'web.tsx',
- 'tsx',
- 'json',
- 'web.jsx',
- 'jsx',
+ "web.mjs",
+ "mjs",
+ "web.js",
+ "js",
+ "web.ts",
+ "ts",
+ "web.tsx",
+ "tsx",
+ "json",
+ "web.jsx",
+ "jsx",
];
// Resolve file paths in the same order as webpack
const resolveModule = (resolveFn, filePath) => {
- const extension = moduleFileExtensions.find(extension =>
- fs.existsSync(resolveFn(`${filePath}.${extension}`))
+ const extension = moduleFileExtensions.find((extension) =>
+ fs.existsSync(resolveFn(`${filePath}.${extension}`)),
);
if (extension) {
@@ -52,28 +53,26 @@ const resolveModule = (resolveFn, filePath) => {
// config after eject: we're in ./config/
module.exports = {
- dotenv: resolveApp('.env'),
- appPath: resolveApp('.'),
+ dotenv: resolveApp(".env"),
+ appPath: resolveApp("."),
appBuild: resolveApp(buildPath),
- appPublic: resolveApp('public'),
- appHtml: resolveApp('public/index.html'),
- appDeniedHtml: resolveApp('public/denied.html'),
- appIndexJs: resolveModule(resolveApp, 'src/index'),
- appDeniedJs: resolveModule(resolveApp, 'src/denied/denied'),
- appPackageJson: resolveApp('package.json'),
- appSrc: resolveApp('src'),
- appTsConfig: resolveApp('tsconfig.json'),
- appJsConfig: resolveApp('jsconfig.json'),
- yarnLockFile: resolveApp('yarn.lock'),
- testsSetup: resolveModule(resolveApp, 'src/setupTests'),
- proxySetup: resolveApp('src/setupProxy.js'),
- appNodeModules: resolveApp('node_modules'),
- appWebpackCache: resolveApp('node_modules/.cache'),
- appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
- swSrc: resolveModule(resolveApp, 'src/service-worker'),
+ appPublic: resolveApp("public"),
+ appHtml: resolveApp("public/index.html"),
+ appDeniedHtml: resolveApp("public/denied.html"),
+ appIndexJs: resolveModule(resolveApp, "src/index"),
+ appDeniedJs: resolveModule(resolveApp, "src/denied/denied"),
+ appPackageJson: resolveApp("package.json"),
+ appSrc: resolveApp("src"),
+ appTsConfig: resolveApp("tsconfig.json"),
+ appJsConfig: resolveApp("jsconfig.json"),
+ yarnLockFile: resolveApp("yarn.lock"),
+ testsSetup: resolveModule(resolveApp, "src/setupTests"),
+ proxySetup: resolveApp("src/setupProxy.js"),
+ appNodeModules: resolveApp("node_modules"),
+ appWebpackCache: resolveApp("node_modules/.cache"),
+ appTsBuildInfoFile: resolveApp("node_modules/.cache/tsconfig.tsbuildinfo"),
+ swSrc: resolveModule(resolveApp, "src/service-worker"),
publicUrlOrPath,
};
-
-
module.exports.moduleFileExtensions = moduleFileExtensions;
diff --git a/ansible_wisdom_console_react/config/webpack.config.js b/ansible_wisdom_console_react/config/webpack.config.js
index dbc582f3a..0dd0f46d6 100644
--- a/ansible_wisdom_console_react/config/webpack.config.js
+++ b/ansible_wisdom_console_react/config/webpack.config.js
@@ -1,58 +1,58 @@
-'use strict';
+"use strict";
-const fs = require('fs');
-const path = require('path');
-const webpack = require('webpack');
-const resolve = require('resolve');
-const HtmlWebpackPlugin = require('html-webpack-plugin');
-const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
-const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
-const TerserPlugin = require('terser-webpack-plugin');
-const MiniCssExtractPlugin = require('mini-css-extract-plugin');
-const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
-const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
-const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
-const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
-const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
-const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
-const ESLintPlugin = require('eslint-webpack-plugin');
-const paths = require('./paths');
-const modules = require('./modules');
-const getClientEnvironment = require('./env');
-const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
+const fs = require("fs");
+const path = require("path");
+const webpack = require("webpack");
+const resolve = require("resolve");
+const HtmlWebpackPlugin = require("html-webpack-plugin");
+const CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin");
+const InlineChunkHtmlPlugin = require("react-dev-utils/InlineChunkHtmlPlugin");
+const TerserPlugin = require("terser-webpack-plugin");
+const MiniCssExtractPlugin = require("mini-css-extract-plugin");
+const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
+const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
+const InterpolateHtmlPlugin = require("react-dev-utils/InterpolateHtmlPlugin");
+const WorkboxWebpackPlugin = require("workbox-webpack-plugin");
+const ModuleScopePlugin = require("react-dev-utils/ModuleScopePlugin");
+const getCSSModuleLocalIdent = require("react-dev-utils/getCSSModuleLocalIdent");
+const ESLintPlugin = require("eslint-webpack-plugin");
+const paths = require("./paths");
+const modules = require("./modules");
+const getClientEnvironment = require("./env");
+const ModuleNotFoundPlugin = require("react-dev-utils/ModuleNotFoundPlugin");
const ForkTsCheckerWebpackPlugin =
- process.env.TSC_COMPILE_ON_ERROR === 'true'
- ? require('react-dev-utils/ForkTsCheckerWarningWebpackPlugin')
- : require('react-dev-utils/ForkTsCheckerWebpackPlugin');
-const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
+ process.env.TSC_COMPILE_ON_ERROR === "true"
+ ? require("react-dev-utils/ForkTsCheckerWarningWebpackPlugin")
+ : require("react-dev-utils/ForkTsCheckerWebpackPlugin");
+const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
-const createEnvironmentHash = require('./webpack/persistentCache/createEnvironmentHash');
+const createEnvironmentHash = require("./webpack/persistentCache/createEnvironmentHash");
// Source maps are resource heavy and can cause out of memory issue for large source files.
-const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
+const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== "false";
-const reactRefreshRuntimeEntry = require.resolve('react-refresh/runtime');
+const reactRefreshRuntimeEntry = require.resolve("react-refresh/runtime");
const reactRefreshWebpackPluginRuntimeEntry = require.resolve(
- '@pmmmwh/react-refresh-webpack-plugin'
+ "@pmmmwh/react-refresh-webpack-plugin",
);
-const babelRuntimeEntry = require.resolve('babel-preset-react-app');
+const babelRuntimeEntry = require.resolve("babel-preset-react-app");
const babelRuntimeEntryHelpers = require.resolve(
- '@babel/runtime/helpers/esm/assertThisInitialized',
- { paths: [babelRuntimeEntry] }
+ "@babel/runtime/helpers/esm/assertThisInitialized",
+ { paths: [babelRuntimeEntry] },
);
-const babelRuntimeRegenerator = require.resolve('@babel/runtime/regenerator', {
+const babelRuntimeRegenerator = require.resolve("@babel/runtime/regenerator", {
paths: [babelRuntimeEntry],
});
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
// makes for a smoother build process.
-const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
+const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== "false";
-const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === 'true';
-const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === 'true';
+const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === "true";
+const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === "true";
const imageInlineSizeLimit = parseInt(
- process.env.IMAGE_INLINE_SIZE_LIMIT || '10000'
+ process.env.IMAGE_INLINE_SIZE_LIMIT || "10000",
);
// Check if TypeScript is setup
@@ -60,7 +60,7 @@ const useTypeScript = fs.existsSync(paths.appTsConfig);
// Check if Tailwind config exists
const useTailwind = fs.existsSync(
- path.join(paths.appPath, 'tailwind.config.js')
+ path.join(paths.appPath, "tailwind.config.js"),
);
// Get the path to the uncompiled service worker (if it exists).
@@ -73,12 +73,12 @@ const sassRegex = /\.(scss|sass)$/;
const sassModuleRegex = /\.module\.(scss|sass)$/;
const hasJsxRuntime = (() => {
- if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
+ if (process.env.DISABLE_NEW_JSX_TRANSFORM === "true") {
return false;
}
try {
- require.resolve('react/jsx-runtime');
+ require.resolve("react/jsx-runtime");
return true;
} catch (e) {
return false;
@@ -88,13 +88,13 @@ const hasJsxRuntime = (() => {
// This is the production and development configuration.
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
module.exports = function (webpackEnv) {
- const isEnvDevelopment = webpackEnv === 'development';
- const isEnvProduction = webpackEnv === 'production';
+ const isEnvDevelopment = webpackEnv === "development";
+ const isEnvProduction = webpackEnv === "production";
// Variable used for enabling profiling in Production
// passed into alias object. Uses a flag if passed into the build command
const isEnvProductionProfile =
- isEnvProduction && process.argv.includes('--profile');
+ isEnvProduction && process.argv.includes("--profile");
// We will provide `paths.publicUrlOrPath` to our app
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
@@ -107,38 +107,38 @@ module.exports = function (webpackEnv) {
// common function to get style loaders
const getStyleLoaders = (cssOptions, preProcessor) => {
const loaders = [
- isEnvDevelopment && require.resolve('style-loader'),
+ isEnvDevelopment && require.resolve("style-loader"),
isEnvProduction && {
loader: MiniCssExtractPlugin.loader,
// css is located in `static/css`, use '../../' to locate index.html folder
// in production `paths.publicUrlOrPath` can be a relative path
- options: paths.publicUrlOrPath.startsWith('.')
- ? { publicPath: '../../' }
+ options: paths.publicUrlOrPath.startsWith(".")
+ ? { publicPath: "../../" }
: {},
},
{
- loader: require.resolve('css-loader'),
+ loader: require.resolve("css-loader"),
options: cssOptions,
},
{
// Options for PostCSS as we reference these options twice
// Adds vendor prefixing based on your specified browser support in
// package.json
- loader: require.resolve('postcss-loader'),
+ loader: require.resolve("postcss-loader"),
options: {
postcssOptions: {
// Necessary for external CSS imports to work
// https://github.com/facebook/create-react-app/issues/2677
- ident: 'postcss',
+ ident: "postcss",
config: false,
plugins: !useTailwind
? [
- 'postcss-flexbugs-fixes',
+ "postcss-flexbugs-fixes",
[
- 'postcss-preset-env',
+ "postcss-preset-env",
{
autoprefixer: {
- flexbox: 'no-2009',
+ flexbox: "no-2009",
},
stage: 3,
},
@@ -146,16 +146,16 @@ module.exports = function (webpackEnv) {
// Adds PostCSS Normalize as the reset css with default options,
// so that it honors browserslist config in package.json
// which in turn let's users customize the target behavior as per their needs.
- 'postcss-normalize',
+ "postcss-normalize",
]
: [
- 'tailwindcss',
- 'postcss-flexbugs-fixes',
+ "tailwindcss",
+ "postcss-flexbugs-fixes",
[
- 'postcss-preset-env',
+ "postcss-preset-env",
{
autoprefixer: {
- flexbox: 'no-2009',
+ flexbox: "no-2009",
},
stage: 3,
},
@@ -169,7 +169,7 @@ module.exports = function (webpackEnv) {
if (preProcessor) {
loaders.push(
{
- loader: require.resolve('resolve-url-loader'),
+ loader: require.resolve("resolve-url-loader"),
options: {
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
root: paths.appSrc,
@@ -180,24 +180,24 @@ module.exports = function (webpackEnv) {
options: {
sourceMap: true,
},
- }
+ },
);
}
return loaders;
};
return {
- target: ['browserslist'],
+ target: ["browserslist"],
// Webpack noise constrained to errors and warnings
- stats: 'errors-warnings',
- mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
+ stats: "errors-warnings",
+ mode: isEnvProduction ? "production" : isEnvDevelopment && "development",
// Stop compilation early in production
bail: isEnvProduction,
devtool: isEnvProduction
? shouldUseSourceMap
- ? 'source-map'
+ ? "source-map"
: false
- : isEnvDevelopment && 'cheap-module-source-map',
+ : isEnvDevelopment && "cheap-module-source-map",
// These are the "entry points" to our application.
// This means they will be the "root" imports that are included in JS bundle.
entry: {
@@ -212,40 +212,41 @@ module.exports = function (webpackEnv) {
// There will be one main bundle, and one file per asynchronous chunk.
// In development, it does not produce real files.
filename: isEnvProduction
- ? 'static/js/[name].js'
- : isEnvDevelopment && 'static/js/[name].bundle.js',
+ ? "static/js/[name].js"
+ : isEnvDevelopment && "static/js/[name].bundle.js",
chunkFilename: isEnvProduction
- ? 'static/js/[name].chunk.js'
- : isEnvDevelopment && 'static/js/[name].chunk.js',
- assetModuleFilename: 'static/media/[name].[hash][ext]',
+ ? "static/js/[name].chunk.js"
+ : isEnvDevelopment && "static/js/[name].chunk.js",
+ assetModuleFilename: "static/media/[name].[hash][ext]",
// webpack uses `publicPath` to determine where the app is being served from.
// It requires a trailing slash, or the file assets will get an incorrect path.
// We inferred the "public path" (such as / or /my-project) from homepage.
publicPath: paths.publicUrlOrPath,
// Point sourcemap entries to original disk location (format as URL on Windows)
devtoolModuleFilenameTemplate: isEnvProduction
- ? info =>
+ ? (info) =>
path
.relative(paths.appSrc, info.absoluteResourcePath)
- .replace(/\\/g, '/')
+ .replace(/\\/g, "/")
: isEnvDevelopment &&
- (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
+ ((info) =>
+ path.resolve(info.absoluteResourcePath).replace(/\\/g, "/")),
},
cache: {
- type: 'filesystem',
+ type: "filesystem",
version: createEnvironmentHash(env.raw),
cacheDirectory: paths.appWebpackCache,
- store: 'pack',
+ store: "pack",
buildDependencies: {
- defaultWebpack: ['webpack/lib/'],
+ defaultWebpack: ["webpack/lib/"],
config: [__filename],
- tsconfig: [paths.appTsConfig, paths.appJsConfig].filter(f =>
- fs.existsSync(f)
+ tsconfig: [paths.appTsConfig, paths.appJsConfig].filter((f) =>
+ fs.existsSync(f),
),
},
},
infrastructureLogging: {
- level: 'none',
+ level: "none",
},
optimization: {
minimize: isEnvProduction,
@@ -299,8 +300,8 @@ module.exports = function (webpackEnv) {
// We placed these paths second because we want `node_modules` to "win"
// if there are any conflicts. This matches Node resolution mechanism.
// https://github.com/facebook/create-react-app/issues/253
- modules: ['node_modules', paths.appNodeModules].concat(
- modules.additionalModulePaths || []
+ modules: ["node_modules", paths.appNodeModules].concat(
+ modules.additionalModulePaths || [],
),
// These are the reasonable defaults supported by the Node ecosystem.
// We also include JSX as a common component filename extension to support
@@ -309,16 +310,16 @@ module.exports = function (webpackEnv) {
// `web` extension prefixes have been added for better support
// for React Native Web.
extensions: paths.moduleFileExtensions
- .map(ext => `.${ext}`)
- .filter(ext => useTypeScript || !ext.includes('ts')),
+ .map((ext) => `.${ext}`)
+ .filter((ext) => useTypeScript || !ext.includes("ts")),
alias: {
// Support React Native Web
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
- 'react-native': 'react-native-web',
+ "react-native": "react-native-web",
// Allows for better profiling with ReactDevTools
...(isEnvProductionProfile && {
- 'react-dom$': 'react-dom/profiling',
- 'scheduler/tracing': 'scheduler/tracing-profiling',
+ "react-dom$": "react-dom/profiling",
+ "scheduler/tracing": "scheduler/tracing-profiling",
}),
...(modules.webpackAliases || {}),
},
@@ -343,10 +344,10 @@ module.exports = function (webpackEnv) {
rules: [
// Handle node_modules packages that contain sourcemaps
shouldUseSourceMap && {
- enforce: 'pre',
+ enforce: "pre",
exclude: /@babel(?:\/|\\{1,2})runtime/,
test: /\.(js|mjs|jsx|ts|tsx|css)$/,
- loader: require.resolve('source-map-loader'),
+ loader: require.resolve("source-map-loader"),
},
{
// "oneOf" will traverse all following loaders until one will
@@ -357,8 +358,8 @@ module.exports = function (webpackEnv) {
// https://github.com/jshttp/mime-db
{
test: [/\.avif$/],
- type: 'asset',
- mimetype: 'image/avif',
+ type: "asset",
+ mimetype: "image/avif",
parser: {
dataUrlCondition: {
maxSize: imageInlineSizeLimit,
@@ -370,7 +371,7 @@ module.exports = function (webpackEnv) {
// A missing `test` is equivalent to a match.
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
- type: 'asset',
+ type: "asset",
parser: {
dataUrlCondition: {
maxSize: imageInlineSizeLimit,
@@ -381,7 +382,7 @@ module.exports = function (webpackEnv) {
test: /\.svg$/,
use: [
{
- loader: require.resolve('@svgr/webpack'),
+ loader: require.resolve("@svgr/webpack"),
options: {
prettier: false,
svgo: false,
@@ -393,9 +394,9 @@ module.exports = function (webpackEnv) {
},
},
{
- loader: require.resolve('file-loader'),
+ loader: require.resolve("file-loader"),
options: {
- name: 'static/media/[name].[hash].[ext]',
+ name: "static/media/[name].[hash].[ext]",
},
},
],
@@ -408,16 +409,16 @@ module.exports = function (webpackEnv) {
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
include: paths.appSrc,
- loader: require.resolve('babel-loader'),
+ loader: require.resolve("babel-loader"),
options: {
customize: require.resolve(
- 'babel-preset-react-app/webpack-overrides'
+ "babel-preset-react-app/webpack-overrides",
),
presets: [
[
- require.resolve('babel-preset-react-app'),
+ require.resolve("babel-preset-react-app"),
{
- runtime: hasJsxRuntime ? 'automatic' : 'classic',
+ runtime: hasJsxRuntime ? "automatic" : "classic",
},
],
],
@@ -425,7 +426,7 @@ module.exports = function (webpackEnv) {
plugins: [
isEnvDevelopment &&
shouldUseReactRefresh &&
- require.resolve('react-refresh/babel'),
+ require.resolve("react-refresh/babel"),
].filter(Boolean),
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
@@ -441,14 +442,14 @@ module.exports = function (webpackEnv) {
{
test: /\.(js|mjs)$/,
exclude: /@babel(?:\/|\\{1,2})runtime/,
- loader: require.resolve('babel-loader'),
+ loader: require.resolve("babel-loader"),
options: {
babelrc: false,
configFile: false,
compact: false,
presets: [
[
- require.resolve('babel-preset-react-app/dependencies'),
+ require.resolve("babel-preset-react-app/dependencies"),
{ helpers: true },
],
],
@@ -479,7 +480,7 @@ module.exports = function (webpackEnv) {
? shouldUseSourceMap
: isEnvDevelopment,
modules: {
- mode: 'icss',
+ mode: "icss",
},
}),
// Don't consider CSS imports dead code even if the
@@ -498,7 +499,7 @@ module.exports = function (webpackEnv) {
? shouldUseSourceMap
: isEnvDevelopment,
modules: {
- mode: 'local',
+ mode: "local",
getLocalIdent: getCSSModuleLocalIdent,
},
}),
@@ -516,10 +517,10 @@ module.exports = function (webpackEnv) {
? shouldUseSourceMap
: isEnvDevelopment,
modules: {
- mode: 'icss',
+ mode: "icss",
},
},
- 'sass-loader'
+ "sass-loader",
),
// Don't consider CSS imports dead code even if the
// containing package claims to have no side effects.
@@ -538,11 +539,11 @@ module.exports = function (webpackEnv) {
? shouldUseSourceMap
: isEnvDevelopment,
modules: {
- mode: 'local',
+ mode: "local",
getLocalIdent: getCSSModuleLocalIdent,
},
},
- 'sass-loader'
+ "sass-loader",
),
},
// "file" loader makes sure those assets get served by WebpackDevServer.
@@ -555,8 +556,13 @@ module.exports = function (webpackEnv) {
// its runtime that would otherwise be processed through "file" loader.
// Also exclude `html` and `json` extensions so they get processed
// by webpacks internal loaders.
- exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx|cjs)$/, /\.html$/, /\.json$/],
- type: 'asset/resource',
+ exclude: [
+ /^$/,
+ /\.(js|mjs|jsx|ts|tsx|cjs)$/,
+ /\.html$/,
+ /\.json$/,
+ ],
+ type: "asset/resource",
},
// ** STOP ** Are you adding a new loader?
// Make sure to add the new loader(s) before the "file" loader.
@@ -569,13 +575,13 @@ module.exports = function (webpackEnv) {
new HtmlWebpackPlugin(
Object.assign(
{},
- {
- inject: true,
- chunks: ['index'],
- template: paths.appHtml,
- filename: 'index.html'
- },
- isEnvProduction
+ {
+ inject: true,
+ chunks: ["index"],
+ template: paths.appHtml,
+ filename: "index.html",
+ },
+ isEnvProduction
? {
minify: {
removeComments: true,
@@ -590,36 +596,36 @@ module.exports = function (webpackEnv) {
minifyURLs: true,
},
}
- : undefined
- )
+ : undefined,
+ ),
),
// Generates an `denied.html` file with the