2 * STOP!!! DO NOT MODIFY.
4 * This file is part of the ongoing work to move the eslintrc-style config
5 * system into the @eslint/eslintrc package. This file needs to remain
6 * unchanged in order for this work to proceed.
8 * If you think you need to change this file, please contact @nzakas first.
10 * Thanks in advance for your cooperation.
14 * Utility for resolving a module relative to another module
20 const Module = require("module");
23 * `Module.createRequire` is added in v12.2.0. It supports URL as well.
24 * We only support the case where the argument is a filepath, not a URL.
26 // eslint-disable-next-line node/no-unsupported-features/node-builtins, node/no-deprecated-api
27 const createRequire = Module.createRequire || Module.createRequireFromPath;
32 * Resolves a Node module relative to another module
33 * @param {string} moduleName The name of a Node module, or a path to a Node module.
34 * @param {string} relativeToPath An absolute path indicating the module that `moduleName` should be resolved relative to. This must be
35 * a file rather than a directory, but the file need not actually exist.
36 * @returns {string} The absolute path that would result from calling `require.resolve(moduleName)` in a file located at `relativeToPath`
38 resolve(moduleName, relativeToPath) {
40 return createRequire(relativeToPath).resolve(moduleName);
43 // This `if` block is for older Node.js than 12.0.0. We can remove this block in the future.
45 typeof error === "object" &&
47 error.code === "MODULE_NOT_FOUND" &&
48 !error.requireStack &&
49 error.message.includes(moduleName)
51 error.message += `\nRequire stack:\n- ${relativeToPath}`;