Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: don't use deprecated API #11689

Merged
merged 3 commits into from May 10, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -8,15 +8,25 @@
const Module = require("module");
const path = require("path");

// Polyfill Node's `Module.createRequireFromPath` if not present (added in Node v10.12.0)
const createRequireFromPath = Module.createRequireFromPath || (filename => {
const mod = new Module(filename, null);
// Polyfill Node's `Module.createRequire` if not present
This conversation was marked as resolved by mysticatea

This comment has been minimized.

Copy link
@not-an-aardvark

not-an-aardvark May 8, 2019

Member
Suggested change
// Polyfill Node's `Module.createRequire` if not present
// Polyfill Node's `Module.createRequire` if not present. We only support the case where the argument is a filepath, not a URL.
const createRequire = (

mod.filename = filename;
mod.paths = Module._nodeModulePaths(path.dirname(filename)); // eslint-disable-line no-underscore-dangle
mod._compile("module.exports = require;", filename); // eslint-disable-line no-underscore-dangle
return mod.exports;
});
// Added in v12.2.0
Module.createRequire ||

// Added in v10.12.0, but deprecated in v12.2.0.
Module.createRequireFromPath ||

// Polyfill.
(filename => {
const mod = new Module(filename, null);

mod.filename = filename;
mod.paths = Module._nodeModulePaths(path.dirname(filename)); // eslint-disable-line no-underscore-dangle
mod._compile("module.exports = require;", filename); // eslint-disable-line no-underscore-dangle
return mod.exports;
})
);

/**
* Resolves a Node module relative to another module
@@ -27,4 +37,4 @@ const createRequireFromPath = Module.createRequireFromPath || (filename => {
* @returns {string} The absolute path that would result from calling `require.resolve(moduleName)` in a file located at `relativeToPath`
*/
module.exports = (moduleName, relativeToPath) =>
createRequireFromPath(relativeToPath).resolve(moduleName);
createRequire(relativeToPath).resolve(moduleName);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.