Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Allow disabling of sourcemaps via env var #10491

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions ui/packages/consul-ui/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
26 changes: 26 additions & 0 deletions ui/packages/consul-ui/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
6 changes: 4 additions & 2 deletions ui/packages/consul-ui/ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand Down