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)
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
includestype: "module"
and when running the migrations with an.js
file extension, it will throw an error, as the migrations usemodule.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:
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)