UNPKG

shrinkpack

Version:

Fast, resilient, reproducible builds with npm install.

38 lines (37 loc) 1.53 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; exports.__esModule = true; exports.getSsriFromFile = void 0; var fs_1 = __importDefault(require("fs")); var ssri_1 = __importDefault(require("ssri")); var log_1 = require("./log"); /** * When shrinkpack is run and a tarball is already in the node_shrinkpack * directory, we still need to read the file to find its SSRI (Standard * Subresource Integrity) so that it can be set on the packages .integrity * property in the lockfile. * * @param filePath /Users/you/my-project/node_shrinkpack/shrinkpack-0.18.1.tar */ function getSsriFromFile(filePath) { return new Promise(function (resolve) { var $integrity = ssri_1["default"].integrityStream(); var $read = fs_1["default"].createReadStream(filePath); $integrity.on('data', function () { /* subscribe so stream runs */ }); $integrity.on('integrity', function (result) { log_1.log.verbose("finished getting integrity hash of ".concat(filePath)); var integrity = ssri_1["default"].parse(result.sha512[0]).toString(); resolve(integrity); }); $read.on('error', function (err) { log_1.log.error("error reading ".concat(filePath, "\n delete this file and run shrinkpack again"), err); process.exit(1); }); $read.pipe($integrity); }); } exports.getSsriFromFile = getSsriFromFile;