diff --git a/lib/manager/npm/monorepos.js b/lib/manager/npm/monorepos.js index 1d44cf3cad102b517a4cb46e70ba940f9b8fd92c..b01f243ad0ec4bc757f391830a01b0007e660456 100644 --- a/lib/manager/npm/monorepos.js +++ b/lib/manager/npm/monorepos.js @@ -1,5 +1,6 @@ const minimatch = require('minimatch'); const path = require('path'); +const upath = require('upath'); module.exports = { checkMonorepos, @@ -25,7 +26,7 @@ async function checkMonorepos(config) { logger.debug({ workspaces }, 'Found yarn workspaces'); } for (const workspace of workspaces) { - const basePath = path.join(workspaceDir, workspace); + const basePath = upath.join(workspaceDir, workspace); logger.info(`basePath=${basePath}`); for (const packageFile of config.packageFiles) { if (minimatch(path.dirname(packageFile.packageFile), basePath)) { diff --git a/lib/manager/resolve.js b/lib/manager/resolve.js index 73e72099c07475b4816aef10a8411159eb552752..c7f74a42c38b5aaa78bf692a3389a09ed56b74e0 100644 --- a/lib/manager/resolve.js +++ b/lib/manager/resolve.js @@ -1,4 +1,5 @@ const path = require('path'); +const upath = require('upath'); const { migrateAndValidate } = require('../config/migrate-validate'); const presets = require('../config/presets'); @@ -50,14 +51,14 @@ async function resolvePackageFiles(config) { } if (!config.ignoreNpmrcFile) { packageFile.npmrc = await platform.getFile( - path.join(path.dirname(packageFile.packageFile), '.npmrc') + upath.join(path.dirname(packageFile.packageFile), '.npmrc') ); } if (!packageFile.npmrc) { delete packageFile.npmrc; } packageFile.yarnrc = await platform.getFile( - path.join(path.dirname(packageFile.packageFile), '.yarnrc') + upath.join(path.dirname(packageFile.packageFile), '.yarnrc') ); if (!packageFile.yarnrc) { delete packageFile.yarnrc; @@ -95,7 +96,7 @@ async function resolvePackageFiles(config) { ); } // Detect if lock files are used - const yarnLockFileName = path.join( + const yarnLockFileName = upath.join( path.dirname(packageFile.packageFile), 'yarn.lock' ); @@ -106,7 +107,7 @@ async function resolvePackageFiles(config) { ); packageFile.yarnLock = yarnLockFileName; } - const packageLockFileName = path.join( + const packageLockFileName = upath.join( path.dirname(packageFile.packageFile), 'package-lock.json' ); diff --git a/lib/workers/branch/lock-files.js b/lib/workers/branch/lock-files.js index d5808c462caf2c445bbc5a574e40d14663c04278..6828ff0cba1c34c83f5f38d48b393f198c73f880 100644 --- a/lib/workers/branch/lock-files.js +++ b/lib/workers/branch/lock-files.js @@ -1,5 +1,6 @@ const fs = require('fs-extra'); const path = require('path'); +const upath = require('upath'); const npm = require('./npm'); const yarn = require('./yarn'); @@ -92,12 +93,12 @@ function determineLockFileDirs(config) { async function writeExistingFiles(config) { if (config.npmrc) { logger.debug('Writing repo .npmrc'); - await fs.outputFile(path.join(config.tmpDir.path, '.npmrc'), config.npmrc); + await fs.outputFile(upath.join(config.tmpDir.path, '.npmrc'), config.npmrc); } if (config.yarnrc) { logger.debug('Writing repo .yarnrc'); await fs.outputFile( - path.join(config.tmpDir.path, '.yarnrc'), + upath.join(config.tmpDir.path, '.yarnrc'), config.yarnrc ); } @@ -105,7 +106,7 @@ async function writeExistingFiles(config) { return; } for (const packageFile of config.packageFiles) { - const basedir = path.join( + const basedir = upath.join( config.tmpDir.path, path.dirname(packageFile.packageFile) ); @@ -119,40 +120,43 @@ async function writeExistingFiles(config) { delete massagedFile.engines; delete massagedFile.scripts; await fs.outputFile( - path.join(basedir, 'package.json'), + upath.join(basedir, 'package.json'), JSON.stringify(massagedFile) ); } if (packageFile.npmrc) { logger.debug(`Writing .npmrc to ${basedir}`); - await fs.outputFile(path.join(basedir, '.npmrc'), packageFile.npmrc); + await fs.outputFile(upath.join(basedir, '.npmrc'), packageFile.npmrc); } else if ( config.npmrc && (packageFile.hasYarnLock || packageFile.hasPackageLock) ) { logger.debug('Writing repo .npmrc to package file dir'); - await fs.outputFile(path.join(basedir, '.npmrc'), config.npmrc); + await fs.outputFile(upath.join(basedir, '.npmrc'), config.npmrc); } if (packageFile.yarnrc) { logger.debug(`Writing .yarnrc to ${basedir}`); await fs.outputFile( - path.join(basedir, '.yarnrc'), + upath.join(basedir, '.yarnrc'), packageFile.yarnrc.replace('--install.pure-lockfile true', '') ); } if (packageFile.packageLock && config.type !== 'lockFileMaintenance') { logger.debug(`Writing package-lock.json to ${basedir}`); const packageLock = await platform.getFile(packageFile.packageLock); - await fs.outputFile(path.join(basedir, 'package-lock.json'), packageLock); + await fs.outputFile( + upath.join(basedir, 'package-lock.json'), + packageLock + ); } else { - await fs.remove(path.join(basedir, 'package-lock.json')); + await fs.remove(upath.join(basedir, 'package-lock.json')); } if (packageFile.yarnLock && config.type !== 'lockFileMaintenance') { logger.debug(`Writing yarn.lock to ${basedir}`); const yarnLock = await platform.getFile(packageFile.yarnLock); - await fs.outputFile(path.join(basedir, 'yarn.lock'), yarnLock); + await fs.outputFile(upath.join(basedir, 'yarn.lock'), yarnLock); } else { - await fs.remove(path.join(basedir, 'yarn.lock')); + await fs.remove(upath.join(basedir, 'yarn.lock')); } } } @@ -176,7 +180,7 @@ async function writeUpdatedPackageFiles(config) { delete massagedFile.engines; delete massagedFile.scripts; await fs.outputFile( - path.join(config.tmpDir.path, packageFile.name), + upath.join(config.tmpDir.path, packageFile.name), JSON.stringify(massagedFile) ); } @@ -200,9 +204,9 @@ async function getUpdatedLockFiles(config) { for (const lockFileDir of dirs.packageLockFileDirs) { logger.debug(`Generating package-lock.json for ${lockFileDir}`); - const lockFileName = path.join(lockFileDir, 'package-lock.json'); + const lockFileName = upath.join(lockFileDir, 'package-lock.json'); const res = await npm.generateLockFile( - path.join(config.tmpDir.path, lockFileDir) + upath.join(config.tmpDir.path, lockFileDir) ); if (res.error) { lockFileErrors.push({ @@ -228,9 +232,9 @@ async function getUpdatedLockFiles(config) { for (const lockFileDir of dirs.yarnLockFileDirs) { logger.debug(`Generating yarn.lock for ${lockFileDir}`); - const lockFileName = path.join(lockFileDir, 'yarn.lock'); + const lockFileName = upath.join(lockFileDir, 'yarn.lock'); const res = await yarn.generateLockFile( - path.join(config.tmpDir.path, lockFileDir) + upath.join(config.tmpDir.path, lockFileDir) ); if (res.error) { lockFileErrors.push({ diff --git a/lib/workers/branch/npm.js b/lib/workers/branch/npm.js index 9e11daec9260f0a565bcc6983f7d30a95f619e8a..7f7b572f69acc9ee0a63636bc084669fab419047 100644 --- a/lib/workers/branch/npm.js +++ b/lib/workers/branch/npm.js @@ -1,5 +1,5 @@ const fs = require('fs-extra'); -const path = require('path'); +const upath = require('upath'); const { getInstalledPath } = require('get-installed-path'); const { exec } = require('child-process-promise'); @@ -17,7 +17,7 @@ async function generateLockFile(tmpDir) { let cmd; try { // See if renovate is installed locally - const installedPath = path.join( + const installedPath = upath.join( await getInstalledPath('npm', { local: true, }), @@ -29,7 +29,7 @@ async function generateLockFile(tmpDir) { // Look inside globally installed renovate try { const renovateLocation = await getInstalledPath('renovate'); - const installedPath = path.join( + const installedPath = upath.join( await getInstalledPath('npm', { local: true, cwd: renovateLocation, @@ -41,7 +41,7 @@ async function generateLockFile(tmpDir) { logger.debug('Could not find globally nested npm'); // look for global npm try { - const installedPath = path.join( + const installedPath = upath.join( await getInstalledPath('npm'), 'bin/npm-cli.js' ); @@ -66,7 +66,7 @@ async function generateLockFile(tmpDir) { const duration = process.hrtime(startTime); const seconds = Math.round(duration[0] + duration[1] / 1e9); lockFile = await fs.readFile( - path.join(tmpDir, 'package-lock.json'), + upath.join(tmpDir, 'package-lock.json'), 'utf8' ); logger.info( diff --git a/lib/workers/branch/yarn.js b/lib/workers/branch/yarn.js index a6cc44c88b4828811e8054efb43e99727d26cfe7..e7b9f1ae804fd36c50ceb7e0105506e950b85703 100644 --- a/lib/workers/branch/yarn.js +++ b/lib/workers/branch/yarn.js @@ -1,5 +1,5 @@ const fs = require('fs-extra'); -const path = require('path'); +const upath = require('upath'); const { getInstalledPath } = require('get-installed-path'); const { exec } = require('child-process-promise'); @@ -17,7 +17,7 @@ async function generateLockFile(tmpDir) { let cmd; try { // See if renovate is installed locally - const installedPath = path.join( + const installedPath = upath.join( await getInstalledPath('yarn', { local: true, }), @@ -29,7 +29,7 @@ async function generateLockFile(tmpDir) { // Look inside globally installed renovate try { const renovateLocation = await getInstalledPath('renovate'); - const installedPath = path.join( + const installedPath = upath.join( await getInstalledPath('yarn', { local: true, cwd: renovateLocation, @@ -41,7 +41,7 @@ async function generateLockFile(tmpDir) { logger.debug('Could not find globally nested yarn'); // look for global yarn try { - const installedPath = path.join( + const installedPath = upath.join( await getInstalledPath('yarn'), 'bin/yarn.js' ); @@ -66,7 +66,7 @@ async function generateLockFile(tmpDir) { logger.debug(`yarn stderr:\n${stderr}`); const duration = process.hrtime(startTime); const seconds = Math.round(duration[0] + duration[1] / 1e9); - lockFile = await fs.readFile(path.join(tmpDir, 'yarn.lock'), 'utf8'); + lockFile = await fs.readFile(upath.join(tmpDir, 'yarn.lock'), 'utf8'); logger.info( { seconds, type: 'yarn.lock', stdout, stderr }, 'Generated lockfile' diff --git a/package.json b/package.json index 31156792d1f0d735d285536c4f8c5c25c1ba2cf3..96239e645f8f2002a038f1637bccb5509162ac84 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "showdown": "1.8.2", "tmp-promise": "1.0.4", "traverse": "0.6.6", + "upath": "true1.0.2", "vso-node-api": "6.2.8-preview", "yarn": "1.3.2" }, diff --git a/yarn.lock b/yarn.lock index 896bc52d9a14d0408c9c63380d74f3a0f988616e..4f1a02c09e60394d6bd2f9cd47fa85ee80628f76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3163,6 +3163,10 @@ lodash.cond@^4.3.0: version "4.5.2" resolved "https://registry.yarnpkg.com/lodash.cond/-/lodash.cond-4.5.2.tgz#f471a1da486be60f6ab955d17115523dd1d255d5" +lodash.endswith@^4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/lodash.endswith/-/lodash.endswith-4.2.1.tgz#fed59ac1738ed3e236edd7064ec456448b37bc09" + lodash.escape@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/lodash.escape/-/lodash.escape-3.2.0.tgz#995ee0dc18c1b48cc92effae71a10aab5b487698" @@ -3185,6 +3189,10 @@ lodash.isboolean@^3.0.3: version "3.0.3" resolved "https://registry.yarnpkg.com/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6" +lodash.isfunction@^3.0.8: + version "3.0.8" + resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.8.tgz#4db709fc81bc4a8fd7127a458a5346c5cdce2c6b" + lodash.isinteger@^4.0.4: version "4.0.4" resolved "https://registry.yarnpkg.com/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz#619c0af3d03f8b04c31f5882840b77b11cd68343" @@ -3217,6 +3225,10 @@ lodash.restparam@^3.0.0: version "3.6.1" resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" +lodash.startswith@^4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/lodash.startswith/-/lodash.startswith-4.2.1.tgz#c598c4adce188a27e53145731cdc6c0e7177600c" + lodash.template@^3.6.1: version "3.6.2" resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-3.6.2.tgz#f8cdecc6169a255be9098ae8b0c53d378931d14f" @@ -5343,6 +5355,15 @@ unzip-response@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97" +upath@true1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/upath/-/upath-1.0.2.tgz#80aaae5395abc5fd402933ae2f58694f0860204c" + dependencies: + lodash.endswith "^4.2.1" + lodash.isfunction "^3.0.8" + lodash.isstring "^4.0.1" + lodash.startswith "^4.2.1" + update-notifier@^2.2.0: version "2.3.0" resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-2.3.0.tgz#4e8827a6bb915140ab093559d7014e3ebb837451"