@voidzero-dev/vite-plus-test 0.0.0-0bfcc90f.20260209-0731
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/browser/context.d.ts +4 -0
- package/browser/context.js +20 -0
- package/config.d.ts +3 -0
- package/coverage.d.ts +1 -0
- package/dist/@vitest/browser/client/.vite/manifest.json +24 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +57 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
- package/dist/@vitest/browser/client/__vitest__/bg.png +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.svg +5 -0
- package/dist/@vitest/browser/client/__vitest__/index.html +32 -0
- package/dist/@vitest/browser/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
- package/dist/@vitest/browser/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
- package/dist/@vitest/browser/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
- package/dist/@vitest/browser/client/error-catcher.js +82 -0
- package/dist/@vitest/browser/client/esm-client-injector.js +67 -0
- package/dist/@vitest/browser/client/favicon.svg +5 -0
- package/dist/@vitest/browser/client/orchestrator.html +35 -0
- package/dist/@vitest/browser/client/tester/tester.html +13 -0
- package/dist/@vitest/browser/client.js +456 -0
- package/dist/@vitest/browser/context.d.ts +792 -0
- package/dist/@vitest/browser/context.js +541 -0
- package/dist/@vitest/browser/expect-element.js +32 -0
- package/dist/@vitest/browser/index-D6m36C6U.js +11 -0
- package/dist/@vitest/browser/index.d.ts +73 -0
- package/dist/@vitest/browser/index.js +3513 -0
- package/dist/@vitest/browser/jest-dom.d.ts +724 -0
- package/dist/@vitest/browser/locators.d.ts +354 -0
- package/dist/@vitest/browser/locators.js +1 -0
- package/dist/@vitest/browser/matchers.d.ts +29 -0
- package/dist/@vitest/browser/shared/screenshotMatcher/types.d.ts +22 -0
- package/dist/@vitest/browser/state.js +280 -0
- package/dist/@vitest/browser/types.d.ts +69 -0
- package/dist/@vitest/browser-playwright/context.d.ts +1 -0
- package/dist/@vitest/browser-playwright/index.d.ts +106 -0
- package/dist/@vitest/browser-playwright/index.js +1111 -0
- package/dist/@vitest/browser-playwright/locators.js +114 -0
- package/dist/@vitest/browser-preview/context.d.ts +1 -0
- package/dist/@vitest/browser-preview/index.d.ts +19 -0
- package/dist/@vitest/browser-preview/index.js +148 -0
- package/dist/@vitest/browser-preview/locators.js +79 -0
- package/dist/@vitest/browser-webdriverio/context.d.ts +1 -0
- package/dist/@vitest/browser-webdriverio/index.d.ts +63 -0
- package/dist/@vitest/browser-webdriverio/index.js +600 -0
- package/dist/@vitest/browser-webdriverio/locators.js +163 -0
- package/dist/@vitest/expect/index.d.ts +807 -0
- package/dist/@vitest/expect/index.js +1875 -0
- package/dist/@vitest/mocker/auto-register.d.ts +2 -0
- package/dist/@vitest/mocker/auto-register.js +9 -0
- package/dist/@vitest/mocker/automock.d.ts +12 -0
- package/dist/@vitest/mocker/automock.js +1 -0
- package/dist/@vitest/mocker/browser.d.ts +53 -0
- package/dist/@vitest/mocker/browser.js +91 -0
- package/dist/@vitest/mocker/chunk-automock.js +354 -0
- package/dist/@vitest/mocker/chunk-interceptor-native.js +15 -0
- package/dist/@vitest/mocker/chunk-mocker.js +521 -0
- package/dist/@vitest/mocker/chunk-pathe.M-eThtNZ.js +174 -0
- package/dist/@vitest/mocker/chunk-registry.js +185 -0
- package/dist/@vitest/mocker/chunk-utils.js +16 -0
- package/dist/@vitest/mocker/index.d-C-sLYZi-.d.ts +25 -0
- package/dist/@vitest/mocker/index.d.ts +2 -0
- package/dist/@vitest/mocker/index.js +185 -0
- package/dist/@vitest/mocker/mocker.d-TnKRhz7N.d.ts +81 -0
- package/dist/@vitest/mocker/node.d.ts +800 -0
- package/dist/@vitest/mocker/node.js +966 -0
- package/dist/@vitest/mocker/redirect.d.ts +3 -0
- package/dist/@vitest/mocker/redirect.js +79 -0
- package/dist/@vitest/mocker/register.d.ts +9 -0
- package/dist/@vitest/mocker/register.js +41 -0
- package/dist/@vitest/mocker/types.d-B8CCKmHt.d.ts +107 -0
- package/dist/@vitest/pretty-format/index.d.ts +124 -0
- package/dist/@vitest/pretty-format/index.js +1022 -0
- package/dist/@vitest/runner/chunk-tasks.js +340 -0
- package/dist/@vitest/runner/index.d.ts +180 -0
- package/dist/@vitest/runner/index.js +2114 -0
- package/dist/@vitest/runner/tasks.d-C7UxawJ9.d.ts +834 -0
- package/dist/@vitest/runner/types.d.ts +183 -0
- package/dist/@vitest/runner/types.js +1 -0
- package/dist/@vitest/runner/utils.d.ts +45 -0
- package/dist/@vitest/runner/utils.js +5 -0
- package/dist/@vitest/snapshot/environment.d-DHdQ1Csl.d.ts +22 -0
- package/dist/@vitest/snapshot/environment.d.ts +16 -0
- package/dist/@vitest/snapshot/environment.js +40 -0
- package/dist/@vitest/snapshot/index.d.ts +130 -0
- package/dist/@vitest/snapshot/index.js +1437 -0
- package/dist/@vitest/snapshot/manager.d.ts +18 -0
- package/dist/@vitest/snapshot/manager.js +73 -0
- package/dist/@vitest/snapshot/rawSnapshot.d-lFsMJFUd.d.ts +61 -0
- package/dist/@vitest/spy/index.d.ts +384 -0
- package/dist/@vitest/spy/index.js +433 -0
- package/dist/@vitest/utils/chunk-_commonjsHelpers.js +5 -0
- package/dist/@vitest/utils/chunk-pathe.M-eThtNZ.js +156 -0
- package/dist/@vitest/utils/constants.d.ts +21 -0
- package/dist/@vitest/utils/constants.js +49 -0
- package/dist/@vitest/utils/diff.d.ts +93 -0
- package/dist/@vitest/utils/diff.js +2199 -0
- package/dist/@vitest/utils/display.d.ts +29 -0
- package/dist/@vitest/utils/display.js +742 -0
- package/dist/@vitest/utils/error.d.ts +7 -0
- package/dist/@vitest/utils/error.js +42 -0
- package/dist/@vitest/utils/helpers.d.ts +73 -0
- package/dist/@vitest/utils/helpers.js +295 -0
- package/dist/@vitest/utils/highlight.d.ts +9 -0
- package/dist/@vitest/utils/highlight.js +538 -0
- package/dist/@vitest/utils/index.d.ts +5 -0
- package/dist/@vitest/utils/index.js +1 -0
- package/dist/@vitest/utils/offset.d.ts +5 -0
- package/dist/@vitest/utils/offset.js +32 -0
- package/dist/@vitest/utils/resolver.d.ts +7 -0
- package/dist/@vitest/utils/resolver.js +71 -0
- package/dist/@vitest/utils/serialize.d.ts +3 -0
- package/dist/@vitest/utils/serialize.js +118 -0
- package/dist/@vitest/utils/source-map.d.ts +55 -0
- package/dist/@vitest/utils/source-map.js +478 -0
- package/dist/@vitest/utils/timers.d.ts +33 -0
- package/dist/@vitest/utils/timers.js +49 -0
- package/dist/@vitest/utils/types.d-BCElaP-c.d.ts +53 -0
- package/dist/@vitest/utils/types.d.ts +34 -0
- package/dist/@vitest/utils/types.js +1 -0
- package/dist/browser-compat.js +3 -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 +13672 -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/client/.vite/manifest.json +24 -0
- package/dist/client/__vitest__/assets/index-BUCFJtth.js +57 -0
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
- package/dist/client/__vitest__/bg.png +0 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +5 -0
- package/dist/client/__vitest__/index.html +32 -0
- package/dist/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
- package/dist/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
- package/dist/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
- package/dist/client/error-catcher.js +82 -0
- package/dist/client/esm-client-injector.js +67 -0
- package/dist/client/favicon.svg +5 -0
- package/dist/client/orchestrator.html +35 -0
- package/dist/client/tester/tester.html +13 -0
- package/dist/client.js +456 -0
- package/dist/config.cjs +94 -0
- package/dist/config.d.ts +104 -0
- package/dist/config.js +15 -0
- package/dist/context.js +541 -0
- package/dist/coverage.d.ts +118 -0
- package/dist/coverage.js +23 -0
- package/dist/dummy.js +2 -0
- package/dist/environments.d.ts +22 -0
- package/dist/environments.js +3 -0
- package/dist/expect-element.js +27 -0
- package/dist/index-D6m36C6U.js +6 -0
- package/dist/index-node.js +7 -0
- package/dist/index.d.ts +510 -0
- package/dist/index.js +19 -0
- package/dist/locators.d.ts +354 -0
- package/dist/locators.js +1 -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-stub.js +44 -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/plugins/browser-client.mjs +2 -0
- package/dist/plugins/browser-context.mjs +2 -0
- package/dist/plugins/browser-locators.mjs +2 -0
- package/dist/plugins/browser-playwright.mjs +2 -0
- package/dist/plugins/browser-preview.mjs +2 -0
- package/dist/plugins/browser-webdriverio.mjs +2 -0
- package/dist/plugins/browser.mjs +2 -0
- package/dist/plugins/expect.mjs +2 -0
- package/dist/plugins/mocker-automock.mjs +2 -0
- package/dist/plugins/mocker-browser.mjs +2 -0
- package/dist/plugins/mocker-node.mjs +2 -0
- package/dist/plugins/mocker-redirect.mjs +2 -0
- package/dist/plugins/mocker-register.mjs +2 -0
- package/dist/plugins/mocker.mjs +2 -0
- package/dist/plugins/pretty-format.mjs +2 -0
- package/dist/plugins/runner-types.mjs +2 -0
- package/dist/plugins/runner-utils.mjs +2 -0
- package/dist/plugins/runner.mjs +2 -0
- package/dist/plugins/snapshot-environment.mjs +2 -0
- package/dist/plugins/snapshot-manager.mjs +2 -0
- package/dist/plugins/snapshot.mjs +2 -0
- package/dist/plugins/spy.mjs +2 -0
- package/dist/plugins/utils-constants.mjs +2 -0
- package/dist/plugins/utils-diff.mjs +2 -0
- package/dist/plugins/utils-display.mjs +2 -0
- package/dist/plugins/utils-error.mjs +2 -0
- package/dist/plugins/utils-helpers.mjs +2 -0
- package/dist/plugins/utils-highlight.mjs +2 -0
- package/dist/plugins/utils-offset.mjs +2 -0
- package/dist/plugins/utils-resolver.mjs +2 -0
- package/dist/plugins/utils-serialize.mjs +2 -0
- package/dist/plugins/utils-source-map.mjs +2 -0
- package/dist/plugins/utils-timers.mjs +2 -0
- package/dist/plugins/utils.mjs +2 -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/shared/screenshotMatcher/types.d.ts +22 -0
- package/dist/snapshot.d.ts +9 -0
- package/dist/snapshot.js +4 -0
- package/dist/spy.js +1 -0
- package/dist/state.js +280 -0
- package/dist/suite.d.ts +5 -0
- package/dist/suite.js +6 -0
- package/dist/types.d.ts +69 -0
- package/dist/vendor/chai.d.mts +1 -0
- package/dist/vendor/chai.mjs +3577 -0
- package/dist/vendor/es-module-lexer.d.mts +193 -0
- package/dist/vendor/es-module-lexer.mjs +79 -0
- package/dist/vendor/estree-walker.d.mts +583 -0
- package/dist/vendor/estree-walker.mjs +339 -0
- package/dist/vendor/expect-type.d.mts +1574 -0
- package/dist/vendor/expect-type.mjs +214 -0
- package/dist/vendor/magic-string.d.mts +261 -0
- package/dist/vendor/magic-string.mjs +1700 -0
- package/dist/vendor/obug.d.mts +56 -0
- package/dist/vendor/obug.mjs +276 -0
- package/dist/vendor/pathe.d.mts +46 -0
- package/dist/vendor/pathe.mjs +496 -0
- package/dist/vendor/picomatch.d.mts +1 -0
- package/dist/vendor/picomatch.mjs +1855 -0
- package/dist/vendor/shared-3g9mwCWP.mjs +31 -0
- package/dist/vendor/std-env.d.mts +88 -0
- package/dist/vendor/std-env.mjs +159 -0
- package/dist/vendor/tinybench.d.mts +317 -0
- package/dist/vendor/tinybench.mjs +504 -0
- package/dist/vendor/tinyexec.d.mts +72 -0
- package/dist/vendor/tinyexec.mjs +637 -0
- package/dist/vendor/tinyglobby.d.mts +157 -0
- package/dist/vendor/tinyglobby.mjs +832 -0
- package/dist/vendor/tinyrainbow.d.mts +60 -0
- package/dist/vendor/tinyrainbow.mjs +93 -0
- package/dist/vendor/vitest_browser.mjs +2 -0
- package/dist/vendor/vitest_internal_browser.mjs +2 -0
- package/dist/vendor/vitest_runner.mjs +2 -0
- package/dist/vendor/vitest_runners.mjs +2 -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 +335 -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,521 @@
|
|
|
1
|
+
import { mockObject } from './index.js';
|
|
2
|
+
import { M as MockerRegistry, R as RedirectedModule, A as AutomockedModule } from './chunk-registry.js';
|
|
3
|
+
import { e as extname, j as join } from './chunk-pathe.M-eThtNZ.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get original stacktrace without source map support the most performant way.
|
|
7
|
+
* - Create only 1 stack frame.
|
|
8
|
+
* - Rewrite prepareStackTrace to bypass "support-stack-trace" (usually takes ~250ms).
|
|
9
|
+
*/
|
|
10
|
+
function createSimpleStackTrace(options) {
|
|
11
|
+
const { message = "$$stack trace error", stackTraceLimit = 1 } = options || {};
|
|
12
|
+
const limit = Error.stackTraceLimit;
|
|
13
|
+
const prepareStackTrace = Error.prepareStackTrace;
|
|
14
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
15
|
+
Error.prepareStackTrace = (e) => e.stack;
|
|
16
|
+
const err = new Error(message);
|
|
17
|
+
const stackTrace = err.stack || "";
|
|
18
|
+
Error.prepareStackTrace = prepareStackTrace;
|
|
19
|
+
Error.stackTraceLimit = limit;
|
|
20
|
+
return stackTrace;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
24
|
+
function normalizeWindowsPath(input = "") {
|
|
25
|
+
if (!input) {
|
|
26
|
+
return input;
|
|
27
|
+
}
|
|
28
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
29
|
+
}
|
|
30
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
31
|
+
function cwd() {
|
|
32
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
33
|
+
return process.cwd().replace(/\\/g, "/");
|
|
34
|
+
}
|
|
35
|
+
return "/";
|
|
36
|
+
}
|
|
37
|
+
const resolve = function(...arguments_) {
|
|
38
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
39
|
+
let resolvedPath = "";
|
|
40
|
+
let resolvedAbsolute = false;
|
|
41
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
42
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
|
43
|
+
if (!path || path.length === 0) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
47
|
+
resolvedAbsolute = isAbsolute(path);
|
|
48
|
+
}
|
|
49
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
50
|
+
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
51
|
+
return `/${resolvedPath}`;
|
|
52
|
+
}
|
|
53
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
54
|
+
};
|
|
55
|
+
function normalizeString(path, allowAboveRoot) {
|
|
56
|
+
let res = "";
|
|
57
|
+
let lastSegmentLength = 0;
|
|
58
|
+
let lastSlash = -1;
|
|
59
|
+
let dots = 0;
|
|
60
|
+
let char = null;
|
|
61
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
62
|
+
if (index < path.length) {
|
|
63
|
+
char = path[index];
|
|
64
|
+
} else if (char === "/") {
|
|
65
|
+
break;
|
|
66
|
+
} else {
|
|
67
|
+
char = "/";
|
|
68
|
+
}
|
|
69
|
+
if (char === "/") {
|
|
70
|
+
if (lastSlash === index - 1 || dots === 1);
|
|
71
|
+
else if (dots === 2) {
|
|
72
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
73
|
+
if (res.length > 2) {
|
|
74
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
75
|
+
if (lastSlashIndex === -1) {
|
|
76
|
+
res = "";
|
|
77
|
+
lastSegmentLength = 0;
|
|
78
|
+
} else {
|
|
79
|
+
res = res.slice(0, lastSlashIndex);
|
|
80
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
81
|
+
}
|
|
82
|
+
lastSlash = index;
|
|
83
|
+
dots = 0;
|
|
84
|
+
continue;
|
|
85
|
+
} else if (res.length > 0) {
|
|
86
|
+
res = "";
|
|
87
|
+
lastSegmentLength = 0;
|
|
88
|
+
lastSlash = index;
|
|
89
|
+
dots = 0;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (allowAboveRoot) {
|
|
94
|
+
res += res.length > 0 ? "/.." : "..";
|
|
95
|
+
lastSegmentLength = 2;
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
if (res.length > 0) {
|
|
99
|
+
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
100
|
+
} else {
|
|
101
|
+
res = path.slice(lastSlash + 1, index);
|
|
102
|
+
}
|
|
103
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
104
|
+
}
|
|
105
|
+
lastSlash = index;
|
|
106
|
+
dots = 0;
|
|
107
|
+
} else if (char === "." && dots !== -1) {
|
|
108
|
+
++dots;
|
|
109
|
+
} else {
|
|
110
|
+
dots = -1;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return res;
|
|
114
|
+
}
|
|
115
|
+
const isAbsolute = function(p) {
|
|
116
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
120
|
+
var intToChar = new Uint8Array(64);
|
|
121
|
+
var charToInt = new Uint8Array(128);
|
|
122
|
+
for (let i = 0; i < chars.length; i++) {
|
|
123
|
+
const c = chars.charCodeAt(i);
|
|
124
|
+
intToChar[i] = c;
|
|
125
|
+
charToInt[c] = i;
|
|
126
|
+
}
|
|
127
|
+
const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
|
|
128
|
+
const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
|
|
129
|
+
function extractLocation(urlLike) {
|
|
130
|
+
// Fail-fast but return locations like "(native)"
|
|
131
|
+
if (!urlLike.includes(":")) {
|
|
132
|
+
return [urlLike];
|
|
133
|
+
}
|
|
134
|
+
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
|
135
|
+
const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
|
|
136
|
+
if (!parts) {
|
|
137
|
+
return [urlLike];
|
|
138
|
+
}
|
|
139
|
+
let url = parts[1];
|
|
140
|
+
if (url.startsWith("async ")) {
|
|
141
|
+
url = url.slice(6);
|
|
142
|
+
}
|
|
143
|
+
if (url.startsWith("http:") || url.startsWith("https:")) {
|
|
144
|
+
const urlObj = new URL(url);
|
|
145
|
+
urlObj.searchParams.delete("import");
|
|
146
|
+
urlObj.searchParams.delete("browserv");
|
|
147
|
+
url = urlObj.pathname + urlObj.hash + urlObj.search;
|
|
148
|
+
}
|
|
149
|
+
if (url.startsWith("/@fs/")) {
|
|
150
|
+
const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
|
|
151
|
+
url = url.slice(isWindows ? 5 : 4);
|
|
152
|
+
}
|
|
153
|
+
return [
|
|
154
|
+
url,
|
|
155
|
+
parts[2] || undefined,
|
|
156
|
+
parts[3] || undefined
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
function parseSingleFFOrSafariStack(raw) {
|
|
160
|
+
let line = raw.trim();
|
|
161
|
+
if (SAFARI_NATIVE_CODE_REGEXP.test(line)) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
if (line.includes(" > eval")) {
|
|
165
|
+
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
|
|
166
|
+
}
|
|
167
|
+
// Early return for lines that don't look like Firefox/Safari stack traces
|
|
168
|
+
// Firefox/Safari stack traces must contain '@' and should have location info after it
|
|
169
|
+
if (!line.includes("@")) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
// Find the correct @ that separates function name from location
|
|
173
|
+
// For cases like '@https://@fs/path' or 'functionName@https://@fs/path'
|
|
174
|
+
// we need to find the first @ that precedes a valid location (containing :)
|
|
175
|
+
let atIndex = -1;
|
|
176
|
+
let locationPart = "";
|
|
177
|
+
let functionName;
|
|
178
|
+
// Try each @ from left to right to find the one that gives us a valid location
|
|
179
|
+
for (let i = 0; i < line.length; i++) {
|
|
180
|
+
if (line[i] === "@") {
|
|
181
|
+
const candidateLocation = line.slice(i + 1);
|
|
182
|
+
// Minimum length 3 for valid location: 1 for filename + 1 for colon + 1 for line number (e.g., "a:1")
|
|
183
|
+
if (candidateLocation.includes(":") && candidateLocation.length >= 3) {
|
|
184
|
+
atIndex = i;
|
|
185
|
+
locationPart = candidateLocation;
|
|
186
|
+
functionName = i > 0 ? line.slice(0, i) : undefined;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Validate we found a valid location with minimum length (filename:line format)
|
|
192
|
+
if (atIndex === -1 || !locationPart.includes(":") || locationPart.length < 3) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
const [url, lineNumber, columnNumber] = extractLocation(locationPart);
|
|
196
|
+
if (!url || !lineNumber || !columnNumber) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
file: url,
|
|
201
|
+
method: functionName || "",
|
|
202
|
+
line: Number.parseInt(lineNumber),
|
|
203
|
+
column: Number.parseInt(columnNumber)
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function parseSingleStack(raw) {
|
|
207
|
+
const line = raw.trim();
|
|
208
|
+
if (!CHROME_IE_STACK_REGEXP.test(line)) {
|
|
209
|
+
return parseSingleFFOrSafariStack(line);
|
|
210
|
+
}
|
|
211
|
+
return parseSingleV8Stack(line);
|
|
212
|
+
}
|
|
213
|
+
// Based on https://github.com/stacktracejs/error-stack-parser
|
|
214
|
+
// Credit to stacktracejs
|
|
215
|
+
function parseSingleV8Stack(raw) {
|
|
216
|
+
let line = raw.trim();
|
|
217
|
+
if (!CHROME_IE_STACK_REGEXP.test(line)) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
if (line.includes("(eval ")) {
|
|
221
|
+
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
|
|
222
|
+
}
|
|
223
|
+
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
|
|
224
|
+
// capture and preserve the parenthesized location "(/foo/my bar.js:12:87)" in
|
|
225
|
+
// case it has spaces in it, as the string is split on \s+ later on
|
|
226
|
+
const location = sanitizedLine.match(/ (\(.+\)$)/);
|
|
227
|
+
// remove the parenthesized location from the line, if it was matched
|
|
228
|
+
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
|
229
|
+
// if a location was matched, pass it to extractLocation() otherwise pass all sanitizedLine
|
|
230
|
+
// because this line doesn't have function name
|
|
231
|
+
const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
|
|
232
|
+
let method = location && sanitizedLine || "";
|
|
233
|
+
let file = url && ["eval", "<anonymous>"].includes(url) ? undefined : url;
|
|
234
|
+
if (!file || !lineNumber || !columnNumber) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
if (method.startsWith("async ")) {
|
|
238
|
+
method = method.slice(6);
|
|
239
|
+
}
|
|
240
|
+
if (file.startsWith("file://")) {
|
|
241
|
+
file = file.slice(7);
|
|
242
|
+
}
|
|
243
|
+
// normalize Windows path (\ -> /)
|
|
244
|
+
file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve(file);
|
|
245
|
+
if (method) {
|
|
246
|
+
method = method.replace(/__vite_ssr_import_\d+__\./g, "").replace(/(Object\.)?__vite_ssr_export_default__\s?/g, "");
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
method,
|
|
250
|
+
file,
|
|
251
|
+
line: Number.parseInt(lineNumber),
|
|
252
|
+
column: Number.parseInt(columnNumber)
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function createCompilerHints(options) {
|
|
257
|
+
const globalThisAccessor = (options === null || options === void 0 ? void 0 : options.globalThisKey) || "__vitest_mocker__";
|
|
258
|
+
function _mocker() {
|
|
259
|
+
// @ts-expect-error injected by the plugin
|
|
260
|
+
return typeof globalThis[globalThisAccessor] !== "undefined" ? globalThis[globalThisAccessor] : new Proxy({}, { get(_, name) {
|
|
261
|
+
throw new Error("Vitest mocker was not initialized in this environment. " + `vi.${String(name)}() is forbidden.`);
|
|
262
|
+
} });
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
hoisted(factory) {
|
|
266
|
+
if (typeof factory !== "function") {
|
|
267
|
+
throw new TypeError(`vi.hoisted() expects a function, but received a ${typeof factory}`);
|
|
268
|
+
}
|
|
269
|
+
return factory();
|
|
270
|
+
},
|
|
271
|
+
mock(path, factory) {
|
|
272
|
+
if (typeof path !== "string") {
|
|
273
|
+
throw new TypeError(`vi.mock() expects a string path, but received a ${typeof path}`);
|
|
274
|
+
}
|
|
275
|
+
const importer = getImporter("mock");
|
|
276
|
+
_mocker().queueMock(path, importer, typeof factory === "function" ? () => factory(() => _mocker().importActual(path, importer)) : factory);
|
|
277
|
+
},
|
|
278
|
+
unmock(path) {
|
|
279
|
+
if (typeof path !== "string") {
|
|
280
|
+
throw new TypeError(`vi.unmock() expects a string path, but received a ${typeof path}`);
|
|
281
|
+
}
|
|
282
|
+
_mocker().queueUnmock(path, getImporter("unmock"));
|
|
283
|
+
},
|
|
284
|
+
doMock(path, factory) {
|
|
285
|
+
if (typeof path !== "string") {
|
|
286
|
+
throw new TypeError(`vi.doMock() expects a string path, but received a ${typeof path}`);
|
|
287
|
+
}
|
|
288
|
+
const importer = getImporter("doMock");
|
|
289
|
+
_mocker().queueMock(path, importer, typeof factory === "function" ? () => factory(() => _mocker().importActual(path, importer)) : factory);
|
|
290
|
+
},
|
|
291
|
+
doUnmock(path) {
|
|
292
|
+
if (typeof path !== "string") {
|
|
293
|
+
throw new TypeError(`vi.doUnmock() expects a string path, but received a ${typeof path}`);
|
|
294
|
+
}
|
|
295
|
+
_mocker().queueUnmock(path, getImporter("doUnmock"));
|
|
296
|
+
},
|
|
297
|
+
async importActual(path) {
|
|
298
|
+
return _mocker().importActual(path, getImporter("importActual"));
|
|
299
|
+
},
|
|
300
|
+
async importMock(path) {
|
|
301
|
+
return _mocker().importMock(path, getImporter("importMock"));
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function getImporter(name) {
|
|
306
|
+
const stackTrace = /* @__PURE__ */ createSimpleStackTrace({ stackTraceLimit: 5 });
|
|
307
|
+
const stackArray = stackTrace.split("\n");
|
|
308
|
+
// if there is no message in a stack trace, use the item - 1
|
|
309
|
+
const importerStackIndex = stackArray.findIndex((stack) => {
|
|
310
|
+
return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`);
|
|
311
|
+
});
|
|
312
|
+
const stack = /* @__PURE__ */ parseSingleStack(stackArray[importerStackIndex + 1]);
|
|
313
|
+
return (stack === null || stack === void 0 ? void 0 : stack.file) || "";
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const hot = import.meta.hot || {
|
|
317
|
+
on: warn,
|
|
318
|
+
off: warn,
|
|
319
|
+
send: warn
|
|
320
|
+
};
|
|
321
|
+
function warn() {
|
|
322
|
+
console.warn("Vitest mocker cannot work if Vite didn't establish WS connection.");
|
|
323
|
+
}
|
|
324
|
+
function rpc(event, data) {
|
|
325
|
+
hot.send(event, data);
|
|
326
|
+
return new Promise((resolve, reject) => {
|
|
327
|
+
const timeout = setTimeout(() => {
|
|
328
|
+
reject(new Error(`Failed to resolve ${event} in time`));
|
|
329
|
+
}, 5e3);
|
|
330
|
+
hot.on(`${event}:result`, function r(data) {
|
|
331
|
+
resolve(data);
|
|
332
|
+
clearTimeout(timeout);
|
|
333
|
+
hot.off(`${event}:result`, r);
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const { now } = Date;
|
|
339
|
+
class ModuleMocker {
|
|
340
|
+
registry = new MockerRegistry();
|
|
341
|
+
queue = new Set();
|
|
342
|
+
mockedIds = new Set();
|
|
343
|
+
constructor(interceptor, rpc, createMockInstance, config) {
|
|
344
|
+
this.interceptor = interceptor;
|
|
345
|
+
this.rpc = rpc;
|
|
346
|
+
this.createMockInstance = createMockInstance;
|
|
347
|
+
this.config = config;
|
|
348
|
+
}
|
|
349
|
+
async prepare() {
|
|
350
|
+
if (!this.queue.size) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
await Promise.all([...this.queue.values()]);
|
|
354
|
+
}
|
|
355
|
+
async resolveFactoryModule(id) {
|
|
356
|
+
const mock = this.registry.get(id);
|
|
357
|
+
if (!mock || mock.type !== "manual") {
|
|
358
|
+
throw new Error(`Mock ${id} wasn't registered. This is probably a Vitest error. Please, open a new issue with reproduction.`);
|
|
359
|
+
}
|
|
360
|
+
const result = await mock.resolve();
|
|
361
|
+
return result;
|
|
362
|
+
}
|
|
363
|
+
getFactoryModule(id) {
|
|
364
|
+
const mock = this.registry.get(id);
|
|
365
|
+
if (!mock || mock.type !== "manual") {
|
|
366
|
+
throw new Error(`Mock ${id} wasn't registered. This is probably a Vitest error. Please, open a new issue with reproduction.`);
|
|
367
|
+
}
|
|
368
|
+
if (!mock.cache) {
|
|
369
|
+
throw new Error(`Mock ${id} wasn't resolved. This is probably a Vitest error. Please, open a new issue with reproduction.`);
|
|
370
|
+
}
|
|
371
|
+
return mock.cache;
|
|
372
|
+
}
|
|
373
|
+
async invalidate() {
|
|
374
|
+
const ids = Array.from(this.mockedIds);
|
|
375
|
+
if (!ids.length) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
await this.rpc.invalidate(ids);
|
|
379
|
+
await this.interceptor.invalidate();
|
|
380
|
+
this.registry.clear();
|
|
381
|
+
}
|
|
382
|
+
async importActual(id, importer) {
|
|
383
|
+
const resolved = await this.rpc.resolveId(id, importer);
|
|
384
|
+
if (resolved == null) {
|
|
385
|
+
throw new Error(`[vitest] Cannot resolve "${id}" imported from "${importer}"`);
|
|
386
|
+
}
|
|
387
|
+
const ext = extname(resolved.id);
|
|
388
|
+
const url = new URL(resolved.url, location.href);
|
|
389
|
+
const query = `_vitest_original&ext${ext}`;
|
|
390
|
+
const actualUrl = `${url.pathname}${url.search ? `${url.search}&${query}` : `?${query}`}${url.hash}`;
|
|
391
|
+
return this.wrapDynamicImport(() => import(
|
|
392
|
+
/* @vite-ignore */
|
|
393
|
+
actualUrl
|
|
394
|
+
)).then((mod) => {
|
|
395
|
+
if (!resolved.optimized || typeof mod.default === "undefined") {
|
|
396
|
+
return mod;
|
|
397
|
+
}
|
|
398
|
+
// vite injects this helper for optimized modules, so we try to follow the same behavior
|
|
399
|
+
const m = mod.default;
|
|
400
|
+
return (m === null || m === void 0 ? void 0 : m.__esModule) ? m : {
|
|
401
|
+
...typeof m === "object" && !Array.isArray(m) || typeof m === "function" ? m : {},
|
|
402
|
+
default: m
|
|
403
|
+
};
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
async importMock(rawId, importer) {
|
|
407
|
+
await this.prepare();
|
|
408
|
+
const { resolvedId, resolvedUrl, redirectUrl } = await this.rpc.resolveMock(rawId, importer, { mock: "auto" });
|
|
409
|
+
const mockUrl = this.resolveMockPath(cleanVersion(resolvedUrl));
|
|
410
|
+
let mock = this.registry.get(mockUrl);
|
|
411
|
+
if (!mock) {
|
|
412
|
+
if (redirectUrl) {
|
|
413
|
+
const resolvedRedirect = new URL(this.resolveMockPath(cleanVersion(redirectUrl)), location.href).toString();
|
|
414
|
+
mock = new RedirectedModule(rawId, resolvedId, mockUrl, resolvedRedirect);
|
|
415
|
+
} else {
|
|
416
|
+
mock = new AutomockedModule(rawId, resolvedId, mockUrl);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (mock.type === "manual") {
|
|
420
|
+
return await mock.resolve();
|
|
421
|
+
}
|
|
422
|
+
if (mock.type === "automock" || mock.type === "autospy") {
|
|
423
|
+
const url = new URL(`/@id/${resolvedId}`, location.href);
|
|
424
|
+
const query = url.search ? `${url.search}&t=${now()}` : `?t=${now()}`;
|
|
425
|
+
const moduleObject = await import(
|
|
426
|
+
/* @vite-ignore */
|
|
427
|
+
`${url.pathname}${query}&mock=${mock.type}${url.hash}`
|
|
428
|
+
);
|
|
429
|
+
return this.mockObject(moduleObject, mock.type);
|
|
430
|
+
}
|
|
431
|
+
return import(
|
|
432
|
+
/* @vite-ignore */
|
|
433
|
+
mock.redirect
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
mockObject(object, moduleType = "automock") {
|
|
437
|
+
return mockObject({
|
|
438
|
+
globalConstructors: {
|
|
439
|
+
Object,
|
|
440
|
+
Function,
|
|
441
|
+
Array,
|
|
442
|
+
Map,
|
|
443
|
+
RegExp
|
|
444
|
+
},
|
|
445
|
+
createMockInstance: this.createMockInstance,
|
|
446
|
+
type: moduleType
|
|
447
|
+
}, object);
|
|
448
|
+
}
|
|
449
|
+
queueMock(rawId, importer, factoryOrOptions) {
|
|
450
|
+
const promise = this.rpc.resolveMock(rawId, importer, { mock: typeof factoryOrOptions === "function" ? "factory" : (factoryOrOptions === null || factoryOrOptions === void 0 ? void 0 : factoryOrOptions.spy) ? "spy" : "auto" }).then(async ({ redirectUrl, resolvedId, resolvedUrl, needsInterop, mockType }) => {
|
|
451
|
+
const mockUrl = this.resolveMockPath(cleanVersion(resolvedUrl));
|
|
452
|
+
this.mockedIds.add(resolvedId);
|
|
453
|
+
const factory = typeof factoryOrOptions === "function" ? async () => {
|
|
454
|
+
const data = await factoryOrOptions();
|
|
455
|
+
// vite wraps all external modules that have "needsInterop" in a function that
|
|
456
|
+
// merges all exports from default into the module object
|
|
457
|
+
return needsInterop ? { default: data } : data;
|
|
458
|
+
} : undefined;
|
|
459
|
+
const mockRedirect = typeof redirectUrl === "string" ? new URL(this.resolveMockPath(cleanVersion(redirectUrl)), location.href).toString() : null;
|
|
460
|
+
let module;
|
|
461
|
+
if (mockType === "manual") {
|
|
462
|
+
module = this.registry.register("manual", rawId, resolvedId, mockUrl, factory);
|
|
463
|
+
} else if (mockType === "autospy") {
|
|
464
|
+
module = this.registry.register("autospy", rawId, resolvedId, mockUrl);
|
|
465
|
+
} else if (mockType === "redirect") {
|
|
466
|
+
module = this.registry.register("redirect", rawId, resolvedId, mockUrl, mockRedirect);
|
|
467
|
+
} else {
|
|
468
|
+
module = this.registry.register("automock", rawId, resolvedId, mockUrl);
|
|
469
|
+
}
|
|
470
|
+
await this.interceptor.register(module);
|
|
471
|
+
}).finally(() => {
|
|
472
|
+
this.queue.delete(promise);
|
|
473
|
+
});
|
|
474
|
+
this.queue.add(promise);
|
|
475
|
+
}
|
|
476
|
+
queueUnmock(id, importer) {
|
|
477
|
+
const promise = this.rpc.resolveId(id, importer).then(async (resolved) => {
|
|
478
|
+
if (!resolved) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const mockUrl = this.resolveMockPath(cleanVersion(resolved.url));
|
|
482
|
+
this.mockedIds.add(resolved.id);
|
|
483
|
+
this.registry.delete(mockUrl);
|
|
484
|
+
await this.interceptor.delete(mockUrl);
|
|
485
|
+
}).finally(() => {
|
|
486
|
+
this.queue.delete(promise);
|
|
487
|
+
});
|
|
488
|
+
this.queue.add(promise);
|
|
489
|
+
}
|
|
490
|
+
// We need to await mock registration before importing the actual module
|
|
491
|
+
// In case there is a mocked module in the import chain
|
|
492
|
+
wrapDynamicImport(moduleFactory) {
|
|
493
|
+
if (typeof moduleFactory === "function") {
|
|
494
|
+
const promise = new Promise((resolve, reject) => {
|
|
495
|
+
this.prepare().finally(() => {
|
|
496
|
+
moduleFactory().then(resolve, reject);
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
return promise;
|
|
500
|
+
}
|
|
501
|
+
return moduleFactory;
|
|
502
|
+
}
|
|
503
|
+
resolveMockPath(path) {
|
|
504
|
+
const config = this.config;
|
|
505
|
+
const fsRoot = join("/@fs/", config.root);
|
|
506
|
+
// URL can be /file/path.js, but path is resolved to /file/path
|
|
507
|
+
if (path.startsWith(config.root)) {
|
|
508
|
+
return path.slice(config.root.length);
|
|
509
|
+
}
|
|
510
|
+
if (path.startsWith(fsRoot)) {
|
|
511
|
+
return path.slice(fsRoot.length);
|
|
512
|
+
}
|
|
513
|
+
return path;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
const versionRegexp = /(\?|&)v=\w{8}/;
|
|
517
|
+
function cleanVersion(url) {
|
|
518
|
+
return url.replace(versionRegexp, "");
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
export { ModuleMocker as M, createCompilerHints as c, hot as h, rpc as r };
|
|
@@ -0,0 +1,174 @@
|
|
|
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 _EXTNAME_RE = /.(\.[^./]+|\.)$/;
|
|
13
|
+
const normalize = function(path) {
|
|
14
|
+
if (path.length === 0) {
|
|
15
|
+
return ".";
|
|
16
|
+
}
|
|
17
|
+
path = normalizeWindowsPath(path);
|
|
18
|
+
const isUNCPath = path.match(_UNC_REGEX);
|
|
19
|
+
const isPathAbsolute = isAbsolute(path);
|
|
20
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
21
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
22
|
+
if (path.length === 0) {
|
|
23
|
+
if (isPathAbsolute) {
|
|
24
|
+
return "/";
|
|
25
|
+
}
|
|
26
|
+
return trailingSeparator ? "./" : ".";
|
|
27
|
+
}
|
|
28
|
+
if (trailingSeparator) {
|
|
29
|
+
path += "/";
|
|
30
|
+
}
|
|
31
|
+
if (_DRIVE_LETTER_RE.test(path)) {
|
|
32
|
+
path += "/";
|
|
33
|
+
}
|
|
34
|
+
if (isUNCPath) {
|
|
35
|
+
if (!isPathAbsolute) {
|
|
36
|
+
return `//./${path}`;
|
|
37
|
+
}
|
|
38
|
+
return `//${path}`;
|
|
39
|
+
}
|
|
40
|
+
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
41
|
+
};
|
|
42
|
+
const join = function(...segments) {
|
|
43
|
+
let path = "";
|
|
44
|
+
for (const seg of segments) {
|
|
45
|
+
if (!seg) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (path.length > 0) {
|
|
49
|
+
const pathTrailing = path[path.length - 1] === "/";
|
|
50
|
+
const segLeading = seg[0] === "/";
|
|
51
|
+
const both = pathTrailing && segLeading;
|
|
52
|
+
if (both) {
|
|
53
|
+
path += seg.slice(1);
|
|
54
|
+
} else {
|
|
55
|
+
path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
path += seg;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return normalize(path);
|
|
62
|
+
};
|
|
63
|
+
function cwd() {
|
|
64
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
65
|
+
return process.cwd().replace(/\\/g, "/");
|
|
66
|
+
}
|
|
67
|
+
return "/";
|
|
68
|
+
}
|
|
69
|
+
const resolve = function(...arguments_) {
|
|
70
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
71
|
+
let resolvedPath = "";
|
|
72
|
+
let resolvedAbsolute = false;
|
|
73
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
74
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
|
75
|
+
if (!path || path.length === 0) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
79
|
+
resolvedAbsolute = isAbsolute(path);
|
|
80
|
+
}
|
|
81
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
82
|
+
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
83
|
+
return `/${resolvedPath}`;
|
|
84
|
+
}
|
|
85
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
86
|
+
};
|
|
87
|
+
function normalizeString(path, allowAboveRoot) {
|
|
88
|
+
let res = "";
|
|
89
|
+
let lastSegmentLength = 0;
|
|
90
|
+
let lastSlash = -1;
|
|
91
|
+
let dots = 0;
|
|
92
|
+
let char = null;
|
|
93
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
94
|
+
if (index < path.length) {
|
|
95
|
+
char = path[index];
|
|
96
|
+
} else if (char === "/") {
|
|
97
|
+
break;
|
|
98
|
+
} else {
|
|
99
|
+
char = "/";
|
|
100
|
+
}
|
|
101
|
+
if (char === "/") {
|
|
102
|
+
if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
|
|
103
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
104
|
+
if (res.length > 2) {
|
|
105
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
106
|
+
if (lastSlashIndex === -1) {
|
|
107
|
+
res = "";
|
|
108
|
+
lastSegmentLength = 0;
|
|
109
|
+
} else {
|
|
110
|
+
res = res.slice(0, lastSlashIndex);
|
|
111
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
112
|
+
}
|
|
113
|
+
lastSlash = index;
|
|
114
|
+
dots = 0;
|
|
115
|
+
continue;
|
|
116
|
+
} else if (res.length > 0) {
|
|
117
|
+
res = "";
|
|
118
|
+
lastSegmentLength = 0;
|
|
119
|
+
lastSlash = index;
|
|
120
|
+
dots = 0;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (allowAboveRoot) {
|
|
125
|
+
res += res.length > 0 ? "/.." : "..";
|
|
126
|
+
lastSegmentLength = 2;
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
if (res.length > 0) {
|
|
130
|
+
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
131
|
+
} else {
|
|
132
|
+
res = path.slice(lastSlash + 1, index);
|
|
133
|
+
}
|
|
134
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
135
|
+
}
|
|
136
|
+
lastSlash = index;
|
|
137
|
+
dots = 0;
|
|
138
|
+
} else if (char === "." && dots !== -1) {
|
|
139
|
+
++dots;
|
|
140
|
+
} else {
|
|
141
|
+
dots = -1;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return res;
|
|
145
|
+
}
|
|
146
|
+
const isAbsolute = function(p) {
|
|
147
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
148
|
+
};
|
|
149
|
+
const extname = function(p) {
|
|
150
|
+
if (p === "..") return "";
|
|
151
|
+
const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
|
|
152
|
+
return match && match[1] || "";
|
|
153
|
+
};
|
|
154
|
+
const dirname = function(p) {
|
|
155
|
+
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
156
|
+
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
|
|
157
|
+
segments[0] += "/";
|
|
158
|
+
}
|
|
159
|
+
return segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
160
|
+
};
|
|
161
|
+
const basename = function(p, extension) {
|
|
162
|
+
const segments = normalizeWindowsPath(p).split("/");
|
|
163
|
+
let lastSegment = "";
|
|
164
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
165
|
+
const val = segments[i];
|
|
166
|
+
if (val) {
|
|
167
|
+
lastSegment = val;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export { basename as b, dirname as d, extname as e, isAbsolute as i, join as j, resolve as r };
|