Skip to content

Commit

Permalink
Merge pull request #867 from browserstack/cypress_split_mac_win_npm
Browse files Browse the repository at this point in the history
Add changes for splitting mac and win config
  • Loading branch information
pranavj1001 authored Sep 13, 2024
2 parents 8c975cb + 69bb193 commit 1a979b9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
25 changes: 23 additions & 2 deletions bin/helpers/archiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,30 @@ const archiveSpecs = (runSettings, filePath, excludeFiles, md5data) => {
});
}

// Split mac and win configs
let macPackageJSON = {};
let winPackageJSON = {};
Object.assign(macPackageJSON, packageJSON);
Object.assign(winPackageJSON, packageJSON);

if (typeof runSettings.npm_dependencies === 'object') {
let macNpmDependencies = Object.assign({}, runSettings.npm_dependencies, runSettings.mac_npm_dependencies || {});
let winNpmDependencies = Object.assign({}, runSettings.npm_dependencies, runSettings.win_npm_dependencies || {});

Object.assign(macPackageJSON, {
devDependencies: macNpmDependencies,
});

Object.assign(winPackageJSON, {
devDependencies: winNpmDependencies,
});
}

if (Object.keys(packageJSON).length > 0) {
let packageJSONString = JSON.stringify(packageJSON, null, 4);
archive.append(packageJSONString, {name: `${cypressAppendFilesZipLocation}browserstack-package.json`});
const macPackageJSONString = JSON.stringify(macPackageJSON, null, 4);
const winPackageJSONString = JSON.stringify(winPackageJSON, null, 4);
archive.append(macPackageJSONString, {name: `${cypressAppendFilesZipLocation}browserstack-mac-package.json`});
archive.append(winPackageJSONString, {name: `${cypressAppendFilesZipLocation}browserstack-win-package.json`});
}

//Create copy of package.json
Expand Down
3 changes: 2 additions & 1 deletion bin/helpers/checkUploaded.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const request = require('request');
const { combineMacWinNpmDependencies } = require('./helper');

const crypto = require('crypto'),
Constants = require('./constants'),
Expand Down Expand Up @@ -59,7 +60,7 @@ const checkPackageMd5 = (runSettings) => {

if (typeof runSettings.npm_dependencies === 'object') {
Object.assign(packageJSON, {
devDependencies: utils.sortJsonKeys(runSettings.npm_dependencies),
devDependencies: utils.sortJsonKeys(combineMacWinNpmDependencies(runSettings)),
});
}

Expand Down
4 changes: 4 additions & 0 deletions bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,11 @@ const filesToIgnoreWhileUploading = [
"package.json",
"**/package.json",
"browserstack-package.json",
"browserstack-mac-package.json",
"browserstack-win-package.json",
"**/browserstack-package.json",
"**/browserstack-mac-package.json",
"**/browserstack-win-package.json",
"tests.zip",
"**/tests.zip",
"cypress.json",
Expand Down
4 changes: 4 additions & 0 deletions bin/helpers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,7 @@ exports.truncateString = (field, truncateSizeInBytes) => {

return field;
};

exports.combineMacWinNpmDependencies = (runSettings) => {
return Object.assign({}, runSettings.npm_dependencies, runSettings.win_npm_dependencies || {}, runSettings.mac_npm_dependencies || {})
};
5 changes: 4 additions & 1 deletion bin/helpers/packageInstaller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
cliUtils = require("./utils"),
util = require('util');

const { combineMacWinNpmDependencies } = require("./helper");

let nodeProcess;

const setupPackageFolder = (runSettings, directoryPath) => {
Expand All @@ -29,9 +31,10 @@ const setupPackageFolder = (runSettings, directoryPath) => {
Object.assign(packageJSON, runSettings.package_config_options);
}

// Combine win and mac specific dependencies if present
if (typeof runSettings.npm_dependencies === 'object') {
Object.assign(packageJSON, {
devDependencies: runSettings.npm_dependencies,
devDependencies: combineMacWinNpmDependencies(runSettings),
});
}

Expand Down
10 changes: 10 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ exports.setDefaults = (bsConfig, args) => {
bsConfig.run_settings.npm_dependencies = {}
}

// setting win_npm_dependencies to {} if not present
if (bsConfig.run_settings && this.isUndefined(bsConfig.run_settings.win_npm_dependencies)) {
bsConfig.run_settings.win_npm_dependencies = {}
}

// setting mac_npm_dependencies to {} if not present
if (bsConfig.run_settings && this.isUndefined(bsConfig.run_settings.mac_npm_dependencies)) {
bsConfig.run_settings.mac_npm_dependencies = {}
}

// setting connection_settings to {} if not present
if (this.isUndefined(bsConfig.connection_settings)) {
bsConfig.connection_settings = {};
Expand Down

0 comments on commit 1a979b9

Please sign in to comment.