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:
1 parent
e04c9cfb04
commit
e9003c3124
3 files changed
+20
-6
No files matched your search
@@ -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 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([
|
expect(result).toEqual([
|
||||||
{ name: "file1.txt", isDirectory: expect.any(Function), path: "/root" },
|
{ name: "file1.txt", isDirectory: expect.any(Function) },
|
||||||
{ name: "subdir", isDirectory: expect.any(Function), path: "/root" },
|
{ name: "subdir", isDirectory: expect.any(Function) },
|
||||||
{
|
{
|
||||||
name: "file2.txt",
|
name: "file2.txt",
|
||||||
isDirectory: expect.any(Function),
|
isDirectory: expect.any(Function),
|
||||||
path: "/root/subdir",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nested",
|
name: "nested",
|
||||||
isDirectory: expect.any(Function),
|
isDirectory: expect.any(Function),
|
||||||
path: "/root/subdir",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "file3.txt",
|
name: "file3.txt",
|
||||||
isDirectory: expect.any(Function),
|
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) {
|
for (const entry of entries) {
|
||||||
const fullPath = join(dir, entry.name)
|
const fullPath = join(dir, entry.name)
|
||||||
entry.path = dir
|
Object.defineProperty(entry, "path", {
|
||||||
|
value: dir,
|
||||||
|
})
|
||||||
allEntries.push(entry)
|
allEntries.push(entry)
|
||||||
|
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
|
|||||||
Reference in new issue
Block a user