Cache identifier follow up (#5055)

* Tweak environment handling

* Add documentation for getCacheIdentifier
This commit is contained in:
Joe Haddad
2018-09-21 10:02:08 -04:00
committed by GitHub
parent 0cfe758f27
commit fdc916a5a0
2 changed files with 13 additions and 3 deletions

View File

@@ -3,8 +3,8 @@
This package includes some utilities used by [Create React App](https://github.com/facebook/create-react-app).<br>
Please refer to its documentation:
* [Getting Started](https://github.com/facebook/create-react-app/blob/master/README.md#getting-started) How to create a new app.
* [User Guide](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md) How to develop apps bootstrapped with Create React App.
- [Getting Started](https://github.com/facebook/create-react-app/blob/master/README.md#getting-started) How to create a new app.
- [User Guide](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md) How to develop apps bootstrapped with Create React App.
## Usage in Create React App Projects
@@ -361,3 +361,13 @@ module: {
];
}
```
#### `getCacheIdentifier(environment: string, packages: string[]): string`
Returns a cache identifier (string) consisting of the specified environment and related package versions, e.g.,
```js
var getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
getCacheIdentifier('prod', ['react-dev-utils', 'chalk']); // # => 'prod:react-dev-utils@5.0.0:chalk@2.4.1'
```

View File

@@ -8,7 +8,7 @@
'use strict';
module.exports = function getCacheIdentifier(environment, packages) {
let cacheIdentifier = `${environment}`;
let cacheIdentifier = environment == null ? '' : environment.toString();
for (const packageName of packages) {
cacheIdentifier += `:${packageName}@`;
try {