Skip to content

Commit 13bbe5d

Browse files
asambstackfrancisf
authored andcommitted
chore: add support for reading .npmrc file during NPM package creation
1 parent 98fb24c commit 13bbe5d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

bin/helpers/packageInstaller.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
{ get_version } = require('./usageReporting'),
1010
process = require('process'),
1111
{ spawn } = require('child_process'),
12+
cliUtils = require("./utils"),
1213
util = require('util');
1314

1415
let nodeProcess;
@@ -58,7 +59,7 @@ const setupPackageFolder = (runSettings, directoryPath) => {
5859
})
5960
};
6061

61-
const packageInstall = (packageDir) => {
62+
const packageInstall = (packageDir, bsConfig) => {
6263
return new Promise(function (resolve, reject) {
6364
const nodeProcessCloseCallback = (code) => {
6465
if(code == 0) {
@@ -74,6 +75,16 @@ const packageInstall = (packageDir) => {
7475
reject(`Packages were not installed successfully. Error Description ${util.format('%j', error)}`);
7576
};
7677

78+
// Moving .npmrc to tmpBstackPackages
79+
try {
80+
logger.debug(`Copying .npmrc file to temporary package directory`);
81+
const npmrcRootPath = path.join(cliUtils.isNotUndefined(bsConfig.run_settings.home_directory) ? path.resolve(bsConfig.run_settings.home_directory) : './', '.npmrc');
82+
const npmrcTmpPath = path.join(path.resolve(packageDir), '.npmrc');
83+
fs.copyFileSync(npmrcRootPath, npmrcTmpPath);
84+
} catch (error) {
85+
logger.debug(`Failed copying .npmrc to ${packageDir}: ${error}`)
86+
}
87+
7788
let nodeProcess;
7889
logger.debug(`Fetching npm version and its major version`);
7990
const npm_version = get_version('npm')
@@ -147,7 +158,7 @@ const packageSetupAndInstaller = (bsConfig, packageDir, instrumentBlocks) => {
147158
instrumentBlocks.markBlockEnd("packageInstaller.folderSetup");
148159
instrumentBlocks.markBlockStart("packageInstaller.packageInstall");
149160
logger.debug("Started installing dependencies specified in browserstack.json");
150-
return packageInstall(packageDir);
161+
return packageInstall(packageDir, bsConfig);
151162
}).then((_result) => {
152163
logger.debug("Completed installing dependencies");
153164
instrumentBlocks.markBlockEnd("packageInstaller.packageInstall");

0 commit comments

Comments
 (0)