1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.isJSONString =
|
7 | exports._replaceRootDirTags =
|
8 | exports.replaceRootDirInPath =
|
9 | exports.escapeGlobCharacters =
|
10 | exports.resolve =
|
11 | exports.DOCUMENTATION_NOTE =
|
12 | exports.BULLET =
|
13 | void 0;
|
14 |
|
15 | function path() {
|
16 | const data = _interopRequireWildcard(require('path'));
|
17 |
|
18 | path = function () {
|
19 | return data;
|
20 | };
|
21 |
|
22 | return data;
|
23 | }
|
24 |
|
25 | function _chalk() {
|
26 | const data = _interopRequireDefault(require('chalk'));
|
27 |
|
28 | _chalk = function () {
|
29 | return data;
|
30 | };
|
31 |
|
32 | return data;
|
33 | }
|
34 |
|
35 | function _jestResolve() {
|
36 | const data = _interopRequireDefault(require('jest-resolve'));
|
37 |
|
38 | _jestResolve = function () {
|
39 | return data;
|
40 | };
|
41 |
|
42 | return data;
|
43 | }
|
44 |
|
45 | function _jestValidate() {
|
46 | const data = require('jest-validate');
|
47 |
|
48 | _jestValidate = function () {
|
49 | return data;
|
50 | };
|
51 |
|
52 | return data;
|
53 | }
|
54 |
|
55 | function _interopRequireDefault(obj) {
|
56 | return obj && obj.__esModule ? obj : {default: obj};
|
57 | }
|
58 |
|
59 | function _getRequireWildcardCache(nodeInterop) {
|
60 | if (typeof WeakMap !== 'function') return null;
|
61 | var cacheBabelInterop = new WeakMap();
|
62 | var cacheNodeInterop = new WeakMap();
|
63 | return (_getRequireWildcardCache = function (nodeInterop) {
|
64 | return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
65 | })(nodeInterop);
|
66 | }
|
67 |
|
68 | function _interopRequireWildcard(obj, nodeInterop) {
|
69 | if (!nodeInterop && obj && obj.__esModule) {
|
70 | return obj;
|
71 | }
|
72 | if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
|
73 | return {default: obj};
|
74 | }
|
75 | var cache = _getRequireWildcardCache(nodeInterop);
|
76 | if (cache && cache.has(obj)) {
|
77 | return cache.get(obj);
|
78 | }
|
79 | var newObj = {};
|
80 | var hasPropertyDescriptor =
|
81 | Object.defineProperty && Object.getOwnPropertyDescriptor;
|
82 | for (var key in obj) {
|
83 | if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
|
84 | var desc = hasPropertyDescriptor
|
85 | ? Object.getOwnPropertyDescriptor(obj, key)
|
86 | : null;
|
87 | if (desc && (desc.get || desc.set)) {
|
88 | Object.defineProperty(newObj, key, desc);
|
89 | } else {
|
90 | newObj[key] = obj[key];
|
91 | }
|
92 | }
|
93 | }
|
94 | newObj.default = obj;
|
95 | if (cache) {
|
96 | cache.set(obj, newObj);
|
97 | }
|
98 | return newObj;
|
99 | }
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | const BULLET = _chalk().default.bold('\u25cf ');
|
108 |
|
109 | exports.BULLET = BULLET;
|
110 | const DOCUMENTATION_NOTE = ` ${_chalk().default.bold(
|
111 | 'Configuration Documentation:'
|
112 | )}
|
113 | https://jestjs.io/docs/configuration
|
114 | `;
|
115 | exports.DOCUMENTATION_NOTE = DOCUMENTATION_NOTE;
|
116 |
|
117 | const createValidationError = message =>
|
118 | new (_jestValidate().ValidationError)(
|
119 | `${BULLET}Validation Error`,
|
120 | message,
|
121 | DOCUMENTATION_NOTE
|
122 | );
|
123 |
|
124 | const resolve = (resolver, {key, filePath, rootDir, optional}) => {
|
125 | const module = _jestResolve().default.findNodeModule(
|
126 | replaceRootDirInPath(rootDir, filePath),
|
127 | {
|
128 | basedir: rootDir,
|
129 | resolver: resolver || undefined
|
130 | }
|
131 | );
|
132 |
|
133 | if (!module && !optional) {
|
134 | throw createValidationError(` Module ${_chalk().default.bold(
|
135 | filePath
|
136 | )} in the ${_chalk().default.bold(key)} option was not found.
|
137 | ${_chalk().default.bold('<rootDir>')} is: ${rootDir}`);
|
138 | }
|
139 |
|
140 | return module;
|
141 | };
|
142 |
|
143 | exports.resolve = resolve;
|
144 |
|
145 | const escapeGlobCharacters = path => path.replace(/([()*{}\[\]!?\\])/g, '\\$1');
|
146 |
|
147 | exports.escapeGlobCharacters = escapeGlobCharacters;
|
148 |
|
149 | const replaceRootDirInPath = (rootDir, filePath) => {
|
150 | if (!/^<rootDir>/.test(filePath)) {
|
151 | return filePath;
|
152 | }
|
153 |
|
154 | return path().resolve(
|
155 | rootDir,
|
156 | path().normalize('./' + filePath.substr('<rootDir>'.length))
|
157 | );
|
158 | };
|
159 |
|
160 | exports.replaceRootDirInPath = replaceRootDirInPath;
|
161 |
|
162 | const _replaceRootDirInObject = (rootDir, config) => {
|
163 | const newConfig = {};
|
164 |
|
165 | for (const configKey in config) {
|
166 | newConfig[configKey] =
|
167 | configKey === 'rootDir'
|
168 | ? config[configKey]
|
169 | : _replaceRootDirTags(rootDir, config[configKey]);
|
170 | }
|
171 |
|
172 | return newConfig;
|
173 | };
|
174 |
|
175 | const _replaceRootDirTags = (rootDir, config) => {
|
176 | if (config == null) {
|
177 | return config;
|
178 | }
|
179 |
|
180 | switch (typeof config) {
|
181 | case 'object':
|
182 | if (Array.isArray(config)) {
|
183 |
|
184 | return config.map(item => _replaceRootDirTags(rootDir, item));
|
185 | }
|
186 |
|
187 | if (config instanceof RegExp) {
|
188 | return config;
|
189 | }
|
190 |
|
191 | return _replaceRootDirInObject(rootDir, config);
|
192 |
|
193 | case 'string':
|
194 | return replaceRootDirInPath(rootDir, config);
|
195 | }
|
196 |
|
197 | return config;
|
198 | };
|
199 |
|
200 | exports._replaceRootDirTags = _replaceRootDirTags;
|
201 |
|
202 |
|
203 | const isJSONString = text =>
|
204 | text != null &&
|
205 | typeof text === 'string' &&
|
206 | text.startsWith('{') &&
|
207 | text.endsWith('}');
|
208 |
|
209 | exports.isJSONString = isJSONString;
|