Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for ES Module detection using npm@7 (#4295) #4296

Merged
merged 6 commits into from
Feb 15, 2021

Conversation

richardsimko
Copy link
Contributor

No description provided.

@kibertoad
Copy link
Collaborator

@richardsimko Bunch of previous tests seem to be failing, see https://github.com/knex/knex/pull/4296/checks?check_run_id=1904682577

@richardsimko
Copy link
Contributor Author

Yeah I don't think my approach to mocking the env vars was good. I'll try another way but if that doesn't work I'm not sure it's possible to add tests for this code in a good way.

@kibertoad
Copy link
Collaborator

@richardsimko Unit tests are fixed, but it looks like something in migration loading logic might be broken, judging by non-mysql integration tests.

@richardsimko
Copy link
Contributor Author

I think what's most likely happening is that I've uncovered latent issues where importFile was not used with await. import(filePath) is an async function and always was - but this function was only used in the ESM case which doesn't seem to be commonly used. Now importFile is always async and this is how that issue manifests. Fixing this would require a lot more in-depth knowledge of knex than what I have but if you have any pointers as to where this might be an issue I'm all ears.

@richardsimko
Copy link
Contributor Author

richardsimko commented Feb 15, 2021

importFile seems to be used here

return importFile(_path);

Which in turn is used in many places without await:

const migrationContent = this.config.migrationSource.getMigration(

this.config.migrationSource.getMigration(migrationToRun)

const migrationContents = this.config.migrationSource.getMigration(

@kibertoad
Copy link
Collaborator

@richardsimko Yeah, noticed same thing:

return importFile(_path);
seems to be the only place where we importFile without awaiting, so I would review all cases where getMigration is used to ensure we await properly.

@richardsimko
Copy link
Contributor Author

I can slap awaits on all the above mentioned locations but in my experience fixing these types of issues is never that easy 😅

@kibertoad
Copy link
Collaborator

@richardsimko You might need to make few more functions async (e. g. waterfallBatch), but that should do it. We have pretty good coverage for migrations at this point, if something breaks down, you'll know immediately.

@richardsimko
Copy link
Contributor Author

It worked 🎉 I added a note in the changelog as well. Do you want me to squash the commits?

@kibertoad
Copy link
Collaborator

@richardsimko Thanks a lot!
Squashing is not worth the effort, I'll squash on merge anyway.

@kibertoad kibertoad merged commit 4899346 into knex:master Feb 15, 2021
@richardsimko
Copy link
Contributor Author

@kibertoad Is there anything I have to do in order to get this backported to 0.21.x?

@kibertoad
Copy link
Collaborator

@richardsimko There is a 0.21 branch, just open a PR targetting that.

@richardsimko
Copy link
Contributor Author

Thanks, I opened #4308

@falkenhawk falkenhawk mentioned this pull request Feb 22, 2021
@richardsimko richardsimko deleted the master branch February 23, 2021 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants