cli
cli copied to clipboard
v6: Improve support for ESM & CJS config files
We currently search for config/config.json and config/config.js
We should also automatically look for extensions .cjs, and .mjs so specifying the config file location is not necessary.
We should do the same for .sequelizerc (https://github.com/sequelize/cli/blob/main/src/core/yargs.js#L7): load it using importHelper and support files: .sequelizerc (as js), .sequelizerc.js, .sequelizerc.cjs, .sequelizerc.mjs, .sequelizerc.json.
Second part would fix #951, correct?
yes :)
I've started working on a PR. Also this would be much easier if we had top-level-await
So to consolidate this with the other feature request; we also need to include a YML to JSON parser (or something equivalent) so we can also accept .yml and .yaml files. And for completeness; there is no demand currently to check if the file without extension is a YAML file so that's not in scope for this feature request
Having it in the package.json directly or passable through the command line is still part of #951 since that requires a different approach probably
If we're going to support YML & package.json as well, we could use https://github.com/davidtheclark/cosmiconfig. But they don't support ESM yet.
CLI options would be a separate feature yes.
This PR https://github.com/sequelize/cli/pull/987
includes docs update which says
ESM configuration files are supported for Node versions that support ESM natively, either via passing `--config config/config.mjs`, or by setting the `type` to `module` in your `package.json`.
In a project using "type": "module",, newly generated migration files are still non ESM:
npx sequelize-cli migration:create --name test1
generates
'use strict'
module.exports = {
async up(queryInterface, Sequelize) {
/**
* Add altering commands here.
*
* Example:
* await queryInterface.createTable('users', { id: Sequelize.INTEGER });
*/
},
async down(queryInterface, Sequelize) {
/**
* Add reverting commands here.
*
* Example:
* await queryInterface.dropTable('users');
*/
}
}
Similarly to https://github.com/sequelize/cli/issues/960, we could detect the module type in package.json, and provide a --module cjs|esm option, and generate the right contents accordingly
@ephys Is there any movement on this :-)? I've just spent an hour or two and still dealing with issues. Should I continue with trying to fix it on my end, or did you guys end up providing a support for mjs?
Thanks a lot
Our efforts are currently focused on getting the first beta version out for sequelize v7. After that we will start looking into updating the CLI but no promises on a timeline yet
But if you open a PR we will make the time to review it
@WikiRik is there any kind of improving to support ESM for running migration using .sequelizerc configuration yet? I thought that migrating to sequelize 7 this is issue would it be fixed but I am still having same issues to not be able to run migrations and seeders written in ESM :(
Any news?