Skip to content

Commit

Permalink
Merge f1da725 into 4906ff2
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-knight committed May 5, 2021
2 parents 4906ff2 + f1da725 commit 55ef11e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/env/config.js
@@ -1,5 +1,6 @@
const fs = require("fs-extra");
const path = require("path");
const url = require("url");
const { get } = require("lodash");

const DEFAULT_CONFIG_FILE_NAME = "migrate-mongo-config.js";
Expand Down Expand Up @@ -60,6 +61,13 @@ module.exports = {
return customConfigContent;
}
const configPath = getConfigPath();
return Promise.resolve(require(configPath)); // eslint-disable-line
try {
return Promise.resolve(require(configPath)); // eslint-disable-line
} catch (e) {
if (e.code === 'ERR_REQUIRE_ESM') {
return (await import(url.pathToFileURL(configPath))).default;
}
throw e;
}
}
};
13 changes: 11 additions & 2 deletions lib/env/migrationsDir.js
@@ -1,5 +1,6 @@
const fs = require("fs-extra");
const path = require("path");
const url = require("url");
const crypto = require("crypto");
const config = require("./config");

Expand Down Expand Up @@ -94,11 +95,19 @@ module.exports = {

async loadMigration(fileName) {
const migrationsDir = await resolveMigrationsDirPath();
return require(path.join(migrationsDir, fileName)); // eslint-disable-line
const migrationPath = path.join(migrationsDir, fileName);
try {
return require(migrationPath); // eslint-disable-line
} catch (e) {
if (e.code === 'ERR_REQUIRE_ESM') {
return import(url.pathToFileURL(migrationPath));
}
throw e;
}
},

async loadFileHash(fileName) {
const migrationsDir = await resolveMigrationsDirPath();
const migrationsDir = await resolveMigrationsDirPath();
const filePath = path.join(migrationsDir, fileName)
const hash = crypto.createHash('sha256');
const input = await fs.readFile(filePath);
Expand Down

0 comments on commit 55ef11e

Please sign in to comment.