db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

Only files with a *.js file extension are considered for execution #782

Closed Valefant closed 2 years ago

Valefant commented 2 years ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch db-migrate@0.11.13 for the project I'm working on.

My package.json includes type: "module" and when running the migrations with an .js file extension, it will throw an error, as the migrations use module.exports (CommonJS).

This is fixed when changing the file extension of the migration to .cjs.

But now, db-migrate won't find the migration anymore, as it filters only for files with an .js extension.

Here is the diff that solved my problem:

diff --git a/node_modules/db-migrate/lib/migration.js b/node_modules/db-migrate/lib/migration.js
index d94ae5e..f43ca0d 100644
--- a/node_modules/db-migrate/lib/migration.js
+++ b/node_modules/db-migrate/lib/migration.js
@@ -4,7 +4,7 @@ var log = require('db-migrate-shared').log;
 var Skeleton = require('./skeleton');
 var Promise = require('bluebird');

-var filesRegEx = /\.js$/;
+var filesRegEx = /(\.js|\.cjs)$/;

 var Migration = Skeleton.extend({
   init: function () {

If I am not mistaken, this behavior is also to be found on the latest commit of the master branch.

My suggestion is, to also support .cjs files, as probably a lot of projects are being of type module (esm)

wzrdtales commented 2 years ago

already fixed in https://github.com/db-migrate/node-db-migrate/pull/724 (you can use the current latest beta version without worrying)