ui: Allow disabling of sourcemaps via env var (#10491)

This commit is contained in:
John Cowen 2021-07-06 16:57:53 +01:00 committed by hc-github-team-consul-core
parent db4ba43398
commit 1d5e17d3cc
3 changed files with 31 additions and 24 deletions

View File

@ -13,29 +13,8 @@ const repositorySHA = utils.repositorySHA;
const binaryVersion = utils.binaryVersion(repositoryRoot); const binaryVersion = utils.binaryVersion(repositoryRoot);
module.exports = function(environment, $ = process.env) { module.exports = function(environment, $ = process.env) {
const env = utils.env($);
// basic 'get env var with fallback' accessor // 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 = { let ENV = {
modulePrefix: 'consul-ui', modulePrefix: 'consul-ui',

View File

@ -25,8 +25,34 @@ const binaryVersion = function(repositoryRoot) {
.split('"')[1]; .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 = { module.exports = {
repositoryYear: repositoryYear, repositoryYear: repositoryYear,
repositorySHA: repositorySHA, repositorySHA: repositorySHA,
binaryVersion: binaryVersion, binaryVersion: binaryVersion,
env: env,
}; };

View File

@ -1,14 +1,16 @@
'use strict'; 'use strict';
const Funnel = require('broccoli-funnel'); const Funnel = require('broccoli-funnel');
const EmberApp = require('ember-cli/lib/broccoli/ember-app'); 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 // available environments
// ['production', 'development', 'staging', 'test']; // ['production', 'development', 'staging', 'test'];
$ = utils.env($);
const env = EmberApp.env(); const env = EmberApp.env();
const prodlike = ['production', 'staging']; const prodlike = ['production', 'staging'];
const sourcemaps = !['production'].includes(env); const sourcemaps = !['production'].includes(env) && !$('BABEL_DISABLE_SOURCEMAPS', false);
const trees = {}; const trees = {};
const addons = {}; const addons = {};