Skip to content

Commit

Permalink
chore: add support for reading .npmrc file during NPM package creation
Browse files Browse the repository at this point in the history
  • Loading branch information
asambstack authored and francisf committed Jul 22, 2024
1 parent 98fb24c commit 13bbe5d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions bin/helpers/packageInstaller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{ get_version } = require('./usageReporting'),
process = require('process'),
{ spawn } = require('child_process'),
cliUtils = require("./utils"),
util = require('util');

let nodeProcess;
Expand Down Expand Up @@ -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) {
Expand All @@ -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')
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 13bbe5d

Please sign in to comment.