@depup/vitest 4.0.18-depup.0
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 +691 -0
- package/README.md +7 -0
- package/browser/context.d.ts +7 -0
- package/browser/context.js +20 -0
- package/config.d.ts +3 -0
- package/coverage.d.ts +1 -0
- package/dist/browser.d.ts +46 -0
- package/dist/browser.js +20 -0
- package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +6 -0
- package/dist/chunks/base.CJ0Y4ePK.js +165 -0
- package/dist/chunks/benchmark.B3N2zMcH.js +40 -0
- package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +24 -0
- package/dist/chunks/browser.d.ChKACdzH.d.ts +59 -0
- package/dist/chunks/cac.DVeoLl0M.js +1409 -0
- package/dist/chunks/cli-api.B7PN_QUv.js +13657 -0
- package/dist/chunks/config.d.Cy95HiCx.d.ts +210 -0
- package/dist/chunks/console.Cf-YriPC.js +146 -0
- package/dist/chunks/constants.D_Q9UYh-.js +36 -0
- package/dist/chunks/coverage.AVPTjMgw.js +3292 -0
- package/dist/chunks/coverage.D_JHT54q.js +25 -0
- package/dist/chunks/coverage.d.BZtK59WP.d.ts +37 -0
- package/dist/chunks/creator.DAmOKTvJ.js +673 -0
- package/dist/chunks/date.Bq6ZW5rf.js +73 -0
- package/dist/chunks/defaults.BOqNVLsY.js +74 -0
- package/dist/chunks/env.D4Lgay0q.js +8 -0
- package/dist/chunks/environment.d.CrsxCzP1.d.ts +29 -0
- package/dist/chunks/evaluatedModules.Dg1zASAC.js +17 -0
- package/dist/chunks/evaluatedModules.d.BxJ5omdx.d.ts +7 -0
- package/dist/chunks/git.Bm2pzPAa.js +71 -0
- package/dist/chunks/global.d.B15mdLcR.d.ts +99 -0
- package/dist/chunks/globals.DOayXfHP.js +30 -0
- package/dist/chunks/index.6Qv1eEA6.js +109 -0
- package/dist/chunks/index.C5r1PdPD.js +231 -0
- package/dist/chunks/index.Chj8NDwU.js +206 -0
- package/dist/chunks/index.CyBMJtT7.js +727 -0
- package/dist/chunks/index.D3XRDfWc.js +213 -0
- package/dist/chunks/index.D4KonVSU.js +6343 -0
- package/dist/chunks/index.M8mOzt4Y.js +3839 -0
- package/dist/chunks/index.Z5E_ObnR.js +37 -0
- package/dist/chunks/init-forks._y3TW739.js +41 -0
- package/dist/chunks/init-threads.DBO2kn-p.js +18 -0
- package/dist/chunks/init.B6MLFIaN.js +334 -0
- package/dist/chunks/inspector.CvyFGlXm.js +53 -0
- package/dist/chunks/modules.BJuCwlRJ.js +36 -0
- package/dist/chunks/node.Ce0vMQM7.js +14 -0
- package/dist/chunks/plugin.d.CtqpEehP.d.ts +38 -0
- package/dist/chunks/reporters.d.CWXNI2jG.d.ts +3271 -0
- package/dist/chunks/rpc.BoxB0q7B.js +76 -0
- package/dist/chunks/rpc.d.RH3apGEf.d.ts +64 -0
- package/dist/chunks/setup-common.Cm-kSBVi.js +60 -0
- package/dist/chunks/startModuleRunner.DEj0jb3e.js +861 -0
- package/dist/chunks/suite.d.BJWk38HB.d.ts +10 -0
- package/dist/chunks/test.B8ej_ZHS.js +254 -0
- package/dist/chunks/traces.CCmnQaNT.js +217 -0
- package/dist/chunks/traces.d.402V_yFI.d.ts +18 -0
- package/dist/chunks/utils.DvEY5TfP.js +52 -0
- package/dist/chunks/vi.2VT5v0um.js +3919 -0
- package/dist/chunks/vm.D3epNOPZ.js +744 -0
- package/dist/chunks/worker.d.Dyxm8DEL.d.ts +255 -0
- package/dist/cli.js +28 -0
- package/dist/config.cjs +94 -0
- package/dist/config.d.ts +104 -0
- package/dist/config.js +15 -0
- package/dist/coverage.d.ts +118 -0
- package/dist/coverage.js +23 -0
- package/dist/environments.d.ts +22 -0
- package/dist/environments.js +3 -0
- package/dist/index.d.ts +510 -0
- package/dist/index.js +20 -0
- package/dist/mocker.d.ts +1 -0
- package/dist/mocker.js +1 -0
- package/dist/module-evaluator.d.ts +124 -0
- package/dist/module-evaluator.js +343 -0
- package/dist/module-runner.js +17 -0
- package/dist/node.d.ts +251 -0
- package/dist/node.js +98 -0
- package/dist/path.js +7 -0
- package/dist/reporters.d.ts +27 -0
- package/dist/reporters.js +24 -0
- package/dist/runners.d.ts +50 -0
- package/dist/runners.js +19 -0
- package/dist/snapshot.d.ts +9 -0
- package/dist/snapshot.js +4 -0
- package/dist/spy.js +1 -0
- package/dist/suite.d.ts +5 -0
- package/dist/suite.js +6 -0
- package/dist/worker.d.ts +32 -0
- package/dist/worker.js +48 -0
- package/dist/workers/forks.js +54 -0
- package/dist/workers/runVmTests.js +95 -0
- package/dist/workers/threads.js +55 -0
- package/dist/workers/vmForks.js +36 -0
- package/dist/workers/vmThreads.js +37 -0
- package/environments.d.ts +1 -0
- package/globals.d.ts +20 -0
- package/import-meta.d.ts +5 -0
- package/importMeta.d.ts +4 -0
- package/index.cjs +5 -0
- package/index.d.cts +1 -0
- package/jsdom.d.ts +6 -0
- package/mocker.d.ts +1 -0
- package/node.d.ts +1 -0
- package/optional-types.d.ts +7 -0
- package/package.json +224 -0
- package/reporters.d.ts +1 -0
- package/runners.d.ts +1 -0
- package/snapshot.d.ts +1 -0
- package/suite.d.ts +1 -0
- package/suppress-warnings.cjs +21 -0
- package/vitest.mjs +2 -0
- package/worker.d.ts +1 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path, { resolve } from 'node:path';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { x } from 'tinyexec';
|
|
6
|
+
|
|
7
|
+
const AGENTS = [
|
|
8
|
+
"npm",
|
|
9
|
+
"yarn",
|
|
10
|
+
"yarn@berry",
|
|
11
|
+
"pnpm",
|
|
12
|
+
"pnpm@6",
|
|
13
|
+
"bun",
|
|
14
|
+
"deno"
|
|
15
|
+
];
|
|
16
|
+
const LOCKS = {
|
|
17
|
+
"bun.lock": "bun",
|
|
18
|
+
"bun.lockb": "bun",
|
|
19
|
+
"deno.lock": "deno",
|
|
20
|
+
"pnpm-lock.yaml": "pnpm",
|
|
21
|
+
"pnpm-workspace.yaml": "pnpm",
|
|
22
|
+
"yarn.lock": "yarn",
|
|
23
|
+
"package-lock.json": "npm",
|
|
24
|
+
"npm-shrinkwrap.json": "npm"
|
|
25
|
+
};
|
|
26
|
+
const INSTALL_METADATA = {
|
|
27
|
+
"node_modules/.deno/": "deno",
|
|
28
|
+
"node_modules/.pnpm/": "pnpm",
|
|
29
|
+
"node_modules/.yarn-state.yml": "yarn",
|
|
30
|
+
// yarn v2+ (node-modules)
|
|
31
|
+
"node_modules/.yarn_integrity": "yarn",
|
|
32
|
+
// yarn v1
|
|
33
|
+
"node_modules/.package-lock.json": "npm",
|
|
34
|
+
".pnp.cjs": "yarn",
|
|
35
|
+
// yarn v3+ (pnp)
|
|
36
|
+
".pnp.js": "yarn",
|
|
37
|
+
// yarn v2 (pnp)
|
|
38
|
+
"bun.lock": "bun",
|
|
39
|
+
"bun.lockb": "bun"
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
async function pathExists(path2, type) {
|
|
43
|
+
try {
|
|
44
|
+
const stat = await fs.stat(path2);
|
|
45
|
+
return type === "file" ? stat.isFile() : stat.isDirectory();
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function* lookup(cwd = process.cwd()) {
|
|
51
|
+
let directory = path.resolve(cwd);
|
|
52
|
+
const { root } = path.parse(directory);
|
|
53
|
+
while (directory && directory !== root) {
|
|
54
|
+
yield directory;
|
|
55
|
+
directory = path.dirname(directory);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function parsePackageJson(filepath, onUnknown) {
|
|
59
|
+
return !filepath || !pathExists(filepath, "file") ? null : await handlePackageManager(filepath, onUnknown);
|
|
60
|
+
}
|
|
61
|
+
async function detect(options = {}) {
|
|
62
|
+
const {
|
|
63
|
+
cwd,
|
|
64
|
+
strategies = ["lockfile", "packageManager-field", "devEngines-field"],
|
|
65
|
+
onUnknown
|
|
66
|
+
} = options;
|
|
67
|
+
let stopDir;
|
|
68
|
+
if (typeof options.stopDir === "string") {
|
|
69
|
+
const resolved = path.resolve(options.stopDir);
|
|
70
|
+
stopDir = (dir) => dir === resolved;
|
|
71
|
+
} else {
|
|
72
|
+
stopDir = options.stopDir;
|
|
73
|
+
}
|
|
74
|
+
for (const directory of lookup(cwd)) {
|
|
75
|
+
for (const strategy of strategies) {
|
|
76
|
+
switch (strategy) {
|
|
77
|
+
case "lockfile": {
|
|
78
|
+
for (const lock of Object.keys(LOCKS)) {
|
|
79
|
+
if (await pathExists(path.join(directory, lock), "file")) {
|
|
80
|
+
const name = LOCKS[lock];
|
|
81
|
+
const result = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
|
|
82
|
+
if (result)
|
|
83
|
+
return result;
|
|
84
|
+
else
|
|
85
|
+
return { name, agent: name };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case "packageManager-field":
|
|
91
|
+
case "devEngines-field": {
|
|
92
|
+
const result = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
|
|
93
|
+
if (result)
|
|
94
|
+
return result;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case "install-metadata": {
|
|
98
|
+
for (const metadata of Object.keys(INSTALL_METADATA)) {
|
|
99
|
+
const fileOrDir = metadata.endsWith("/") ? "dir" : "file";
|
|
100
|
+
if (await pathExists(path.join(directory, metadata), fileOrDir)) {
|
|
101
|
+
const name = INSTALL_METADATA[metadata];
|
|
102
|
+
const agent = name === "yarn" ? isMetadataYarnClassic(metadata) ? "yarn" : "yarn@berry" : name;
|
|
103
|
+
return { name, agent };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (stopDir?.(directory))
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
function getNameAndVer(pkg) {
|
|
116
|
+
const handelVer = (version) => version?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version;
|
|
117
|
+
if (typeof pkg.packageManager === "string") {
|
|
118
|
+
const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
|
|
119
|
+
return { name, ver: handelVer(ver) };
|
|
120
|
+
}
|
|
121
|
+
if (typeof pkg.devEngines?.packageManager?.name === "string") {
|
|
122
|
+
return {
|
|
123
|
+
name: pkg.devEngines.packageManager.name,
|
|
124
|
+
ver: handelVer(pkg.devEngines.packageManager.version)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return void 0;
|
|
128
|
+
}
|
|
129
|
+
async function handlePackageManager(filepath, onUnknown) {
|
|
130
|
+
try {
|
|
131
|
+
const pkg = JSON.parse(await fs.readFile(filepath, "utf8"));
|
|
132
|
+
let agent;
|
|
133
|
+
const nameAndVer = getNameAndVer(pkg);
|
|
134
|
+
if (nameAndVer) {
|
|
135
|
+
const name = nameAndVer.name;
|
|
136
|
+
const ver = nameAndVer.ver;
|
|
137
|
+
let version = ver;
|
|
138
|
+
if (name === "yarn" && ver && Number.parseInt(ver) > 1) {
|
|
139
|
+
agent = "yarn@berry";
|
|
140
|
+
version = "berry";
|
|
141
|
+
return { name, agent, version };
|
|
142
|
+
} else if (name === "pnpm" && ver && Number.parseInt(ver) < 7) {
|
|
143
|
+
agent = "pnpm@6";
|
|
144
|
+
return { name, agent, version };
|
|
145
|
+
} else if (AGENTS.includes(name)) {
|
|
146
|
+
agent = name;
|
|
147
|
+
return { name, agent, version };
|
|
148
|
+
} else {
|
|
149
|
+
return onUnknown?.(pkg.packageManager) ?? null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} catch {
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
function isMetadataYarnClassic(metadataPath) {
|
|
157
|
+
return metadataPath.endsWith(".yarn_integrity");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/detect.ts
|
|
161
|
+
async function detectPackageManager(cwd = process.cwd()) {
|
|
162
|
+
const result = await detect({
|
|
163
|
+
cwd,
|
|
164
|
+
onUnknown(packageManager) {
|
|
165
|
+
console.warn("[@antfu/install-pkg] Unknown packageManager:", packageManager);
|
|
166
|
+
return void 0;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
return result?.agent || null;
|
|
170
|
+
}
|
|
171
|
+
async function installPackage(names, options = {}) {
|
|
172
|
+
const detectedAgent = options.packageManager || await detectPackageManager(options.cwd) || "npm";
|
|
173
|
+
const [agent] = detectedAgent.split("@");
|
|
174
|
+
if (!Array.isArray(names))
|
|
175
|
+
names = [names];
|
|
176
|
+
const args = (typeof options.additionalArgs === "function" ? options.additionalArgs(agent, detectedAgent) : options.additionalArgs) || [];
|
|
177
|
+
if (options.preferOffline) {
|
|
178
|
+
if (detectedAgent === "yarn@berry")
|
|
179
|
+
args.unshift("--cached");
|
|
180
|
+
else
|
|
181
|
+
args.unshift("--prefer-offline");
|
|
182
|
+
}
|
|
183
|
+
if (agent === "pnpm") {
|
|
184
|
+
args.unshift(
|
|
185
|
+
/**
|
|
186
|
+
* Prevent pnpm from removing installed devDeps while `NODE_ENV` is `production`
|
|
187
|
+
* @see https://pnpm.io/cli/install#--prod--p
|
|
188
|
+
*/
|
|
189
|
+
"--prod=false"
|
|
190
|
+
);
|
|
191
|
+
if (existsSync(resolve(options.cwd ?? process.cwd(), "pnpm-workspace.yaml"))) {
|
|
192
|
+
args.unshift("-w");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return x(
|
|
196
|
+
agent,
|
|
197
|
+
[
|
|
198
|
+
agent === "yarn" ? "add" : "install",
|
|
199
|
+
options.dev ? "-D" : "",
|
|
200
|
+
...args,
|
|
201
|
+
...names
|
|
202
|
+
].filter(Boolean),
|
|
203
|
+
{
|
|
204
|
+
nodeOptions: {
|
|
205
|
+
stdio: options.silent ? "ignore" : "inherit",
|
|
206
|
+
cwd: options.cwd
|
|
207
|
+
},
|
|
208
|
+
throwOnError: true
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { detectPackageManager, installPackage };
|