From 21bec261464eff3141201dadb6fc067c5a46440c Mon Sep 17 00:00:00 2001 From: John Cowen Date: Tue, 6 Jul 2021 16:57:53 +0100 Subject: [PATCH] ui: Allow disabling of sourcemaps via env var (#10491) --- ui/packages/consul-ui/config/environment.js | 23 +----------------- ui/packages/consul-ui/config/utils.js | 26 +++++++++++++++++++++ ui/packages/consul-ui/ember-cli-build.js | 6 +++-- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/ui/packages/consul-ui/config/environment.js b/ui/packages/consul-ui/config/environment.js index dd2442f73..4d628dee0 100644 --- a/ui/packages/consul-ui/config/environment.js +++ b/ui/packages/consul-ui/config/environment.js @@ -13,29 +13,8 @@ const repositorySHA = utils.repositorySHA; const binaryVersion = utils.binaryVersion(repositoryRoot); module.exports = function(environment, $ = process.env) { + const env = utils.env($); // basic 'get env var with fallback' accessor - const env = function(flag, fallback) { - // a fallback value MUST be set - if (typeof fallback === 'undefined') { - throw new Error(`Please provide a fallback value for $${flag}`); - } - // return the env var if set - if (typeof $[flag] !== 'undefined') { - if (typeof fallback === 'boolean') { - // if we are expecting a boolean JSON parse strings to numbers/booleans - return !!JSON.parse($[flag]); - } - return $[flag]; - } - // If the fallback is a function call it and return the result. - // Lazily calling the function means binaries used for fallback don't need - // to be available if we are sure the environment variables will be set - if (typeof fallback === 'function') { - return fallback(); - } - // just return the fallback value - return fallback; - }; let ENV = { modulePrefix: 'consul-ui', diff --git a/ui/packages/consul-ui/config/utils.js b/ui/packages/consul-ui/config/utils.js index cc16e26ac..b1b58a54e 100644 --- a/ui/packages/consul-ui/config/utils.js +++ b/ui/packages/consul-ui/config/utils.js @@ -25,8 +25,34 @@ const binaryVersion = function(repositoryRoot) { .split('"')[1]; }; }; +const env = function($) { + return function(flag, fallback) { + // a fallback value MUST be set + if (typeof fallback === 'undefined') { + throw new Error(`Please provide a fallback value for $${flag}`); + } + // return the env var if set + if (typeof $[flag] !== 'undefined') { + if (typeof fallback === 'boolean') { + // if we are expecting a boolean JSON parse strings to numbers/booleans + return !!JSON.parse($[flag]); + } + return $[flag]; + } + // If the fallback is a function call it and return the result. + // Lazily calling the function means binaries used for fallback don't need + // to be available if we are sure the environment variables will be set + if (typeof fallback === 'function') { + return fallback(); + } + // just return the fallback value + return fallback; + }; +}; + module.exports = { repositoryYear: repositoryYear, repositorySHA: repositorySHA, binaryVersion: binaryVersion, + env: env, }; diff --git a/ui/packages/consul-ui/ember-cli-build.js b/ui/packages/consul-ui/ember-cli-build.js index 1cbb99195..cd993ed90 100644 --- a/ui/packages/consul-ui/ember-cli-build.js +++ b/ui/packages/consul-ui/ember-cli-build.js @@ -1,14 +1,16 @@ 'use strict'; const Funnel = require('broccoli-funnel'); const EmberApp = require('ember-cli/lib/broccoli/ember-app'); +const utils = require('./config/utils'); -module.exports = function(defaults) { +module.exports = function(defaults, $ = process.env) { // available environments // ['production', 'development', 'staging', 'test']; + $ = utils.env($); const env = EmberApp.env(); const prodlike = ['production', 'staging']; - const sourcemaps = !['production'].includes(env); + const sourcemaps = !['production'].includes(env) && !$('BABEL_DISABLE_SOURCEMAPS', false); const trees = {}; const addons = {};