fix(utils): read dir recursive (#10318)
What: - Using `Object.defineProperty) to avoid issues on Node versions that set this property as readonly.
This commit is contained in:
committed by
GitHub
parent
e04c9cfb04
commit
e9003c3124
5
.changeset/clever-singers-vanish.md
Normal file
5
.changeset/clever-singers-vanish.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/utils": patch
|
||||
---
|
||||
|
||||
fix(utils): set readonly property on recursive dir read
|
||||
@@ -30,23 +30,30 @@ describe("readDirRecursive", () => {
|
||||
|
||||
const result = await readDirRecursive("/root")
|
||||
|
||||
const paths = result.map((r) => r.path)
|
||||
|
||||
expect(paths).toEqual([
|
||||
"/root",
|
||||
"/root",
|
||||
"/root/subdir",
|
||||
"/root/subdir",
|
||||
"/root/subdir/nested",
|
||||
])
|
||||
|
||||
expect(result).toEqual([
|
||||
{ name: "file1.txt", isDirectory: expect.any(Function), path: "/root" },
|
||||
{ name: "subdir", isDirectory: expect.any(Function), path: "/root" },
|
||||
{ name: "file1.txt", isDirectory: expect.any(Function) },
|
||||
{ name: "subdir", isDirectory: expect.any(Function) },
|
||||
{
|
||||
name: "file2.txt",
|
||||
isDirectory: expect.any(Function),
|
||||
path: "/root/subdir",
|
||||
},
|
||||
{
|
||||
name: "nested",
|
||||
isDirectory: expect.any(Function),
|
||||
path: "/root/subdir",
|
||||
},
|
||||
{
|
||||
name: "file3.txt",
|
||||
isDirectory: expect.any(Function),
|
||||
path: "/root/subdir/nested",
|
||||
},
|
||||
])
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@ export async function readDirRecursive(dir: string): Promise<Dirent[]> {
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = join(dir, entry.name)
|
||||
entry.path = dir
|
||||
Object.defineProperty(entry, "path", {
|
||||
value: dir,
|
||||
})
|
||||
allEntries.push(entry)
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
|
||||
Reference in New Issue
Block a user