From e6f8cbd86c1902dbce93031c09e8dd0531a5ef40 Mon Sep 17 00:00:00 2001 From: Matt Hinchliffe Date: Wed, 26 Mar 2025 10:59:32 +0000 Subject: [PATCH] feat: normalise app info environment string The FT may use multiple values across different platforms to indicate the environment that an app is running in. For example, AWS resources may be assigned an environment variable named ENVIRONMENT with the value "p" which is short for "production". --- packages/app-info/lib/index.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/app-info/lib/index.js b/packages/app-info/lib/index.js index f7494d1d..95755d97 100644 --- a/packages/app-info/lib/index.js +++ b/packages/app-info/lib/index.js @@ -79,18 +79,44 @@ exports.commitHash = process.env.GIT_COMMIT || null; +/** + * Normalize environment tag + * @param {string} tag + * The environment tag to normalize. + * @returns {string} + * Returns the normalized environment tag + */ +function normalizeEnvironmentTag(tag) { + const tagLower = tag.toLowerCase(); + + if (['d', 'dev', 'development'].includes(tagLower)) { + return 'development'; + } + + if (['t', 'test'].includes(tagLower)) { + return 'test'; + } + + if (['p', 'prod', 'production'].includes(tagLower)) { + return 'production'; + } + + return tag; +} + /** * The application deployment environment. * * @readonly * @type {string} */ -exports.environment = +exports.environment = normalizeEnvironmentTag( process.env.DEPLOYMENT_ENVIRONMENT || process.env.RELEASE_ENV || process.env.ENVIRONMENT || process.env.NODE_ENV || - 'development'; + 'development' +); /** * The region the application is running in.