diff --git a/local-cli/bundle/output/meta.js b/local-cli/bundle/output/meta.js index 2bfc3a670..4c110ada7 100644 --- a/local-cli/bundle/output/meta.js +++ b/local-cli/bundle/output/meta.js @@ -5,6 +5,8 @@ * 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 * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow */ 'use strict'; @@ -19,12 +21,16 @@ const constantFor = encoding => isUTF8(encoding) ? 2 : /^(?: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'); - hash.update(code, encoding); - const digest = hash.digest('binary'); - 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 - signature.write(digest, 'binary'); + // remove `new Buffer` calls when RN drops support for Node 4 + hash.update(Buffer.from ? Buffer.from(code, encoding) : new Buffer(code, encoding)); + const digest = hash.digest(); + const signature = Buffer.alloc ? Buffer.alloc(digest.length + 1) : new Buffer(digest.length + 1); + digest.copy(signature); signature.writeUInt8( constantFor(tryAsciiPromotion(code, encoding)), signature.length - 1);