Skip to content

Commit 7786edf

Browse files
committed
build step to replace stack version info
1 parent 7ed4d0c commit 7786edf

File tree

3 files changed

+50
-24
lines changed

3 files changed

+50
-24
lines changed

CHANGELOG-FRONTIER.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 8.6.0
2+
3+
- Add some logic in env.js to look for REACT_APP_ZION_UI_VERSION and REACT_APP_REACT_SCRIPTS_VERSION env vars and calculate
4+
those versions based on the info in their respective package.json files
5+
16
## 8.5.5
27

38
- Fix proxy to work with Russian test user

packages/react-scripts/config/env.js

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,35 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88
// @remove-on-eject-end
9-
'use strict';
9+
'use strict'
1010

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+
}
1431

1532
// 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')]
1734

18-
const NODE_ENV = process.env.NODE_ENV;
35+
const NODE_ENV = process.env.NODE_ENV
1936
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.')
2338
}
2439

2540
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
@@ -31,7 +46,7 @@ const dotenvFiles = [
3146
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
3247
`${paths.dotenv}.${NODE_ENV}`,
3348
paths.dotenv,
34-
].filter(Boolean);
49+
].filter(Boolean)
3550

3651
// Load environment variables from .env* files. Suppress warnings using silent
3752
// if this file is missing. dotenv will never modify any environment variables
@@ -44,9 +59,9 @@ dotenvFiles.forEach(dotenvFile => {
4459
require('dotenv').config({
4560
path: dotenvFile,
4661
})
47-
);
62+
)
4863
}
49-
});
64+
})
5065

5166
// We support resolving modules according to `NODE_PATH`.
5267
// This lets you use absolute paths in imports inside large monorepos:
@@ -57,24 +72,30 @@ dotenvFiles.forEach(dotenvFile => {
5772
// Otherwise, we risk importing Node.js core modules into an app instead of webpack shims.
5873
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
5974
// 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())
6176
process.env.NODE_PATH = (process.env.NODE_PATH || '')
6277
.split(path.delimiter)
6378
.filter(folder => folder && !path.isAbsolute(folder))
6479
.map(folder => path.resolve(appDirectory, folder))
65-
.join(path.delimiter);
80+
.join(path.delimiter)
6681

6782
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
6883
// injected into the application via DefinePlugin in webpack configuration.
69-
const REACT_APP = /^REACT_APP_/i;
84+
const REACT_APP = /^REACT_APP_/i
7085

7186
function getClientEnvironment(publicUrl) {
7287
const raw = Object.keys(process.env)
7388
.filter(key => REACT_APP.test(key))
7489
.reduce(
7590
(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
7899
},
79100
{
80101
// Useful for determining whether we’re running in production mode.
@@ -97,16 +118,16 @@ function getClientEnvironment(publicUrl) {
97118
// It is defined here so it is available in the webpackHotDevClient.
98119
FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
99120
}
100-
);
121+
)
101122
// Stringify all values so we can feed into webpack DefinePlugin
102123
const stringified = {
103124
'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
106127
}, {}),
107-
};
128+
}
108129

109-
return { raw, stringified };
130+
return { raw, stringified }
110131
}
111132

112-
module.exports = getClientEnvironment;
133+
module.exports = getClientEnvironment

packages/react-scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fs/react-scripts",
3-
"version": "8.5.5",
3+
"version": "8.6.0",
44
"upstreamVersion": "5.0.1",
55
"description": "Configuration and scripts for Create React App.",
66
"repository": {

0 commit comments

Comments
 (0)