Skip to content

Commit

Permalink
fix(install): Use the current working directory instead of the instal…
Browse files Browse the repository at this point in the history
…led directory when finding package.json (Fixes #234)
  • Loading branch information
TimothyJones committed Feb 9, 2021
1 parent 495b943 commit 30c41dc
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions standalone/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,14 @@ function throwError(msg: string): never {
throw new Error(chalk.red(`Error while installing binary: ${msg}`));
}

function getBinaryLocation(
location: string,
basePath: string,
): string | undefined {
function getBinaryLocation(location: string): string | undefined {
// Check if location is valid and is a string
if (!location || location.length === 0) {
return undefined;
}

// Check if it's a URL, if not, try to resolve the path to work with either absolute or relative paths
return HTTP_REGEX.test(location)
? location
: path.resolve(basePath, location);
return HTTP_REGEX.test(location) ? location : path.resolve(location);
}

function findPackageConfig(location: string, tries = 10): PackageConfig {
Expand All @@ -59,10 +54,7 @@ function findPackageConfig(location: string, tries = 10): PackageConfig {
const config = require(packagePath).config;
if (config && (config.pact_binary_location || config.pact_do_not_track)) {
return {
binaryLocation: getBinaryLocation(
config.pact_binary_location,
location,
),
binaryLocation: getBinaryLocation(config.pact_binary_location),
doNotTrack: config.pact_do_not_track,
};
}
Expand All @@ -72,7 +64,7 @@ function findPackageConfig(location: string, tries = 10): PackageConfig {
}

export function createConfig(): Config {
const packageConfig = findPackageConfig(path.resolve(__dirname, '..', '..'));
const packageConfig = findPackageConfig(process.cwd());
const PACT_BINARY_LOCATION =
packageConfig.binaryLocation || PACT_DEFAULT_LOCATION;
const CHECKSUM_SUFFIX = '.checksum';
Expand Down

0 comments on commit 30c41dc

Please sign in to comment.