@salesforce/core
Version:
Core libraries to interact with SFDX projects, orgs, and APIs.
167 lines • 10.6 kB
JavaScript
;
/*
* Copyright 2026, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__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 path = __importStar(require("node:path"));
const fs_1 = require("../fs/fs");
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", "%s 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."], ["invalidProjectLoginUrl", "The sfdcLoginUrl \"%s\" is not a valid Salesforce domain. Only Salesforce or internal URLs are allowed as the OAuth login endpoint."], ["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', [dir]);
}
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', [dir]);
}
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: (dir, file) => Promise.resolve(findFileInParentDirectories(dir, file)),
/**
* 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) => findFileInParentDirectories(dir, file),
};
const findFileInParentDirectories = (dir, file) => {
const normalizedDir = path.normalize(dir);
let startDir;
if (path.isAbsolute(normalizedDir)) {
startDir = normalizedDir;
}
else {
const cwd = process.cwd();
if (path.isAbsolute(cwd)) {
startDir = path.normalize(path.join(cwd, normalizedDir));
}
}
// A relative path is only meaningful when the active runtime supplies an absolute cwd.
// In web builds process.cwd() may be empty; do not probe a relative path or ascend from it.
if (!startDir || !path.isAbsolute(startDir)) {
return undefined;
}
const visitedDirs = new Set();
let currentDir = startDir;
while (currentDir && !visitedDirs.has(currentDir)) {
visitedDirs.add(currentDir);
try {
fs_1.fs.statSync(path.join(currentDir, file));
return currentDir;
}
catch (err) {
if (!err || err.code !== 'ENOENT') {
return undefined;
}
}
const parentDir = path.dirname(currentDir);
if (parentDir === currentDir) {
return undefined;
}
currentDir = parentDir;
}
return undefined;
};
//# sourceMappingURL=internal.js.map