* Save updated integrity and lockfiles.
(patterns, workspaceLayout)
| 7246 | */ |
| 7247 | |
| 7248 | saveLockfileAndIntegrity(patterns, workspaceLayout) { |
| 7249 | var _this11 = this; |
| 7250 | |
| 7251 | return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { |
| 7252 | const resolvedPatterns = {}; |
| 7253 | Object.keys(_this11.resolver.patterns).forEach(function (pattern) { |
| 7254 | if (!workspaceLayout || !workspaceLayout.getManifestByPattern(pattern)) { |
| 7255 | resolvedPatterns[pattern] = _this11.resolver.patterns[pattern]; |
| 7256 | } |
| 7257 | }); |
| 7258 | |
| 7259 | // TODO this code is duplicated in a few places, need a common way to filter out workspace patterns from lockfile |
| 7260 | patterns = patterns.filter(function (p) { |
| 7261 | return !workspaceLayout || !workspaceLayout.getManifestByPattern(p); |
| 7262 | }); |
| 7263 | |
| 7264 | const lockfileBasedOnResolver = _this11.lockfile.getLockfile(resolvedPatterns); |
| 7265 | |
| 7266 | if (_this11.config.pruneOfflineMirror) { |
| 7267 | yield _this11.pruneOfflineMirror(lockfileBasedOnResolver); |
| 7268 | } |
| 7269 | |
| 7270 | // write integrity hash |
| 7271 | if (!_this11.config.plugnplayEnabled) { |
| 7272 | yield _this11.integrityChecker.save(patterns, lockfileBasedOnResolver, _this11.flags, workspaceLayout, _this11.scripts.getArtifacts()); |
| 7273 | } |
| 7274 | |
| 7275 | // --no-lockfile or --pure-lockfile or --frozen-lockfile |
| 7276 | if (_this11.flags.lockfile === false || _this11.flags.pureLockfile || _this11.flags.frozenLockfile) { |
| 7277 | return; |
| 7278 | } |
| 7279 | |
| 7280 | const lockFileHasAllPatterns = patterns.every(function (p) { |
| 7281 | return _this11.lockfile.getLocked(p); |
| 7282 | }); |
| 7283 | const lockfilePatternsMatch = Object.keys(_this11.lockfile.cache || {}).every(function (p) { |
| 7284 | return lockfileBasedOnResolver[p]; |
| 7285 | }); |
| 7286 | const resolverPatternsAreSameAsInLockfile = Object.keys(lockfileBasedOnResolver).every(function (pattern) { |
| 7287 | const manifest = _this11.lockfile.getLocked(pattern); |
| 7288 | return manifest && manifest.resolved === lockfileBasedOnResolver[pattern].resolved && deepEqual(manifest.prebuiltVariants, lockfileBasedOnResolver[pattern].prebuiltVariants); |
| 7289 | }); |
| 7290 | const integrityPatternsAreSameAsInLockfile = Object.keys(lockfileBasedOnResolver).every(function (pattern) { |
| 7291 | const existingIntegrityInfo = lockfileBasedOnResolver[pattern].integrity; |
| 7292 | if (!existingIntegrityInfo) { |
| 7293 | // if this entry does not have an integrity, no need to re-write the lockfile because of it |
| 7294 | return true; |
| 7295 | } |
| 7296 | const manifest = _this11.lockfile.getLocked(pattern); |
| 7297 | if (manifest && manifest.integrity) { |
| 7298 | const manifestIntegrity = ssri.stringify(manifest.integrity); |
| 7299 | return manifestIntegrity === existingIntegrityInfo; |
| 7300 | } |
| 7301 | return false; |
| 7302 | }); |
| 7303 | |
| 7304 | // remove command is followed by install with force, lockfile will be rewritten in any case then |
| 7305 | if (!_this11.flags.force && _this11.lockfile.parseResultType === 'success' && lockFileHasAllPatterns && lockfilePatternsMatch && resolverPatternsAreSameAsInLockfile && integrityPatternsAreSameAsInLockfile && patterns.length) { |
no test coverage detected