w3tecch / typeorm-seeding

🌱 A delightful way to seed test data into your database.
https://www.npmjs.com/package/typeorm-seeding
MIT License
887 stars 132 forks source link

File loader always uses process.cwd(), fails to find seeds and factories in monorepos with globs #123

Open coaxial opened 3 years ago

coaxial commented 3 years ago

Given an ormconfig.js file with:

module.exports = {
  // ...
  seeds: ['src/**/*.seed.ts'],
  factories: ['src/**/*.factory.ts],
}

The ormconfig file is located at apps/api/src/config/ormconfig.js within a monorepo, and package.json is located at ./process.cwd().

Then the file loader fails to find the factory or seed files.

However, if I change this line: https://github.com/w3tecch/typeorm-seeding/blob/4136b0e0f58a4ec13b17c717bd026043fbdf7ddd/src/utils/file.util.ts#L10 to .map((pattern) => glob.sync(path.resolve(process.cwd(), 'apps/api', pattern))), then it finds the seed and factory files.

Specifying a root with the -r argument at the CLI should, in my opinion, alter the way that fonction resolves paths to find the globs from the ormconfig.