UNPKG

@salesforce/core

Version:

Core libraries to interact with SFDX projects, orgs, and APIs.

142 lines 9.41 kB
"use strict"; /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.traverse = exports.SFDX_PROJECT_JSON = void 0; exports.resolveProjectPath = resolveProjectPath; exports.resolveProjectPathSync = resolveProjectPathSync; const fs = __importStar(require("node:fs")); const node_path_1 = require("node:path"); const messages_1 = require("../messages"); ; const messages = new messages_1.Messages('@salesforce/core', 'config', new Map([["unknownConfigKey", "Unknown config name: %s."], ["deprecatedConfigKey", "Deprecated config name: %s. Please use %s instead."], ["invalidWrite", "The writeSync method is not allowed on SfdxConfig. Use the async write method instead."], ["invalidConfigValue", "Invalid config value: %s."], ["invalidInstanceUrl", "Specify a valid Salesforce instance URL."], ["invalidApiVersion", "Specify a valid Salesforce API version, for example, 42.0."], ["invalidCustomOrgMetadataTemplates", "Specify a valid repository URL or directory for the custom org metadata templates."], ["invalidIsvDebuggerSid", "Specify a valid Debugger SID."], ["invalidIsvDebuggerUrl", "Specify a valid Debugger URL."], ["invalidNumberConfigValue", "Specify a valid positive integer, for example, 150000."], ["invalidBooleanConfigValue", "The config value can only be set to true or false."], ["invalidProjectWorkspace", "This directory does not contain a valid Salesforce DX project."], ["schemaValidationError", "The config file \"%s\" is not schema valid.\nDue to: %s"], ["schemaValidationError.actions", ["Fix the invalid entries at %s."]], ["missingDefaultPath", "In sfdx-project.json, be sure to specify which package directory (path) is the default. Example: `[{ \"path\": \"packageDirectory1\", \"default\": true }, { \"path\": \"packageDirectory2\" }]`"], ["missingPackageDirectory", "The path \"%s\", specified in sfdx-project.json, does not exist. Be sure this directory is included in your project root."], ["invalidPackageDirectory", "The path \"%s\", specified in sfdx-project.json, must be indicated as a relative path to the project root."], ["multipleDefaultPaths", "In sfdx-project.json, indicate only one package directory (path) as the default."], ["singleNonDefaultPackage", "The sfdx-project.json file must include one, and only one, default package directory (path). Because your sfdx-project.json file contains only one package directory, it must be the default. Remove the `\"default\": false` key and try again."], ["target-org", "Username or alias of the org that all commands run against by default. (sf only)"], ["target-dev-hub", "Username or alias of your default Dev Hub org. (sf only)"], ["defaultUsername", "Username or alias of the org that all commands run against by default. (sfdx only)"], ["defaultDevHubUsername", "Username or alias of your default Dev Hub org. (sfdx only)"], ["isvDebuggerSid", "ISV debugger SID (sfdx only)"], ["isvDebuggerUrl", "ISV debugger URL (sfdx only)"], ["org-isv-debugger-sid", "ISV debugger SID."], ["org-isv-debugger-url", "ISV debugger URL."], ["apiVersion", "API version of your project. Default: API version of your Dev Hub org. (sfdx only)"], ["org-api-version", "API version of your project. Default: API version of your Dev Hub org."], ["disableTelemetry", "Disables the collection of usage and user environment information, etc. Default: false. (sfdx only)"], ["disable-telemetry", "Disables the collection of usage and user environment information, etc. Default: false."], ["maxQueryLimit", "Maximum number of Salesforce records returned by a CLI command. Default: 10,000. (sfdx only)"], ["org-max-query-limit", "Maximum number of Salesforce records returned by a CLI command. Default: 10,000."], ["restDeploy", "Whether deployments use the Metadata REST API (true) or SOAP API (false, default value). (sfdx only)"], ["instanceUrl", "URL of the Salesforce instance hosting your org. Default: https://login.salesforce.com. (sfdx only)"], ["org-instance-url", "URL of the Salesforce instance hosting your org. Default: https://login.salesforce.com."], ["customOrgMetadataTemplates", "A valid repository URL or directory for the custom org metadata templates."], ["org-custom-metadata-templates", "A valid repository URL or directory for the custom org metadata templates."], ["org-capitalize-record-types", "Whether record types are capitalized on scratch org creation."], ["invalidId", "The given id %s is not a valid 15 or 18 character Salesforce ID."]])); /** * The name of the project config file. * * @ignore */ // This has to be defined on util to prevent circular deps with project and configFile. exports.SFDX_PROJECT_JSON = 'sfdx-project.json'; /** * Performs an upward directory search for an sfdx project file. Returns the absolute path to the project. * * **See** {@link SFDX_PROJECT_JSON} * * **See** {@link traverseForFile} * * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace. * * @param dir The directory path to start traversing from. * @ignore */ async function resolveProjectPath(dir = process.cwd()) { const projectPath = await exports.traverse.forFile(dir, exports.SFDX_PROJECT_JSON); if (!projectPath) { throw messages.createError('invalidProjectWorkspace'); } return projectPath; } /** * Performs a synchronous upward directory search for an sfdx project file. Returns the absolute path to the project. * * **See** {@link SFDX_PROJECT_JSON} * * **See** {@link traverseForFile} * * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace. * * @param dir The directory path to start traversing from. * @ignore */ function resolveProjectPathSync(dir = process.cwd()) { const projectPath = exports.traverse.forFileSync(dir, exports.SFDX_PROJECT_JSON); if (!projectPath) { throw messages.createError('invalidProjectWorkspace'); } return projectPath; } /** * These methods were moved from the deprecated 'fs' module in v2 and are only used in sfdx-core above * * They were migrated into the 'traverse' constant in order to stub them in unit tests */ exports.traverse = { /** * Searches a file path in an ascending manner (until reaching the filesystem root) for the first occurrence a * specific file name. Resolves with the directory path containing the located file, or `null` if the file was * not found. * * @param dir The directory path in which to start the upward search. * @param file The file name to look for. */ forFile: async (dir, file) => { let foundProjectDir; try { fs.statSync((0, node_path_1.join)(dir, file)); foundProjectDir = dir; } catch (err) { if (err && err.code === 'ENOENT') { const nextDir = (0, node_path_1.resolve)(dir, '..'); if (nextDir !== dir) { // stop at root foundProjectDir = await exports.traverse.forFile(nextDir, file); } } } return foundProjectDir; }, /** * Searches a file path synchronously in an ascending manner (until reaching the filesystem root) for the first occurrence a * specific file name. Resolves with the directory path containing the located file, or `null` if the file was * not found. * * @param dir The directory path in which to start the upward search. * @param file The file name to look for. */ forFileSync: (dir, file) => { let foundProjectDir; try { fs.statSync((0, node_path_1.join)(dir, file)); foundProjectDir = dir; } catch (err) { if (err && err.code === 'ENOENT') { const nextDir = (0, node_path_1.resolve)(dir, '..'); if (nextDir !== dir) { // stop at root foundProjectDir = exports.traverse.forFileSync(nextDir, file); } } } return foundProjectDir; }, }; //# sourceMappingURL=internal.js.map