Skip to content

Commit

Permalink
chore: change env var name and getContents override
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed May 27, 2020
1 parent 5d017b1 commit 917242a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
8 changes: 4 additions & 4 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Pre-requisites

1. We are using Node 12. If you need to work with multiple versions of Node, you
1. We are using Node 10 LTS. If you need to work with multiple versions of Node, you
might consider using [nvm](https://github.com/creationix/nvm).
1. This repository uses [yarn](https://yarnpkg.com/) to manage node dependencies. Please install yarn globally using `npm install --global yarn`.

Expand Down Expand Up @@ -28,7 +28,7 @@ This compiles the typescript to javascript.

### `yarn clean`

This cleans all generated files and directories. Run `yarn cleal-all` will also clean up the node_module directories.
This cleans all generated files and directories. Run `yarn clean-all` to also clean up the node_module directories.

### `yarn test`

Expand All @@ -37,9 +37,9 @@ This tests the typescript using ts-node.
### `yarn lint`

This lints all the typescript. If there are no errors/warnings
from tslint, then you get a clean output. But, if they are errors from tslint,
from tslint, then you get clean output. But, if there are errors from tslint,
you will see a long error that can be confusing – just focus on the tslint
errors. The results of this is deeper than what the tslint extension in VS Code
errors. The results of this are deeper than what the tslint extension in VS Code
does because of [semantic lint
rules](https://palantir.github.io/tslint/usage/type-checking/) which requires a
tsconfig.json to be passed to tslint.
24 changes: 14 additions & 10 deletions src/sfdxProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { resolveProjectPath, SFDX_PROJECT_JSON } from './util/internal';
import { SfdxError } from './sfdxError';
import { sfdc } from './util/sfdc';

export interface PackageDirDependency {
export type PackageDirDependency = {
package: string;
versionNumber?: string;
[k: string]: unknown;
}
};

export interface PackageDir {
export type PackageDir = {
ancestorId?: string;
ancestorVersion?: string;
default?: boolean;
Expand All @@ -40,9 +40,9 @@ export interface PackageDir {
versionDescription?: string;
versionName?: string;
versionNumber?: string;
}
};

export interface ProjectJson {
export type ProjectJson = ConfigContents & {
packageDirectories: PackageDir[];
namespace?: string;
sourceApiVersion?: string;
Expand All @@ -51,7 +51,7 @@ export interface ProjectJson {
oauthLocalPort?: number;
plugins?: { [k: string]: unknown };
packageAliases?: { [k: string]: string };
}
};

/**
* The sfdx-project.json config object. This file determines if a folder is a valid sfdx project.
Expand Down Expand Up @@ -112,6 +112,10 @@ export class SfdxProjectJson extends ConfigFile<ConfigFile.Options> {
return super.write(newContents);
}

public getContents(): ProjectJson {
return super.getContents() as ProjectJson;
}

public getDefaultOptions(options?: ConfigFile.Options): ConfigFile.Options {
const defaultOptions: ConfigFile.Options = {
isState: false
Expand All @@ -124,8 +128,8 @@ export class SfdxProjectJson extends ConfigFile<ConfigFile.Options> {
/**
* Validates sfdx-project.json against the schema.
*
* Set the `SFDX_SCHEMA_VALIDATE` environment variable to `true` to throw an error when schema validation fails.
* A warning is logged by default.
* Set the `SFDX_PROJECT_JSON_VALIDATION` environment variable to `true` to throw an error when schema validation fails.
* A warning is logged by default when the file is invalid.
*
* ***See*** [sfdx-project.schema.json] (https://raw.githubusercontent.com/forcedotcom/schemas/master/schemas/sfdx-project.schema.json)
*/
Expand All @@ -140,7 +144,7 @@ export class SfdxProjectJson extends ConfigFile<ConfigFile.Options> {
await validator.load();
await validator.validate(this.getContents());
} catch (err) {
if (env.getBoolean('SFDX_SCHEMA_VALIDATE', false)) {
if (env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false)) {
err.name = 'SfdxSchemaValidationError';
const sfdxError = SfdxError.wrap(err);
sfdxError.actions = [this.messages.getMessage('SchemaValidationErrorAction', [this.getPath()])];
Expand All @@ -162,7 +166,7 @@ export class SfdxProjectJson extends ConfigFile<ConfigFile.Options> {
await this.read();
}

const contents = (this.getContents() as unknown) as ProjectJson;
const contents = this.getContents();
const packageDirs: PackageDir[] = contents.packageDirectories.map(packageDir => {
// Change packageDir paths to have path separators that match the OS
const regex = pathSep === '/' ? /\\/g : /\//g;
Expand Down
6 changes: 3 additions & 3 deletions test/unit/projectTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ describe('SfdxProject', async () => {
await SfdxProjectJson.create({});
expect(loggerSpy.called).to.be.false;
});
it('schemaValidate throws when SFDX_SCHEMA_VALIDATE=true and invalid file', async () => {
it('schemaValidate throws when SFDX_PROJECT_JSON_VALIDATION=true and invalid file', async () => {
$$.setConfigStubContents('SfdxProjectJson', {
contents: {
packageDirectories: [{ path: 'force-app', default: true }],
foo: 'bar'
}
});
$$.SANDBOX.stub(env, 'getBoolean').callsFake(envVarName => envVarName === 'SFDX_SCHEMA_VALIDATE');
$$.SANDBOX.stub(env, 'getBoolean').callsFake(envVarName => envVarName === 'SFDX_PROJECT_JSON_VALIDATION');
const expectedError = "Validation errors:\n should NOT have additional properties 'foo'";
try {
// create() calls read() which calls schemaValidate()
Expand All @@ -114,7 +114,7 @@ describe('SfdxProject', async () => {
expect(e.message).to.equal(expectedError);
}
});
it('schemaValidate warns when SFDX_SCHEMA_VALIDATE=false and invalid file', async () => {
it('schemaValidate warns when SFDX_PROJECT_JSON_VALIDATION=false and invalid file', async () => {
$$.setConfigStubContents('SfdxProjectJson', {
contents: {
packageDirectories: [{ path: 'force-app', default: true }],
Expand Down

0 comments on commit 917242a

Please sign in to comment.