thecodrr/fdir

Need help debugging an issue?? with fdir

glenn2223 opened this issue · 4 comments

I've had an issue opened over on a repo - glenn2223/vscode-live-sass-compiler#145

I can't for the life of me figure out why fdir has returned a file count of 0 when the filters applied all return true for one file

They have an SSH connection in VS Code but I don't see why that would be a problem


I have copied out a section of code that produces the below output (copied from this comment)

Code

const isMatch = picomatch(fileList, { ignore: excludeItems, dot: true, nocase: true });

OutputWindow.Show(OutputLevel.Trace, "Searching folder", null, false);

const searchLogs: Map<string, string[]> = new Map<string, string[]>();

const searchFileCount = (
    (await new fdir()
        .crawlWithOptions(basePath, {
            filters: [
                (filePath) =>
                    filePath.toLowerCase().endsWith(".scss") ||
                    filePath.toLowerCase().endsWith(".sass"),
                (filePath) => {
                    const result = isMatch(path.relative(basePath, filePath));

                    searchLogs.set(`Path: ${filePath}`, [
                        `  isMatch: ${result}`,
                        `   - Base path: ${basePath}`,
                        `   - Rela path: ${path.relative(basePath, filePath)}`,
                    ]);

                    return result;
                },
                (filePath) => {
                    const result =
                        path
                            .toNamespacedPath(filePath)
                            .localeCompare(path.toNamespacedPath(sassPath), undefined, {
                                sensitivity: "accent",
                            }) === 0;

                    searchLogs
                        .get(`Path: ${filePath}`)
                        ?.push(
                            `  compare: ${result}`,
                            `   - Orig file path: ${filePath}`,
                            `   - Orig sass path: ${sassPath}`
                        );

                    return result;
                },
            ],
            includeBasePath: true,
            onlyCounts: true,
            resolvePaths: true,
            suppressErrors: true,
        })
        .withPromise()) as OnlyCountsOutput
).files;

const x = await new fdir()
    .crawlWithOptions(basePath, {
        includeBasePath: true,
        group: true,
        resolvePaths: true,
        suppressErrors: true,
    })
    .withPromise();

OutputWindow.Show(OutputLevel.Trace, "FDIR OUTPUT", [JSON.stringify(x)]);

OutputWindow.Show(OutputLevel.Trace, "Search results", undefined, false);

searchLogs.forEach((logs, key) => {
    OutputWindow.Show(OutputLevel.Trace, key, logs, false);
});

And here is the section from the output

Searching folder
FDIR OUTPUT
[
   {
      "dir":"/home/dave/MagentoAPI",
      "files":[ ]
   },
   {
      "dir":"/home/dave/MagentoAPI/dev",
      "files":[
         "/home/dave/MagentoAPI/dev/docker-compose.yml",
         "/home/dave/MagentoAPI/dev/dockerfile"
      ]
   },
   {
      "dir":"/home/dave/MagentoAPI/dev/.app",
      "files":[
         "/home/dave/MagentoAPI/dev/.app/composer.json",
         "/home/dave/MagentoAPI/dev/.app/composer.lock"
      ]
   },
   {
      "dir":"/home/dave/MagentoAPI/dev/.vscode",
      "files":[
         "/home/dave/MagentoAPI/dev/.vscode/settings.json"
      ]
   },
   {
      "dir":"/home/dave/MagentoAPI/dev/mysql-data",
      "files":[
         /// Bunch of SQL files removed for brevity
      ]
   },
   {
      "dir":"/home/dave/MagentoAPI/dev/php-confs",
      "files":[
         "/home/dave/MagentoAPI/dev/php-confs/override.ini"
      ]
   },
   {
      "dir":"/home/dave/MagentoAPI/dev/src",
      "files":[
         /// Bunch of PHP files removed for brevity
         "/home/dave/MagentoAPI/dev/src/AttributesSamplePayload.json",
         "/home/dave/MagentoAPI/dev/src/MageAPIdev.code-workspace",
         "/home/dave/MagentoAPI/dev/src/newfile.txt",
         "/home/dave/MagentoAPI/dev/src/style.css",
         "/home/dave/MagentoAPI/dev/src/workspace.code-workspace"
      ]
   },
   {
      "dir":"/home/dave/MagentoAPI/dev/.app/vendor",
      "files":[
         "/home/dave/MagentoAPI/dev/.app/vendor/autoload.php"
      ]
   }
]
--------------------
Search results
Path: /home/dave/MagentoAPI/dev/src/styles/main.scss
  isMatch: true
   - Base path: /home/dave/MagentoAPI
   - Rela path: dev/src/styles/main.scss
  compare: true
   - Orig file path: /home/dave/MagentoAPI/dev/src/styles/main.scss
   - Orig sass path: /home/dave/MagentoAPI/dev/src/styles/main.scss

I am taking a look at this. Hold on.

@glenn2223 can you try this again with v5.2.0?

Thanks for working on this and turning it around so quickly!

I have asked the individual to test this release and get back to me

Report back soon with good news I hope 🤞

They have confirmed that it's fixed in v5.2