JezK
Edit File: integrity-checker.js
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.integrityErrors = exports["default"] = void 0; function _regenerator() { var data = _interopRequireDefault(require("@babel/runtime/regenerator")); _regenerator = function _regenerator() { return data; }; return data; } function _asyncToGenerator2() { var data = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); _asyncToGenerator2 = function _asyncToGenerator2() { return data; }; return data; } function _classCallCheck2() { var data = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); _classCallCheck2 = function _classCallCheck2() { return data; }; return data; } function _createClass2() { var data = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); _createClass2 = function _createClass2() { return data; }; return data; } function _defineProperty2() { var data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); _defineProperty2 = function _defineProperty2() { return data; }; return data; } function constants() { var data = _interopRequireWildcard(require("./constants.js")); constants = function constants() { return data; }; return data; } function fs() { var data = _interopRequireWildcard(require("./util/fs.js")); fs = function fs() { return data; }; return data; } function _misc() { var data = require("./util/misc.js"); _misc = function _misc() { return data; }; return data; } function _packageNameUtils() { var data = require("./util/package-name-utils.js"); _packageNameUtils = function _packageNameUtils() { return data; }; return data; } function _workspaceLayout() { var data = _interopRequireDefault(require("./workspace-layout.js")); _workspaceLayout = function _workspaceLayout() { return data; }; return data; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2()["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } var invariant = require('invariant'); var path = require('path'); var integrityErrors = { EXPECTED_IS_NOT_A_JSON: 'integrityFailedExpectedIsNotAJSON', FILES_MISSING: 'integrityFailedFilesMissing', LOCKFILE_DONT_MATCH: 'integrityLockfilesDontMatch', FLAGS_DONT_MATCH: 'integrityFlagsDontMatch', LINKED_MODULES_DONT_MATCH: 'integrityCheckLinkedModulesDontMatch', PATTERNS_DONT_MATCH: 'integrityPatternsDontMatch', MODULES_FOLDERS_MISSING: 'integrityModulesFoldersMissing', SYSTEM_PARAMS_DONT_MATCH: 'integritySystemParamsDontMatch' }; exports.integrityErrors = integrityErrors; var INTEGRITY_FILE_DEFAULTS = function INTEGRITY_FILE_DEFAULTS() { return { systemParams: (0, _packageNameUtils().getSystemParams)(), modulesFolders: [], flags: [], linkedModules: [], topLevelPatterns: [], lockfileEntries: {}, files: [] }; }; /** * */ var InstallationIntegrityChecker = /*#__PURE__*/function () { function InstallationIntegrityChecker(config) { (0, _classCallCheck2()["default"])(this, InstallationIntegrityChecker); (0, _defineProperty2()["default"])(this, "config", void 0); this.config = config; } (0, _createClass2()["default"])(InstallationIntegrityChecker, [{ key: "_getModulesRootFolder", value: /** * Get the common ancestor of every node_modules - it may be a node_modules directory itself, but isn't required to. */ function _getModulesRootFolder() { if (this.config.modulesFolder) { return this.config.modulesFolder; } else if (this.config.workspaceRootFolder) { return this.config.workspaceRootFolder; } else { return path.join(this.config.lockfileFolder, constants().NODE_MODULES_FOLDER); } } /** * Get the directory in which the yarn-integrity file should be written. */ }, { key: "_getIntegrityFileFolder", value: function _getIntegrityFileFolder() { if (this.config.modulesFolder) { return this.config.modulesFolder; } else if (this.config.enableMetaFolder) { return path.join(this.config.lockfileFolder, constants().META_FOLDER); } else { return path.join(this.config.lockfileFolder, constants().NODE_MODULES_FOLDER); } } /** * Get the full path of the yarn-integrity file. */ }, { key: "_getIntegrityFileLocation", value: function () { var _getIntegrityFileLocation2 = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee() { var locationFolder, locationPath, exists; return _regenerator()["default"].wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: locationFolder = this._getIntegrityFileFolder(); locationPath = path.join(locationFolder, constants().INTEGRITY_FILENAME); _context.next = 4; return fs().exists(locationPath); case 4: exists = _context.sent; return _context.abrupt("return", { locationFolder: locationFolder, locationPath: locationPath, exists: exists }); case 6: case "end": return _context.stop(); } }, _callee, this); })); function _getIntegrityFileLocation() { return _getIntegrityFileLocation2.apply(this, arguments); } return _getIntegrityFileLocation; }() /** * Get the list of the directories that contain our modules (there might be multiple such folders b/c of workspaces). */ }, { key: "_getModulesFolders", value: function _getModulesFolders() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, workspaceLayout = _ref.workspaceLayout; var locations = []; if (this.config.modulesFolder) { locations.push(this.config.modulesFolder); } else { locations.push(path.join(this.config.lockfileFolder, constants().NODE_MODULES_FOLDER)); } if (workspaceLayout) { for (var _i = 0, _Object$keys = Object.keys(workspaceLayout.workspaces); _i < _Object$keys.length; _i++) { var workspaceName = _Object$keys[_i]; var loc = workspaceLayout.workspaces[workspaceName].loc; if (loc) { locations.push(path.join(loc, constants().NODE_MODULES_FOLDER)); } } } return locations.sort(_misc().sortAlpha); } /** * Get a list of the files that are located inside our module folders. */ }, { key: "_getIntegrityListing", value: function () { var _getIntegrityListing2 = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee3() { var _ref2, workspaceLayout, files, recurse, _iterator2, _step2, modulesFolder, _args3 = arguments; return _regenerator()["default"].wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: _ref2 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, workspaceLayout = _ref2.workspaceLayout; files = []; recurse = /*#__PURE__*/function () { var _ref3 = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee2(dir) { var _iterator, _step, file, entry, stat; return _regenerator()["default"].wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _context2.t0 = _createForOfIteratorHelper; _context2.next = 3; return fs().readdir(dir); case 3: _context2.t1 = _context2.sent; _iterator = (0, _context2.t0)(_context2.t1); _context2.prev = 5; _iterator.s(); case 7: if ((_step = _iterator.n()).done) { _context2.next = 21; break; } file = _step.value; entry = path.join(dir, file); _context2.next = 12; return fs().lstat(entry); case 12: stat = _context2.sent; if (!stat.isDirectory()) { _context2.next = 18; break; } _context2.next = 16; return recurse(entry); case 16: _context2.next = 19; break; case 18: files.push(entry); case 19: _context2.next = 7; break; case 21: _context2.next = 26; break; case 23: _context2.prev = 23; _context2.t2 = _context2["catch"](5); _iterator.e(_context2.t2); case 26: _context2.prev = 26; _iterator.f(); return _context2.finish(26); case 29: case "end": return _context2.stop(); } }, _callee2, null, [[5, 23, 26, 29]]); })); return function recurse(_x) { return _ref3.apply(this, arguments); }; }(); _iterator2 = _createForOfIteratorHelper(this._getModulesFolders({ workspaceLayout: workspaceLayout })); _context3.prev = 4; _iterator2.s(); case 6: if ((_step2 = _iterator2.n()).done) { _context3.next = 15; break; } modulesFolder = _step2.value; _context3.next = 10; return fs().exists(modulesFolder); case 10: if (!_context3.sent) { _context3.next = 13; break; } _context3.next = 13; return recurse(modulesFolder); case 13: _context3.next = 6; break; case 15: _context3.next = 20; break; case 17: _context3.prev = 17; _context3.t0 = _context3["catch"](4); _iterator2.e(_context3.t0); case 20: _context3.prev = 20; _iterator2.f(); return _context3.finish(20); case 23: return _context3.abrupt("return", files); case 24: case "end": return _context3.stop(); } }, _callee3, this, [[4, 17, 20, 23]]); })); function _getIntegrityListing() { return _getIntegrityListing2.apply(this, arguments); } return _getIntegrityListing; }() /** * Generate integrity hash of input lockfile. */ }, { key: "_generateIntegrityFile", value: function () { var _generateIntegrityFile2 = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee4(lockfile, patterns, flags, workspaceLayout, artifacts) { var result, _i2, _Object$keys2, name, manifest, _iterator3, _step3, dependencyType, dependencies, _i3, _Object$keys3, dep, linkedModules, _i4, _Object$keys4, _key, _iterator4, _step4, modulesFolder, modulesRoot; return _regenerator()["default"].wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: result = _objectSpread(_objectSpread({}, INTEGRITY_FILE_DEFAULTS()), {}, { artifacts: artifacts }); result.topLevelPatterns = patterns; // If using workspaces, we also need to add the workspaces patterns to the top-level, so that we'll know if a // dependency is added or removed into one of them. We must take care not to read the aggregator (if !loc). // // Also note that we can't use of workspaceLayout.workspaces[].manifest._reference.patterns, because when // doing a "yarn check", the _reference property hasn't yet been properly initialized. if (!workspaceLayout) { _context4.next = 33; break; } result.topLevelPatterns = result.topLevelPatterns.filter(function (p) { // $FlowFixMe return !workspaceLayout.getManifestByPattern(p); }); _i2 = 0, _Object$keys2 = Object.keys(workspaceLayout.workspaces); case 5: if (!(_i2 < _Object$keys2.length)) { _context4.next = 33; break; } name = _Object$keys2[_i2]; if (workspaceLayout.workspaces[name].loc) { _context4.next = 9; break; } return _context4.abrupt("continue", 30); case 9: manifest = workspaceLayout.workspaces[name].manifest; if (!manifest) { _context4.next = 30; break; } _iterator3 = _createForOfIteratorHelper(constants().DEPENDENCY_TYPES); _context4.prev = 12; _iterator3.s(); case 14: if ((_step3 = _iterator3.n()).done) { _context4.next = 22; break; } dependencyType = _step3.value; dependencies = manifest[dependencyType]; if (dependencies) { _context4.next = 19; break; } return _context4.abrupt("continue", 20); case 19: for (_i3 = 0, _Object$keys3 = Object.keys(dependencies); _i3 < _Object$keys3.length; _i3++) { dep = _Object$keys3[_i3]; result.topLevelPatterns.push("".concat(dep, "@").concat(dependencies[dep])); } case 20: _context4.next = 14; break; case 22: _context4.next = 27; break; case 24: _context4.prev = 24; _context4.t0 = _context4["catch"](12); _iterator3.e(_context4.t0); case 27: _context4.prev = 27; _iterator3.f(); return _context4.finish(27); case 30: _i2++; _context4.next = 5; break; case 33: result.topLevelPatterns.sort(_misc().sortAlpha); if (flags.checkFiles) { result.flags.push('checkFiles'); } if (flags.flat) { result.flags.push('flat'); } if (this.config.ignoreScripts) { result.flags.push('ignoreScripts'); } if (this.config.focus) { result.flags.push('focus: ' + this.config.focusedWorkspaceName); } if (this.config.production) { result.flags.push('production'); } if (this.config.plugnplayEnabled) { result.flags.push('plugnplay'); } linkedModules = this.config.linkedModules; if (linkedModules.length) { result.linkedModules = linkedModules.sort(_misc().sortAlpha); } for (_i4 = 0, _Object$keys4 = Object.keys(lockfile); _i4 < _Object$keys4.length; _i4++) { _key = _Object$keys4[_i4]; result.lockfileEntries[_key] = lockfile[_key].resolved || ''; } _iterator4 = _createForOfIteratorHelper(this._getModulesFolders({ workspaceLayout: workspaceLayout })); _context4.prev = 44; _iterator4.s(); case 46: if ((_step4 = _iterator4.n()).done) { _context4.next = 54; break; } modulesFolder = _step4.value; _context4.next = 50; return fs().exists(modulesFolder); case 50: if (!_context4.sent) { _context4.next = 52; break; } result.modulesFolders.push(path.relative(this.config.lockfileFolder, modulesFolder)); case 52: _context4.next = 46; break; case 54: _context4.next = 59; break; case 56: _context4.prev = 56; _context4.t1 = _context4["catch"](44); _iterator4.e(_context4.t1); case 59: _context4.prev = 59; _iterator4.f(); return _context4.finish(59); case 62: if (!flags.checkFiles) { _context4.next = 67; break; } modulesRoot = this._getModulesRootFolder(); _context4.next = 66; return this._getIntegrityListing({ workspaceLayout: workspaceLayout }); case 66: result.files = _context4.sent.map(function (entry) { return path.relative(modulesRoot, entry); }).sort(_misc().sortAlpha); case 67: return _context4.abrupt("return", result); case 68: case "end": return _context4.stop(); } }, _callee4, this, [[12, 24, 27, 30], [44, 56, 59, 62]]); })); function _generateIntegrityFile(_x2, _x3, _x4, _x5, _x6) { return _generateIntegrityFile2.apply(this, arguments); } return _generateIntegrityFile; }() }, { key: "_getIntegrityFile", value: function () { var _getIntegrityFile2 = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee5(locationPath) { var expectedRaw; return _regenerator()["default"].wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return fs().readFile(locationPath); case 2: expectedRaw = _context5.sent; _context5.prev = 3; return _context5.abrupt("return", _objectSpread(_objectSpread({}, INTEGRITY_FILE_DEFAULTS()), JSON.parse(expectedRaw))); case 7: _context5.prev = 7; _context5.t0 = _context5["catch"](3); case 9: return _context5.abrupt("return", null); case 10: case "end": return _context5.stop(); } }, _callee5, null, [[3, 7]]); })); function _getIntegrityFile(_x7) { return _getIntegrityFile2.apply(this, arguments); } return _getIntegrityFile; }() }, { key: "_compareIntegrityFiles", value: function _compareIntegrityFiles(actual, expected, checkFiles, workspaceLayout) { if (!expected) { return 'EXPECTED_IS_NOT_A_JSON'; } if (!(0, _misc().compareSortedArrays)(actual.linkedModules, expected.linkedModules)) { return 'LINKED_MODULES_DONT_MATCH'; } if (actual.systemParams !== expected.systemParams) { return 'SYSTEM_PARAMS_DONT_MATCH'; } var relevantExpectedFlags = expected.flags.slice(); // If we run "yarn" after "yarn --check-files", we shouldn't fail the less strict validation if (actual.flags.indexOf('checkFiles') === -1) { relevantExpectedFlags = relevantExpectedFlags.filter(function (flag) { return flag !== 'checkFiles'; }); } if (!(0, _misc().compareSortedArrays)(actual.flags, relevantExpectedFlags)) { return 'FLAGS_DONT_MATCH'; } if (!(0, _misc().compareSortedArrays)(actual.topLevelPatterns, expected.topLevelPatterns || [])) { return 'PATTERNS_DONT_MATCH'; } for (var _i5 = 0, _Object$keys5 = Object.keys(actual.lockfileEntries); _i5 < _Object$keys5.length; _i5++) { var _key2 = _Object$keys5[_i5]; if (actual.lockfileEntries[_key2] !== expected.lockfileEntries[_key2]) { return 'LOCKFILE_DONT_MATCH'; } } for (var _i6 = 0, _Object$keys6 = Object.keys(expected.lockfileEntries); _i6 < _Object$keys6.length; _i6++) { var _key3 = _Object$keys6[_i6]; if (actual.lockfileEntries[_key3] !== expected.lockfileEntries[_key3]) { return 'LOCKFILE_DONT_MATCH'; } } if (checkFiles) { // Early bailout if we expect more files than what we have if (expected.files.length > actual.files.length) { return 'FILES_MISSING'; } // Since we know the "files" array is sorted (alphabetically), we can optimize the thing // Instead of storing the files in a Set, we can just iterate both arrays at once. O(n)! for (var u = 0, v = 0; u < expected.files.length; ++u) { // Index that, if reached, means that we won't have enough food to match the remaining expected entries anyway var max = v + (actual.files.length - v) - (expected.files.length - u) + 1; // Skip over files that have been added (ie not present in 'expected') while (v < max && actual.files[v] !== expected.files[u]) { v += 1; } // If we've reached the index defined above, the file is either missing or we can early exit if (v === max) { return 'FILES_MISSING'; } } } return 'OK'; } }, { key: "check", value: function () { var _check = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee6(patterns, lockfile, flags, workspaceLayout) { var missingPatterns, loc, actual, expected, integrityMatches, _iterator5, _step5, modulesFolder; return _regenerator()["default"].wrap(function _callee6$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: // check if patterns exist in lockfile missingPatterns = patterns.filter(function (p) { return !lockfile[p] && (!workspaceLayout || !workspaceLayout.getManifestByPattern(p)); }); _context6.next = 3; return this._getIntegrityFileLocation(); case 3: loc = _context6.sent; if (!(missingPatterns.length || !loc.exists)) { _context6.next = 6; break; } return _context6.abrupt("return", { integrityFileMissing: !loc.exists, missingPatterns: missingPatterns }); case 6: _context6.next = 8; return this._generateIntegrityFile(lockfile, patterns, flags, workspaceLayout); case 8: actual = _context6.sent; _context6.next = 11; return this._getIntegrityFile(loc.locationPath); case 11: expected = _context6.sent; integrityMatches = this._compareIntegrityFiles(actual, expected, flags.checkFiles, workspaceLayout); if (!(integrityMatches === 'OK')) { _context6.next = 34; break; } invariant(expected, "The integrity shouldn't pass without integrity file"); _iterator5 = _createForOfIteratorHelper(expected.modulesFolders); _context6.prev = 16; _iterator5.s(); case 18: if ((_step5 = _iterator5.n()).done) { _context6.next = 26; break; } modulesFolder = _step5.value; _context6.next = 22; return fs().exists(path.join(this.config.lockfileFolder, modulesFolder)); case 22: if (_context6.sent) { _context6.next = 24; break; } integrityMatches = 'MODULES_FOLDERS_MISSING'; case 24: _context6.next = 18; break; case 26: _context6.next = 31; break; case 28: _context6.prev = 28; _context6.t0 = _context6["catch"](16); _iterator5.e(_context6.t0); case 31: _context6.prev = 31; _iterator5.f(); return _context6.finish(31); case 34: return _context6.abrupt("return", { integrityFileMissing: false, integrityMatches: integrityMatches === 'OK', integrityError: integrityMatches === 'OK' ? undefined : integrityMatches, missingPatterns: missingPatterns, hardRefreshRequired: integrityMatches === 'SYSTEM_PARAMS_DONT_MATCH' }); case 35: case "end": return _context6.stop(); } }, _callee6, this, [[16, 28, 31, 34]]); })); function check(_x8, _x9, _x10, _x11) { return _check.apply(this, arguments); } return check; }() /** * Get artifacts from integrity file if it exists. */ }, { key: "getArtifacts", value: function () { var _getArtifacts = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee7() { var loc, expectedRaw, expected; return _regenerator()["default"].wrap(function _callee7$(_context7) { while (1) switch (_context7.prev = _context7.next) { case 0: _context7.next = 2; return this._getIntegrityFileLocation(); case 2: loc = _context7.sent; if (loc.exists) { _context7.next = 5; break; } return _context7.abrupt("return", null); case 5: _context7.next = 7; return fs().readFile(loc.locationPath); case 7: expectedRaw = _context7.sent; try { expected = JSON.parse(expectedRaw); } catch (e) { // ignore JSON parsing for legacy text integrity files compatibility } return _context7.abrupt("return", expected ? expected.artifacts : null); case 10: case "end": return _context7.stop(); } }, _callee7, this); })); function getArtifacts() { return _getArtifacts.apply(this, arguments); } return getArtifacts; }() /** * Write the integrity hash of the current install to disk. */ }, { key: "save", value: function () { var _save = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee8(patterns, lockfile, flags, workspaceLayout, artifacts) { var integrityFile, loc; return _regenerator()["default"].wrap(function _callee8$(_context8) { while (1) switch (_context8.prev = _context8.next) { case 0: _context8.next = 2; return this._generateIntegrityFile(lockfile, patterns, flags, workspaceLayout, artifacts); case 2: integrityFile = _context8.sent; _context8.next = 5; return this._getIntegrityFileLocation(); case 5: loc = _context8.sent; invariant(loc.locationPath, 'expected integrity hash location'); _context8.next = 9; return fs().mkdirp(path.dirname(loc.locationPath)); case 9: _context8.next = 11; return fs().writeFile(loc.locationPath, JSON.stringify(integrityFile, null, 2)); case 11: case "end": return _context8.stop(); } }, _callee8, this); })); function save(_x12, _x13, _x14, _x15, _x16) { return _save.apply(this, arguments); } return save; }() }, { key: "removeIntegrityFile", value: function () { var _removeIntegrityFile = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee9() { var loc; return _regenerator()["default"].wrap(function _callee9$(_context9) { while (1) switch (_context9.prev = _context9.next) { case 0: _context9.next = 2; return this._getIntegrityFileLocation(); case 2: loc = _context9.sent; if (!loc.exists) { _context9.next = 6; break; } _context9.next = 6; return fs().unlink(loc.locationPath); case 6: case "end": return _context9.stop(); } }, _callee9, this); })); function removeIntegrityFile() { return _removeIntegrityFile.apply(this, arguments); } return removeIntegrityFile; }() }]); return InstallationIntegrityChecker; }(); exports["default"] = InstallationIntegrityChecker; //# sourceMappingURL=integrity-checker.js.map