cli icon indicating copy to clipboard operation
cli copied to clipboard

v6: Improve support for ESM & CJS config files

Open ephys opened this issue 3 years ago • 11 comments

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.

ephys avatar Jan 13 '22 09:01 ephys

Second part would fix #951, correct?

WikiRik avatar Jan 13 '22 11:01 WikiRik

yes :)

I've started working on a PR. Also this would be much easier if we had top-level-await

ephys avatar Jan 13 '22 11:01 ephys

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

WikiRik avatar Jan 13 '22 11:01 WikiRik

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.

ephys avatar Jan 13 '22 11:01 ephys

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');
         */
    }
}

mariusa avatar May 09 '22 13:05 mariusa

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 avatar May 13 '22 11:05 ephys

@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

agjs avatar Jan 20 '23 21:01 agjs

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 avatar Jan 20 '23 21:01 WikiRik

@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 :(

IvanGarzon avatar May 16 '23 21:05 IvanGarzon

Any news?

mahnunchik avatar Oct 19 '23 02:10 mahnunchik