Skip to content

Commit

Permalink
fix: config aggregator show changes to local and global config
Browse files Browse the repository at this point in the history
  • Loading branch information
amphro committed Nov 10, 2020
1 parent 52be813 commit e3b3a55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
17 changes: 5 additions & 12 deletions src/config/configAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class ConfigAggregator extends AsyncOptionalCreatable<JsonMap> {
private localConfig!: Config;
private globalConfig!: Config;
private envVars!: Dictionary<string>;
private config!: JsonMap;
private get config(): JsonMap {
return this.resolveProperties(this.globalConfig.getContents(), this.localConfig.getContents());
}
/**
* **Do not directly construct instances of this class -- use {@link ConfigAggregator.create} instead.**
*
Expand Down Expand Up @@ -297,7 +299,7 @@ export class ConfigAggregator extends AsyncOptionalCreatable<JsonMap> {
this.resolveProperties(this.globalConfig.readSync(), this.localConfig && this.localConfig.readSync());
}

private resolveProperties(globalConfig: JsonMap, localConfig?: JsonMap): void {
private resolveProperties(globalConfig: JsonMap, localConfig?: JsonMap): JsonMap {
const accumulator: Dictionary<string> = {};
this.setEnvVars(
this.getAllowedProperties().reduce((obj, property) => {
Expand All @@ -323,16 +325,7 @@ export class ConfigAggregator extends AsyncOptionalCreatable<JsonMap> {

const json: JsonMap = {};
const reduced = configs.filter(isJsonMap).reduce((acc: JsonMap, el: AnyJson) => merge(acc, el), json);
this.setConfig(reduced);
}

/**
* Set the resolved config object.
*
* @param config The config object to set.
*/
private setConfig(config: JsonMap) {
this.config = config;
return reduced;
}

/**
Expand Down
13 changes: 10 additions & 3 deletions src/sfdxProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export class SfdxProjectJson extends ConfigFile<ConfigFile.Options> {
await validator.load();
await validator.validate(this.getContents());
} catch (err) {
if (env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false)) {
// Don't throw errors if the global isn't valid, but still warn the user.
if (env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false) && !this.options.isGlobal) {
err.name = 'SfdxSchemaValidationError';
const sfdxError = SfdxError.wrap(err);
sfdxError.actions = [this.messages.getMessage('SchemaValidationErrorAction', [this.getPath()])];
Expand Down Expand Up @@ -198,7 +199,8 @@ export class SfdxProjectJson extends ConfigFile<ConfigFile.Options> {
validator.loadSync();
validator.validateSync(this.getContents());
} catch (err) {
if (env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false)) {
// Don't throw errors if the global isn't valid, but still warn the user.
if (env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false) && !this.options.isGlobal) {
err.name = 'SfdxSchemaValidationError';
const sfdxError = SfdxError.wrap(err);
sfdxError.actions = [this.messages.getMessage('SchemaValidationErrorAction', [this.getPath()])];
Expand Down Expand Up @@ -248,7 +250,9 @@ export class SfdxProjectJson extends ConfigFile<ConfigFile.Options> {

const defaultDirs = packageDirs.filter((packageDir) => packageDir.default);

if (defaultDirs.length === 0) {
// Don't throw about a missing default path if we are in the global file.
// Package directories are not really meant to be set at the global level.
if (defaultDirs.length === 0 && !this.isGlobal()) {
throw new SfdxError(this.messages.getMessage('MissingDefaultPath'));
} else if (defaultDirs.length > 1) {
throw new SfdxError(this.messages.getMessage('MultipleDefaultPaths'));
Expand Down Expand Up @@ -603,6 +607,9 @@ export class SfdxProject {
* {@link ConfigAggregator}, and a set of defaults. It is recommended to use
* this when reading values from SfdxProjectJson.
*
* The global {@link SfdxProjectJson} is used to allow the user to provide default values they
* may not want checked into their project's source.
*
* @returns A resolved config object that contains a bunch of different
* properties, including some 3rd party custom properties.
*/
Expand Down

0 comments on commit e3b3a55

Please sign in to comment.