From 7fc1207683568a23b162050e674383c8ee919e7d Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Wed, 17 Jul 2019 09:13:07 +0200 Subject: [PATCH] feat(yarn): support yarn offline mirror (#4102) Look for .yarnrc in same directory as yarn.lock. If found, look for yarn-offine-mirror line and check that folder for changes. Closes #1452 --- lib/manager/npm/post-update/index.js | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/manager/npm/post-update/index.js b/lib/manager/npm/post-update/index.js index 97a62370af..bde075d86d 100644 --- a/lib/manager/npm/post-update/index.js +++ b/lib/manager/npm/post-update/index.js @@ -482,6 +482,45 @@ async function getAdditionalFiles(config, packageFiles) { name: lockFileName, contents: res.lockFile, }); + // istanbul ignore next + try { + const yarnrc = await platform.getFile( + upath.join(lockFileDir, '.yarnrc') + ); + if (yarnrc) { + const mirrorLine = yarnrc + .split('\n') + .find(line => line.startsWith('yarn-offline-mirror ')); + if (mirrorLine) { + const mirrorPath = mirrorLine + .split(' ')[1] + .replace(/"/g, '') + .replace(/\/?$/, '/'); + const resolvedPath = upath.join(lockFileDir, mirrorPath); + logger.info('Found yarn offline mirror: ' + resolvedPath); + const status = await platform.getRepoStatus(); + for (const f of status.modified.concat(status.not_added)) { + if (f.startsWith(resolvedPath)) { + const localModified = upath.join(config.localDir, f); + updatedArtifacts.push({ + name: f, + contents: await fs.readFile(localModified, 'utf8'), + }); + } + } + for (const f of status.deleted || []) { + if (f.startsWith(resolvedPath)) { + updatedArtifacts.push({ + name: '|delete|', + contents: f, + }); + } + } + } + } + } catch (err) { + logger.error({ err }, 'Error updating yarn offline packages'); + } } else { logger.debug("yarn.lock hasn't changed"); } -- GitLab