Skip to content

Commit 463749a

Browse files
committed
Change REACT_APP prefix to CY_APP to align with our standards
1 parent 099d797 commit 463749a

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

packages/react-cy-scripts/config/env.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
*/
1010
// @remove-on-eject-end
1111

12-
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
12+
// Grab NODE_ENV and CY_APP_* environment variables and prepare them to be
1313
// injected into the application via DefinePlugin in Webpack configuration.
1414

15-
var REACT_APP = /^REACT_APP_/i;
15+
var CY_APP = /^CY_APP_/i;
1616

1717
function getClientEnvironment(publicUrl) {
1818
var raw = Object
1919
.keys(process.env)
20-
.filter(key => REACT_APP.test(key))
20+
.filter(key => CY_APP.test(key))
2121
.reduce((env, key) => {
2222
env[key] = process.env[key];
2323
return env;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
REACT_APP_FILE_ENV_MESSAGE=fromtheenvfile
1+
CY_APP_FILE_ENV_MESSAGE=fromtheenvfile
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
22

33
export default () => (
4-
<span id="feature-file-env-variables">{process.env.REACT_APP_FILE_ENV_MESSAGE}.</span>
4+
<span id="feature-file-env-variables">{process.env.CY_APP_FILE_ENV_MESSAGE}.</span>
55
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
22

33
export default () => (
4-
<span id="feature-shell-env-variables">{process.env.REACT_APP_SHELL_ENV_MESSAGE}.</span>
4+
<span id="feature-shell-env-variables">{process.env.CY_APP_SHELL_ENV_MESSAGE}.</span>
55
)

packages/react-cy-scripts/template/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,14 @@ Alternatively, you can force the linter to ignore any line by adding `// eslint-
442442

443443
Your project can consume variables declared in your environment as if they were declared locally in your JS files. By
444444
default you will have `NODE_ENV` defined for you, and any other environment variables starting with
445-
`REACT_APP_`.
445+
`CY_APP_`.
446446

447447
**The environment variables are embedded during the build time**. Since Create React App produces a static HTML/CSS/JS bundle, it can’t possibly read them at runtime. To read them at runtime, you would need to load HTML into memory on the server and replace placeholders in runtime, just like [described here](#injecting-data-from-the-server-into-the-page). Alternatively you can rebuild the app on the server anytime you change them.
448448

449-
>Note: You must create custom environment variables beginning with `REACT_APP_`. Any other variables except `NODE_ENV` will be ignored to avoid accidentally [exposing a private key on the machine that could have the same name](https://github.com/facebookincubator/create-react-app/issues/865#issuecomment-252199527). Changing any environment variables will require you to restart the development server if it is running.
449+
>Note: You must create custom environment variables beginning with `CY_APP_`. Any other variables except `NODE_ENV` will be ignored to avoid accidentally [exposing a private key on the machine that could have the same name](https://github.com/facebookincubator/create-react-app/issues/865#issuecomment-252199527). Changing any environment variables will require you to restart the development server if it is running.
450450
451451
These environment variables will be defined for you on `process.env`. For example, having an environment
452-
variable named `REACT_APP_SECRET_CODE` will be exposed in your JS as `process.env.REACT_APP_SECRET_CODE`.
452+
variable named `CY_APP_SECRET_CODE` will be exposed in your JS as `process.env.CY_APP_SECRET_CODE`.
453453

454454
There is also a special built-in environment variable called `NODE_ENV`. You can read it from `process.env.NODE_ENV`. When you run `npm start`, it is always equal to `'development'`, when you run `npm test` it is always equal to `'test'`, and when you run `npm run build` to make a production bundle, it is always equal to `'production'`. **You cannot override `NODE_ENV` manually.** This prevents developers from accidentally deploying a slow development build to production.
455455

@@ -465,14 +465,14 @@ render() {
465465
<div>
466466
<small>You are running this application in <b>{process.env.NODE_ENV}</b> mode.</small>
467467
<form>
468-
<input type="hidden" defaultValue={process.env.REACT_APP_SECRET_CODE} />
468+
<input type="hidden" defaultValue={process.env.CY_APP_SECRET_CODE} />
469469
</form>
470470
</div>
471471
);
472472
}
473473
```
474474

475-
During the build, `process.env.REACT_APP_SECRET_CODE` will be replaced with the current value of the `REACT_APP_SECRET_CODE` environment variable. Remember that the `NODE_ENV` variable will be set for you automatically.
475+
During the build, `process.env.CY_APP_SECRET_CODE` will be replaced with the current value of the `CY_APP_SECRET_CODE` environment variable. Remember that the `NODE_ENV` variable will be set for you automatically.
476476

477477
When you load the app in the browser and inspect the `<input>`, you will see its value set to `abcdef`, and the bold text will show the environment provided when using `npm start`:
478478

@@ -485,7 +485,7 @@ When you load the app in the browser and inspect the `<input>`, you will see its
485485
</div>
486486
```
487487

488-
The above form is looking for a variable called `REACT_APP_SECRET_CODE` from the environment. In order to consume this
488+
The above form is looking for a variable called `CY_APP_SECRET_CODE` from the environment. In order to consume this
489489
value, we need to have it defined in the environment. This can be done using two ways: either in your shell or in
490490
a `.env` file. Both of these ways are described in the next few sections.
491491

@@ -501,15 +501,15 @@ When you compile the app with `npm run build`, the minification step will strip
501501

502502
### Referencing Environment Variables in the HTML
503503

504-
You can also access the environment variables starting with `REACT_APP_` in the `public/index.html`. For example:
504+
You can also access the environment variables starting with `CY_APP_` in the `public/index.html`. For example:
505505

506506
```html
507-
<title>%REACT_APP_WEBSITE_NAME%</title>
507+
<title>%CY_APP_WEBSITE_NAME%</title>
508508
```
509509

510510
Note that the caveats from the above section apply:
511511

512-
* Apart from a few built-in variables (`NODE_ENV` and `PUBLIC_URL`), variable names must start with `REACT_APP_` to work.
512+
* Apart from a few built-in variables (`NODE_ENV` and `PUBLIC_URL`), variable names must start with `CY_APP_` to work.
513513
* The environment variables are injected at build time. If you need to inject them at runtime, [follow this approach instead](#generating-dynamic-meta-tags-on-the-server).
514514

515515
### Adding Temporary Environment Variables In Your Shell
@@ -520,15 +520,15 @@ life of the shell session.
520520
#### Windows (cmd.exe)
521521

522522
```cmd
523-
set REACT_APP_SECRET_CODE=abcdef&&npm start
523+
set CY_APP_SECRET_CODE=abcdef&&npm start
524524
```
525525

526526
(Note: the lack of whitespace is intentional.)
527527

528528
#### Linux, macOS (Bash)
529529

530530
```bash
531-
REACT_APP_SECRET_CODE=abcdef npm start
531+
CY_APP_SECRET_CODE=abcdef npm start
532532
```
533533

534534
### Adding Development Environment Variables In `.env`
@@ -537,7 +537,7 @@ REACT_APP_SECRET_CODE=abcdef npm start
537537
To define permanent environment variables, create a file called `.env` in the root of your project:
538538

539539
```
540-
REACT_APP_SECRET_CODE=abcdef
540+
CY_APP_SECRET_CODE=abcdef
541541
```
542542

543543
These variables will act as the defaults if the machine does not explicitly set them.<br>

0 commit comments

Comments
 (0)