Skip to content

Commit 3c196aa

Browse files
Normalise environment string captured by app info package
1 parent 3f45037 commit 3c196aa

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

packages/app-info/lib/index.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,44 @@ exports.commitHash =
7979
process.env.GIT_COMMIT ||
8080
null;
8181

82+
/**
83+
* Normalize environment tag
84+
* @param {string} tag
85+
* The environment tag to normalize.
86+
* @returns {string}
87+
* Returns the normalized environment tag
88+
*/
89+
function normalizeEnvironmentTag(tag) {
90+
const tagLower = tag.toLowerCase();
91+
92+
if (['d', 'dev', 'development'].includes(tagLower)) {
93+
return 'development';
94+
}
95+
96+
if (['t', 'test'].includes(tagLower)) {
97+
return 'test';
98+
}
99+
100+
if (['p', 'prod', 'production'].includes(tagLower)) {
101+
return 'production';
102+
}
103+
104+
return tag;
105+
}
106+
82107
/**
83108
* The application deployment environment.
84109
*
85110
* @readonly
86111
* @type {string}
87112
*/
88-
exports.environment =
113+
exports.environment = normalizeEnvironmentTag(
89114
process.env.DEPLOYMENT_ENVIRONMENT ||
90115
process.env.RELEASE_ENV ||
91116
process.env.ENVIRONMENT ||
92117
process.env.NODE_ENV ||
93-
'development';
118+
'development'
119+
);
94120

95121
/**
96122
* The region the application is running in.

0 commit comments

Comments
 (0)