]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15864 Use esbuild for core-extension-securityreport
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Mon, 27 Dec 2021 15:51:37 +0000 (16:51 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 28 Dec 2021 20:02:47 +0000 (20:02 +0000)
server/sonar-web/config/esbuild-config.js
server/sonar-web/config/utils.js

index 8497d8978dac3e808e22aafa7c85a962518bdfe2..95cfc711a56bcc2b25e36eac9df2071ffa6f04f1 100644 (file)
@@ -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
index a9fe52eafc0c459dd45c48a46d7e2298092313d5..7119cff3cabbff2554834c2ffcfe51d0b784069f 100644 (file)
@@ -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']
 };