Skip to content

[bug] false-positive success when using named export on seeder fileΒ #119

Open
@micalevisk

Description

@micalevisk

Basically, when the seeder file has some export const foo = 'bar'-ish statement, the run method is not invoked and the output is this:

🌱  TypeORM Seeding v1.6.1
βœ” ORM Config loaded
βœ” Factories are imported
βœ” Seeders are imported
β ‹ Connecting to the databaseINFO: All classes found using provided glob pattern xxx
INFO: All classes found using provided glob pattern xxx
βœ” Database connected
πŸ‘  Finished Seeding

I think that typeorm-seeding CLI should ignore these statements regardless of whether it is right or not to have them in a seeder file.


I've notice that this behavior is due to seedFileObject[keys[0]]

export const importSeed = async (filePath: string): Promise<SeederConstructor> => {
const seedFileObject: { [key: string]: SeederConstructor } = await import(filePath)
const keys = Object.keys(seedFileObject)
return seedFileObject[keys[0]]
}

because this will return the foo variable instead of the seeder class. I've thought that return seedFileObject.default was enough but @hirsch88 already use this in the past with require (on 84df811)

Maybe this should work but I'm not sure:

export const importSeed = async (filePath: string): Promise<SeederConstructor> => {
  const seedFileObject: { [key: string]: SeederConstructor } = await import(filePath)
  return seedFileObject.default
}

Metadata

Metadata

Assignees

Labels

on holdExternal action is required to work on this

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions