@vitest/utils 4.0.0-beta.4 → 4.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/chunk-helpers.js +329 -0
- package/dist/chunk-pathe.M-eThtNZ.js +156 -0
- package/dist/diff.js +1 -1
- package/dist/error.js +1 -1
- package/dist/helpers.d.ts +15 -1
- package/dist/helpers.js +1 -251
- package/dist/index.d.ts +23 -2
- package/dist/index.js +1 -1
- package/dist/resolver.d.ts +7 -0
- package/dist/resolver.js +71 -0
- package/dist/source-map.js +7 -99
- package/package.json +7 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2021-Present Vitest
|
|
3
|
+
Copyright (c) 2021-Present VoidZero Inc. and Vitest contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
// TODO: this is all copy pasted from Vite - can they expose a module that exports only constants?
|
|
2
|
+
const KNOWN_ASSET_TYPES = [
|
|
3
|
+
"apng",
|
|
4
|
+
"bmp",
|
|
5
|
+
"png",
|
|
6
|
+
"jpe?g",
|
|
7
|
+
"jfif",
|
|
8
|
+
"pjpeg",
|
|
9
|
+
"pjp",
|
|
10
|
+
"gif",
|
|
11
|
+
"svg",
|
|
12
|
+
"ico",
|
|
13
|
+
"webp",
|
|
14
|
+
"avif",
|
|
15
|
+
"mp4",
|
|
16
|
+
"webm",
|
|
17
|
+
"ogg",
|
|
18
|
+
"mp3",
|
|
19
|
+
"wav",
|
|
20
|
+
"flac",
|
|
21
|
+
"aac",
|
|
22
|
+
"woff2?",
|
|
23
|
+
"eot",
|
|
24
|
+
"ttf",
|
|
25
|
+
"otf",
|
|
26
|
+
"webmanifest",
|
|
27
|
+
"pdf",
|
|
28
|
+
"txt"
|
|
29
|
+
];
|
|
30
|
+
const KNOWN_ASSET_RE = new RegExp(`\\.(${KNOWN_ASSET_TYPES.join("|")})$`);
|
|
31
|
+
const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
32
|
+
/**
|
|
33
|
+
* Prefix for resolved Ids that are not valid browser import specifiers
|
|
34
|
+
*/
|
|
35
|
+
const VALID_ID_PREFIX = `/@id/`;
|
|
36
|
+
/**
|
|
37
|
+
* Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
|
|
38
|
+
* module ID with `\0`, a convention from the rollup ecosystem.
|
|
39
|
+
* This prevents other plugins from trying to process the id (like node resolution),
|
|
40
|
+
* and core features like sourcemaps can use this info to differentiate between
|
|
41
|
+
* virtual modules and regular files.
|
|
42
|
+
* `\0` is not a permitted char in import URLs so we have to replace them during
|
|
43
|
+
* import analysis. The id will be decoded back before entering the plugins pipeline.
|
|
44
|
+
* These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
|
|
45
|
+
* modules in the browser end up encoded as `/@id/__x00__{id}`
|
|
46
|
+
*/
|
|
47
|
+
const NULL_BYTE_PLACEHOLDER = `__x00__`;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get original stacktrace without source map support the most performant way.
|
|
51
|
+
* - Create only 1 stack frame.
|
|
52
|
+
* - Rewrite prepareStackTrace to bypass "support-stack-trace" (usually takes ~250ms).
|
|
53
|
+
*/
|
|
54
|
+
function createSimpleStackTrace(options) {
|
|
55
|
+
const { message = "$$stack trace error", stackTraceLimit = 1 } = options || {};
|
|
56
|
+
const limit = Error.stackTraceLimit;
|
|
57
|
+
const prepareStackTrace = Error.prepareStackTrace;
|
|
58
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
59
|
+
Error.prepareStackTrace = (e) => e.stack;
|
|
60
|
+
const err = new Error(message);
|
|
61
|
+
const stackTrace = err.stack || "";
|
|
62
|
+
Error.prepareStackTrace = prepareStackTrace;
|
|
63
|
+
Error.stackTraceLimit = limit;
|
|
64
|
+
return stackTrace;
|
|
65
|
+
}
|
|
66
|
+
function notNullish(v) {
|
|
67
|
+
return v != null;
|
|
68
|
+
}
|
|
69
|
+
function assertTypes(value, name, types) {
|
|
70
|
+
const receivedType = typeof value;
|
|
71
|
+
const pass = types.includes(receivedType);
|
|
72
|
+
if (!pass) {
|
|
73
|
+
throw new TypeError(`${name} value must be ${types.join(" or ")}, received "${receivedType}"`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function isPrimitive(value) {
|
|
77
|
+
return value === null || typeof value !== "function" && typeof value !== "object";
|
|
78
|
+
}
|
|
79
|
+
function slash(path) {
|
|
80
|
+
return path.replace(/\\/g, "/");
|
|
81
|
+
}
|
|
82
|
+
const postfixRE = /[?#].*$/;
|
|
83
|
+
function cleanUrl(url) {
|
|
84
|
+
return url.replace(postfixRE, "");
|
|
85
|
+
}
|
|
86
|
+
const externalRE = /^(?:[a-z]+:)?\/\//;
|
|
87
|
+
const isExternalUrl = (url) => externalRE.test(url);
|
|
88
|
+
/**
|
|
89
|
+
* Prepend `/@id/` and replace null byte so the id is URL-safe.
|
|
90
|
+
* This is prepended to resolved ids that are not valid browser
|
|
91
|
+
* import specifiers by the importAnalysis plugin.
|
|
92
|
+
*/
|
|
93
|
+
function wrapId(id) {
|
|
94
|
+
return id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Undo {@link wrapId}'s `/@id/` and null byte replacements.
|
|
98
|
+
*/
|
|
99
|
+
function unwrapId(id) {
|
|
100
|
+
return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0") : id;
|
|
101
|
+
}
|
|
102
|
+
function withTrailingSlash(path) {
|
|
103
|
+
if (path[path.length - 1] !== "/") {
|
|
104
|
+
return `${path}/`;
|
|
105
|
+
}
|
|
106
|
+
return path;
|
|
107
|
+
}
|
|
108
|
+
const bareImportRE = /^(?![a-z]:)[\w@](?!.*:\/\/)/i;
|
|
109
|
+
function isBareImport(id) {
|
|
110
|
+
return bareImportRE.test(id);
|
|
111
|
+
}
|
|
112
|
+
// convert RegExp.toString to RegExp
|
|
113
|
+
function parseRegexp(input) {
|
|
114
|
+
// Parse input
|
|
115
|
+
// eslint-disable-next-line regexp/no-misleading-capturing-group
|
|
116
|
+
const m = input.match(/(\/?)(.+)\1([a-z]*)/i);
|
|
117
|
+
// match nothing
|
|
118
|
+
if (!m) {
|
|
119
|
+
return /$^/;
|
|
120
|
+
}
|
|
121
|
+
// Invalid flags
|
|
122
|
+
// eslint-disable-next-line regexp/optimal-quantifier-concatenation
|
|
123
|
+
if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) {
|
|
124
|
+
return new RegExp(input);
|
|
125
|
+
}
|
|
126
|
+
// Create the regular expression
|
|
127
|
+
return new RegExp(m[2], m[3]);
|
|
128
|
+
}
|
|
129
|
+
function toArray(array) {
|
|
130
|
+
if (array === null || array === undefined) {
|
|
131
|
+
array = [];
|
|
132
|
+
}
|
|
133
|
+
if (Array.isArray(array)) {
|
|
134
|
+
return array;
|
|
135
|
+
}
|
|
136
|
+
return [array];
|
|
137
|
+
}
|
|
138
|
+
function isObject(item) {
|
|
139
|
+
return item != null && typeof item === "object" && !Array.isArray(item);
|
|
140
|
+
}
|
|
141
|
+
function isFinalObj(obj) {
|
|
142
|
+
return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
|
|
143
|
+
}
|
|
144
|
+
function getType(value) {
|
|
145
|
+
return Object.prototype.toString.apply(value).slice(8, -1);
|
|
146
|
+
}
|
|
147
|
+
function collectOwnProperties(obj, collector) {
|
|
148
|
+
const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
|
|
149
|
+
Object.getOwnPropertyNames(obj).forEach(collect);
|
|
150
|
+
Object.getOwnPropertySymbols(obj).forEach(collect);
|
|
151
|
+
}
|
|
152
|
+
function getOwnProperties(obj) {
|
|
153
|
+
const ownProps = new Set();
|
|
154
|
+
if (isFinalObj(obj)) {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
collectOwnProperties(obj, ownProps);
|
|
158
|
+
return Array.from(ownProps);
|
|
159
|
+
}
|
|
160
|
+
const defaultCloneOptions = { forceWritable: false };
|
|
161
|
+
function deepClone(val, options = defaultCloneOptions) {
|
|
162
|
+
const seen = new WeakMap();
|
|
163
|
+
return clone(val, seen, options);
|
|
164
|
+
}
|
|
165
|
+
function clone(val, seen, options = defaultCloneOptions) {
|
|
166
|
+
let k, out;
|
|
167
|
+
if (seen.has(val)) {
|
|
168
|
+
return seen.get(val);
|
|
169
|
+
}
|
|
170
|
+
if (Array.isArray(val)) {
|
|
171
|
+
out = Array.from({ length: k = val.length });
|
|
172
|
+
seen.set(val, out);
|
|
173
|
+
while (k--) {
|
|
174
|
+
out[k] = clone(val[k], seen, options);
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
if (Object.prototype.toString.call(val) === "[object Object]") {
|
|
179
|
+
out = Object.create(Object.getPrototypeOf(val));
|
|
180
|
+
seen.set(val, out);
|
|
181
|
+
// we don't need properties from prototype
|
|
182
|
+
const props = getOwnProperties(val);
|
|
183
|
+
for (const k of props) {
|
|
184
|
+
const descriptor = Object.getOwnPropertyDescriptor(val, k);
|
|
185
|
+
if (!descriptor) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const cloned = clone(val[k], seen, options);
|
|
189
|
+
if (options.forceWritable) {
|
|
190
|
+
Object.defineProperty(out, k, {
|
|
191
|
+
enumerable: descriptor.enumerable,
|
|
192
|
+
configurable: true,
|
|
193
|
+
writable: true,
|
|
194
|
+
value: cloned
|
|
195
|
+
});
|
|
196
|
+
} else if ("get" in descriptor) {
|
|
197
|
+
Object.defineProperty(out, k, {
|
|
198
|
+
...descriptor,
|
|
199
|
+
get() {
|
|
200
|
+
return cloned;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
} else {
|
|
204
|
+
Object.defineProperty(out, k, {
|
|
205
|
+
...descriptor,
|
|
206
|
+
value: cloned
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
return val;
|
|
213
|
+
}
|
|
214
|
+
function noop() {}
|
|
215
|
+
function objectAttr(source, path, defaultValue = undefined) {
|
|
216
|
+
// a[3].b -> a.3.b
|
|
217
|
+
const paths = path.replace(/\[(\d+)\]/g, ".$1").split(".");
|
|
218
|
+
let result = source;
|
|
219
|
+
for (const p of paths) {
|
|
220
|
+
result = new Object(result)[p];
|
|
221
|
+
if (result === undefined) {
|
|
222
|
+
return defaultValue;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
function createDefer() {
|
|
228
|
+
let resolve = null;
|
|
229
|
+
let reject = null;
|
|
230
|
+
const p = new Promise((_resolve, _reject) => {
|
|
231
|
+
resolve = _resolve;
|
|
232
|
+
reject = _reject;
|
|
233
|
+
});
|
|
234
|
+
p.resolve = resolve;
|
|
235
|
+
p.reject = reject;
|
|
236
|
+
return p;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* If code starts with a function call, will return its last index, respecting arguments.
|
|
240
|
+
* This will return 25 - last ending character of toMatch ")"
|
|
241
|
+
* Also works with callbacks
|
|
242
|
+
* ```
|
|
243
|
+
* toMatch({ test: '123' });
|
|
244
|
+
* toBeAliased('123')
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
function getCallLastIndex(code) {
|
|
248
|
+
let charIndex = -1;
|
|
249
|
+
let inString = null;
|
|
250
|
+
let startedBracers = 0;
|
|
251
|
+
let endedBracers = 0;
|
|
252
|
+
let beforeChar = null;
|
|
253
|
+
while (charIndex <= code.length) {
|
|
254
|
+
beforeChar = code[charIndex];
|
|
255
|
+
charIndex++;
|
|
256
|
+
const char = code[charIndex];
|
|
257
|
+
const isCharString = char === "\"" || char === "'" || char === "`";
|
|
258
|
+
if (isCharString && beforeChar !== "\\") {
|
|
259
|
+
if (inString === char) {
|
|
260
|
+
inString = null;
|
|
261
|
+
} else if (!inString) {
|
|
262
|
+
inString = char;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (!inString) {
|
|
266
|
+
if (char === "(") {
|
|
267
|
+
startedBracers++;
|
|
268
|
+
}
|
|
269
|
+
if (char === ")") {
|
|
270
|
+
endedBracers++;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (startedBracers && endedBracers && startedBracers === endedBracers) {
|
|
274
|
+
return charIndex;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
function isNegativeNaN(val) {
|
|
280
|
+
if (!Number.isNaN(val)) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
const f64 = new Float64Array(1);
|
|
284
|
+
f64[0] = val;
|
|
285
|
+
const u32 = new Uint32Array(f64.buffer);
|
|
286
|
+
const isNegative = u32[1] >>> 31 === 1;
|
|
287
|
+
return isNegative;
|
|
288
|
+
}
|
|
289
|
+
function toString(v) {
|
|
290
|
+
return Object.prototype.toString.call(v);
|
|
291
|
+
}
|
|
292
|
+
function isPlainObject(val) {
|
|
293
|
+
return toString(val) === "[object Object]" && (!val.constructor || val.constructor.name === "Object");
|
|
294
|
+
}
|
|
295
|
+
function isMergeableObject(item) {
|
|
296
|
+
return isPlainObject(item) && !Array.isArray(item);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Deep merge :P
|
|
300
|
+
*
|
|
301
|
+
* Will merge objects only if they are plain
|
|
302
|
+
*
|
|
303
|
+
* Do not merge types - it is very expensive and usually it's better to case a type here
|
|
304
|
+
*/
|
|
305
|
+
function deepMerge(target, ...sources) {
|
|
306
|
+
if (!sources.length) {
|
|
307
|
+
return target;
|
|
308
|
+
}
|
|
309
|
+
const source = sources.shift();
|
|
310
|
+
if (source === undefined) {
|
|
311
|
+
return target;
|
|
312
|
+
}
|
|
313
|
+
if (isMergeableObject(target) && isMergeableObject(source)) {
|
|
314
|
+
Object.keys(source).forEach((key) => {
|
|
315
|
+
const _source = source;
|
|
316
|
+
if (isMergeableObject(_source[key])) {
|
|
317
|
+
if (!target[key]) {
|
|
318
|
+
target[key] = {};
|
|
319
|
+
}
|
|
320
|
+
deepMerge(target[key], _source[key]);
|
|
321
|
+
} else {
|
|
322
|
+
target[key] = _source[key];
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
return deepMerge(target, ...sources);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export { CSS_LANGS_RE as C, KNOWN_ASSET_RE as K, NULL_BYTE_PLACEHOLDER as N, VALID_ID_PREFIX as V, KNOWN_ASSET_TYPES as a, assertTypes as b, cleanUrl as c, clone as d, createDefer as e, createSimpleStackTrace as f, deepClone as g, deepMerge as h, isPrimitive as i, getCallLastIndex as j, getOwnProperties as k, getType as l, isBareImport as m, notNullish as n, isExternalUrl as o, isNegativeNaN as p, isObject as q, noop as r, objectAttr as s, parseRegexp as t, slash as u, toArray as v, unwrapId as w, withTrailingSlash as x, wrapId as y };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
2
|
+
function normalizeWindowsPath(input = "") {
|
|
3
|
+
if (!input) {
|
|
4
|
+
return input;
|
|
5
|
+
}
|
|
6
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const _UNC_REGEX = /^[/\\]{2}/;
|
|
10
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
11
|
+
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
12
|
+
const normalize = function(path) {
|
|
13
|
+
if (path.length === 0) {
|
|
14
|
+
return ".";
|
|
15
|
+
}
|
|
16
|
+
path = normalizeWindowsPath(path);
|
|
17
|
+
const isUNCPath = path.match(_UNC_REGEX);
|
|
18
|
+
const isPathAbsolute = isAbsolute(path);
|
|
19
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
20
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
21
|
+
if (path.length === 0) {
|
|
22
|
+
if (isPathAbsolute) {
|
|
23
|
+
return "/";
|
|
24
|
+
}
|
|
25
|
+
return trailingSeparator ? "./" : ".";
|
|
26
|
+
}
|
|
27
|
+
if (trailingSeparator) {
|
|
28
|
+
path += "/";
|
|
29
|
+
}
|
|
30
|
+
if (_DRIVE_LETTER_RE.test(path)) {
|
|
31
|
+
path += "/";
|
|
32
|
+
}
|
|
33
|
+
if (isUNCPath) {
|
|
34
|
+
if (!isPathAbsolute) {
|
|
35
|
+
return `//./${path}`;
|
|
36
|
+
}
|
|
37
|
+
return `//${path}`;
|
|
38
|
+
}
|
|
39
|
+
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
40
|
+
};
|
|
41
|
+
const join = function(...segments) {
|
|
42
|
+
let path = "";
|
|
43
|
+
for (const seg of segments) {
|
|
44
|
+
if (!seg) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (path.length > 0) {
|
|
48
|
+
const pathTrailing = path[path.length - 1] === "/";
|
|
49
|
+
const segLeading = seg[0] === "/";
|
|
50
|
+
const both = pathTrailing && segLeading;
|
|
51
|
+
if (both) {
|
|
52
|
+
path += seg.slice(1);
|
|
53
|
+
} else {
|
|
54
|
+
path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
path += seg;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return normalize(path);
|
|
61
|
+
};
|
|
62
|
+
function cwd() {
|
|
63
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
64
|
+
return process.cwd().replace(/\\/g, "/");
|
|
65
|
+
}
|
|
66
|
+
return "/";
|
|
67
|
+
}
|
|
68
|
+
const resolve = function(...arguments_) {
|
|
69
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
70
|
+
let resolvedPath = "";
|
|
71
|
+
let resolvedAbsolute = false;
|
|
72
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
73
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
|
74
|
+
if (!path || path.length === 0) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
78
|
+
resolvedAbsolute = isAbsolute(path);
|
|
79
|
+
}
|
|
80
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
81
|
+
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
82
|
+
return `/${resolvedPath}`;
|
|
83
|
+
}
|
|
84
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
85
|
+
};
|
|
86
|
+
function normalizeString(path, allowAboveRoot) {
|
|
87
|
+
let res = "";
|
|
88
|
+
let lastSegmentLength = 0;
|
|
89
|
+
let lastSlash = -1;
|
|
90
|
+
let dots = 0;
|
|
91
|
+
let char = null;
|
|
92
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
93
|
+
if (index < path.length) {
|
|
94
|
+
char = path[index];
|
|
95
|
+
} else if (char === "/") {
|
|
96
|
+
break;
|
|
97
|
+
} else {
|
|
98
|
+
char = "/";
|
|
99
|
+
}
|
|
100
|
+
if (char === "/") {
|
|
101
|
+
if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
|
|
102
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
103
|
+
if (res.length > 2) {
|
|
104
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
105
|
+
if (lastSlashIndex === -1) {
|
|
106
|
+
res = "";
|
|
107
|
+
lastSegmentLength = 0;
|
|
108
|
+
} else {
|
|
109
|
+
res = res.slice(0, lastSlashIndex);
|
|
110
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
111
|
+
}
|
|
112
|
+
lastSlash = index;
|
|
113
|
+
dots = 0;
|
|
114
|
+
continue;
|
|
115
|
+
} else if (res.length > 0) {
|
|
116
|
+
res = "";
|
|
117
|
+
lastSegmentLength = 0;
|
|
118
|
+
lastSlash = index;
|
|
119
|
+
dots = 0;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (allowAboveRoot) {
|
|
124
|
+
res += res.length > 0 ? "/.." : "..";
|
|
125
|
+
lastSegmentLength = 2;
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
if (res.length > 0) {
|
|
129
|
+
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
130
|
+
} else {
|
|
131
|
+
res = path.slice(lastSlash + 1, index);
|
|
132
|
+
}
|
|
133
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
134
|
+
}
|
|
135
|
+
lastSlash = index;
|
|
136
|
+
dots = 0;
|
|
137
|
+
} else if (char === "." && dots !== -1) {
|
|
138
|
+
++dots;
|
|
139
|
+
} else {
|
|
140
|
+
dots = -1;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return res;
|
|
144
|
+
}
|
|
145
|
+
const isAbsolute = function(p) {
|
|
146
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
147
|
+
};
|
|
148
|
+
const dirname = function(p) {
|
|
149
|
+
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
150
|
+
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
|
|
151
|
+
segments[0] += "/";
|
|
152
|
+
}
|
|
153
|
+
return segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export { dirname as d, join as j, resolve as r };
|
package/dist/diff.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { plugins, format } from '@vitest/pretty-format';
|
|
2
2
|
import c from 'tinyrainbow';
|
|
3
3
|
import { g as getDefaultExportFromCjs, s as stringify } from './chunk-_commonjsHelpers.js';
|
|
4
|
-
import { deepClone, getOwnProperties,
|
|
4
|
+
import { g as deepClone, k as getOwnProperties, l as getType$1 } from './chunk-helpers.js';
|
|
5
5
|
import 'loupe';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/error.js
CHANGED
|
@@ -2,7 +2,7 @@ import { printDiffOrStringify } from './diff.js';
|
|
|
2
2
|
import { f as format, s as stringify } from './chunk-_commonjsHelpers.js';
|
|
3
3
|
import '@vitest/pretty-format';
|
|
4
4
|
import 'tinyrainbow';
|
|
5
|
-
import './helpers.js';
|
|
5
|
+
import './chunk-helpers.js';
|
|
6
6
|
import 'loupe';
|
|
7
7
|
|
|
8
8
|
const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
|
package/dist/helpers.d.ts
CHANGED
|
@@ -17,6 +17,20 @@ declare function notNullish<T>(v: T | null | undefined): v is NonNullable<T>;
|
|
|
17
17
|
declare function assertTypes(value: unknown, name: string, types: string[]): void;
|
|
18
18
|
declare function isPrimitive(value: unknown): boolean;
|
|
19
19
|
declare function slash(path: string): string;
|
|
20
|
+
declare function cleanUrl(url: string): string;
|
|
21
|
+
declare const isExternalUrl: (url: string) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Prepend `/@id/` and replace null byte so the id is URL-safe.
|
|
24
|
+
* This is prepended to resolved ids that are not valid browser
|
|
25
|
+
* import specifiers by the importAnalysis plugin.
|
|
26
|
+
*/
|
|
27
|
+
declare function wrapId(id: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Undo {@link wrapId}'s `/@id/` and null byte replacements.
|
|
30
|
+
*/
|
|
31
|
+
declare function unwrapId(id: string): string;
|
|
32
|
+
declare function withTrailingSlash(path: string): string;
|
|
33
|
+
declare function isBareImport(id: string): boolean;
|
|
20
34
|
// convert RegExp.toString to RegExp
|
|
21
35
|
declare function parseRegexp(input: string): RegExp;
|
|
22
36
|
declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
|
|
@@ -52,5 +66,5 @@ declare function isNegativeNaN(val: number): boolean;
|
|
|
52
66
|
*/
|
|
53
67
|
declare function deepMerge<T extends object = object>(target: T, ...sources: any[]): T;
|
|
54
68
|
|
|
55
|
-
export { assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
|
69
|
+
export { assertTypes, cleanUrl, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isBareImport, isExternalUrl, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray, unwrapId, withTrailingSlash, wrapId };
|
|
56
70
|
export type { DeferPromise };
|
package/dist/helpers.js
CHANGED
|
@@ -1,251 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Get original stacktrace without source map support the most performant way.
|
|
3
|
-
* - Create only 1 stack frame.
|
|
4
|
-
* - Rewrite prepareStackTrace to bypass "support-stack-trace" (usually takes ~250ms).
|
|
5
|
-
*/
|
|
6
|
-
function createSimpleStackTrace(options) {
|
|
7
|
-
const { message = "$$stack trace error", stackTraceLimit = 1 } = options || {};
|
|
8
|
-
const limit = Error.stackTraceLimit;
|
|
9
|
-
const prepareStackTrace = Error.prepareStackTrace;
|
|
10
|
-
Error.stackTraceLimit = stackTraceLimit;
|
|
11
|
-
Error.prepareStackTrace = (e) => e.stack;
|
|
12
|
-
const err = new Error(message);
|
|
13
|
-
const stackTrace = err.stack || "";
|
|
14
|
-
Error.prepareStackTrace = prepareStackTrace;
|
|
15
|
-
Error.stackTraceLimit = limit;
|
|
16
|
-
return stackTrace;
|
|
17
|
-
}
|
|
18
|
-
function notNullish(v) {
|
|
19
|
-
return v != null;
|
|
20
|
-
}
|
|
21
|
-
function assertTypes(value, name, types) {
|
|
22
|
-
const receivedType = typeof value;
|
|
23
|
-
const pass = types.includes(receivedType);
|
|
24
|
-
if (!pass) {
|
|
25
|
-
throw new TypeError(`${name} value must be ${types.join(" or ")}, received "${receivedType}"`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function isPrimitive(value) {
|
|
29
|
-
return value === null || typeof value !== "function" && typeof value !== "object";
|
|
30
|
-
}
|
|
31
|
-
function slash(path) {
|
|
32
|
-
return path.replace(/\\/g, "/");
|
|
33
|
-
}
|
|
34
|
-
// convert RegExp.toString to RegExp
|
|
35
|
-
function parseRegexp(input) {
|
|
36
|
-
// Parse input
|
|
37
|
-
// eslint-disable-next-line regexp/no-misleading-capturing-group
|
|
38
|
-
const m = input.match(/(\/?)(.+)\1([a-z]*)/i);
|
|
39
|
-
// match nothing
|
|
40
|
-
if (!m) {
|
|
41
|
-
return /$^/;
|
|
42
|
-
}
|
|
43
|
-
// Invalid flags
|
|
44
|
-
// eslint-disable-next-line regexp/optimal-quantifier-concatenation
|
|
45
|
-
if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) {
|
|
46
|
-
return new RegExp(input);
|
|
47
|
-
}
|
|
48
|
-
// Create the regular expression
|
|
49
|
-
return new RegExp(m[2], m[3]);
|
|
50
|
-
}
|
|
51
|
-
function toArray(array) {
|
|
52
|
-
if (array === null || array === undefined) {
|
|
53
|
-
array = [];
|
|
54
|
-
}
|
|
55
|
-
if (Array.isArray(array)) {
|
|
56
|
-
return array;
|
|
57
|
-
}
|
|
58
|
-
return [array];
|
|
59
|
-
}
|
|
60
|
-
function isObject(item) {
|
|
61
|
-
return item != null && typeof item === "object" && !Array.isArray(item);
|
|
62
|
-
}
|
|
63
|
-
function isFinalObj(obj) {
|
|
64
|
-
return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
|
|
65
|
-
}
|
|
66
|
-
function getType(value) {
|
|
67
|
-
return Object.prototype.toString.apply(value).slice(8, -1);
|
|
68
|
-
}
|
|
69
|
-
function collectOwnProperties(obj, collector) {
|
|
70
|
-
const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
|
|
71
|
-
Object.getOwnPropertyNames(obj).forEach(collect);
|
|
72
|
-
Object.getOwnPropertySymbols(obj).forEach(collect);
|
|
73
|
-
}
|
|
74
|
-
function getOwnProperties(obj) {
|
|
75
|
-
const ownProps = new Set();
|
|
76
|
-
if (isFinalObj(obj)) {
|
|
77
|
-
return [];
|
|
78
|
-
}
|
|
79
|
-
collectOwnProperties(obj, ownProps);
|
|
80
|
-
return Array.from(ownProps);
|
|
81
|
-
}
|
|
82
|
-
const defaultCloneOptions = { forceWritable: false };
|
|
83
|
-
function deepClone(val, options = defaultCloneOptions) {
|
|
84
|
-
const seen = new WeakMap();
|
|
85
|
-
return clone(val, seen, options);
|
|
86
|
-
}
|
|
87
|
-
function clone(val, seen, options = defaultCloneOptions) {
|
|
88
|
-
let k, out;
|
|
89
|
-
if (seen.has(val)) {
|
|
90
|
-
return seen.get(val);
|
|
91
|
-
}
|
|
92
|
-
if (Array.isArray(val)) {
|
|
93
|
-
out = Array.from({ length: k = val.length });
|
|
94
|
-
seen.set(val, out);
|
|
95
|
-
while (k--) {
|
|
96
|
-
out[k] = clone(val[k], seen, options);
|
|
97
|
-
}
|
|
98
|
-
return out;
|
|
99
|
-
}
|
|
100
|
-
if (Object.prototype.toString.call(val) === "[object Object]") {
|
|
101
|
-
out = Object.create(Object.getPrototypeOf(val));
|
|
102
|
-
seen.set(val, out);
|
|
103
|
-
// we don't need properties from prototype
|
|
104
|
-
const props = getOwnProperties(val);
|
|
105
|
-
for (const k of props) {
|
|
106
|
-
const descriptor = Object.getOwnPropertyDescriptor(val, k);
|
|
107
|
-
if (!descriptor) {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
const cloned = clone(val[k], seen, options);
|
|
111
|
-
if (options.forceWritable) {
|
|
112
|
-
Object.defineProperty(out, k, {
|
|
113
|
-
enumerable: descriptor.enumerable,
|
|
114
|
-
configurable: true,
|
|
115
|
-
writable: true,
|
|
116
|
-
value: cloned
|
|
117
|
-
});
|
|
118
|
-
} else if ("get" in descriptor) {
|
|
119
|
-
Object.defineProperty(out, k, {
|
|
120
|
-
...descriptor,
|
|
121
|
-
get() {
|
|
122
|
-
return cloned;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
} else {
|
|
126
|
-
Object.defineProperty(out, k, {
|
|
127
|
-
...descriptor,
|
|
128
|
-
value: cloned
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return out;
|
|
133
|
-
}
|
|
134
|
-
return val;
|
|
135
|
-
}
|
|
136
|
-
function noop() {}
|
|
137
|
-
function objectAttr(source, path, defaultValue = undefined) {
|
|
138
|
-
// a[3].b -> a.3.b
|
|
139
|
-
const paths = path.replace(/\[(\d+)\]/g, ".$1").split(".");
|
|
140
|
-
let result = source;
|
|
141
|
-
for (const p of paths) {
|
|
142
|
-
result = new Object(result)[p];
|
|
143
|
-
if (result === undefined) {
|
|
144
|
-
return defaultValue;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return result;
|
|
148
|
-
}
|
|
149
|
-
function createDefer() {
|
|
150
|
-
let resolve = null;
|
|
151
|
-
let reject = null;
|
|
152
|
-
const p = new Promise((_resolve, _reject) => {
|
|
153
|
-
resolve = _resolve;
|
|
154
|
-
reject = _reject;
|
|
155
|
-
});
|
|
156
|
-
p.resolve = resolve;
|
|
157
|
-
p.reject = reject;
|
|
158
|
-
return p;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* If code starts with a function call, will return its last index, respecting arguments.
|
|
162
|
-
* This will return 25 - last ending character of toMatch ")"
|
|
163
|
-
* Also works with callbacks
|
|
164
|
-
* ```
|
|
165
|
-
* toMatch({ test: '123' });
|
|
166
|
-
* toBeAliased('123')
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
function getCallLastIndex(code) {
|
|
170
|
-
let charIndex = -1;
|
|
171
|
-
let inString = null;
|
|
172
|
-
let startedBracers = 0;
|
|
173
|
-
let endedBracers = 0;
|
|
174
|
-
let beforeChar = null;
|
|
175
|
-
while (charIndex <= code.length) {
|
|
176
|
-
beforeChar = code[charIndex];
|
|
177
|
-
charIndex++;
|
|
178
|
-
const char = code[charIndex];
|
|
179
|
-
const isCharString = char === "\"" || char === "'" || char === "`";
|
|
180
|
-
if (isCharString && beforeChar !== "\\") {
|
|
181
|
-
if (inString === char) {
|
|
182
|
-
inString = null;
|
|
183
|
-
} else if (!inString) {
|
|
184
|
-
inString = char;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (!inString) {
|
|
188
|
-
if (char === "(") {
|
|
189
|
-
startedBracers++;
|
|
190
|
-
}
|
|
191
|
-
if (char === ")") {
|
|
192
|
-
endedBracers++;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (startedBracers && endedBracers && startedBracers === endedBracers) {
|
|
196
|
-
return charIndex;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
function isNegativeNaN(val) {
|
|
202
|
-
if (!Number.isNaN(val)) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
const f64 = new Float64Array(1);
|
|
206
|
-
f64[0] = val;
|
|
207
|
-
const u32 = new Uint32Array(f64.buffer);
|
|
208
|
-
const isNegative = u32[1] >>> 31 === 1;
|
|
209
|
-
return isNegative;
|
|
210
|
-
}
|
|
211
|
-
function toString(v) {
|
|
212
|
-
return Object.prototype.toString.call(v);
|
|
213
|
-
}
|
|
214
|
-
function isPlainObject(val) {
|
|
215
|
-
return toString(val) === "[object Object]" && (!val.constructor || val.constructor.name === "Object");
|
|
216
|
-
}
|
|
217
|
-
function isMergeableObject(item) {
|
|
218
|
-
return isPlainObject(item) && !Array.isArray(item);
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Deep merge :P
|
|
222
|
-
*
|
|
223
|
-
* Will merge objects only if they are plain
|
|
224
|
-
*
|
|
225
|
-
* Do not merge types - it is very expensive and usually it's better to case a type here
|
|
226
|
-
*/
|
|
227
|
-
function deepMerge(target, ...sources) {
|
|
228
|
-
if (!sources.length) {
|
|
229
|
-
return target;
|
|
230
|
-
}
|
|
231
|
-
const source = sources.shift();
|
|
232
|
-
if (source === undefined) {
|
|
233
|
-
return target;
|
|
234
|
-
}
|
|
235
|
-
if (isMergeableObject(target) && isMergeableObject(source)) {
|
|
236
|
-
Object.keys(source).forEach((key) => {
|
|
237
|
-
const _source = source;
|
|
238
|
-
if (isMergeableObject(_source[key])) {
|
|
239
|
-
if (!target[key]) {
|
|
240
|
-
target[key] = {};
|
|
241
|
-
}
|
|
242
|
-
deepMerge(target[key], _source[key]);
|
|
243
|
-
} else {
|
|
244
|
-
target[key] = _source[key];
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
return deepMerge(target, ...sources);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export { assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
|
1
|
+
export { b as assertTypes, c as cleanUrl, d as clone, e as createDefer, f as createSimpleStackTrace, g as deepClone, h as deepMerge, j as getCallLastIndex, k as getOwnProperties, l as getType, m as isBareImport, o as isExternalUrl, p as isNegativeNaN, q as isObject, i as isPrimitive, r as noop, n as notNullish, s as objectAttr, t as parseRegexp, u as slash, v as toArray, w as unwrapId, x as withTrailingSlash, y as wrapId } from './chunk-helpers.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
2
|
-
export { DeferPromise, assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
|
2
|
+
export { DeferPromise, assertTypes, cleanUrl, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isBareImport, isExternalUrl, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray, unwrapId, withTrailingSlash, wrapId } from './helpers.js';
|
|
3
3
|
import { Colors } from 'tinyrainbow';
|
|
4
4
|
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, MergeInsertions, Nullable, ParsedStack, SerializedError, TestError } from './types.js';
|
|
5
5
|
|
|
6
|
+
// TODO: this is all copy pasted from Vite - can they expose a module that exports only constants?
|
|
7
|
+
declare const KNOWN_ASSET_TYPES: string[];
|
|
8
|
+
declare const KNOWN_ASSET_RE: RegExp;
|
|
9
|
+
declare const CSS_LANGS_RE: RegExp;
|
|
10
|
+
/**
|
|
11
|
+
* Prefix for resolved Ids that are not valid browser import specifiers
|
|
12
|
+
*/
|
|
13
|
+
declare const VALID_ID_PREFIX = "/@id/";
|
|
14
|
+
/**
|
|
15
|
+
* Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
|
|
16
|
+
* module ID with `\0`, a convention from the rollup ecosystem.
|
|
17
|
+
* This prevents other plugins from trying to process the id (like node resolution),
|
|
18
|
+
* and core features like sourcemaps can use this info to differentiate between
|
|
19
|
+
* virtual modules and regular files.
|
|
20
|
+
* `\0` is not a permitted char in import URLs so we have to replace them during
|
|
21
|
+
* import analysis. The id will be decoded back before entering the plugins pipeline.
|
|
22
|
+
* These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
|
|
23
|
+
* modules in the browser end up encoded as `/@id/__x00__{id}`
|
|
24
|
+
*/
|
|
25
|
+
declare const NULL_BYTE_PLACEHOLDER = "__x00__";
|
|
26
|
+
|
|
6
27
|
type Inspect = (value: unknown, options: Options) => string;
|
|
7
28
|
interface Options {
|
|
8
29
|
showHidden: boolean;
|
|
@@ -58,5 +79,5 @@ interface SafeTimers {
|
|
|
58
79
|
declare function getSafeTimers(): SafeTimers;
|
|
59
80
|
declare function setSafeTimers(): void;
|
|
60
81
|
|
|
61
|
-
export { format, getSafeTimers, highlight, inspect, lineSplitRE, nanoid, objDisplay, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle, stringify };
|
|
82
|
+
export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES, NULL_BYTE_PLACEHOLDER, VALID_ID_PREFIX, format, getSafeTimers, highlight, inspect, lineSplitRE, nanoid, objDisplay, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle, stringify };
|
|
62
83
|
export type { LoupeOptions, SafeTimers, StringifyOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
export { C as CSS_LANGS_RE, K as KNOWN_ASSET_RE, a as KNOWN_ASSET_TYPES, N as NULL_BYTE_PLACEHOLDER, V as VALID_ID_PREFIX, b as assertTypes, c as cleanUrl, d as clone, e as createDefer, f as createSimpleStackTrace, g as deepClone, h as deepMerge, j as getCallLastIndex, k as getOwnProperties, l as getType, m as isBareImport, o as isExternalUrl, p as isNegativeNaN, q as isObject, i as isPrimitive, r as noop, n as notNullish, s as objectAttr, t as parseRegexp, u as slash, v as toArray, w as unwrapId, x as withTrailingSlash, y as wrapId } from './chunk-helpers.js';
|
|
1
2
|
import { g as getDefaultExportFromCjs } from './chunk-_commonjsHelpers.js';
|
|
2
3
|
export { f as format, i as inspect, o as objDisplay, s as stringify } from './chunk-_commonjsHelpers.js';
|
|
3
|
-
export { assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
|
4
4
|
import c from 'tinyrainbow';
|
|
5
5
|
import '@vitest/pretty-format';
|
|
6
6
|
import 'loupe';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare function findNearestPackageData(basedir: string): {
|
|
2
|
+
type?: "module" | "commonjs";
|
|
3
|
+
};
|
|
4
|
+
declare function getCachedData<T>(cache: Map<string, T>, basedir: string, originalBasedir: string): NonNullable<T> | undefined;
|
|
5
|
+
declare function setCacheData<T>(cache: Map<string, T>, data: T, basedir: string, originalBasedir: string): void;
|
|
6
|
+
|
|
7
|
+
export { findNearestPackageData, getCachedData, setCacheData };
|
package/dist/resolver.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { j as join, d as dirname } from './chunk-pathe.M-eThtNZ.js';
|
|
3
|
+
|
|
4
|
+
const packageCache = new Map();
|
|
5
|
+
function findNearestPackageData(basedir) {
|
|
6
|
+
const originalBasedir = basedir;
|
|
7
|
+
while (basedir) {
|
|
8
|
+
var _tryStatSync;
|
|
9
|
+
const cached = getCachedData(packageCache, basedir, originalBasedir);
|
|
10
|
+
if (cached) {
|
|
11
|
+
return cached;
|
|
12
|
+
}
|
|
13
|
+
const pkgPath = join(basedir, "package.json");
|
|
14
|
+
if ((_tryStatSync = tryStatSync(pkgPath)) === null || _tryStatSync === void 0 ? void 0 : _tryStatSync.isFile()) {
|
|
15
|
+
const pkgData = JSON.parse(stripBomTag(fs.readFileSync(pkgPath, "utf8")));
|
|
16
|
+
if (packageCache) {
|
|
17
|
+
setCacheData(packageCache, pkgData, basedir, originalBasedir);
|
|
18
|
+
}
|
|
19
|
+
return pkgData;
|
|
20
|
+
}
|
|
21
|
+
const nextBasedir = dirname(basedir);
|
|
22
|
+
if (nextBasedir === basedir) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
basedir = nextBasedir;
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
function stripBomTag(content) {
|
|
30
|
+
if (content.charCodeAt(0) === 65279) {
|
|
31
|
+
return content.slice(1);
|
|
32
|
+
}
|
|
33
|
+
return content;
|
|
34
|
+
}
|
|
35
|
+
function tryStatSync(file) {
|
|
36
|
+
try {
|
|
37
|
+
// The "throwIfNoEntry" is a performance optimization for cases where the file does not exist
|
|
38
|
+
return fs.statSync(file, { throwIfNoEntry: false });
|
|
39
|
+
} catch {}
|
|
40
|
+
}
|
|
41
|
+
function getCachedData(cache, basedir, originalBasedir) {
|
|
42
|
+
const pkgData = cache.get(getFnpdCacheKey(basedir));
|
|
43
|
+
if (pkgData) {
|
|
44
|
+
traverseBetweenDirs(originalBasedir, basedir, (dir) => {
|
|
45
|
+
cache.set(getFnpdCacheKey(dir), pkgData);
|
|
46
|
+
});
|
|
47
|
+
return pkgData;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function setCacheData(cache, data, basedir, originalBasedir) {
|
|
51
|
+
cache.set(getFnpdCacheKey(basedir), data);
|
|
52
|
+
traverseBetweenDirs(originalBasedir, basedir, (dir) => {
|
|
53
|
+
cache.set(getFnpdCacheKey(dir), data);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function getFnpdCacheKey(basedir) {
|
|
57
|
+
return `fnpd_${basedir}`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Traverse between `longerDir` (inclusive) and `shorterDir` (exclusive) and call `cb` for each dir.
|
|
61
|
+
* @param longerDir Longer dir path, e.g. `/User/foo/bar/baz`
|
|
62
|
+
* @param shorterDir Shorter dir path, e.g. `/User/foo`
|
|
63
|
+
*/
|
|
64
|
+
function traverseBetweenDirs(longerDir, shorterDir, cb) {
|
|
65
|
+
while (longerDir !== shorterDir) {
|
|
66
|
+
cb(longerDir);
|
|
67
|
+
longerDir = dirname(longerDir);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { findNearestPackageData, getCachedData, setCacheData };
|
package/dist/source-map.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { isPrimitive, notNullish } from './helpers.js';
|
|
1
|
+
import { i as isPrimitive, n as notNullish } from './chunk-helpers.js';
|
|
2
|
+
import { r as resolve$1 } from './chunk-pathe.M-eThtNZ.js';
|
|
2
3
|
|
|
3
4
|
const comma = ','.charCodeAt(0);
|
|
4
5
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
@@ -282,7 +283,7 @@ function normalizePath(url, type) {
|
|
|
282
283
|
/**
|
|
283
284
|
* Attempts to resolve `input` URL/path relative to `base`.
|
|
284
285
|
*/
|
|
285
|
-
function resolve
|
|
286
|
+
function resolve(input, base) {
|
|
286
287
|
if (!input && !base)
|
|
287
288
|
return '';
|
|
288
289
|
const url = parseUrl(input);
|
|
@@ -355,7 +356,7 @@ function stripFilename(path) {
|
|
|
355
356
|
function resolver(mapUrl, sourceRoot) {
|
|
356
357
|
const from = stripFilename(mapUrl);
|
|
357
358
|
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
358
|
-
return (source) => resolve
|
|
359
|
+
return (source) => resolve(prefix + (source || ""), from);
|
|
359
360
|
}
|
|
360
361
|
|
|
361
362
|
// src/sourcemap-segment.ts
|
|
@@ -637,101 +638,6 @@ function generatedPosition(map, source, line, column, bias, all) {
|
|
|
637
638
|
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
|
638
639
|
}
|
|
639
640
|
|
|
640
|
-
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
641
|
-
function normalizeWindowsPath(input = "") {
|
|
642
|
-
if (!input) {
|
|
643
|
-
return input;
|
|
644
|
-
}
|
|
645
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
646
|
-
}
|
|
647
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
648
|
-
function cwd() {
|
|
649
|
-
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
650
|
-
return process.cwd().replace(/\\/g, "/");
|
|
651
|
-
}
|
|
652
|
-
return "/";
|
|
653
|
-
}
|
|
654
|
-
const resolve = function(...arguments_) {
|
|
655
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
656
|
-
let resolvedPath = "";
|
|
657
|
-
let resolvedAbsolute = false;
|
|
658
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
659
|
-
const path = index >= 0 ? arguments_[index] : cwd();
|
|
660
|
-
if (!path || path.length === 0) {
|
|
661
|
-
continue;
|
|
662
|
-
}
|
|
663
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
|
664
|
-
resolvedAbsolute = isAbsolute(path);
|
|
665
|
-
}
|
|
666
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
667
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
668
|
-
return `/${resolvedPath}`;
|
|
669
|
-
}
|
|
670
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
671
|
-
};
|
|
672
|
-
function normalizeString(path, allowAboveRoot) {
|
|
673
|
-
let res = "";
|
|
674
|
-
let lastSegmentLength = 0;
|
|
675
|
-
let lastSlash = -1;
|
|
676
|
-
let dots = 0;
|
|
677
|
-
let char = null;
|
|
678
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
679
|
-
if (index < path.length) {
|
|
680
|
-
char = path[index];
|
|
681
|
-
} else if (char === "/") {
|
|
682
|
-
break;
|
|
683
|
-
} else {
|
|
684
|
-
char = "/";
|
|
685
|
-
}
|
|
686
|
-
if (char === "/") {
|
|
687
|
-
if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
|
|
688
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
689
|
-
if (res.length > 2) {
|
|
690
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
691
|
-
if (lastSlashIndex === -1) {
|
|
692
|
-
res = "";
|
|
693
|
-
lastSegmentLength = 0;
|
|
694
|
-
} else {
|
|
695
|
-
res = res.slice(0, lastSlashIndex);
|
|
696
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
697
|
-
}
|
|
698
|
-
lastSlash = index;
|
|
699
|
-
dots = 0;
|
|
700
|
-
continue;
|
|
701
|
-
} else if (res.length > 0) {
|
|
702
|
-
res = "";
|
|
703
|
-
lastSegmentLength = 0;
|
|
704
|
-
lastSlash = index;
|
|
705
|
-
dots = 0;
|
|
706
|
-
continue;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
if (allowAboveRoot) {
|
|
710
|
-
res += res.length > 0 ? "/.." : "..";
|
|
711
|
-
lastSegmentLength = 2;
|
|
712
|
-
}
|
|
713
|
-
} else {
|
|
714
|
-
if (res.length > 0) {
|
|
715
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
716
|
-
} else {
|
|
717
|
-
res = path.slice(lastSlash + 1, index);
|
|
718
|
-
}
|
|
719
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
720
|
-
}
|
|
721
|
-
lastSlash = index;
|
|
722
|
-
dots = 0;
|
|
723
|
-
} else if (char === "." && dots !== -1) {
|
|
724
|
-
++dots;
|
|
725
|
-
} else {
|
|
726
|
-
dots = -1;
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
return res;
|
|
730
|
-
}
|
|
731
|
-
const isAbsolute = function(p) {
|
|
732
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
733
|
-
};
|
|
734
|
-
|
|
735
641
|
const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
|
|
736
642
|
const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
|
|
737
643
|
const stackIgnorePatterns = [
|
|
@@ -745,6 +651,8 @@ const stackIgnorePatterns = [
|
|
|
745
651
|
"/node_modules/chai/",
|
|
746
652
|
"/node_modules/tinypool/",
|
|
747
653
|
"/node_modules/tinyspy/",
|
|
654
|
+
"/vite/dist/node/module-runner",
|
|
655
|
+
"/rolldown-vite/dist/node/module-runner",
|
|
748
656
|
"/deps/chunk-",
|
|
749
657
|
"/deps/@vitest",
|
|
750
658
|
"/deps/loupe",
|
|
@@ -848,7 +756,7 @@ function parseSingleV8Stack(raw) {
|
|
|
848
756
|
file = file.slice(7);
|
|
849
757
|
}
|
|
850
758
|
// normalize Windows path (\ -> /)
|
|
851
|
-
file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve(file);
|
|
759
|
+
file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve$1(file);
|
|
852
760
|
if (method) {
|
|
853
761
|
method = method.replace(/__vite_ssr_import_\d+__\./g, "");
|
|
854
762
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.6",
|
|
5
5
|
"description": "Shared Vitest utility functions",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
"types": "./dist/ast.d.ts",
|
|
29
29
|
"default": "./dist/ast.js"
|
|
30
30
|
},
|
|
31
|
+
"./resolver": {
|
|
32
|
+
"types": "./dist/resolver.d.ts",
|
|
33
|
+
"default": "./dist/resolver.js"
|
|
34
|
+
},
|
|
31
35
|
"./error": {
|
|
32
36
|
"types": "./dist/error.d.ts",
|
|
33
37
|
"default": "./dist/error.js"
|
|
@@ -60,9 +64,9 @@
|
|
|
60
64
|
"dist"
|
|
61
65
|
],
|
|
62
66
|
"dependencies": {
|
|
63
|
-
"loupe": "^3.
|
|
67
|
+
"loupe": "^3.2.0",
|
|
64
68
|
"tinyrainbow": "^2.0.0",
|
|
65
|
-
"@vitest/pretty-format": "4.0.0-beta.
|
|
69
|
+
"@vitest/pretty-format": "4.0.0-beta.6"
|
|
66
70
|
},
|
|
67
71
|
"devDependencies": {
|
|
68
72
|
"@jridgewell/trace-mapping": "^0.3.29",
|