@salesforce/source-deploy-retrieve
Version:
JavaScript library to run Salesforce metadata deploys and retrieves
106 lines • 4.83 kB
JavaScript
/*
* 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;
};
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 core_1 = require("@salesforce/core");
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 core_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 core_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) {
let potentialForceIgnorePath = '';
const projectConfigPath = (0, fileSystemHandler_1.searchUp)(seed, ForceIgnore.FILE_NAME);
if (projectConfigPath) {
potentialForceIgnorePath = (0, node_path_1.join)((0, node_path_1.dirname)(projectConfigPath), ForceIgnore.FILE_NAME);
}
return new ForceIgnore(potentialForceIgnorePath);
}
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
;