Skip to content

Using require.main.require instead of require for dialects #7354

Closed

Description

@grimurd

I wanted to suggest that when sequelize is loading in dialect modules that instead of using require() like normally, you use require.main.require(). Or at least provide the option to do so.

The difference between the two is that normal require() always point to the module that is calling the require method. However require.main.require() uses the scope of the topmost module in the hierarchy which is usually the module that is being run by the user.

My use case is that I have created a small framework for my employer which is using sequelize. When using this framework in a project it is installed using npm and then required by the project. However the framework needs to include all the possible dialects in it's project.json which makes the install take significantly longer which hurts our build process and increases the size on disk.
However if sequelize was using require.main.require() wouldn't have to install all the dialects in the framework but could instead install only the dialects I need directly in the project.

This should not break anything that is using sequelize directly as require.main always points at the top level module.

I hope what I said made sense and I apologize for any grammar errors.

Activity

  1. added
    type: feature
    good first issue
    on Mar 14, 2017
  2. janmeier commented on Mar 14, 2017

    @janmeier
    Member

    I've never had this issue myself, but it should be fine to go so - PR welcome!

    BTW, why do you have to include all dialects? We use sequelize with postgres, and only have pg in our package

  3. grimurd commented on Mar 14, 2017

    @grimurd
    Author

    @janmeier Because it's a framework, and not all the projects using the framework are using the same database :)

    I'll try to make a PR in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuestaletype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions