vitest 0.0.33 → 0.0.37
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/README.gh.md +67 -11
- package/dist/chunk-4OVO6RD6.js +1 -0
- package/dist/chunk-CUG6SVUZ.js +1 -0
- package/dist/chunk-F27UALKJ.js +1 -0
- package/dist/chunk-XPSQDVUG.js +1 -0
- package/dist/global-CKRMAXWF.js +1 -0
- package/dist/happy-dom-RNJZR3YC.js +1 -0
- package/dist/index.d.ts +73 -6
- package/dist/index.js +1 -4
- package/dist/jsdom-6QAZGE6T.js +1 -0
- package/dist/node/cli.d.ts +5 -1
- package/dist/node/cli.js +7 -86
- package/dist/node/entry.d.ts +1 -1
- package/dist/node/entry.js +19 -12
- package/dist/types-d3253f2d.d.ts +213 -0
- package/package.json +9 -4
- package/dist/constants.d.ts +0 -3
- package/dist/constants.js +0 -23
- package/dist/context.d.ts +0 -2
- package/dist/context.js +0 -4
- package/dist/integrations/chai/index.d.ts +0 -3
- package/dist/integrations/chai/index.js +0 -3
- package/dist/integrations/chai/jest-expect.d.ts +0 -2
- package/dist/integrations/chai/jest-expect.js +0 -67
- package/dist/integrations/chai/setup.d.ts +0 -2
- package/dist/integrations/chai/setup.js +0 -11
- package/dist/integrations/chai/snapshot/index.d.ts +0 -8
- package/dist/integrations/chai/snapshot/index.js +0 -27
- package/dist/integrations/chai/snapshot/manager.d.ts +0 -30
- package/dist/integrations/chai/snapshot/manager.js +0 -77
- package/dist/integrations/chai/snapshot/utils/jest-config-helper.d.ts +0 -3
- package/dist/integrations/chai/snapshot/utils/jest-config-helper.js +0 -39
- package/dist/integrations/chai/snapshot/utils/jest-reporters-lite.d.ts +0 -2
- package/dist/integrations/chai/snapshot/utils/jest-reporters-lite.js +0 -71
- package/dist/integrations/chai/snapshot/utils/jest-test-result-helper.d.ts +0 -6
- package/dist/integrations/chai/snapshot/utils/jest-test-result-helper.js +0 -66
- package/dist/integrations/chai/snapshot/utils/types.d.ts +0 -29
- package/dist/integrations/chai/snapshot/utils/types.js +0 -1
- package/dist/integrations/chai/types.d.ts +0 -3
- package/dist/integrations/chai/types.js +0 -1
- package/dist/integrations/global.d.ts +0 -1
- package/dist/integrations/global.js +0 -8
- package/dist/integrations/jsdom/index.d.ts +0 -5
- package/dist/integrations/jsdom/index.js +0 -21
- package/dist/integrations/jsdom/keys.d.ts +0 -1
- package/dist/integrations/jsdom/keys.js +0 -220
- package/dist/integrations/sinon.d.ts +0 -3
- package/dist/integrations/sinon.js +0 -5
- package/dist/node/node.d.ts +0 -23
- package/dist/node/node.js +0 -159
- package/dist/reporters/default.d.ts +0 -24
- package/dist/reporters/default.js +0 -149
- package/dist/reporters/error.d.ts +0 -9
- package/dist/reporters/error.js +0 -182
- package/dist/run/index.d.ts +0 -8
- package/dist/run/index.js +0 -248
- package/dist/suite.d.ts +0 -26
- package/dist/suite.js +0 -91
- package/dist/types.d.ts +0 -138
- package/dist/types.js +0 -1
- package/dist/utils/hook.d.ts +0 -5
- package/dist/utils/hook.js +0 -14
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
import Test from '@jest/test-result';
|
|
9
|
-
const { makeEmptyAggregatedTestResult, } = Test;
|
|
10
|
-
export const makeEmptySnapshotSummary = (options) => {
|
|
11
|
-
const summary = makeEmptyAggregatedTestResult().snapshot;
|
|
12
|
-
summary.didUpdate = options.updateSnapshot === 'all';
|
|
13
|
-
return summary;
|
|
14
|
-
};
|
|
15
|
-
export const packSnapshotState = (snapshotState) => {
|
|
16
|
-
const snapshot = {
|
|
17
|
-
added: 0,
|
|
18
|
-
fileDeleted: false,
|
|
19
|
-
matched: 0,
|
|
20
|
-
unchecked: 0,
|
|
21
|
-
uncheckedKeys: [],
|
|
22
|
-
unmatched: 0,
|
|
23
|
-
updated: 0,
|
|
24
|
-
};
|
|
25
|
-
const uncheckedCount = snapshotState.getUncheckedCount();
|
|
26
|
-
const uncheckedKeys = snapshotState.getUncheckedKeys();
|
|
27
|
-
if (uncheckedCount)
|
|
28
|
-
snapshotState.removeUncheckedKeys();
|
|
29
|
-
const status = snapshotState.save();
|
|
30
|
-
snapshot.fileDeleted = status.deleted;
|
|
31
|
-
snapshot.added = snapshotState.added;
|
|
32
|
-
snapshot.matched = snapshotState.matched;
|
|
33
|
-
snapshot.unmatched = snapshotState.unmatched;
|
|
34
|
-
snapshot.updated = snapshotState.updated;
|
|
35
|
-
snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
|
|
36
|
-
// Copy the array to prevent memory leaks
|
|
37
|
-
snapshot.uncheckedKeys = Array.from(uncheckedKeys);
|
|
38
|
-
return snapshot;
|
|
39
|
-
};
|
|
40
|
-
export const addSnapshotResult = (snapshotSummary, snapshotResult, testFilePath) => {
|
|
41
|
-
// Snapshot data
|
|
42
|
-
if (snapshotResult.added)
|
|
43
|
-
snapshotSummary.filesAdded++;
|
|
44
|
-
if (snapshotResult.fileDeleted)
|
|
45
|
-
snapshotSummary.filesRemoved++;
|
|
46
|
-
if (snapshotResult.unmatched)
|
|
47
|
-
snapshotSummary.filesUnmatched++;
|
|
48
|
-
if (snapshotResult.updated)
|
|
49
|
-
snapshotSummary.filesUpdated++;
|
|
50
|
-
snapshotSummary.added += snapshotResult.added;
|
|
51
|
-
snapshotSummary.matched += snapshotResult.matched;
|
|
52
|
-
snapshotSummary.unchecked += snapshotResult.unchecked;
|
|
53
|
-
if (snapshotResult.uncheckedKeys && snapshotResult.uncheckedKeys.length > 0) {
|
|
54
|
-
snapshotSummary.uncheckedKeysByFile.push({
|
|
55
|
-
filePath: testFilePath,
|
|
56
|
-
keys: snapshotResult.uncheckedKeys,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
snapshotSummary.unmatched += snapshotResult.unmatched;
|
|
60
|
-
snapshotSummary.updated += snapshotResult.updated;
|
|
61
|
-
snapshotSummary.total
|
|
62
|
-
+= snapshotResult.added
|
|
63
|
-
+ snapshotResult.matched
|
|
64
|
-
+ snapshotResult.unmatched
|
|
65
|
-
+ snapshotResult.updated;
|
|
66
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export interface SnapshotResult {
|
|
2
|
-
added: number;
|
|
3
|
-
fileDeleted: boolean;
|
|
4
|
-
matched: number;
|
|
5
|
-
unchecked: number;
|
|
6
|
-
uncheckedKeys: Array<string>;
|
|
7
|
-
unmatched: number;
|
|
8
|
-
updated: number;
|
|
9
|
-
}
|
|
10
|
-
export interface UncheckedSnapshot {
|
|
11
|
-
filePath: string;
|
|
12
|
-
keys: Array<string>;
|
|
13
|
-
}
|
|
14
|
-
export interface SnapshotSummary {
|
|
15
|
-
added: number;
|
|
16
|
-
didUpdate: boolean;
|
|
17
|
-
failure: boolean;
|
|
18
|
-
filesAdded: number;
|
|
19
|
-
filesRemoved: number;
|
|
20
|
-
filesRemovedList: Array<string>;
|
|
21
|
-
filesUnmatched: number;
|
|
22
|
-
filesUpdated: number;
|
|
23
|
-
matched: number;
|
|
24
|
-
total: number;
|
|
25
|
-
unchecked: number;
|
|
26
|
-
uncheckedKeysByFile: Array<UncheckedSnapshot>;
|
|
27
|
-
unmatched: number;
|
|
28
|
-
updated: number;
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function registerApiGlobally(): void;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { JSDOM } from 'jsdom';
|
|
2
|
-
import { KEYS } from './keys';
|
|
3
|
-
export function setupJSDOM(global) {
|
|
4
|
-
const dom = new JSDOM('<!DOCTYPE html>', {
|
|
5
|
-
pretendToBeVisual: true,
|
|
6
|
-
runScripts: 'dangerously',
|
|
7
|
-
// TODO: options
|
|
8
|
-
url: 'http://localhost:3000',
|
|
9
|
-
});
|
|
10
|
-
const keys = KEYS.concat(Object.getOwnPropertyNames(dom.window))
|
|
11
|
-
.filter(k => !k.startsWith('_'))
|
|
12
|
-
.filter(k => !(k in global));
|
|
13
|
-
for (const key of keys)
|
|
14
|
-
global[key] = dom.window[key];
|
|
15
|
-
return {
|
|
16
|
-
dom,
|
|
17
|
-
restore() {
|
|
18
|
-
keys.forEach(key => delete global[key]);
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const KEYS: string[];
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
// SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
|
|
2
|
-
const LIVING_KEYS = [
|
|
3
|
-
'DOMException',
|
|
4
|
-
'URL',
|
|
5
|
-
'URLSearchParams',
|
|
6
|
-
'EventTarget',
|
|
7
|
-
'NamedNodeMap',
|
|
8
|
-
'Node',
|
|
9
|
-
'Attr',
|
|
10
|
-
'Element',
|
|
11
|
-
'DocumentFragment',
|
|
12
|
-
'DOMImplementation',
|
|
13
|
-
'Document',
|
|
14
|
-
'XMLDocument',
|
|
15
|
-
'CharacterData',
|
|
16
|
-
'Text',
|
|
17
|
-
'CDATASection',
|
|
18
|
-
'ProcessingInstruction',
|
|
19
|
-
'Comment',
|
|
20
|
-
'DocumentType',
|
|
21
|
-
'NodeList',
|
|
22
|
-
'HTMLCollection',
|
|
23
|
-
'HTMLOptionsCollection',
|
|
24
|
-
'DOMStringMap',
|
|
25
|
-
'DOMTokenList',
|
|
26
|
-
'StyleSheetList',
|
|
27
|
-
'HTMLElement',
|
|
28
|
-
'HTMLHeadElement',
|
|
29
|
-
'HTMLTitleElement',
|
|
30
|
-
'HTMLBaseElement',
|
|
31
|
-
'HTMLLinkElement',
|
|
32
|
-
'HTMLMetaElement',
|
|
33
|
-
'HTMLStyleElement',
|
|
34
|
-
'HTMLBodyElement',
|
|
35
|
-
'HTMLHeadingElement',
|
|
36
|
-
'HTMLParagraphElement',
|
|
37
|
-
'HTMLHRElement',
|
|
38
|
-
'HTMLPreElement',
|
|
39
|
-
'HTMLUListElement',
|
|
40
|
-
'HTMLOListElement',
|
|
41
|
-
'HTMLLIElement',
|
|
42
|
-
'HTMLMenuElement',
|
|
43
|
-
'HTMLDListElement',
|
|
44
|
-
'HTMLDivElement',
|
|
45
|
-
'HTMLAnchorElement',
|
|
46
|
-
'HTMLAreaElement',
|
|
47
|
-
'HTMLBRElement',
|
|
48
|
-
'HTMLButtonElement',
|
|
49
|
-
'HTMLCanvasElement',
|
|
50
|
-
'HTMLDataElement',
|
|
51
|
-
'HTMLDataListElement',
|
|
52
|
-
'HTMLDetailsElement',
|
|
53
|
-
'HTMLDialogElement',
|
|
54
|
-
'HTMLDirectoryElement',
|
|
55
|
-
'HTMLFieldSetElement',
|
|
56
|
-
'HTMLFontElement',
|
|
57
|
-
'HTMLFormElement',
|
|
58
|
-
'HTMLHtmlElement',
|
|
59
|
-
'HTMLImageElement',
|
|
60
|
-
'HTMLInputElement',
|
|
61
|
-
'HTMLLabelElement',
|
|
62
|
-
'HTMLLegendElement',
|
|
63
|
-
'HTMLMapElement',
|
|
64
|
-
'HTMLMarqueeElement',
|
|
65
|
-
'HTMLMediaElement',
|
|
66
|
-
'HTMLMeterElement',
|
|
67
|
-
'HTMLModElement',
|
|
68
|
-
'HTMLOptGroupElement',
|
|
69
|
-
'HTMLOptionElement',
|
|
70
|
-
'HTMLOutputElement',
|
|
71
|
-
'HTMLPictureElement',
|
|
72
|
-
'HTMLProgressElement',
|
|
73
|
-
'HTMLQuoteElement',
|
|
74
|
-
'HTMLScriptElement',
|
|
75
|
-
'HTMLSelectElement',
|
|
76
|
-
'HTMLSlotElement',
|
|
77
|
-
'HTMLSourceElement',
|
|
78
|
-
'HTMLSpanElement',
|
|
79
|
-
'HTMLTableCaptionElement',
|
|
80
|
-
'HTMLTableCellElement',
|
|
81
|
-
'HTMLTableColElement',
|
|
82
|
-
'HTMLTableElement',
|
|
83
|
-
'HTMLTimeElement',
|
|
84
|
-
'HTMLTableRowElement',
|
|
85
|
-
'HTMLTableSectionElement',
|
|
86
|
-
'HTMLTemplateElement',
|
|
87
|
-
'HTMLTextAreaElement',
|
|
88
|
-
'HTMLUnknownElement',
|
|
89
|
-
'HTMLFrameElement',
|
|
90
|
-
'HTMLFrameSetElement',
|
|
91
|
-
'HTMLIFrameElement',
|
|
92
|
-
'HTMLEmbedElement',
|
|
93
|
-
'HTMLObjectElement',
|
|
94
|
-
'HTMLParamElement',
|
|
95
|
-
'HTMLVideoElement',
|
|
96
|
-
'HTMLAudioElement',
|
|
97
|
-
'HTMLTrackElement',
|
|
98
|
-
'SVGElement',
|
|
99
|
-
'SVGGraphicsElement',
|
|
100
|
-
'SVGSVGElement',
|
|
101
|
-
'SVGTitleElement',
|
|
102
|
-
'SVGAnimatedString',
|
|
103
|
-
'SVGNumber',
|
|
104
|
-
'SVGStringList',
|
|
105
|
-
'Event',
|
|
106
|
-
'CloseEvent',
|
|
107
|
-
'CustomEvent',
|
|
108
|
-
'MessageEvent',
|
|
109
|
-
'ErrorEvent',
|
|
110
|
-
'HashChangeEvent',
|
|
111
|
-
'PopStateEvent',
|
|
112
|
-
'StorageEvent',
|
|
113
|
-
'ProgressEvent',
|
|
114
|
-
'PageTransitionEvent',
|
|
115
|
-
'UIEvent',
|
|
116
|
-
'FocusEvent',
|
|
117
|
-
'InputEvent',
|
|
118
|
-
'MouseEvent',
|
|
119
|
-
'KeyboardEvent',
|
|
120
|
-
'TouchEvent',
|
|
121
|
-
'CompositionEvent',
|
|
122
|
-
'WheelEvent',
|
|
123
|
-
'BarProp',
|
|
124
|
-
'External',
|
|
125
|
-
'Location',
|
|
126
|
-
'History',
|
|
127
|
-
'Screen',
|
|
128
|
-
'Performance',
|
|
129
|
-
'Navigator',
|
|
130
|
-
'PluginArray',
|
|
131
|
-
'MimeTypeArray',
|
|
132
|
-
'Plugin',
|
|
133
|
-
'MimeType',
|
|
134
|
-
'FileReader',
|
|
135
|
-
'Blob',
|
|
136
|
-
'File',
|
|
137
|
-
'FileList',
|
|
138
|
-
'ValidityState',
|
|
139
|
-
'DOMParser',
|
|
140
|
-
'XMLSerializer',
|
|
141
|
-
'FormData',
|
|
142
|
-
'XMLHttpRequestEventTarget',
|
|
143
|
-
'XMLHttpRequestUpload',
|
|
144
|
-
'XMLHttpRequest',
|
|
145
|
-
'WebSocket',
|
|
146
|
-
'NodeFilter',
|
|
147
|
-
'NodeIterator',
|
|
148
|
-
'TreeWalker',
|
|
149
|
-
'AbstractRange',
|
|
150
|
-
'Range',
|
|
151
|
-
'StaticRange',
|
|
152
|
-
'Selection',
|
|
153
|
-
'Storage',
|
|
154
|
-
'CustomElementRegistry',
|
|
155
|
-
'ShadowRoot',
|
|
156
|
-
'MutationObserver',
|
|
157
|
-
'MutationRecord',
|
|
158
|
-
'Headers',
|
|
159
|
-
'AbortController',
|
|
160
|
-
'AbortSignal',
|
|
161
|
-
];
|
|
162
|
-
const OTHER_KEYS = [
|
|
163
|
-
'addEventListener',
|
|
164
|
-
'alert',
|
|
165
|
-
'atob',
|
|
166
|
-
'blur',
|
|
167
|
-
'btoa',
|
|
168
|
-
/* 'clearInterval', */
|
|
169
|
-
/* 'clearTimeout', */
|
|
170
|
-
'close',
|
|
171
|
-
'confirm',
|
|
172
|
-
/* 'console', */
|
|
173
|
-
'createPopup',
|
|
174
|
-
'dispatchEvent',
|
|
175
|
-
'document',
|
|
176
|
-
'focus',
|
|
177
|
-
'frames',
|
|
178
|
-
'getComputedStyle',
|
|
179
|
-
'history',
|
|
180
|
-
'innerHeight',
|
|
181
|
-
'innerWidth',
|
|
182
|
-
'length',
|
|
183
|
-
'location',
|
|
184
|
-
'moveBy',
|
|
185
|
-
'moveTo',
|
|
186
|
-
'name',
|
|
187
|
-
'navigator',
|
|
188
|
-
'open',
|
|
189
|
-
'outerHeight',
|
|
190
|
-
'outerWidth',
|
|
191
|
-
'pageXOffset',
|
|
192
|
-
'pageYOffset',
|
|
193
|
-
'parent',
|
|
194
|
-
'postMessage',
|
|
195
|
-
'print',
|
|
196
|
-
'prompt',
|
|
197
|
-
'removeEventListener',
|
|
198
|
-
'resizeBy',
|
|
199
|
-
'resizeTo',
|
|
200
|
-
'screen',
|
|
201
|
-
'screenLeft',
|
|
202
|
-
'screenTop',
|
|
203
|
-
'screenX',
|
|
204
|
-
'screenY',
|
|
205
|
-
'scroll',
|
|
206
|
-
'scrollBy',
|
|
207
|
-
'scrollLeft',
|
|
208
|
-
'scrollTo',
|
|
209
|
-
'scrollTop',
|
|
210
|
-
'scrollX',
|
|
211
|
-
'scrollY',
|
|
212
|
-
'self',
|
|
213
|
-
/* 'setInterval', */
|
|
214
|
-
/* 'setTimeout', */
|
|
215
|
-
'stop',
|
|
216
|
-
/* 'toString', */
|
|
217
|
-
'top',
|
|
218
|
-
'window',
|
|
219
|
-
];
|
|
220
|
-
export const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
|
package/dist/node/node.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { InlineConfig, ViteDevServer, TransformResult } from 'vite';
|
|
2
|
-
declare global {
|
|
3
|
-
namespace NodeJS {
|
|
4
|
-
interface Process {
|
|
5
|
-
__vite_node__: {
|
|
6
|
-
server: ViteDevServer;
|
|
7
|
-
watch?: boolean;
|
|
8
|
-
moduleCache: Map<string, Promise<any>>;
|
|
9
|
-
modulesTransformResult: Map<string, TransformResult>;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export interface ViteNodeOptions {
|
|
15
|
-
silent?: boolean;
|
|
16
|
-
root: string;
|
|
17
|
-
files: string[];
|
|
18
|
-
_?: string[];
|
|
19
|
-
shouldExternalize?: (file: string, server: ViteDevServer) => boolean;
|
|
20
|
-
config?: string;
|
|
21
|
-
defaultConfig?: InlineConfig;
|
|
22
|
-
}
|
|
23
|
-
export declare function run(argv: ViteNodeOptions): Promise<void>;
|
package/dist/node/node.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { builtinModules, createRequire } from 'module';
|
|
2
|
-
import { pathToFileURL } from 'url';
|
|
3
|
-
import { dirname, resolve, relative } from 'path';
|
|
4
|
-
import vm from 'vm';
|
|
5
|
-
import { createServer, mergeConfig } from 'vite';
|
|
6
|
-
import c from 'picocolors';
|
|
7
|
-
const { red, dim, yellow } = c;
|
|
8
|
-
const moduleCache = new Map();
|
|
9
|
-
const modulesTransformResult = new Map();
|
|
10
|
-
export async function run(argv) {
|
|
11
|
-
process.exitCode = 0;
|
|
12
|
-
const root = argv.root || process.cwd();
|
|
13
|
-
process.chdir(root);
|
|
14
|
-
const files = argv.files || argv._;
|
|
15
|
-
argv.shouldExternalize = argv.shouldExternalize || (id => id.includes('/node_modules/'));
|
|
16
|
-
const server = await createServer(mergeConfig(argv.defaultConfig || {}, {
|
|
17
|
-
logLevel: 'error',
|
|
18
|
-
clearScreen: false,
|
|
19
|
-
configFile: argv.config,
|
|
20
|
-
root,
|
|
21
|
-
resolve: {},
|
|
22
|
-
}));
|
|
23
|
-
await server.pluginContainer.buildStart({});
|
|
24
|
-
process.__vite_node__ = {
|
|
25
|
-
server,
|
|
26
|
-
moduleCache,
|
|
27
|
-
modulesTransformResult,
|
|
28
|
-
};
|
|
29
|
-
try {
|
|
30
|
-
await execute(files, server, argv);
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
process.exitCode = 1;
|
|
34
|
-
throw e;
|
|
35
|
-
}
|
|
36
|
-
finally {
|
|
37
|
-
if (!process.__vite_node__.watch)
|
|
38
|
-
await server.close();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function normalizeId(id) {
|
|
42
|
-
// Virtual modules start with `\0`
|
|
43
|
-
if (id && id.startsWith('/@id/__x00__'))
|
|
44
|
-
id = `\0${id.slice('/@id/__x00__'.length)}`;
|
|
45
|
-
if (id && id.startsWith('/@id/'))
|
|
46
|
-
id = id.slice('/@id/'.length);
|
|
47
|
-
if (id.startsWith('__vite-browser-external:'))
|
|
48
|
-
id = id.slice('__vite-browser-external:'.length);
|
|
49
|
-
return id;
|
|
50
|
-
}
|
|
51
|
-
function toFilePath(id, server) {
|
|
52
|
-
let absolute = id.startsWith('/@fs/')
|
|
53
|
-
? id.slice(4)
|
|
54
|
-
: id.startsWith(dirname(server.config.root))
|
|
55
|
-
? id
|
|
56
|
-
: id.startsWith('/')
|
|
57
|
-
? slash(resolve(server.config.root, id.slice(1)))
|
|
58
|
-
: id;
|
|
59
|
-
if (absolute.startsWith('//'))
|
|
60
|
-
absolute = absolute.slice(1);
|
|
61
|
-
if (!absolute.startsWith('/'))
|
|
62
|
-
absolute = `/${absolute}`;
|
|
63
|
-
return absolute;
|
|
64
|
-
}
|
|
65
|
-
const stubRequests = {
|
|
66
|
-
'/@vite/client': {
|
|
67
|
-
injectQuery: (id) => id,
|
|
68
|
-
createHotContext() {
|
|
69
|
-
return {
|
|
70
|
-
accept: () => { },
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
async function transform(server, id) {
|
|
76
|
-
if (id.match(/\.(?:[cm]?[jt]sx?|json)$/)) {
|
|
77
|
-
return await server.transformRequest(id, { ssr: true });
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
// for components like Vue, we want to use the client side
|
|
81
|
-
// plugins but then covert the code to be consumed by the server
|
|
82
|
-
const result = await server.transformRequest(id);
|
|
83
|
-
if (!result)
|
|
84
|
-
return undefined;
|
|
85
|
-
return await server.ssrTransform(result.code, result.map, id);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
async function execute(files, server, options) {
|
|
89
|
-
const result = [];
|
|
90
|
-
for (const file of files)
|
|
91
|
-
result.push(await cachedRequest(`/@fs/${slash(resolve(file))}`, []));
|
|
92
|
-
return result;
|
|
93
|
-
async function directRequest(id, fsPath, callstack) {
|
|
94
|
-
callstack = [...callstack, id];
|
|
95
|
-
const request = async (dep) => {
|
|
96
|
-
if (callstack.includes(dep)) {
|
|
97
|
-
throw new Error(`${red('Circular dependency detected')}\nStack:\n${[...callstack, dep].reverse().map((i) => {
|
|
98
|
-
const path = relative(server.config.root, toFilePath(normalizeId(i), server));
|
|
99
|
-
return dim(' -> ') + (i === dep ? yellow(path) : path);
|
|
100
|
-
}).join('\n')}\n`);
|
|
101
|
-
}
|
|
102
|
-
return cachedRequest(dep, callstack);
|
|
103
|
-
};
|
|
104
|
-
if (id in stubRequests)
|
|
105
|
-
return stubRequests[id];
|
|
106
|
-
const result = await transform(server, id);
|
|
107
|
-
if (!result)
|
|
108
|
-
throw new Error(`failed to load ${id}`);
|
|
109
|
-
modulesTransformResult.set(id, result);
|
|
110
|
-
const url = pathToFileURL(fsPath);
|
|
111
|
-
const exports = {};
|
|
112
|
-
const context = {
|
|
113
|
-
require: createRequire(url),
|
|
114
|
-
__filename: fsPath,
|
|
115
|
-
__dirname: dirname(fsPath),
|
|
116
|
-
__vite_ssr_import__: request,
|
|
117
|
-
__vite_ssr_dynamic_import__: request,
|
|
118
|
-
__vite_ssr_exports__: exports,
|
|
119
|
-
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
120
|
-
__vite_ssr_import_meta__: { url },
|
|
121
|
-
};
|
|
122
|
-
const fn = vm.runInThisContext(`async (${Object.keys(context).join(',')}) => { ${result.code} }`, {
|
|
123
|
-
filename: fsPath,
|
|
124
|
-
lineOffset: 0,
|
|
125
|
-
});
|
|
126
|
-
await fn(...Object.values(context));
|
|
127
|
-
return exports;
|
|
128
|
-
}
|
|
129
|
-
async function cachedRequest(rawId, callstack) {
|
|
130
|
-
const id = normalizeId(rawId);
|
|
131
|
-
if (builtinModules.includes(id))
|
|
132
|
-
return import(id);
|
|
133
|
-
const fsPath = toFilePath(id, server);
|
|
134
|
-
if (options.shouldExternalize(fsPath, server))
|
|
135
|
-
return import(fsPath);
|
|
136
|
-
if (moduleCache.has(fsPath))
|
|
137
|
-
return moduleCache.get(fsPath);
|
|
138
|
-
moduleCache.set(fsPath, directRequest(id, fsPath, callstack));
|
|
139
|
-
return await moduleCache.get(fsPath);
|
|
140
|
-
}
|
|
141
|
-
function exportAll(exports, sourceModule) {
|
|
142
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
143
|
-
for (const key in sourceModule) {
|
|
144
|
-
if (key !== 'default') {
|
|
145
|
-
try {
|
|
146
|
-
Object.defineProperty(exports, key, {
|
|
147
|
-
enumerable: true,
|
|
148
|
-
configurable: true,
|
|
149
|
-
get() { return sourceModule[key]; },
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
catch (_err) { }
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
function slash(path) {
|
|
158
|
-
return path.replace(/\\/g, '/');
|
|
159
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import Listr from 'listr';
|
|
2
|
-
import { File, Reporter, RunnerContext, Task, ResolvedConfig } from '../types';
|
|
3
|
-
interface TaskPromise {
|
|
4
|
-
promise: Promise<void>;
|
|
5
|
-
resolve: () => void;
|
|
6
|
-
reject: (e: unknown) => void;
|
|
7
|
-
}
|
|
8
|
-
export declare class DefaultReporter implements Reporter {
|
|
9
|
-
start: number;
|
|
10
|
-
end: number;
|
|
11
|
-
listr: Listr | null;
|
|
12
|
-
listrPromise: Promise<void> | null;
|
|
13
|
-
taskMap: Map<Task, TaskPromise>;
|
|
14
|
-
cwd: string;
|
|
15
|
-
relative(path: string): string;
|
|
16
|
-
onStart(config: ResolvedConfig): void;
|
|
17
|
-
onCollected(files: File[]): void;
|
|
18
|
-
onTaskEnd(task: Task): void;
|
|
19
|
-
onFinished(ctx: RunnerContext, files?: File[]): Promise<void>;
|
|
20
|
-
onWatcherStart(ctx: RunnerContext): Promise<void>;
|
|
21
|
-
onWatcherRerun(files: string[], trigger: string): Promise<void>;
|
|
22
|
-
onSnapshotUpdate(): void;
|
|
23
|
-
}
|
|
24
|
-
export {};
|