diff --git a/bin/helpers/packageInstaller.js b/bin/helpers/packageInstaller.js index 1cdc3ea4..a3f71fbe 100644 --- a/bin/helpers/packageInstaller.js +++ b/bin/helpers/packageInstaller.js @@ -9,6 +9,7 @@ { get_version } = require('./usageReporting'), process = require('process'), { spawn } = require('child_process'), + cliUtils = require("./utils"), util = require('util'); let nodeProcess; @@ -58,7 +59,7 @@ const setupPackageFolder = (runSettings, directoryPath) => { }) }; -const packageInstall = (packageDir) => { +const packageInstall = (packageDir, bsConfig) => { return new Promise(function (resolve, reject) { const nodeProcessCloseCallback = (code) => { if(code == 0) { @@ -74,6 +75,16 @@ const packageInstall = (packageDir) => { reject(`Packages were not installed successfully. Error Description ${util.format('%j', error)}`); }; + // Moving .npmrc to tmpBstackPackages + try { + logger.debug(`Copying .npmrc file to temporary package directory`); + const npmrcRootPath = path.join(cliUtils.isNotUndefined(bsConfig.run_settings.home_directory) ? path.resolve(bsConfig.run_settings.home_directory) : './', '.npmrc'); + const npmrcTmpPath = path.join(path.resolve(packageDir), '.npmrc'); + fs.copyFileSync(npmrcRootPath, npmrcTmpPath); + } catch (error) { + logger.debug(`Failed copying .npmrc to ${packageDir}: ${error}`) + } + let nodeProcess; logger.debug(`Fetching npm version and its major version`); const npm_version = get_version('npm') @@ -147,7 +158,7 @@ const packageSetupAndInstaller = (bsConfig, packageDir, instrumentBlocks) => { instrumentBlocks.markBlockEnd("packageInstaller.folderSetup"); instrumentBlocks.markBlockStart("packageInstaller.packageInstall"); logger.debug("Started installing dependencies specified in browserstack.json"); - return packageInstall(packageDir); + return packageInstall(packageDir, bsConfig); }).then((_result) => { logger.debug("Completed installing dependencies"); instrumentBlocks.markBlockEnd("packageInstaller.packageInstall");