Bug: can't find files in relative path when use in Windows OS
lucasfontesgaspareto opened this issue · 2 comments
Versions
- Node: 18.13.0
- OS: Windows 11
Reproduction
Additional Details
Steps to reproduce
Use typeorm-extension in windows with relative path
What is Expected?
Import seeds and factories
What is actually happening?
typeorm-extension can not find files for seeds and factories
i managed to fixed it by change the path from windows like to unix like as you guys can see below
// eslint-disable-next-line @typescript-eslint/no-var-requires
const os = require('os')
let seedsPath = resolve(__dirname, '../../database/seeders/*{.ts,.js}')
let factoriesPath = resolve(__dirname, '../../database/factories/*{.ts,.js}')
if (os.platform() === 'win32') {
seedsPath = seedsPath.replace(/\\/g, '/')
factoriesPath = factoriesPath.replace(/\\/g, '/')
}
The problem is that glob matching is based on unix paths, so so far the paths have to be defined relative to the root directory with posix (/
) path syntax. I will probably soon enable compatibility for Windows paths as well ✌️. Sorry for the inconvenience, but I'm glad you found a workaround right away 😊 .
The only drawback is that it is no longer possible to compare paths with literal global pattern characters. Therefore, I'm still struggling a bit with myself whether I really want to take this.
i decided to continue supporting paths with literal global pattern characters, but since unix/posix path separator works the same under windows, i added this note to the documentation. I hope that this fits for all involved.