diff options
Diffstat (limited to 'server/sonar-web/config/utils.js')
-rw-r--r-- | server/sonar-web/config/utils.js | 43 |
1 files changed, 42 insertions, 1 deletions
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'] }; |