* The `_removeLinks` method removes from the dependencies of the manifest the * assets which will be linked in so that we don't duplicate install. It saves * off the values in the internal `PackageCache` metadata for restoration after * linking as those values may be necessary. * * It
(label, type)
| 355 | * @param {String} type The type of package cache. |
| 356 | */ |
| 357 | _removeLinks(label, type) { |
| 358 | let cachedManifest = this._readManifest(label, type); |
| 359 | if (!cachedManifest) { |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | let jsonManifest = JSON.parse(cachedManifest); |
| 364 | let links = jsonManifest._packageCache.links; |
| 365 | |
| 366 | // Blindly remove existing links whether or not they appear in the manifest. |
| 367 | let link, linkPath; |
| 368 | for (let i = 0; i < links.length; i++) { |
| 369 | link = links[i]; |
| 370 | if (typeof link === 'string') { |
| 371 | commands[type].invoke('unlink', link, { cwd: this.dirs[label] }); |
| 372 | } else { |
| 373 | linkPath = path.join(this.dirs[label], translate(type, 'path'), link.name); |
| 374 | try { |
| 375 | fs.removeSync(linkPath); |
| 376 | } catch (error) { |
| 377 | // Catch unexceptional error but rethrow if something is truly wrong. |
| 378 | if (error.code !== 'ENOENT') { |
| 379 | throw error; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | // Remove things from the manifest which we know we'll link back in. |
| 386 | let originals = {}; |
| 387 | let key, linkName; |
| 388 | for (let i = 0; i < DEPENDENCY_KEYS.length; i++) { |
| 389 | key = DEPENDENCY_KEYS[i]; |
| 390 | if (jsonManifest[key]) { |
| 391 | // Get a clone of the original object. |
| 392 | originals[key] = JSON.parse(JSON.stringify(jsonManifest[key])); |
| 393 | } |
| 394 | for (let j = 0; j < links.length; j++) { |
| 395 | link = links[j]; |
| 396 | |
| 397 | // Support object-style invocation for "manual" linking. |
| 398 | if (typeof link === 'string') { |
| 399 | linkName = link; |
| 400 | } else { |
| 401 | linkName = link.name; |
| 402 | } |
| 403 | |
| 404 | if (jsonManifest[key] && jsonManifest[key][linkName]) { |
| 405 | delete jsonManifest[key][linkName]; |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | jsonManifest._packageCache.originals = originals; |
| 411 | let manifest = JSON.stringify(jsonManifest); |
| 412 | |
| 413 | this._writeManifest(label, type, manifest); |
| 414 | } |
no test coverage detected