diff options
-rw-r--r-- | server/sonar-web/.eslintrc | 9 | ||||
-rw-r--r-- | server/sonar-web/config/vite-dev-server-l10n-plugin.mjs (renamed from server/sonar-web/scripts/utils.js) | 43 | ||||
-rw-r--r-- | server/sonar-web/vite.config.mjs | 3 |
3 files changed, 35 insertions, 20 deletions
diff --git a/server/sonar-web/.eslintrc b/server/sonar-web/.eslintrc index 09c65f0aba4..71a90d503cc 100644 --- a/server/sonar-web/.eslintrc +++ b/server/sonar-web/.eslintrc @@ -6,7 +6,12 @@ "eslint-plugin-local-rules" ], "ignorePatterns": [ - "config/jest/**/*.ts", + "babel.config.js", + "jest.config.js", + "vite.config.mjs", + "tailwind*.js", + "script/**/*", + "config/**/*", "eslint-local-rules/**/*" ], "root": true, @@ -100,4 +105,4 @@ } ] } -}
\ No newline at end of file +} diff --git a/server/sonar-web/scripts/utils.js b/server/sonar-web/config/vite-dev-server-l10n-plugin.mjs index 5e4534fbddd..4e53c09ded8 100644 --- a/server/sonar-web/scripts/utils.js +++ b/server/sonar-web/config/vite-dev-server-l10n-plugin.mjs @@ -18,9 +18,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -const fs = require('fs'); -const path = require('path'); -const { promisify } = require('util'); +import fs from 'node:fs'; +import path from 'node:path'; +import { promisify } from 'node:util'; const readFileAsync = promisify(fs.readFile); @@ -59,17 +59,26 @@ function getMessages() { ).then((filesMessages) => filesMessages.reduce((acc, messages) => ({ ...acc, ...messages }), {})); } -function handleL10n(res) { - getMessages() - .then((messages) => { - res.writeHead(STATUS_OK, { 'Content-Type': 'application/json' }); - res.end(JSON.stringify({ effectiveLocale: 'en', messages })); - }) - .catch((e) => { - console.error(e); - res.writeHead(STATUS_ERROR); - res.end(e); - }); -} - -module.exports = { handleL10n }; +// this is a custom l10n-dev-server when proxying locally against another environment so that +// we don't need to rebuild the server when changing the l10n files +export const viteDevServerL10nPlugin = () => { + return { + name: 'l10n-dev-server', + apply: 'serve', + configureServer(server) { + const app = server.middlewares; + app.use('/api/l10n', (_req, res) => { + getMessages() + .then((messages) => { + res.writeHead(STATUS_OK, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ effectiveLocale: 'en', messages })); + }) + .catch((e) => { + console.error(e); + res.writeHead(STATUS_ERROR); + res.end(e); + }); + }); + }, + }; +}; diff --git a/server/sonar-web/vite.config.mjs b/server/sonar-web/vite.config.mjs index 715553c3ace..5fcf039cacb 100644 --- a/server/sonar-web/vite.config.mjs +++ b/server/sonar-web/vite.config.mjs @@ -32,6 +32,7 @@ import requireTransform from 'vite-plugin-require-transform'; import babelConfig from './babel.config'; import { ALLOWED_LICENSES, ALLOWED_LICENSE_TEXT, generateLicenseText } from './config/license'; import { viteDevServerHtmlPlugin } from './config/vite-dev-server-html-plugin.mjs'; +import { viteDevServerL10nPlugin } from './config/vite-dev-server-l10n-plugin.mjs'; import packageJson from './package.json'; const DEFAULT_DEV_SERVER_PORT = 3000; @@ -39,7 +40,6 @@ const DEFAULT_WS_PROXY_PORT = 3010; const port = process.env.PORT || DEFAULT_DEV_SERVER_PORT; const proxyTarget = (process.env.PROXY || 'http://localhost:9000').replace(/\/$/, ''); -const isProxied = !proxyTarget.includes('localhost'); const isProduction = process.env.NODE_ENV === 'production'; const analyzeBundle = process.env.BUNDLE_ANALYSIS || false; @@ -165,6 +165,7 @@ export default ({ mode }) => { // More Info: https://www.npmjs.com/package/babel-plugin-macros macrosPlugin(), viteDevServerHtmlPlugin(), + viteDevServerL10nPlugin(), analyzeBundle && visualizer({ filename: './build/bundle-analyzer.html', |