aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/config
diff options
context:
space:
mode:
authorWouter Admiraal <wouter.admiraal@sonarsource.com>2021-12-27 16:51:37 +0100
committersonartech <sonartech@sonarsource.com>2021-12-28 20:02:47 +0000
commite214060191812769be914d79f4126f801914740c (patch)
tree3109b7cf9494b5c5c38e02057a87510bc87dd7c4 /server/sonar-web/config
parent0bffaef9955651d160502c5df77c8f4a859778b9 (diff)
downloadsonarqube-e214060191812769be914d79f4126f801914740c.tar.gz
sonarqube-e214060191812769be914d79f4126f801914740c.zip
SONAR-15864 Use esbuild for core-extension-securityreport
Diffstat (limited to 'server/sonar-web/config')
-rw-r--r--server/sonar-web/config/esbuild-config.js4
-rw-r--r--server/sonar-web/config/utils.js43
2 files changed, 44 insertions, 3 deletions
diff --git a/server/sonar-web/config/esbuild-config.js b/server/sonar-web/config/esbuild-config.js
index 8497d8978da..95cfc711a56 100644
--- a/server/sonar-web/config/esbuild-config.js
+++ b/server/sonar-web/config/esbuild-config.js
@@ -24,7 +24,7 @@ const postCssCustomProperties = require('postcss-custom-properties');
const documentationPlugin = require('./esbuild-documentation-plugin');
const htmlPlugin = require('./esbuild-html-plugin');
const htmlTemplate = require('./indexHtmlTemplate');
-const { getCustomProperties } = require('./utils');
+const { getCustomProperties, TARGET_BROWSERS } = require('./utils');
module.exports = release => {
const plugins = [
@@ -63,7 +63,7 @@ module.exports = release => {
minify: release,
metafile: true,
sourcemap: true,
- target: ['chrome58', 'firefox57', 'safari11', 'edge18'],
+ target: TARGET_BROWSERS,
outdir: 'build/webapp/js',
entryNames: release ? 'out[hash]' : 'out',
plugins
diff --git a/server/sonar-web/config/utils.js b/server/sonar-web/config/utils.js
index a9fe52eafc0..7119cff3cab 100644
--- a/server/sonar-web/config/utils.js
+++ b/server/sonar-web/config/utils.js
@@ -43,6 +43,47 @@ function getCustomProperties() {
return customProperties;
}
+// See https://github.com/evanw/esbuild/issues/337
+function importAsGlobals(mapping) {
+ const escRe = s => s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
+ const filter = new RegExp(
+ Object.keys(mapping)
+ .map(moduleName => `^${escRe(moduleName)}$`)
+ .join('|')
+ );
+
+ return {
+ name: 'import-as-globals',
+ setup(build) {
+ build.onResolve({ filter }, args => {
+ if (!mapping[args.path]) {
+ throw new Error('Unknown global: ' + args.path);
+ }
+ return {
+ path: args.path,
+ namespace: 'external-global'
+ };
+ });
+
+ build.onLoad(
+ {
+ filter,
+ namespace: 'external-global'
+ },
+ args => {
+ const globalName = mapping[args.path];
+ return {
+ contents: `module.exports = ${globalName};`,
+ loader: 'js'
+ };
+ }
+ );
+ }
+ };
+}
+
module.exports = {
- getCustomProperties
+ getCustomProperties,
+ importAsGlobals,
+ TARGET_BROWSERS: ['chrome58', 'firefox57', 'safari11', 'edge18']
};