UNPKG

3.19 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.default = void 0;
7
8function path() {
9 const data = _interopRequireWildcard(require('path'));
10
11 path = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _slash() {
19 const data = _interopRequireDefault(require('slash'));
20
21 _slash = function () {
22 return data;
23 };
24
25 return data;
26}
27
28function _interopRequireDefault(obj) {
29 return obj && obj.__esModule ? obj : {default: obj};
30}
31
32function _getRequireWildcardCache() {
33 if (typeof WeakMap !== 'function') return null;
34 var cache = new WeakMap();
35 _getRequireWildcardCache = function () {
36 return cache;
37 };
38 return cache;
39}
40
41function _interopRequireWildcard(obj) {
42 if (obj && obj.__esModule) {
43 return obj;
44 }
45 if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
46 return {default: obj};
47 }
48 var cache = _getRequireWildcardCache();
49 if (cache && cache.has(obj)) {
50 return cache.get(obj);
51 }
52 var newObj = {};
53 var hasPropertyDescriptor =
54 Object.defineProperty && Object.getOwnPropertyDescriptor;
55 for (var key in obj) {
56 if (Object.prototype.hasOwnProperty.call(obj, key)) {
57 var desc = hasPropertyDescriptor
58 ? Object.getOwnPropertyDescriptor(obj, key)
59 : null;
60 if (desc && (desc.get || desc.set)) {
61 Object.defineProperty(newObj, key, desc);
62 } else {
63 newObj[key] = obj[key];
64 }
65 }
66 }
67 newObj.default = obj;
68 if (cache) {
69 cache.set(obj, newObj);
70 }
71 return newObj;
72}
73
74function _defineProperty(obj, key, value) {
75 if (key in obj) {
76 Object.defineProperty(obj, key, {
77 value: value,
78 enumerable: true,
79 configurable: true,
80 writable: true
81 });
82 } else {
83 obj[key] = value;
84 }
85 return obj;
86}
87
88class ModuleNotFoundError extends Error {
89 constructor(message, moduleName) {
90 super(message);
91
92 _defineProperty(this, 'code', 'MODULE_NOT_FOUND');
93
94 _defineProperty(this, 'hint', void 0);
95
96 _defineProperty(this, 'requireStack', void 0);
97
98 _defineProperty(this, 'siblingWithSimilarExtensionFound', void 0);
99
100 _defineProperty(this, 'moduleName', void 0);
101
102 _defineProperty(this, '_originalMessage', void 0);
103
104 this._originalMessage = message;
105 this.moduleName = moduleName;
106 }
107
108 buildMessage(rootDir) {
109 var _this$requireStack;
110
111 if (!this._originalMessage) {
112 this._originalMessage = this.message || '';
113 }
114
115 let message = this._originalMessage;
116
117 if (
118 (this === null || this === void 0
119 ? void 0
120 : (_this$requireStack = this.requireStack) === null ||
121 _this$requireStack === void 0
122 ? void 0
123 : _this$requireStack.length) &&
124 this.requireStack.length > 1
125 ) {
126 message += `
127
128Require stack:
129 ${this.requireStack
130 .map(p => p.replace(`${rootDir}${path().sep}`, ''))
131 .map(_slash().default)
132 .join('\n ')}
133`;
134 }
135
136 if (this.hint) {
137 message += this.hint;
138 }
139
140 this.message = message;
141 }
142
143 static duckType(error) {
144 error.buildMessage = ModuleNotFoundError.prototype.buildMessage;
145 return error;
146 }
147}
148
149exports.default = ModuleNotFoundError;