1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = defaultResolver;
|
7 | exports.clearDefaultResolverCache = clearDefaultResolverCache;
|
8 |
|
9 | function fs() {
|
10 | const data = _interopRequireWildcard(require('fs'));
|
11 |
|
12 | fs = function () {
|
13 | return data;
|
14 | };
|
15 |
|
16 | return data;
|
17 | }
|
18 |
|
19 | function _resolve() {
|
20 | const data = require('resolve');
|
21 |
|
22 | _resolve = function () {
|
23 | return data;
|
24 | };
|
25 |
|
26 | return data;
|
27 | }
|
28 |
|
29 | function _browserResolve() {
|
30 | const data = require('browser-resolve');
|
31 |
|
32 | _browserResolve = function () {
|
33 | return data;
|
34 | };
|
35 |
|
36 | return data;
|
37 | }
|
38 |
|
39 | function _realpathNative() {
|
40 | const data = require('realpath-native');
|
41 |
|
42 | _realpathNative = function () {
|
43 | return data;
|
44 | };
|
45 |
|
46 | return data;
|
47 | }
|
48 |
|
49 | function _jestPnpResolver() {
|
50 | const data = _interopRequireDefault(require('jest-pnp-resolver'));
|
51 |
|
52 | _jestPnpResolver = function () {
|
53 | return data;
|
54 | };
|
55 |
|
56 | return data;
|
57 | }
|
58 |
|
59 | function _interopRequireDefault(obj) {
|
60 | return obj && obj.__esModule ? obj : {default: obj};
|
61 | }
|
62 |
|
63 | function _getRequireWildcardCache() {
|
64 | if (typeof WeakMap !== 'function') return null;
|
65 | var cache = new WeakMap();
|
66 | _getRequireWildcardCache = function () {
|
67 | return cache;
|
68 | };
|
69 | return cache;
|
70 | }
|
71 |
|
72 | function _interopRequireWildcard(obj) {
|
73 | if (obj && obj.__esModule) {
|
74 | return obj;
|
75 | }
|
76 | if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
|
77 | return {default: obj};
|
78 | }
|
79 | var cache = _getRequireWildcardCache();
|
80 | if (cache && cache.has(obj)) {
|
81 | return cache.get(obj);
|
82 | }
|
83 | var newObj = {};
|
84 | var hasPropertyDescriptor =
|
85 | Object.defineProperty && Object.getOwnPropertyDescriptor;
|
86 | for (var key in obj) {
|
87 | if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
88 | var desc = hasPropertyDescriptor
|
89 | ? Object.getOwnPropertyDescriptor(obj, key)
|
90 | : null;
|
91 | if (desc && (desc.get || desc.set)) {
|
92 | Object.defineProperty(newObj, key, desc);
|
93 | } else {
|
94 | newObj[key] = obj[key];
|
95 | }
|
96 | }
|
97 | }
|
98 | newObj.default = obj;
|
99 | if (cache) {
|
100 | cache.set(obj, newObj);
|
101 | }
|
102 | return newObj;
|
103 | }
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | function defaultResolver(path, options) {
|
112 |
|
113 | if (process.versions.pnp) {
|
114 | return (0, _jestPnpResolver().default)(path, options);
|
115 | }
|
116 |
|
117 | const resolve = options.browser ? _browserResolve().sync : _resolve().sync;
|
118 | const result = resolve(path, {
|
119 | basedir: options.basedir,
|
120 | extensions: options.extensions,
|
121 | isDirectory,
|
122 | isFile,
|
123 | moduleDirectory: options.moduleDirectory,
|
124 | paths: options.paths,
|
125 | preserveSymlinks: false
|
126 | });
|
127 |
|
128 | try {
|
129 |
|
130 |
|
131 | const resolved = (0, _realpathNative().sync)(result);
|
132 |
|
133 | if (resolved) {
|
134 | return resolved;
|
135 | }
|
136 | } catch (_unused) {
|
137 |
|
138 | }
|
139 |
|
140 | return result;
|
141 | }
|
142 |
|
143 | function clearDefaultResolverCache() {
|
144 | checkedPaths.clear();
|
145 | }
|
146 |
|
147 | var IPathType;
|
148 |
|
149 | (function (IPathType) {
|
150 | IPathType[(IPathType['FILE'] = 1)] = 'FILE';
|
151 | IPathType[(IPathType['DIRECTORY'] = 2)] = 'DIRECTORY';
|
152 | IPathType[(IPathType['OTHER'] = 3)] = 'OTHER';
|
153 | })(IPathType || (IPathType = {}));
|
154 |
|
155 | const checkedPaths = new Map();
|
156 |
|
157 | function statSyncCached(path) {
|
158 | const result = checkedPaths.get(path);
|
159 |
|
160 | if (result !== undefined) {
|
161 | return result;
|
162 | }
|
163 |
|
164 | let stat;
|
165 |
|
166 | try {
|
167 | stat = fs().statSync(path);
|
168 | } catch (e) {
|
169 | if (!(e && (e.code === 'ENOENT' || e.code === 'ENOTDIR'))) {
|
170 | throw e;
|
171 | }
|
172 | }
|
173 |
|
174 | if (stat) {
|
175 | if (stat.isFile() || stat.isFIFO()) {
|
176 | checkedPaths.set(path, IPathType.FILE);
|
177 | return IPathType.FILE;
|
178 | } else if (stat.isDirectory()) {
|
179 | checkedPaths.set(path, IPathType.DIRECTORY);
|
180 | return IPathType.DIRECTORY;
|
181 | }
|
182 | }
|
183 |
|
184 | checkedPaths.set(path, IPathType.OTHER);
|
185 | return IPathType.OTHER;
|
186 | }
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | function isFile(file) {
|
192 | return statSyncCached(file) === IPathType.FILE;
|
193 | }
|
194 |
|
195 | function isDirectory(dir) {
|
196 | return statSyncCached(dir) === IPathType.DIRECTORY;
|
197 | }
|