glob paths don't work in my Windows environment

Viewed 445

I don't know what happened, suddenly, all my applications that make use of glob paths broke.

Jasmine, TypeORM, any library I need to specify directories through of glob patterns don't work on my Windows.

I dove deeply into those libraries trying to solve the issue. I figured out that libraries use some path module's functions, like join and normalize, to handle the paths before passing them to the glob module. Let me show a code snippet from Jasmine library:

 includeFiles.forEach(function(file) {
      if(!(path.isAbsolute && path.isAbsolute(file))) {
        file = path.join(jasmineRunner.projectBaseDir, jasmineRunner.specDir, file);
      }
      
      var filePaths = glob.sync(file, { ignore: excludeFiles });

C:\Users\User\Programmation\project\test***[sS]pec.js

The join function converts all slashes from path to backslashes, but the glob module doesn't recognize paths with backslashes. The same thing happens with TypeORM using the normalize function from the path module under the hood.

const allFiles = directories.reduce((allDirs, dir) => {

        return allDirs.concat(glob_1.default.sync(PlatformTools_1.PlatformTools.pathNormalize(dir)));
    }, []);

The curious thing is that everything has worked before. I don't know exactly when it stopped working, but it did.

1 Answers

I encountered a similar problem.

After digging inside the TypeORM code I realized the problem is with the glob library.

glob has a problem with the windows separator. I ended up replacing the separator like this:

entities: [
   (__dirname+"\\..\\entities\\**\\*.entity{.ts,.js}").replace(/\\/g,'/')
],
Related