@@ -6,42 +6,28 @@ const path = require('node:path');
6
6
// - Heroku: https://devcenter.heroku.com/articles/dyno-metadata
7
7
// - Lambda: https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html
8
8
9
- /**
10
- * Get the application system code from a package.json file.
11
- *
12
- * @param {string } directoryPath
13
- * The directory to look for a package.json file in.
14
- * @returns {(string | null) }
15
- * Returns a system code if one is found in `process.env`.
16
- */
17
- function getSystemCodeFromPackage ( directoryPath ) {
18
- try {
19
- const manifest = require ( path . join ( directoryPath , 'package.json' ) ) ;
20
- return typeof manifest ?. name === 'string'
21
- ? normalizePackageName ( manifest . name )
22
- : null ;
23
- } catch ( error ) { }
24
- return null ;
25
- }
26
-
27
- /**
28
- * Normalize the name property of a package.json file.
29
- *
30
- * @param {string } name
31
- * The name to normalize.
32
- * @returns {string }
33
- * Returns a normalized copy of the package name.
34
- */
35
- function normalizePackageName ( name ) {
36
- // Remove a prefix of "ft-", this is a hangover and we have plenty of
37
- // apps which use this prefix but their system code does not include
38
- // it. E.g. MyFT API has a system code of "next-myft-api", but a
39
- // package.json `name` field of "ft-next-myft-api"
40
- // - https://biz-ops.in.ft.com/System/next-myft-api
41
- // - https://github.com/Financial-Times/next-myft-api/blob/main/package.json
42
- //
43
- return name . replace ( / ^ f t - / , '' ) ;
44
- }
9
+ /** @type {null | any } */
10
+ let manifest = null ;
11
+ try {
12
+ manifest = require ( path . join ( process . cwd ( ) , 'package.json' ) ) ;
13
+ } catch ( error ) { }
14
+
15
+ /** @type {string | null } */
16
+ const manifestName =
17
+ typeof manifest ?. name === 'string'
18
+ ? // Remove a prefix of "ft-", this is a hangover and we have plenty of
19
+ // apps which use this prefix but their system code does not include
20
+ // it. E.g. MyFT API has a system code of "next-myft-api", but a
21
+ // package.json `name` field of "ft-next-myft-api"
22
+ // - https://biz-ops.in.ft.com/System/next-myft-api
23
+ // - https://github.com/Financial-Times/next-myft-api/blob/main/package.json
24
+ //
25
+ manifest . name . replace ( / ^ f t - / , '' )
26
+ : null ;
27
+
28
+ /** @type {string | null } */
29
+ const manifestVersion =
30
+ typeof manifest ?. version === 'string' ? manifest . version : null ;
45
31
46
32
/**
47
33
* Extract the process type from a Heroku dyno name.
@@ -55,9 +41,6 @@ function normalizeHerokuProcessType(dyno) {
55
41
return dyno . split ( '.' ) [ 0 ] ;
56
42
}
57
43
58
- const systemCode =
59
- process . env . SYSTEM_CODE || getSystemCodeFromPackage ( process . cwd ( ) ) || null ;
60
-
61
44
const processType =
62
45
process . env . AWS_LAMBDA_FUNCTION_NAME ||
63
46
( process . env . DYNO && normalizeHerokuProcessType ( process . env . DYNO ) ) ||
@@ -124,15 +107,15 @@ exports.releaseDate = process.env.HEROKU_RELEASE_CREATED_AT || null;
124
107
exports . releaseVersion =
125
108
process . env . HEROKU_RELEASE_VERSION ||
126
109
process . env . AWS_LAMBDA_FUNCTION_VERSION ||
127
- null ;
110
+ manifestVersion ;
128
111
129
112
/**
130
113
* The application system code.
131
114
*
132
115
* @readonly
133
116
* @type {string | null }
134
117
*/
135
- exports . systemCode = systemCode ;
118
+ exports . systemCode = process . env . SYSTEM_CODE || manifestName ;
136
119
137
120
/**
138
121
* The dyno process type.
0 commit comments