vitest 0.0.113 → 0.0.114
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.md +29 -0
- package/dist/cli.js +10 -10
- package/dist/{constants-900abe4a.js → constants-9c7f06df.js} +2 -2
- package/dist/{diff-9c43ab50.js → diff-3cfdad26.js} +1 -2
- package/dist/entry.js +14 -12
- package/dist/{global-75208c77.js → global-12653c72.js} +8 -9
- package/dist/{index-c3f2f9fe.js → index-36694964.js} +118 -84
- package/dist/index-7889832e.js +53 -0
- package/dist/index-ea5153a0.js +360 -0
- package/dist/{index-09437c50.js → index-ebf35a56.js} +2 -2
- package/dist/index.d.ts +19 -19
- package/dist/index.js +6 -4
- package/dist/{jest-mock-a57b745c.js → jest-mock-4a754991.js} +1 -12
- package/dist/{middleware-0ebc5238.js → middleware-85ff8fbf.js} +4 -2
- package/dist/node.d.ts +9 -0
- package/dist/node.js +9 -9
- package/dist/{rpc-7de86f29.js → rpc-85fe6402.js} +4 -4
- package/dist/utils.js +2 -2
- package/dist/{vi-51946984.js → vi-67e478ef.js} +14 -3
- package/dist/worker.js +22 -38
- package/package.json +2 -1
- package/dist/index-041e627e.js +0 -168
- package/dist/index-1488b423.js +0 -186
package/dist/worker.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { c as distDir } from './constants-
|
|
1
|
+
import { j as resolve, d as dirname$2, b as basename$2, o as mergeSlashes, s as slash, t as toFilePath } from './index-ea5153a0.js';
|
|
2
|
+
import { c as createBirpc } from './index-7889832e.js';
|
|
3
|
+
import { c as distDir } from './constants-9c7f06df.js';
|
|
4
4
|
import { builtinModules, createRequire } from 'module';
|
|
5
5
|
import { pathToFileURL, fileURLToPath as fileURLToPath$2, URL as URL$1 } from 'url';
|
|
6
6
|
import vm from 'vm';
|
|
7
7
|
import path from 'path';
|
|
8
|
-
import fs, { promises, realpathSync, statSync, Stats,
|
|
8
|
+
import fs, { promises, realpathSync, statSync, Stats, existsSync, readdirSync } from 'fs';
|
|
9
9
|
import assert from 'assert';
|
|
10
10
|
import { format as format$2, inspect } from 'util';
|
|
11
|
-
import {
|
|
12
|
-
import { s as send } from './rpc-
|
|
13
|
-
import 'chai';
|
|
14
|
-
import 'tinyspy';
|
|
11
|
+
import { a as spyOn, s as spies } from './jest-mock-4a754991.js';
|
|
12
|
+
import { s as send } from './rpc-85fe6402.js';
|
|
15
13
|
import 'tty';
|
|
16
14
|
import 'local-pkg';
|
|
15
|
+
import 'chai';
|
|
16
|
+
import 'tinyspy';
|
|
17
17
|
|
|
18
18
|
const BUILTIN_MODULES$1 = new Set(builtinModules);
|
|
19
19
|
function normalizeSlash$1(str) {
|
|
@@ -7664,7 +7664,7 @@ function find(dir) {
|
|
|
7664
7664
|
|
|
7665
7665
|
// Manually “tree shaken” from:
|
|
7666
7666
|
|
|
7667
|
-
const isWindows
|
|
7667
|
+
const isWindows = process.platform === 'win32';
|
|
7668
7668
|
|
|
7669
7669
|
const own$1 = {}.hasOwnProperty;
|
|
7670
7670
|
|
|
@@ -7838,7 +7838,7 @@ codes.ERR_UNSUPPORTED_ESM_URL_SCHEME = createError(
|
|
|
7838
7838
|
let message =
|
|
7839
7839
|
'Only file and data URLs are supported by the default ESM loader';
|
|
7840
7840
|
|
|
7841
|
-
if (isWindows
|
|
7841
|
+
if (isWindows && url.protocol.length === 2) {
|
|
7842
7842
|
message += '. On Windows, absolute paths must be valid file:// URLs';
|
|
7843
7843
|
}
|
|
7844
7844
|
|
|
@@ -9219,6 +9219,8 @@ var __spreadValues = (a, b) => {
|
|
|
9219
9219
|
function resolveMockPath(mockPath, root, nmName) {
|
|
9220
9220
|
if (nmName) {
|
|
9221
9221
|
const mockFolder = resolve(root, "__mocks__");
|
|
9222
|
+
if (!existsSync(mockFolder))
|
|
9223
|
+
return null;
|
|
9222
9224
|
const files = readdirSync(mockFolder);
|
|
9223
9225
|
for (const file of files) {
|
|
9224
9226
|
const [basename2] = file.split(".");
|
|
@@ -9326,7 +9328,6 @@ const depsExternal = [
|
|
|
9326
9328
|
/\.cjs.js$/,
|
|
9327
9329
|
/\.mjs$/
|
|
9328
9330
|
];
|
|
9329
|
-
const isWindows = process.platform === "win32";
|
|
9330
9331
|
const stubRequests = {
|
|
9331
9332
|
"/@vite/client": {
|
|
9332
9333
|
injectQuery: (id) => id,
|
|
@@ -9531,12 +9532,6 @@ async function shouldExternalize(id, config) {
|
|
|
9531
9532
|
return false;
|
|
9532
9533
|
return id.includes("/node_modules/") && await isValidNodeImport(id);
|
|
9533
9534
|
}
|
|
9534
|
-
function toFilePath(id, root) {
|
|
9535
|
-
let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname$2(root)) ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
|
|
9536
|
-
if (absolute.startsWith("//"))
|
|
9537
|
-
absolute = absolute.slice(1);
|
|
9538
|
-
return isWindows && absolute.startsWith("/") ? fileURLToPath$2(pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
9539
|
-
}
|
|
9540
9535
|
function matchExternalizePattern(id, patterns) {
|
|
9541
9536
|
for (const ex of patterns) {
|
|
9542
9537
|
if (typeof ex === "string") {
|
|
@@ -9579,7 +9574,7 @@ async function startViteNode(ctx) {
|
|
|
9579
9574
|
resolve(distDir, "entry.js")
|
|
9580
9575
|
],
|
|
9581
9576
|
fetch(id) {
|
|
9582
|
-
return process.__vitest_worker__.rpc("fetch", id);
|
|
9577
|
+
return process.__vitest_worker__.rpc.call("fetch", id);
|
|
9583
9578
|
},
|
|
9584
9579
|
inline: config.depsInline,
|
|
9585
9580
|
external: config.depsExternal,
|
|
@@ -9595,31 +9590,20 @@ function init(ctx) {
|
|
|
9595
9590
|
throw new Error(`worker for ${ctx.files.join(",")} already initialized by ${process.__vitest_worker__.ctx.files.join(",")}. This is probably an internal bug of Vitest.`);
|
|
9596
9591
|
process.stdout.write("\0");
|
|
9597
9592
|
const { config, port } = ctx;
|
|
9598
|
-
const rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
9599
9593
|
process.__vitest_worker__ = {
|
|
9600
9594
|
ctx,
|
|
9601
9595
|
moduleCache,
|
|
9602
9596
|
config,
|
|
9603
|
-
rpc: (
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
}
|
|
9597
|
+
rpc: createBirpc({
|
|
9598
|
+
functions: {},
|
|
9599
|
+
post(v) {
|
|
9600
|
+
port.postMessage(v);
|
|
9601
|
+
},
|
|
9602
|
+
on(fn) {
|
|
9603
|
+
port.addListener("message", fn);
|
|
9604
|
+
}
|
|
9605
|
+
})
|
|
9613
9606
|
};
|
|
9614
|
-
port.addListener("message", async (data) => {
|
|
9615
|
-
const api = rpcPromiseMap.get(data.id);
|
|
9616
|
-
if (api) {
|
|
9617
|
-
if (data.error)
|
|
9618
|
-
api.reject(data.error);
|
|
9619
|
-
else
|
|
9620
|
-
api.resolve(data.result);
|
|
9621
|
-
}
|
|
9622
|
-
});
|
|
9623
9607
|
if (ctx.invalidates)
|
|
9624
9608
|
ctx.invalidates.forEach((i) => moduleCache.delete(i));
|
|
9625
9609
|
ctx.files.forEach((i) => moduleCache.delete(i));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.114",
|
|
4
4
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"@types/natural-compare": "^1.4.1",
|
|
63
63
|
"@types/node": "^17.0.4",
|
|
64
64
|
"@types/prompts": "^2.4.0",
|
|
65
|
+
"birpc": "^0.0.0",
|
|
65
66
|
"c8": "^7.10.0",
|
|
66
67
|
"cac": "^6.7.12",
|
|
67
68
|
"chai-subset": "^1.6.0",
|
package/dist/index-041e627e.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import require$$0 from 'tty';
|
|
2
|
-
import { isPackageExists } from 'local-pkg';
|
|
3
|
-
|
|
4
|
-
var picocolors = {exports: {}};
|
|
5
|
-
|
|
6
|
-
let tty = require$$0;
|
|
7
|
-
|
|
8
|
-
let isColorSupported =
|
|
9
|
-
!("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
|
|
10
|
-
("FORCE_COLOR" in process.env ||
|
|
11
|
-
process.argv.includes("--color") ||
|
|
12
|
-
process.platform === "win32" ||
|
|
13
|
-
(tty.isatty(1) && process.env.TERM !== "dumb") ||
|
|
14
|
-
"CI" in process.env);
|
|
15
|
-
|
|
16
|
-
let formatter =
|
|
17
|
-
(open, close, replace = open) =>
|
|
18
|
-
input => {
|
|
19
|
-
let string = "" + input;
|
|
20
|
-
let index = string.indexOf(close, open.length);
|
|
21
|
-
return ~index
|
|
22
|
-
? open + replaceClose(string, close, replace, index) + close
|
|
23
|
-
: open + string + close
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
let replaceClose = (string, close, replace, index) => {
|
|
27
|
-
let start = string.substring(0, index) + replace;
|
|
28
|
-
let end = string.substring(index + close.length);
|
|
29
|
-
let nextIndex = end.indexOf(close);
|
|
30
|
-
return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
let createColors = (enabled = isColorSupported) => ({
|
|
34
|
-
isColorSupported: enabled,
|
|
35
|
-
reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
|
|
36
|
-
bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
|
|
37
|
-
dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
|
|
38
|
-
italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
|
|
39
|
-
underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
|
|
40
|
-
inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
|
|
41
|
-
hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
|
|
42
|
-
strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
|
|
43
|
-
black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
|
|
44
|
-
red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
|
|
45
|
-
green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
|
|
46
|
-
yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
|
|
47
|
-
blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
|
|
48
|
-
magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
|
|
49
|
-
cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
|
|
50
|
-
white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
|
|
51
|
-
gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
|
|
52
|
-
bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
|
|
53
|
-
bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
|
|
54
|
-
bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
|
|
55
|
-
bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
|
|
56
|
-
bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
|
|
57
|
-
bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
|
|
58
|
-
bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
|
|
59
|
-
bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
picocolors.exports = createColors();
|
|
63
|
-
picocolors.exports.createColors = createColors;
|
|
64
|
-
|
|
65
|
-
var c = picocolors.exports;
|
|
66
|
-
|
|
67
|
-
function toArray(array) {
|
|
68
|
-
array = array || [];
|
|
69
|
-
if (Array.isArray(array))
|
|
70
|
-
return array;
|
|
71
|
-
return [array];
|
|
72
|
-
}
|
|
73
|
-
function notNullish(v) {
|
|
74
|
-
return v != null;
|
|
75
|
-
}
|
|
76
|
-
function slash(str) {
|
|
77
|
-
return str.replace(/\\/g, "/");
|
|
78
|
-
}
|
|
79
|
-
function mergeSlashes(str) {
|
|
80
|
-
return str.replace(/\/\//g, "/");
|
|
81
|
-
}
|
|
82
|
-
const noop = () => {
|
|
83
|
-
};
|
|
84
|
-
function partitionSuiteChildren(suite) {
|
|
85
|
-
let tasksGroup = [];
|
|
86
|
-
const tasksGroups = [];
|
|
87
|
-
for (const c2 of suite.tasks) {
|
|
88
|
-
if (tasksGroup.length === 0 || c2.computeMode === tasksGroup[0].computeMode) {
|
|
89
|
-
tasksGroup.push(c2);
|
|
90
|
-
} else {
|
|
91
|
-
tasksGroups.push(tasksGroup);
|
|
92
|
-
tasksGroup = [c2];
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (tasksGroup.length > 0)
|
|
96
|
-
tasksGroups.push(tasksGroup);
|
|
97
|
-
return tasksGroups;
|
|
98
|
-
}
|
|
99
|
-
function interpretOnlyMode(tasks) {
|
|
100
|
-
if (tasks.some((t) => t.mode === "only")) {
|
|
101
|
-
tasks.forEach((t) => {
|
|
102
|
-
if (t.mode === "run")
|
|
103
|
-
t.mode = "skip";
|
|
104
|
-
else if (t.mode === "only")
|
|
105
|
-
t.mode = "run";
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
tasks.forEach((t) => {
|
|
109
|
-
if (t.type === "suite") {
|
|
110
|
-
if (t.mode === "skip")
|
|
111
|
-
t.tasks.forEach((c2) => c2.mode === "run" && (c2.mode = "skip"));
|
|
112
|
-
else
|
|
113
|
-
interpretOnlyMode(t.tasks);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function getTests(suite) {
|
|
118
|
-
return toArray(suite).flatMap((s) => s.type === "test" ? [s] : s.tasks.flatMap((c2) => c2.type === "test" ? [c2] : getTests(c2)));
|
|
119
|
-
}
|
|
120
|
-
function getTasks(tasks) {
|
|
121
|
-
return toArray(tasks).flatMap((s) => s.type === "test" ? [s] : [s, ...getTasks(s.tasks)]);
|
|
122
|
-
}
|
|
123
|
-
function getSuites(suite) {
|
|
124
|
-
return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []);
|
|
125
|
-
}
|
|
126
|
-
function hasTests(suite) {
|
|
127
|
-
return toArray(suite).some((s) => s.tasks.some((c2) => c2.type === "test" || hasTests(c2)));
|
|
128
|
-
}
|
|
129
|
-
function hasFailed(suite) {
|
|
130
|
-
return toArray(suite).some((s) => {
|
|
131
|
-
var _a;
|
|
132
|
-
return ((_a = s.result) == null ? void 0 : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
function getNames(task) {
|
|
136
|
-
const names = [task.name];
|
|
137
|
-
let current = task;
|
|
138
|
-
while ((current == null ? void 0 : current.suite) || (current == null ? void 0 : current.file)) {
|
|
139
|
-
current = current.suite || current.file;
|
|
140
|
-
if (current == null ? void 0 : current.name)
|
|
141
|
-
names.unshift(current.name);
|
|
142
|
-
}
|
|
143
|
-
return names;
|
|
144
|
-
}
|
|
145
|
-
function getFullName(task) {
|
|
146
|
-
return getNames(task).join(c.dim(" > "));
|
|
147
|
-
}
|
|
148
|
-
async function ensurePackageInstalled(dependency, promptInstall = !process.env.CI && process.stdout.isTTY) {
|
|
149
|
-
if (isPackageExists(dependency))
|
|
150
|
-
return true;
|
|
151
|
-
console.log(c.red(`${c.inverse(c.red(" MISSING DEP "))} Can not find dependency '${dependency}'
|
|
152
|
-
`));
|
|
153
|
-
if (!promptInstall)
|
|
154
|
-
return false;
|
|
155
|
-
const prompts = await import('./index-fa899e66.js').then(function (n) { return n.i; });
|
|
156
|
-
const { install } = await prompts.prompt({
|
|
157
|
-
type: "confirm",
|
|
158
|
-
name: "install",
|
|
159
|
-
message: c.reset(`Do you want to install ${c.green(dependency)}?`)
|
|
160
|
-
});
|
|
161
|
-
if (install) {
|
|
162
|
-
await (await import('./index-9f4b9905.js')).installPackage(dependency, { dev: true });
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export { getSuites as a, getTests as b, c, notNullish as d, ensurePackageInstalled as e, getNames as f, getFullName as g, hasFailed as h, interpretOnlyMode as i, hasTests as j, getTasks as k, mergeSlashes as m, noop as n, partitionSuiteChildren as p, slash as s, toArray as t };
|
package/dist/index-1488b423.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
|
|
3
|
-
function normalizeWindowsPath(input = "") {
|
|
4
|
-
if (!input.includes("\\")) {
|
|
5
|
-
return input;
|
|
6
|
-
}
|
|
7
|
-
return input.replace(/\\/g, "/");
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const _UNC_REGEX = /^[/][/]/;
|
|
11
|
-
const _UNC_DRIVE_REGEX = /^[/][/]([.]{1,2}[/])?([a-zA-Z]):[/]/;
|
|
12
|
-
const _IS_ABSOLUTE_RE = /^\/|^\\|^[a-zA-Z]:[/\\]/;
|
|
13
|
-
const sep = "/";
|
|
14
|
-
const delimiter = ":";
|
|
15
|
-
const normalize = function(path2) {
|
|
16
|
-
if (path2.length === 0) {
|
|
17
|
-
return ".";
|
|
18
|
-
}
|
|
19
|
-
path2 = normalizeWindowsPath(path2);
|
|
20
|
-
const isUNCPath = path2.match(_UNC_REGEX);
|
|
21
|
-
const hasUNCDrive = isUNCPath && path2.match(_UNC_DRIVE_REGEX);
|
|
22
|
-
const isPathAbsolute = isAbsolute(path2);
|
|
23
|
-
const trailingSeparator = path2[path2.length - 1] === "/";
|
|
24
|
-
path2 = normalizeString(path2, !isPathAbsolute);
|
|
25
|
-
if (path2.length === 0) {
|
|
26
|
-
if (isPathAbsolute) {
|
|
27
|
-
return "/";
|
|
28
|
-
}
|
|
29
|
-
return trailingSeparator ? "./" : ".";
|
|
30
|
-
}
|
|
31
|
-
if (trailingSeparator) {
|
|
32
|
-
path2 += "/";
|
|
33
|
-
}
|
|
34
|
-
if (isUNCPath) {
|
|
35
|
-
if (hasUNCDrive) {
|
|
36
|
-
return `//./${path2}`;
|
|
37
|
-
}
|
|
38
|
-
return `//${path2}`;
|
|
39
|
-
}
|
|
40
|
-
return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
|
|
41
|
-
};
|
|
42
|
-
const join = function(...args) {
|
|
43
|
-
if (args.length === 0) {
|
|
44
|
-
return ".";
|
|
45
|
-
}
|
|
46
|
-
let joined;
|
|
47
|
-
for (let i = 0; i < args.length; ++i) {
|
|
48
|
-
const arg = args[i];
|
|
49
|
-
if (arg.length > 0) {
|
|
50
|
-
if (joined === void 0) {
|
|
51
|
-
joined = arg;
|
|
52
|
-
} else {
|
|
53
|
-
joined += `/${arg}`;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (joined === void 0) {
|
|
58
|
-
return ".";
|
|
59
|
-
}
|
|
60
|
-
return normalize(joined);
|
|
61
|
-
};
|
|
62
|
-
const resolve = function(...args) {
|
|
63
|
-
args = args.map((arg) => normalizeWindowsPath(arg));
|
|
64
|
-
let resolvedPath = "";
|
|
65
|
-
let resolvedAbsolute = false;
|
|
66
|
-
for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
67
|
-
const path2 = i >= 0 ? args[i] : process.cwd();
|
|
68
|
-
if (path2.length === 0) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
resolvedPath = `${path2}/${resolvedPath}`;
|
|
72
|
-
resolvedAbsolute = isAbsolute(path2);
|
|
73
|
-
}
|
|
74
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
75
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
76
|
-
return `/${resolvedPath}`;
|
|
77
|
-
}
|
|
78
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
79
|
-
};
|
|
80
|
-
function normalizeString(path2, allowAboveRoot) {
|
|
81
|
-
let res = "";
|
|
82
|
-
let lastSegmentLength = 0;
|
|
83
|
-
let lastSlash = -1;
|
|
84
|
-
let dots = 0;
|
|
85
|
-
let char = null;
|
|
86
|
-
for (let i = 0; i <= path2.length; ++i) {
|
|
87
|
-
if (i < path2.length) {
|
|
88
|
-
char = path2[i];
|
|
89
|
-
} else if (char === "/") {
|
|
90
|
-
break;
|
|
91
|
-
} else {
|
|
92
|
-
char = "/";
|
|
93
|
-
}
|
|
94
|
-
if (char === "/") {
|
|
95
|
-
if (lastSlash === i - 1 || dots === 1) ; else if (dots === 2) {
|
|
96
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
97
|
-
if (res.length > 2) {
|
|
98
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
99
|
-
if (lastSlashIndex === -1) {
|
|
100
|
-
res = "";
|
|
101
|
-
lastSegmentLength = 0;
|
|
102
|
-
} else {
|
|
103
|
-
res = res.slice(0, lastSlashIndex);
|
|
104
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
105
|
-
}
|
|
106
|
-
lastSlash = i;
|
|
107
|
-
dots = 0;
|
|
108
|
-
continue;
|
|
109
|
-
} else if (res.length !== 0) {
|
|
110
|
-
res = "";
|
|
111
|
-
lastSegmentLength = 0;
|
|
112
|
-
lastSlash = i;
|
|
113
|
-
dots = 0;
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (allowAboveRoot) {
|
|
118
|
-
res += res.length > 0 ? "/.." : "..";
|
|
119
|
-
lastSegmentLength = 2;
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
if (res.length > 0) {
|
|
123
|
-
res += `/${path2.slice(lastSlash + 1, i)}`;
|
|
124
|
-
} else {
|
|
125
|
-
res = path2.slice(lastSlash + 1, i);
|
|
126
|
-
}
|
|
127
|
-
lastSegmentLength = i - lastSlash - 1;
|
|
128
|
-
}
|
|
129
|
-
lastSlash = i;
|
|
130
|
-
dots = 0;
|
|
131
|
-
} else if (char === "." && dots !== -1) {
|
|
132
|
-
++dots;
|
|
133
|
-
} else {
|
|
134
|
-
dots = -1;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return res;
|
|
138
|
-
}
|
|
139
|
-
const isAbsolute = function(p) {
|
|
140
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
141
|
-
};
|
|
142
|
-
const toNamespacedPath = function(p) {
|
|
143
|
-
return normalizeWindowsPath(p);
|
|
144
|
-
};
|
|
145
|
-
const extname = function(p) {
|
|
146
|
-
return path.posix.extname(normalizeWindowsPath(p));
|
|
147
|
-
};
|
|
148
|
-
const relative = function(from, to) {
|
|
149
|
-
return path.posix.relative(normalizeWindowsPath(from), normalizeWindowsPath(to));
|
|
150
|
-
};
|
|
151
|
-
const dirname = function(p) {
|
|
152
|
-
return path.posix.dirname(normalizeWindowsPath(p));
|
|
153
|
-
};
|
|
154
|
-
const format = function(p) {
|
|
155
|
-
return normalizeWindowsPath(path.posix.format(p));
|
|
156
|
-
};
|
|
157
|
-
const basename = function(p, ext) {
|
|
158
|
-
return path.posix.basename(normalizeWindowsPath(p), ext);
|
|
159
|
-
};
|
|
160
|
-
const parse = function(p) {
|
|
161
|
-
return path.posix.parse(normalizeWindowsPath(p));
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const _path = /*#__PURE__*/Object.freeze({
|
|
165
|
-
__proto__: null,
|
|
166
|
-
sep: sep,
|
|
167
|
-
delimiter: delimiter,
|
|
168
|
-
normalize: normalize,
|
|
169
|
-
join: join,
|
|
170
|
-
resolve: resolve,
|
|
171
|
-
normalizeString: normalizeString,
|
|
172
|
-
isAbsolute: isAbsolute,
|
|
173
|
-
toNamespacedPath: toNamespacedPath,
|
|
174
|
-
extname: extname,
|
|
175
|
-
relative: relative,
|
|
176
|
-
dirname: dirname,
|
|
177
|
-
format: format,
|
|
178
|
-
basename: basename,
|
|
179
|
-
parse: parse
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
const index = {
|
|
183
|
-
..._path
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
export { resolve as a, basename as b, index as c, dirname as d, isAbsolute as i, relative as r };
|