@salesforce/core
Advanced tools
Comparing version 2.4.1 to 2.5.0
@@ -0,1 +1,13 @@ | ||
# [2.5.0](https://github.com/forcedotcom/sfdx-core/compare/v2.4.1...v2.5.0) (2020-06-08) | ||
### Bug Fixes | ||
* update mkdirp for updated dep ([e2b471b](https://github.com/forcedotcom/sfdx-core/commit/e2b471b120edd1b55bca50d71a2fe8d995ef8bbd)) | ||
### Features | ||
* add fs.fileExists ([0c5d0a7](https://github.com/forcedotcom/sfdx-core/commit/0c5d0a75867094f5b05d9d356f23c94c38d6213e)) | ||
## [2.4.1](https://github.com/forcedotcom/sfdx-core/compare/v2.4.0...v2.4.1) (2020-05-05) | ||
@@ -2,0 +14,0 @@ |
import { Stats as fsStats } from 'fs'; | ||
import { Logger } from '../logger'; | ||
import { Messages } from '../messages'; | ||
import { BaseConfigStore, ConfigContents } from './configStore'; | ||
@@ -39,2 +41,5 @@ /** | ||
static resolveRootFolder(isGlobal: boolean): Promise<string>; | ||
protected hasRead: boolean; | ||
protected logger: Logger; | ||
protected messages: Messages; | ||
private path; | ||
@@ -57,7 +62,10 @@ /** | ||
/** | ||
* Read the config file and set the config contents. Returns the config contents of the config file. | ||
* Read the config file and set the config contents. Returns the config contents of the config file. As an | ||
* optimization, files are only read once per process and updated in memory and via `write()`. To force | ||
* a read from the filesystem pass `force=true`. | ||
* **Throws** *{@link SfdxError}{ name: 'UnexpectedJsonFileFormat' }* There was a problem reading or parsing the file. | ||
* @param [throwOnNotFound = false] Optionally indicate if a throw should occur on file read. | ||
* @param [force = false] Optionally force the file to be read from disk even when already read within the process. | ||
*/ | ||
read(throwOnNotFound?: boolean): Promise<ConfigContents>; | ||
read(throwOnNotFound?: boolean, force?: boolean): Promise<ConfigContents>; | ||
/** | ||
@@ -64,0 +72,0 @@ * Write the config file with new contents. If no new contents are provided it will write the existing config |
@@ -14,2 +14,4 @@ "use strict"; | ||
const global_1 = require("../global"); | ||
const logger_1 = require("../logger"); | ||
const messages_1 = require("../messages"); | ||
const sfdxError_1 = require("../sfdxError"); | ||
@@ -19,2 +21,3 @@ const fs_2 = require("../util/fs"); | ||
const configStore_1 = require("./configStore"); | ||
messages_1.Messages.importMessagesDirectory(path_1.join(__dirname)); | ||
/** | ||
@@ -48,2 +51,4 @@ * Represents a json config file used to manage settings and state. Global config | ||
super(options); | ||
// whether file contents have been read | ||
this.hasRead = false; | ||
} | ||
@@ -97,10 +102,18 @@ /** | ||
/** | ||
* Read the config file and set the config contents. Returns the config contents of the config file. | ||
* Read the config file and set the config contents. Returns the config contents of the config file. As an | ||
* optimization, files are only read once per process and updated in memory and via `write()`. To force | ||
* a read from the filesystem pass `force=true`. | ||
* **Throws** *{@link SfdxError}{ name: 'UnexpectedJsonFileFormat' }* There was a problem reading or parsing the file. | ||
* @param [throwOnNotFound = false] Optionally indicate if a throw should occur on file read. | ||
* @param [force = false] Optionally force the file to be read from disk even when already read within the process. | ||
*/ | ||
async read(throwOnNotFound = false) { | ||
async read(throwOnNotFound = false, force = false) { | ||
try { | ||
const obj = await fs_2.fs.readJsonMap(this.getPath()); | ||
this.setContentsFromObject(obj); | ||
// Only need to read config files once. They are kept up to date | ||
// internally and updated persistently via write(). | ||
if (!this.hasRead || force) { | ||
this.logger.info(`Reading config file: ${this.getPath()}`); | ||
const obj = await fs_2.fs.readJsonMap(this.getPath()); | ||
this.setContentsFromObject(obj); | ||
} | ||
return this.getContents(); | ||
@@ -117,2 +130,7 @@ } | ||
} | ||
finally { | ||
// Necessarily set this even when an error happens to avoid infinite re-reading. | ||
// To attempt another read, pass `force=true`. | ||
this.hasRead = true; | ||
} | ||
} | ||
@@ -130,2 +148,3 @@ /** | ||
await fs_2.fs.mkdirp(path_1.dirname(this.getPath())); | ||
this.logger.info(`Writing to config file: ${this.getPath()}`); | ||
await fs_2.fs.writeJson(this.getPath(), this.toObject()); | ||
@@ -179,2 +198,3 @@ return this.getContents(); | ||
async init() { | ||
this.logger = await logger_1.Logger.child(this.constructor.name); | ||
const statics = this.constructor; | ||
@@ -203,2 +223,3 @@ let defaultOptions = {}; | ||
} | ||
this.messages = messages_1.Messages.loadMessages('@salesforce/core', 'config'); | ||
this.path = path_1.join(configRootFolder, this.options.filePath ? this.options.filePath : '', this.options.filename); | ||
@@ -205,0 +226,0 @@ await this.read(this.options.throwOnNotFound); |
@@ -26,3 +26,3 @@ "use strict"; | ||
this.options = options; | ||
this.setContents(this.options.contents || {}); | ||
this.setContents(this.options.contents); | ||
} | ||
@@ -157,3 +157,3 @@ /** | ||
// Allows extended classes the ability to override the set method. i.e. maybe they don't want | ||
// nexted object set from kit. | ||
// nested object set from kit. | ||
setMethod(contents, key, value) { | ||
@@ -160,0 +160,0 @@ kit_1.set(contents, key, value); |
@@ -15,3 +15,3 @@ "use strict"; | ||
const Debug = require("debug"); | ||
const EventEmitter = require("events"); | ||
const events_1 = require("events"); | ||
const os = require("os"); | ||
@@ -496,3 +496,3 @@ const path = require("path"); | ||
Logger.lifecycle = (() => { | ||
const events = new EventEmitter(); | ||
const events = new events_1.EventEmitter(); | ||
events.setMaxListeners(0); // never warn on listener counts | ||
@@ -499,0 +499,0 @@ process.on('uncaughtException', err => events.emit('uncaughtException', err)); |
@@ -15,3 +15,3 @@ import { AnyJson, JsonMap } from '@salesforce/ts-types'; | ||
* @param logger An {@link Logger} instance on which to base this class's logger. | ||
* @param schemaPath The path from which the schema with which to validate should be loaded. | ||
* @param schemaPath The path to the schema file to load and use for validation. | ||
*/ | ||
@@ -18,0 +18,0 @@ constructor(logger: Logger, schemaPath: string); |
@@ -23,3 +23,3 @@ "use strict"; | ||
* @param logger An {@link Logger} instance on which to base this class's logger. | ||
* @param schemaPath The path from which the schema with which to validate should be loaded. | ||
* @param schemaPath The path to the schema file to load and use for validation. | ||
*/ | ||
@@ -26,0 +26,0 @@ constructor(logger, schemaPath) { |
import { ConfigFile } from './config/configFile'; | ||
import { ConfigContents } from './config/configStore'; | ||
import { JsonMap } from '@salesforce/ts-types'; | ||
export declare type PackageDirDependency = { | ||
package: string; | ||
versionNumber?: string; | ||
[k: string]: unknown; | ||
}; | ||
export declare type PackageDir = { | ||
ancestorId?: string; | ||
ancestorVersion?: string; | ||
default?: boolean; | ||
definitionFile?: string; | ||
dependencies?: PackageDirDependency[]; | ||
includeProfileUserLicenses?: boolean; | ||
package?: string; | ||
path: string; | ||
postInstallScript?: string; | ||
postInstallUrl?: string; | ||
releaseNotesUrl?: string; | ||
uninstallScript?: string; | ||
versionDescription?: string; | ||
versionName?: string; | ||
versionNumber?: string; | ||
}; | ||
export declare type ProjectJson = ConfigContents & { | ||
packageDirectories: PackageDir[]; | ||
namespace?: string; | ||
sourceApiVersion?: string; | ||
sfdcLoginUrl?: string; | ||
signupTargetLoginUrl?: string; | ||
oauthLocalPort?: number; | ||
plugins?: { | ||
[k: string]: unknown; | ||
}; | ||
packageAliases?: { | ||
[k: string]: string; | ||
}; | ||
}; | ||
/** | ||
@@ -27,3 +63,18 @@ * The sfdx-project.json config object. This file determines if a folder is a valid sfdx project. | ||
write(newContents?: ConfigContents): Promise<ConfigContents>; | ||
getContents(): ProjectJson; | ||
getDefaultOptions(options?: ConfigFile.Options): ConfigFile.Options; | ||
/** | ||
* Validates sfdx-project.json against the schema. | ||
* | ||
* 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) | ||
*/ | ||
schemaValidate(): Promise<void>; | ||
/** | ||
* Returns the `packageDirectories` within sfdx-project.json, first reading | ||
* and validating the file if necessary. | ||
*/ | ||
getPackageDirectories(): Promise<PackageDir[]>; | ||
} | ||
@@ -61,2 +112,3 @@ /** | ||
static resolveProjectPath(dir?: string): Promise<string>; | ||
private static instances; | ||
private projectConfig; | ||
@@ -63,0 +115,0 @@ private sfdxProjectJson; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* | ||
@@ -8,8 +9,9 @@ * Copyright (c) 2018, salesforce.com, inc. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const kit_1 = require("@salesforce/kit"); | ||
const path_1 = require("path"); | ||
const configAggregator_1 = require("./config/configAggregator"); | ||
const configFile_1 = require("./config/configFile"); | ||
const kit_1 = require("@salesforce/kit"); | ||
const validator_1 = require("./schema/validator"); | ||
const internal_1 = require("./util/internal"); | ||
const sfdxError_1 = require("./sfdxError"); | ||
const internal_1 = require("./util/internal"); | ||
const sfdc_1 = require("./util/sfdc"); | ||
@@ -51,2 +53,3 @@ /** | ||
} | ||
await this.schemaValidate(); | ||
return contents; | ||
@@ -60,4 +63,8 @@ } | ||
} | ||
await this.schemaValidate(); | ||
return super.write(newContents); | ||
} | ||
getContents() { | ||
return super.getContents(); | ||
} | ||
getDefaultOptions(options) { | ||
@@ -70,2 +77,53 @@ const defaultOptions = { | ||
} | ||
/** | ||
* Validates sfdx-project.json against the schema. | ||
* | ||
* 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) | ||
*/ | ||
async schemaValidate() { | ||
if (!this.hasRead) { | ||
// read calls back into this method after necessarily setting this.hasRead=true | ||
await this.read(); | ||
} | ||
else { | ||
try { | ||
const projectJsonSchemaPath = require.resolve('@salesforce/schemas/sfdx-project.schema.json'); | ||
const validator = new validator_1.SchemaValidator(this.logger, projectJsonSchemaPath); | ||
await validator.load(); | ||
await validator.validate(this.getContents()); | ||
} | ||
catch (err) { | ||
if (kit_1.env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false)) { | ||
err.name = 'SfdxSchemaValidationError'; | ||
const sfdxError = sfdxError_1.SfdxError.wrap(err); | ||
sfdxError.actions = [this.messages.getMessage('SchemaValidationErrorAction', [this.getPath()])]; | ||
throw sfdxError; | ||
} | ||
else { | ||
this.logger.warn(this.messages.getMessage('SchemaValidationWarning', [this.getPath(), err.message])); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* Returns the `packageDirectories` within sfdx-project.json, first reading | ||
* and validating the file if necessary. | ||
*/ | ||
async getPackageDirectories() { | ||
// Ensure sfdx-project.json has first been read and validated. | ||
if (!this.hasRead) { | ||
await this.read(); | ||
} | ||
const contents = this.getContents(); | ||
const packageDirs = contents.packageDirectories.map(packageDir => { | ||
// Change packageDir paths to have path separators that match the OS | ||
const regex = path_1.sep === '/' ? /\\/g : /\//g; | ||
packageDir.path = packageDir.path.replace(regex, path_1.sep); | ||
return packageDir; | ||
}); | ||
return packageDirs; | ||
} | ||
} | ||
@@ -100,3 +158,9 @@ SfdxProjectJson.BLACKLIST = ['packageAliases']; | ||
static async resolve(path) { | ||
return new SfdxProject(await this.resolveProjectPath(path)); | ||
const _path = path || process.cwd(); | ||
if (!SfdxProject.instances.has(_path)) { | ||
const project = new SfdxProject(await this.resolveProjectPath(_path)); | ||
SfdxProject.instances.set(_path, project); | ||
} | ||
// @ts-ignore Because of the pattern above this is guaranteed to return an instance | ||
return SfdxProject.instances.get(_path); | ||
} | ||
@@ -176,3 +240,5 @@ /** | ||
} | ||
// Cache of SfdxProject instances per path. | ||
SfdxProject.instances = new Map(); | ||
exports.SfdxProject = SfdxProject; | ||
//# sourceMappingURL=sfdxProject.js.map |
@@ -143,2 +143,4 @@ "use strict"; | ||
const stub = testContext.configStubs[this.constructor.name] || {}; | ||
// @ts-ignore set this to true to avoid an infinite loop in tests when reading config files. | ||
this.hasRead = true; | ||
if (stub.readFn) { | ||
@@ -145,0 +147,0 @@ return await stub.readFn.call(this); |
@@ -91,2 +91,8 @@ import { AnyJson, JsonMap } from '@salesforce/ts-types'; | ||
writeJson: (jsonPath: string, data: AnyJson) => Promise<void>; | ||
/** | ||
* Checks if a file path exists | ||
* | ||
* @param filePath the file path to check the existence of | ||
*/ | ||
fileExists: (filePath: string) => Promise<boolean>; | ||
}; |
@@ -65,3 +65,3 @@ "use strict"; | ||
// @ts-ignore TODO: figure out how to bind to correct promisify overload | ||
mkdirp: (folderPath, mode) => util_1.promisify(mkdirpLib)(folderPath, mode), | ||
mkdirp: (folderPath, mode) => mkdirpLib(folderPath, mode), | ||
/** | ||
@@ -147,4 +147,18 @@ * Deletes a folder recursively, removing all descending files and folders. | ||
}); | ||
}, | ||
/** | ||
* Checks if a file path exists | ||
* | ||
* @param filePath the file path to check the existence of | ||
*/ | ||
fileExists: async (filePath) => { | ||
try { | ||
await exports.fs.access(filePath); | ||
return true; | ||
} | ||
catch (err) { | ||
return false; | ||
} | ||
} | ||
}; | ||
//# sourceMappingURL=fs.js.map |
@@ -28,2 +28,3 @@ "use strict"; | ||
const whitelistOfSalesforceDomainPatterns = [ | ||
'.cloudforce.com', | ||
'.content.force.com', | ||
@@ -30,0 +31,0 @@ '.force.com', |
{ | ||
"UnknownConfigKey": "Unknown config name \"%s\"", | ||
"InvalidConfigValue": "Invalid config value. %s", | ||
"InvalidInstanceUrl": "Specify a valid Salesforce instance URL", | ||
"InvalidApiVersion": "Specify a valid Salesforce API version, for example, 42.0", | ||
"InvalidBooleanConfigValue": "The config value can only be set to true or false.", | ||
"InvalidProjectWorkspace": "This directory does not contain a valid Salesforce DX project" | ||
} | ||
"UnknownConfigKey": "Unknown config name \"%s\"", | ||
"InvalidConfigValue": "Invalid config value. %s", | ||
"InvalidInstanceUrl": "Specify a valid Salesforce instance URL", | ||
"InvalidApiVersion": "Specify a valid Salesforce API version, for example, 42.0", | ||
"InvalidBooleanConfigValue": "The config value can only be set to true or false.", | ||
"InvalidProjectWorkspace": "This directory does not contain a valid Salesforce DX project", | ||
"SchemaValidationWarning": "The config file: %s is not schema valid\nDue to: %s", | ||
"SchemaValidationErrorAction": "Check the file: %s for invalid entries" | ||
} |
{ | ||
"name": "@salesforce/core", | ||
"version": "2.4.1", | ||
"version": "2.5.0", | ||
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.", | ||
@@ -43,2 +43,3 @@ "main": "lib/exported", | ||
"@salesforce/kit": "^1.0.0", | ||
"@salesforce/schemas": "^1.0.1", | ||
"@salesforce/ts-types": "^1.0.0", | ||
@@ -50,12 +51,12 @@ "@types/jsforce": "1.9.2", | ||
"jsonwebtoken": "8.5.0", | ||
"mkdirp": "0.5.1", | ||
"mkdirp": "1.0.4", | ||
"sfdx-faye": "^1.0.9" | ||
}, | ||
"devDependencies": { | ||
"@salesforce/dev-scripts": "0.3.14", | ||
"@salesforce/ts-sinon": "^1.0.0", | ||
"@salesforce/dev-scripts": "0.3.14", | ||
"@types/debug": "0.0.30", | ||
"@types/jsen": "0.0.19", | ||
"@types/jsonwebtoken": "8.3.2", | ||
"@types/mkdirp": "0.5.2", | ||
"@types/mkdirp": "1.0.0", | ||
"@types/shelljs": "0.7.8", | ||
@@ -62,0 +63,0 @@ "commitizen": "^3.0.5", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
462363
11530
11
+ Added@salesforce/schemas@^1.0.1
+ Added@salesforce/schemas@1.9.0(transitive)
+ Addedmkdirp@0.5.61.0.4(transitive)
- Removedminimist@0.0.8(transitive)
- Removedmkdirp@0.5.1(transitive)
Updatedmkdirp@1.0.4