mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 09:45:04 +00:00
meta.js
: add flow
Summary: Adds flow to `local-cli/bundle/output/meta.js`, and makes some changes to avoid errors. Reviewed By: cpojer Differential Revision: D5077563 fbshipit-source-id: bafb9e6705319f6f2e8ae1c820667ad343191b3c
This commit is contained in:
parent
44955dfa17
commit
47f52bae67
@ -5,6 +5,8 @@
|
|||||||
* This source code is licensed under the BSD-style license found in the
|
* This source code is licensed under the BSD-style license found in the
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -19,12 +21,16 @@ const constantFor = encoding =>
|
|||||||
isUTF8(encoding) ? 2 :
|
isUTF8(encoding) ? 2 :
|
||||||
/^(?:utf-?16(?:le)?|ucs-?2)$/.test(encoding) ? 3 : 0;
|
/^(?:utf-?16(?:le)?|ucs-?2)$/.test(encoding) ? 3 : 0;
|
||||||
|
|
||||||
module.exports = function(code, encoding) {
|
module.exports = function(
|
||||||
|
code: string,
|
||||||
|
encoding: 'ascii' | 'utf8' | 'utf16le' = 'utf8',
|
||||||
|
): Buffer {
|
||||||
const hash = crypto.createHash('sha1');
|
const hash = crypto.createHash('sha1');
|
||||||
hash.update(code, encoding);
|
// remove `new Buffer` calls when RN drops support for Node 4
|
||||||
const digest = hash.digest('binary');
|
hash.update(Buffer.from ? Buffer.from(code, encoding) : new Buffer(code, encoding));
|
||||||
const signature = Buffer.alloc ? Buffer.alloc(digest.length + 1) : new Buffer(digest.length + 1); // remove the new Buffer call when RN drops support for Node 4
|
const digest = hash.digest();
|
||||||
signature.write(digest, 'binary');
|
const signature = Buffer.alloc ? Buffer.alloc(digest.length + 1) : new Buffer(digest.length + 1);
|
||||||
|
digest.copy(signature);
|
||||||
signature.writeUInt8(
|
signature.writeUInt8(
|
||||||
constantFor(tryAsciiPromotion(code, encoding)),
|
constantFor(tryAsciiPromotion(code, encoding)),
|
||||||
signature.length - 1);
|
signature.length - 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user