@salesforce/source-deploy-retrieve
Version:
JavaScript library to run Salesforce metadata deploys and retrieves
121 lines • 5.43 kB
JavaScript
;
/*
* Copyright 2025, 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;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ForceIgnore = void 0;
const node_path_1 = require("node:path");
const os = __importStar(require("node:os"));
const index_1 = __importDefault(require("ignore/index"));
const graceful_fs_1 = require("graceful-fs");
const lifecycle_1 = require("@salesforce/core/lifecycle");
const fileSystemHandler_1 = require("../utils/fileSystemHandler");
class ForceIgnore {
static FILE_NAME = '.forceignore';
parser;
forceIgnoreDirectory;
DEFAULT_IGNORE = ['**/*.dup', '**/.*', '**/package2-descriptor.json', '**/package2-manifest.json'];
constructor(forceIgnorePath = '') {
try {
const contents = (0, graceful_fs_1.readFileSync)(forceIgnorePath, 'utf-8');
// check if file `.forceignore` exists
if (contents !== undefined) {
// check for windows style separators (\) and warn, that aren't comments
if (contents.split(os.EOL).find((c) => c.includes('\\') && !c.startsWith('#'))) {
// void because you cannot await a method in a constructor
void lifecycle_1.Lifecycle.getInstance().emitWarning('Your .forceignore file incorrectly uses the backslash ("\\") as a folder separator; it should use the slash ("/") instead. The ignore rules will not work as expected until you fix this.');
}
if (contents.includes('**/unpackaged/**')) {
void lifecycle_1.Lifecycle.getInstance().emitWarning('Your .forceignore file contains the "**/unpackaged/**" rule. This will cause all files to be ignored during a retrieve.');
}
// add the default ignore paths, and then parse the .forceignore file
this.parser = (0, index_1.default)().add(`${this.DEFAULT_IGNORE.join('\n')}\n${contents}`);
this.forceIgnoreDirectory = (0, node_path_1.dirname)(forceIgnorePath);
}
}
catch (e) {
// TODO: log no force ignore
}
}
/**
* Performs an upward directory search for a `.forceignore` file and returns a
* `ForceIgnore` object based on the result. If there is no `.forceignore` file,
* the returned `ForceIgnore` object will accept everything.
*
* @param seed Path to begin the `.forceignore` search from
*/
static findAndCreate(seed) {
const projectConfigPath = (0, fileSystemHandler_1.searchUp)(seed, ForceIgnore.FILE_NAME);
return new ForceIgnore(projectConfigPath ? (0, node_path_1.join)((0, node_path_1.dirname)(projectConfigPath), ForceIgnore.FILE_NAME) : '');
}
denies(fsPath) {
if (!this.parser || !this.forceIgnoreDirectory)
return false;
try {
return this.parser.ignores((0, node_path_1.relative)(this.forceIgnoreDirectory, fsPath));
}
catch (e) {
return false;
}
}
accepts(fsPath) {
if (!this.parser || !this.forceIgnoreDirectory)
return true;
try {
return !this.parser.ignores((0, node_path_1.relative)(this.forceIgnoreDirectory, fsPath));
}
catch (e) {
return true;
}
}
}
exports.ForceIgnore = ForceIgnore;
//# sourceMappingURL=forceIgnore.js.map