Skip to content

Commit

Permalink
fix: Fix file stat issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 19, 2022
1 parent eba3bf6 commit 7027e76
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/index.test.ts
Expand Up @@ -27,9 +27,9 @@ it('ignored test case', async () => {
'mtime',
'ctime',
'birthtime',
'ext',
'name',
'path',
'ext',
]);
});

Expand All @@ -40,8 +40,10 @@ it('ignored/exclude/include test case', async () => {
include: /(package\.json)$/,
});
expect(files.length).toBe(9);
expect(typeof files[0].isFile === 'function').toBeTruthy();
const arrs = files.filter((item) => /package\.json$/.test(item.path)).map((item) => item.name);
expect(arrs[0]).toEqual('package.json');

const arrs2 = files.filter((item) => /renovate\.json$/.test(item.path)).map((item) => item.name);
expect(arrs2.length).toEqual(0);
expect(Object.keys(files[0])).toEqual([
Expand All @@ -63,9 +65,9 @@ it('ignored/exclude/include test case', async () => {
'mtime',
'ctime',
'birthtime',
'ext',
'name',
'path',
'ext',
]);
});

Expand Down
13 changes: 7 additions & 6 deletions src/index.ts
Expand Up @@ -91,16 +91,17 @@ async function getFiles(
} else {
await Promise.all(
fileDir.map(async (item: IFileDirStat) => {
const stat = await fs.promises.stat(item.path);
item.size = stat.size;
item.ext = '';
const stat = (await fs.promises.stat(item.path)) as IFileDirStat;
// item.size = stat.size;
stat.ext = '';
if (stat.isDirectory()) {
const arr = await getFiles(item.path, options, []);
files = files.concat(arr);
} else if (stat.isFile()) {
item.ext = getExt(item.path);
item = { ...stat, ...item };
files.push(item);
stat.ext = getExt(item.path);
stat.name = item.name;
stat.path = item.path;
files.push(stat);
}
}),
);
Expand Down

0 comments on commit 7027e76

Please sign in to comment.