fix: use basename for name field of static-pattern entries in object mode
With objectMode enabled, static patterns exposed the full pattern string as entry.name and dirent.name instead of the basename, unlike dynamic patterns which already returned the basename via @nodelib/fs.walk. Reader#_makeEntry now derives the basename once and uses it consistently for both fields, leaving entry.path unchanged.
This commit is contained in:
1 parent
75a80a0c79
commit
79f1b99f82
2 files changed
+15
-2
No files matched your search
@@ -85,6 +85,18 @@ describe('Readers → Reader', () => {
|
||||
|
||||
assert.ok(actual.stats);
|
||||
});
|
||||
|
||||
it('should return created entry with basename as `name` for a pattern with a directory part', () => {
|
||||
const reader = getReader();
|
||||
const pattern = './directory/config.json';
|
||||
const stats = new Stats({ mode: StatsMode.File });
|
||||
|
||||
const actual = reader.makeEntry(stats, pattern);
|
||||
|
||||
assert.strictEqual(actual.name, 'config.json');
|
||||
assert.strictEqual(actual.path, pattern);
|
||||
assert.strictEqual(actual.dirent.name, 'config.json');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.isFatalError', () => {
|
||||
|
||||
@@ -33,10 +33,11 @@ export abstract class Reader<T> {
|
||||
}
|
||||
|
||||
protected _makeEntry(stats: FsStats, pattern: Pattern): Entry {
|
||||
const name = path.basename(pattern);
|
||||
const entry: Entry = {
|
||||
name: pattern,
|
||||
name,
|
||||
path: pattern,
|
||||
dirent: utils.fs.createDirentFromStats(pattern, stats),
|
||||
dirent: utils.fs.createDirentFromStats(name, stats),
|
||||
};
|
||||
|
||||
if (this.#settings.stats) {
|
||||
|
||||
Reference in new issue
Block a user