Skip to content

Commit 30709cc

Browse files
committed
fix: define workspace module path
1 parent ba94f31 commit 30709cc

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

bin/testObservability/helper/helper.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,8 @@ exports.getOSDetailsFromSystem = async (product) => {
723723
};
724724
}
725725

726+
let WORKSPACE_MODULE_PATH;
727+
726728
exports.requireModule = (module) => {
727729
const modulePath = exports.resolveModule(module, _package);
728730
if (modulePath.error) {
@@ -737,6 +739,15 @@ exports.resolveModule = (module) => {
737739
throw new Error('Invalid module name');
738740
}
739741

742+
if (WORKSPACE_MODULE_PATH == undefined) {
743+
try {
744+
WORKSPACE_MODULE_PATH = execSync('npm ls').toString().trim();
745+
WORKSPACE_MODULE_PATH = WORKSPACE_MODULE_PATH.split('\n')[0].split(' ')[1];
746+
} catch (e) {
747+
WORKSPACE_MODULE_PATH = null;
748+
logger.debug('Could not locate npm module path with error ', e);
749+
}
750+
}
740751

741752
/*
742753
Modules will be resolved in the following order,
@@ -750,12 +761,7 @@ exports.resolveModule = (module) => {
750761
} catch (_) {
751762
/* Find from current working directory */
752763
exports.debug(`Getting ${module} from ${process.cwd()}`);
753-
let local_path = '';
754-
if (process.env['browserStackCwd']) {
755-
local_path = path.join(process.env['browserStackCwd'], 'node_modules', module);
756-
} else {
757-
local_path = path.join(process.cwd(), 'node_modules', module);
758-
}
764+
let local_path = path.join(process.cwd(), 'node_modules', module);
759765
if (!fs.existsSync(local_path)) {
760766
exports.debug(`${module} doesn't exist at ${process.cwd()}`);
761767

0 commit comments

Comments
 (0)