From 585bd803134db999425fae322fd4e7259caaa27a Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Mon, 27 Apr 2020 18:33:41 +0100 Subject: [PATCH] Fix knex migration require translation Change-type: patch Closes: #1274 Signed-off-by: Cameron Diver --- hardcode-migrations.js | 10 ++++++---- webpack.config.js | 9 +++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/hardcode-migrations.js b/hardcode-migrations.js index 00c25810..9bd4998f 100644 --- a/hardcode-migrations.js +++ b/hardcode-migrations.js @@ -1,9 +1,11 @@ // knex migrations use dynamic requires which break with webpack. // This hack makes the migrations directory a constant so that at least we can use webpack contexts for the // require. -module.exports = function (source) { +module.exports = function(source) { return source .toString() - .replace(/require\(_path2\.default\.join\(_?this\._absoluteConfigDir\(\), name\)\);/g, "require('./migrations/' + name);") - .replace("require(directory + '/' + name);", "require('./migrations/' + name);") -} + .replace( + 'path.join(absoluteDir, migration.file)', + `'./migrations/'+migration.file`, + ); +}; diff --git a/webpack.config.js b/webpack.config.js index 4a9b1efd..15a80520 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -97,10 +97,11 @@ module.exports = function(env) { module: { rules: [ { - test: new RegExp( - _.escapeRegExp(path.join('knex', 'lib', 'migrate', 'index.js')) + - '$', - ), + include: [ + new RegExp( + _.escapeRegExp(path.join('knex', 'lib', 'migrate', 'sources')), + ), + ], use: require.resolve('./hardcode-migrations'), }, {