main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.7 KB
|
Line | |
---|
1 | /*
|
---|
2 | * STOP!!! DO NOT MODIFY.
|
---|
3 | *
|
---|
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.
|
---|
7 | *
|
---|
8 | * If you think you need to change this file, please contact @nzakas first.
|
---|
9 | *
|
---|
10 | * Thanks in advance for your cooperation.
|
---|
11 | */
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Utility for resolving a module relative to another module
|
---|
15 | * @author Teddy Katz
|
---|
16 | */
|
---|
17 |
|
---|
18 | "use strict";
|
---|
19 |
|
---|
20 | const { createRequire } = require("module");
|
---|
21 |
|
---|
22 | module.exports = {
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Resolves a Node module relative to another module
|
---|
26 | * @param {string} moduleName The name of a Node module, or a path to a Node module.
|
---|
27 | * @param {string} relativeToPath An absolute path indicating the module that `moduleName` should be resolved relative to. This must be
|
---|
28 | * a file rather than a directory, but the file need not actually exist.
|
---|
29 | * @throws {Error} Any error from `module.createRequire` or its `resolve`.
|
---|
30 | * @returns {string} The absolute path that would result from calling `require.resolve(moduleName)` in a file located at `relativeToPath`
|
---|
31 | */
|
---|
32 | resolve(moduleName, relativeToPath) {
|
---|
33 | try {
|
---|
34 | return createRequire(relativeToPath).resolve(moduleName);
|
---|
35 | } catch (error) {
|
---|
36 |
|
---|
37 | // This `if` block is for older Node.js than 12.0.0. We can remove this block in the future.
|
---|
38 | if (
|
---|
39 | typeof error === "object" &&
|
---|
40 | error !== null &&
|
---|
41 | error.code === "MODULE_NOT_FOUND" &&
|
---|
42 | !error.requireStack &&
|
---|
43 | error.message.includes(moduleName)
|
---|
44 | ) {
|
---|
45 | error.message += `\nRequire stack:\n- ${relativeToPath}`;
|
---|
46 | }
|
---|
47 | throw error;
|
---|
48 | }
|
---|
49 | }
|
---|
50 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.