Skip to content

Commit 33061b0

Browse files
committed
fix: forceIgnore issues debug logs when files are ignored @W-19470890@
1 parent 252251c commit 33061b0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/resolve/forceIgnore.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as os from 'node:os';
1919
import ignore, { Ignore } from 'ignore/index';
2020
import { readFileSync } from 'graceful-fs';
2121
import { Lifecycle } from '@salesforce/core/lifecycle';
22+
import { Logger } from '@salesforce/core/logger';
2223
import { SourcePath } from '../common/types';
2324
import { searchUp } from '../utils/fileSystemHandler';
2425

@@ -71,7 +72,13 @@ export class ForceIgnore {
7172
public denies(fsPath: SourcePath): boolean {
7273
if (!this.parser || !this.forceIgnoreDirectory) return false;
7374
try {
74-
return this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
75+
const res = this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
76+
if (res) {
77+
Logger.childFromRoot('forceIgnore.denies').debug(
78+
`Ignoring file '${fsPath}' because it matched .forceignore patterns.`
79+
);
80+
}
81+
return res;
7582
} catch (e) {
7683
return false;
7784
}

test/resolve/forceIgnore.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
import { join } from 'node:path';
1717
import * as os from 'node:os';
1818
import { expect } from 'chai';
19-
import { createSandbox } from 'sinon';
19+
import Sinon, { createSandbox } from 'sinon';
2020
import fs from 'graceful-fs';
2121
import { Lifecycle } from '@salesforce/core';
22+
import { Logger } from '@salesforce/core/logger';
2223
import { ForceIgnore } from '../../src/resolve/forceIgnore';
2324
import * as fsUtil from '../../src/utils/fileSystemHandler';
2425

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

32-
afterEach(() => env.restore());
33+
afterEach(() => {
34+
env.restore();
35+
Sinon.restore();
36+
});
3337

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

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

4855
it('windows separators no longer have any effect', () => {

0 commit comments

Comments
 (0)