Fix knex migration require translation

Change-type: patch
Closes: #1274
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2020-04-27 18:33:41 +01:00
parent a9b830e68c
commit 585bd80313
2 changed files with 11 additions and 8 deletions

View File

@ -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`,
);
};

View File

@ -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'),
},
{