From 917242a1dd4c1809fb809246af8ee856c803d7f2 Mon Sep 17 00:00:00 2001 From: Steve Hetzel Date: Wed, 27 May 2020 11:28:15 -0600 Subject: [PATCH] chore: change env var name and getContents override --- DEVELOPING.md | 8 ++++---- src/sfdxProject.ts | 24 ++++++++++++++---------- test/unit/projectTest.ts | 6 +++--- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/DEVELOPING.md b/DEVELOPING.md index ce388213ce..e39c0ab881 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -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`. @@ -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` @@ -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. diff --git a/src/sfdxProject.ts b/src/sfdxProject.ts index 9898c48d49..bd32f9e613 100644 --- a/src/sfdxProject.ts +++ b/src/sfdxProject.ts @@ -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; @@ -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; @@ -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. @@ -112,6 +112,10 @@ export class SfdxProjectJson extends ConfigFile { 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 @@ -124,8 +128,8 @@ export class SfdxProjectJson extends ConfigFile { /** * 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) */ @@ -140,7 +144,7 @@ export class SfdxProjectJson extends ConfigFile { 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()])]; @@ -162,7 +166,7 @@ export class SfdxProjectJson extends ConfigFile { 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; diff --git a/test/unit/projectTest.ts b/test/unit/projectTest.ts index 88f599df82..dd94e00675 100644 --- a/test/unit/projectTest.ts +++ b/test/unit/projectTest.ts @@ -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() @@ -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 }],