6
6
* LICENSE file in the root directory of this source tree.
7
7
*/
8
8
// @remove -on-eject-end
9
- 'use strict' ;
9
+ 'use strict'
10
10
11
- const fs = require ( 'fs' ) ;
12
- const path = require ( 'path' ) ;
13
- const paths = require ( './paths' ) ;
11
+ const fs = require ( 'fs' )
12
+ const path = require ( 'path' )
13
+ const paths = require ( './paths' )
14
+
15
+ let zionUiVersion
16
+ try {
17
+ const resolvedZionUiPath = require . resolve ( '@fs/zion-ui' )
18
+ const zionUiPackageJson = require ( `${ resolvedZionUiPath . split ( '@fs/zion-ui' ) [ 0 ] } @fs/zion-ui/package.json` )
19
+ zionUiVersion = zionUiPackageJson . version
20
+ } catch ( error ) {
21
+ zionUiVersion = '-'
22
+ }
23
+
24
+ let reactScriptsVersion
25
+ try {
26
+ const reactScriptsPackageJson = require ( '../package.json' )
27
+ reactScriptsVersion = reactScriptsPackageJson . version
28
+ } catch ( error ) {
29
+ reactScriptsVersion = '-'
30
+ }
14
31
15
32
// Make sure that including paths.js after env.js will read .env variables.
16
- delete require . cache [ require . resolve ( './paths' ) ] ;
33
+ delete require . cache [ require . resolve ( './paths' ) ]
17
34
18
- const NODE_ENV = process . env . NODE_ENV ;
35
+ const NODE_ENV = process . env . NODE_ENV
19
36
if ( ! NODE_ENV ) {
20
- throw new Error (
21
- 'The NODE_ENV environment variable is required but was not specified.'
22
- ) ;
37
+ throw new Error ( 'The NODE_ENV environment variable is required but was not specified.' )
23
38
}
24
39
25
40
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
@@ -31,7 +46,7 @@ const dotenvFiles = [
31
46
NODE_ENV !== 'test' && `${ paths . dotenv } .local` ,
32
47
`${ paths . dotenv } .${ NODE_ENV } ` ,
33
48
paths . dotenv ,
34
- ] . filter ( Boolean ) ;
49
+ ] . filter ( Boolean )
35
50
36
51
// Load environment variables from .env* files. Suppress warnings using silent
37
52
// if this file is missing. dotenv will never modify any environment variables
@@ -44,9 +59,9 @@ dotenvFiles.forEach(dotenvFile => {
44
59
require ( 'dotenv' ) . config ( {
45
60
path : dotenvFile ,
46
61
} )
47
- ) ;
62
+ )
48
63
}
49
- } ) ;
64
+ } )
50
65
51
66
// We support resolving modules according to `NODE_PATH`.
52
67
// This lets you use absolute paths in imports inside large monorepos:
@@ -57,24 +72,30 @@ dotenvFiles.forEach(dotenvFile => {
57
72
// Otherwise, we risk importing Node.js core modules into an app instead of webpack shims.
58
73
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
59
74
// We also resolve them to make sure all tools using them work consistently.
60
- const appDirectory = fs . realpathSync ( process . cwd ( ) ) ;
75
+ const appDirectory = fs . realpathSync ( process . cwd ( ) )
61
76
process . env . NODE_PATH = ( process . env . NODE_PATH || '' )
62
77
. split ( path . delimiter )
63
78
. filter ( folder => folder && ! path . isAbsolute ( folder ) )
64
79
. map ( folder => path . resolve ( appDirectory , folder ) )
65
- . join ( path . delimiter ) ;
80
+ . join ( path . delimiter )
66
81
67
82
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
68
83
// injected into the application via DefinePlugin in webpack configuration.
69
- const REACT_APP = / ^ R E A C T _ A P P _ / i;
84
+ const REACT_APP = / ^ R E A C T _ A P P _ / i
70
85
71
86
function getClientEnvironment ( publicUrl ) {
72
87
const raw = Object . keys ( process . env )
73
88
. filter ( key => REACT_APP . test ( key ) )
74
89
. reduce (
75
90
( env , key ) => {
76
- env [ key ] = process . env [ key ] ;
77
- return env ;
91
+ if ( key === 'REACT_APP_ZION_UI_VERSION' ) {
92
+ env [ key ] = zionUiVersion
93
+ } else if ( key === 'REACT_APP_REACT_SCRIPTS_VERSION' ) {
94
+ env [ key ] = reactScriptsVersion
95
+ } else {
96
+ env [ key ] = process . env [ key ]
97
+ }
98
+ return env
78
99
} ,
79
100
{
80
101
// Useful for determining whether we’re running in production mode.
@@ -97,16 +118,16 @@ function getClientEnvironment(publicUrl) {
97
118
// It is defined here so it is available in the webpackHotDevClient.
98
119
FAST_REFRESH : process . env . FAST_REFRESH !== 'false' ,
99
120
}
100
- ) ;
121
+ )
101
122
// Stringify all values so we can feed into webpack DefinePlugin
102
123
const stringified = {
103
124
'process.env' : Object . keys ( raw ) . reduce ( ( env , key ) => {
104
- env [ key ] = JSON . stringify ( raw [ key ] ) ;
105
- return env ;
125
+ env [ key ] = JSON . stringify ( raw [ key ] )
126
+ return env
106
127
} , { } ) ,
107
- } ;
128
+ }
108
129
109
- return { raw, stringified } ;
130
+ return { raw, stringified }
110
131
}
111
132
112
- module . exports = getClientEnvironment ;
133
+ module . exports = getClientEnvironment
0 commit comments