@vitest/utils 3.2.4 → 4.0.0-beta.10
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.d.ts +2 -13
- package/dist/diff.js +3 -2
- package/dist/error.d.ts +0 -1
- package/dist/error.js +1 -1
- package/dist/helpers.d.ts +17 -4
- package/dist/helpers.js +1 -251
- package/dist/index.d.ts +29 -6
- package/dist/index.js +3 -3
- package/dist/resolver.d.ts +7 -0
- package/dist/resolver.js +71 -0
- package/dist/source-map.d.ts +12 -7
- package/dist/source-map.js +244 -387
- package/dist/types.d.ts +2 -21
- package/package.json +7 -10
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.at(-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.d.ts
CHANGED
|
@@ -61,13 +61,8 @@ declare class Diff {
|
|
|
61
61
|
* LICENSE file in the root directory of this source tree.
|
|
62
62
|
*/
|
|
63
63
|
|
|
64
|
-
// Compare two arrays of strings line-by-line. Format as comparison lines.
|
|
65
64
|
declare function diffLinesUnified(aLines: Array<string>, bLines: Array<string>, options?: DiffOptions): string;
|
|
66
|
-
// Given two pairs of arrays of strings:
|
|
67
|
-
// Compare the pair of comparison arrays line-by-line.
|
|
68
|
-
// Format the corresponding lines in the pair of displayable arrays.
|
|
69
65
|
declare function diffLinesUnified2(aLinesDisplay: Array<string>, bLinesDisplay: Array<string>, aLinesCompare: Array<string>, bLinesCompare: Array<string>, options?: DiffOptions): string;
|
|
70
|
-
// Compare two arrays of strings line-by-line.
|
|
71
66
|
declare function diffLinesRaw(aLines: Array<string>, bLines: Array<string>, options?: DiffOptions): [Array<Diff>, boolean];
|
|
72
67
|
|
|
73
68
|
/**
|
|
@@ -77,15 +72,9 @@ declare function diffLinesRaw(aLines: Array<string>, bLines: Array<string>, opti
|
|
|
77
72
|
* LICENSE file in the root directory of this source tree.
|
|
78
73
|
*/
|
|
79
74
|
|
|
80
|
-
// Compare two strings character-by-character.
|
|
81
|
-
// Format as comparison lines in which changed substrings have inverse colors.
|
|
82
75
|
declare function diffStringsUnified(a: string, b: string, options?: DiffOptions): string;
|
|
83
|
-
// Compare two strings character-by-character.
|
|
84
|
-
// Optionally clean up small common substrings, also known as chaff.
|
|
85
76
|
declare function diffStringsRaw(a: string, b: string, cleanup: boolean, options?: DiffOptions): [Array<Diff>, boolean];
|
|
86
77
|
|
|
87
|
-
// Generate a string that will highlight the difference between two values
|
|
88
|
-
// with green and red. (similar to how github does code diffing)
|
|
89
78
|
/**
|
|
90
79
|
* @param a Expected value
|
|
91
80
|
* @param b Received value
|
|
@@ -95,8 +84,8 @@ declare function diffStringsRaw(a: string, b: string, cleanup: boolean, options?
|
|
|
95
84
|
declare function diff(a: any, b: any, options?: DiffOptions): string | undefined;
|
|
96
85
|
declare function printDiffOrStringify(received: unknown, expected: unknown, options?: DiffOptions): string | undefined;
|
|
97
86
|
declare function replaceAsymmetricMatcher(actual: any, expected: any, actualReplaced?: WeakSet<WeakKey>, expectedReplaced?: WeakSet<WeakKey>): {
|
|
98
|
-
replacedActual: any
|
|
99
|
-
replacedExpected: any
|
|
87
|
+
replacedActual: any;
|
|
88
|
+
replacedExpected: any;
|
|
100
89
|
};
|
|
101
90
|
type PrintLabel = (string: string) => string;
|
|
102
91
|
declare function getLabelPrinter(...strings: Array<string>): PrintLabel;
|
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
|
/**
|
|
@@ -332,6 +332,7 @@ function diff_cleanupSemanticLossless(diffs) {
|
|
|
332
332
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
333
333
|
*/
|
|
334
334
|
function diff_cleanupMerge(diffs) {
|
|
335
|
+
var _diffs$at;
|
|
335
336
|
// Add a dummy entry at the end.
|
|
336
337
|
diffs.push(new Diff(DIFF_EQUAL, ""));
|
|
337
338
|
let pointer = 0;
|
|
@@ -402,7 +403,7 @@ function diff_cleanupMerge(diffs) {
|
|
|
402
403
|
break;
|
|
403
404
|
}
|
|
404
405
|
}
|
|
405
|
-
if (diffs
|
|
406
|
+
if (((_diffs$at = diffs.at(-1)) === null || _diffs$at === void 0 ? void 0 : _diffs$at[1]) === "") {
|
|
406
407
|
diffs.pop();
|
|
407
408
|
}
|
|
408
409
|
// Second pass: look for single edits surrounded on both sides by equalities
|
package/dist/error.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { D as DiffOptions } from './types.d-BCElaP-c.js';
|
|
2
2
|
import '@vitest/pretty-format';
|
|
3
3
|
|
|
4
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
|
|
5
4
|
declare function serializeValue(val: any, seen?: WeakMap<WeakKey, any>): any;
|
|
6
5
|
|
|
7
6
|
declare function processError(_err: any, diffOptions?: DiffOptions, seen?: WeakSet<WeakKey>): any;
|
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,7 +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
|
-
|
|
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;
|
|
21
34
|
declare function parseRegexp(input: string): RegExp;
|
|
22
35
|
declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
|
|
23
36
|
declare function isObject(item: unknown): boolean;
|
|
@@ -28,8 +41,8 @@ declare function clone<T>(val: T, seen: WeakMap<any, any>, options?: CloneOption
|
|
|
28
41
|
declare function noop(): void;
|
|
29
42
|
declare function objectAttr(source: any, path: string, defaultValue?: undefined): any;
|
|
30
43
|
type DeferPromise<T> = Promise<T> & {
|
|
31
|
-
resolve: (value: T | PromiseLike<T>) => void
|
|
32
|
-
reject: (reason?: any) => void
|
|
44
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
45
|
+
reject: (reason?: any) => void;
|
|
33
46
|
};
|
|
34
47
|
declare function createDefer<T>(): DeferPromise<T>;
|
|
35
48
|
/**
|
|
@@ -52,5 +65,5 @@ declare function isNegativeNaN(val: number): boolean;
|
|
|
52
65
|
*/
|
|
53
66
|
declare function deepMerge<T extends object = object>(target: T, ...sources: any[]): T;
|
|
54
67
|
|
|
55
|
-
export { assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
|
68
|
+
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
69
|
export type { DeferPromise };
|