Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/resolve/forceIgnore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as os from 'node:os';
import ignore, { Ignore } from 'ignore/index';
import { readFileSync } from 'graceful-fs';
import { Lifecycle } from '@salesforce/core/lifecycle';
import { Logger } from '@salesforce/core/logger';
import { SourcePath } from '../common/types';
import { searchUp } from '../utils/fileSystemHandler';

Expand Down Expand Up @@ -71,7 +72,13 @@ export class ForceIgnore {
public denies(fsPath: SourcePath): boolean {
if (!this.parser || !this.forceIgnoreDirectory) return false;
try {
return this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
const res = this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
if (res) {
Logger.childFromRoot('forceIgnore.denies').debug(
`Ignoring file '${fsPath}' because it matched .forceignore patterns.`
);
}
return res;
} catch (e) {
return false;
}
Expand Down
11 changes: 9 additions & 2 deletions test/resolve/forceIgnore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
import { join } from 'node:path';
import * as os from 'node:os';
import { expect } from 'chai';
import { createSandbox } from 'sinon';
import Sinon, { createSandbox } from 'sinon';
import fs from 'graceful-fs';
import { Lifecycle } from '@salesforce/core';
import { Logger } from '@salesforce/core/logger';
import { ForceIgnore } from '../../src/resolve/forceIgnore';
import * as fsUtil from '../../src/utils/fileSystemHandler';

Expand All @@ -29,7 +30,10 @@ describe('ForceIgnore', () => {
const testPath = join('some', 'path', '__tests__', 'myTest.x');
const testPattern = '**/__tests__/**';

afterEach(() => env.restore());
afterEach(() => {
env.restore();
Sinon.restore();
});

it('Should default to not ignoring a file if forceignore is not loaded', () => {
const path = join('some', 'path');
Expand All @@ -40,9 +44,12 @@ describe('ForceIgnore', () => {

it('Should ignore files with a given pattern', () => {
env.stub(fs, 'readFileSync').returns(testPattern);
const debugSpy = Sinon.spy(Logger.prototype, 'debug');
const forceIgnore = new ForceIgnore(forceIgnorePath);
expect(forceIgnore.accepts(testPath)).to.be.false;
expect(forceIgnore.denies(testPath)).to.be.true;
expect(debugSpy.calledOnce).to.be.true;
expect(debugSpy.getCall(0).args[0]).to.match(/Ignoring file .+ because it matched .forceignore patterns./g);
});

it('windows separators no longer have any effect', () => {
Expand Down
Loading