镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

When using glob can't exclude all directs #56260

Description

@babakfp

Version

v23.4.0

Platform

Microsoft Windows NT 10.0.22631.0 x64

Subsystem

No response

What steps will reproduce the bug?

  1. Create a folder and open it in your code editor (we use this as current working directory).

  2. Make/create the files/folders shown below:

    src
    src\a
    src\a\b
    src\a\c
    src\index.ts
    src\zip.ts
    
  3. Run the code below:

    console.log(
        fs.globSync("src/**", {
            withFileTypes: true,
            cwd: process.cwd(),
            exclude: (dirent) => {
                console.log(dirent)
            },
        }),
    )

How often does it reproduce? Is there a required condition?

.

What is the expected behavior? Why is that the expected behavior?

I expect the exclude function to receive all the output directs, so that they can be excluded. (See "Additional information" part).

Even with just returning true in exclude function, you can't exclude DirentFromStats from the result.

What do you see instead?

The first direct from output is missing in exclude. (See "Additional information" part).

Additional information

Exclude:

Dirent {
  name: 'a',
  parentPath: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
  path: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
  [Symbol(type)]: 2
}
Dirent {
  name: 'index.ts',
  parentPath: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
  path: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
  [Symbol(type)]: 1
}
Dirent {
  name: 'zip.ts',
  parentPath: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
  path: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
  [Symbol(type)]: 1
}
Dirent {
  name: 'b',
  parentPath: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src\\a',
  path: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src\\a',
  [Symbol(type)]: 2
}
Dirent {
  name: 'c',
  parentPath: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src\\a',
  path: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src\\a',
  [Symbol(type)]: 2
}

Output:

[
  DirentFromStats {
    name: 'src',
    parentPath: 'C:\\Users\\Babak\\Documents\\Code\\tosk',
    path: 'C:\\Users\\Babak\\Documents\\Code\\tosk',
    [Symbol(type)]: null,
    [Symbol(stats)]: Stats {
      dev: 1247631908,
      mode: 16822,
      nlink: 1,
      uid: 0,
      gid: 0,
      rdev: 0,
      blksize: 4096,
      ino: 1970324837878618,
      size: 0,
      blocks: 0,
      atimeMs: 1734234059936.9617,
      mtimeMs: 1734231659493.8164,
      ctimeMs: 1734231659493.8164,
      birthtimeMs: 1734197097735.2148
    }
  },
  Dirent {
    name: 'index.ts',
    parentPath: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
    path: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
    [Symbol(type)]: 1
  },
  Dirent {
    name: 'zip.ts',
    parentPath: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
    path: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
    [Symbol(type)]: 1
  },
  Dirent {
    name: 'a',
    parentPath: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
    path: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src',
    [Symbol(type)]: 2
  },
  Dirent {
    name: 'c',
    parentPath: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src\\a',
    path: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src\\a',
    [Symbol(type)]: 2
  },
  Dirent {
    name: 'b',
    parentPath: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src\\a',
    path: 'C:\\Users\\Babak\\Documents\\Code\\tosk\\src\\a',
    [Symbol(type)]: 2
  }
]

Activity

  1. added
    fsIssues and PRs related to file-system APIs and the fs module.
    on Dec 15, 2024
  2. Trott commented on Mar 11, 2025

    @Trott
    Member

    I expect the exclude function to receive all the output directs

    I would not expect that. That is an internal implementation detail. If you're globbing for src/**, there's no reason for the exclude function to receive the src directory itself (although I suppose it could--again, it's an internal implementation detail).

  3. babakfp commented on Mar 11, 2025

    @babakfp
    Author

    I expect the exclude function to receive all the output directs

    I would not expect that. That is an internal implementation detail. If you're globbing for src/**, there's no reason for the exclude function to receive the src directory itself (although I suppose it could--again, it's an internal implementation detail).

    Hey 👋

    This is an unexpected behavior. It shouldn't work this way.

    How is that src/** selects the src folder and shows it in the output but it isn't available in the exclude?

    This is just a bug. I don't know what this implementation details is, but it is a bug.

    So, can we open this back?

    @Trott

  4. Trott commented on Mar 11, 2025

    @Trott
    Member

    @nodejs/fs Is the behavior here a bug? DirentFromStats doesn't appear to be documented so I'm not sure what to make of it. To me, the key question is this:

    How is it that src/** selects the src folder and shows it in the output but it isn't available in the exclude?

  5. Trott commented on Mar 11, 2025

    @Trott
  6. reopened this on Mar 11, 2025
  7. Trott commented on Mar 11, 2025

    @Trott
    Member

    ...or maybe returning src makes perfect sense as ** matches nothing. But in that case, it should be passed to exclude for processing....

  8. Trott commented on Mar 12, 2025

    @Trott
    Member

    I'm not familiar with the globbing code, but I attempted a fix in #57420.

  9. added a commit that references this issue on Mar 13, 2025
  10. added a commit that references this issue on Mar 16, 2025
  11. added a commit that references this issue on Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to file-system APIs and the fs module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions