vite-node 3.2.0-beta.2 → 3.2.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/dist/chunk-hmr.cjs +29 -12
- package/dist/chunk-hmr.mjs +29 -12
- package/dist/cli.cjs +5 -2
- package/dist/cli.d.ts +1 -1
- package/dist/cli.mjs +7 -4
- package/dist/client.cjs +84 -8
- package/dist/client.d.ts +1 -1
- package/dist/client.mjs +84 -8
- package/dist/hmr.d.ts +4 -1
- package/dist/{index.d-CWZbpOcv.d.ts → index.d-DGmxD2U7.d.ts} +48 -8
- package/dist/index.d.ts +1 -1
- package/dist/server.cjs +36 -15
- package/dist/server.d.ts +1 -1
- package/dist/server.mjs +36 -15
- package/dist/source-map.cjs +90 -7
- package/dist/source-map.mjs +90 -7
- package/dist/types.d.ts +1 -1
- package/dist/utils.cjs +10 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.mjs +10 -1
- package/package.json +3 -3
package/dist/client.mjs
CHANGED
|
@@ -55,8 +55,8 @@ class ModuleCacheMap extends Map {
|
|
|
55
55
|
if (!super.has(modulePath)) this.setByModuleId(modulePath, {});
|
|
56
56
|
const mod = super.get(modulePath);
|
|
57
57
|
if (!mod.imports) Object.assign(mod, {
|
|
58
|
-
imports: new Set(),
|
|
59
|
-
importers: new Set()
|
|
58
|
+
imports: /* @__PURE__ */ new Set(),
|
|
59
|
+
importers: /* @__PURE__ */ new Set()
|
|
60
60
|
});
|
|
61
61
|
return mod;
|
|
62
62
|
}
|
|
@@ -82,7 +82,7 @@ class ModuleCacheMap extends Map {
|
|
|
82
82
|
/**
|
|
83
83
|
* Invalidate modules that dependent on the given modules, up to the main entry
|
|
84
84
|
*/
|
|
85
|
-
invalidateDepTree(ids, invalidated = new Set()) {
|
|
85
|
+
invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
|
86
86
|
for (const _id of ids) {
|
|
87
87
|
const id = this.normalizePath(_id);
|
|
88
88
|
if (invalidated.has(id)) continue;
|
|
@@ -96,7 +96,7 @@ class ModuleCacheMap extends Map {
|
|
|
96
96
|
/**
|
|
97
97
|
* Invalidate dependency modules of the given modules, down to the bottom-level dependencies
|
|
98
98
|
*/
|
|
99
|
-
invalidateSubDepTree(ids, invalidated = new Set()) {
|
|
99
|
+
invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
|
100
100
|
for (const _id of ids) {
|
|
101
101
|
const id = this.normalizePath(_id);
|
|
102
102
|
if (invalidated.has(id)) continue;
|
|
@@ -132,6 +132,25 @@ class ViteNodeRunner {
|
|
|
132
132
|
* Keys of the map are filepaths, or plain package names
|
|
133
133
|
*/
|
|
134
134
|
moduleCache;
|
|
135
|
+
/**
|
|
136
|
+
* Tracks the stack of modules being executed for the purpose of calculating import self-time.
|
|
137
|
+
*
|
|
138
|
+
* Note that while in most cases, imports are a linear stack of modules,
|
|
139
|
+
* this is occasionally not the case, for example when you have parallel top-level dynamic imports like so:
|
|
140
|
+
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* await Promise.all([
|
|
143
|
+
* import('./module1'),
|
|
144
|
+
* import('./module2'),
|
|
145
|
+
* ]);
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* In this case, the self time will be reported incorrectly for one of the modules (could go negative).
|
|
149
|
+
* As top-level awaits with dynamic imports like this are uncommon, we don't handle this case specifically.
|
|
150
|
+
*/
|
|
151
|
+
executionStack = [];
|
|
152
|
+
// `performance` can be mocked, so make sure we're using the original function
|
|
153
|
+
performanceNow = performance.now.bind(performance);
|
|
135
154
|
constructor(options) {
|
|
136
155
|
this.options = options;
|
|
137
156
|
this.root = options.root ?? process.cwd();
|
|
@@ -153,12 +172,14 @@ class ViteNodeRunner {
|
|
|
153
172
|
const { imports, importers } = mod;
|
|
154
173
|
if (importee) importers.add(importee);
|
|
155
174
|
const getStack = () => `stack:\n${[...callstack, fsPath].reverse().map((p) => ` - ${p}`).join("\n")}`;
|
|
175
|
+
// check circular dependency
|
|
156
176
|
if (callstack.includes(fsPath) || Array.from(imports.values()).some((i) => importers.has(i))) {
|
|
157
177
|
if (mod.exports) return mod.exports;
|
|
158
178
|
}
|
|
159
179
|
let debugTimer;
|
|
160
180
|
if (this.debug) debugTimer = setTimeout(() => console.warn(`[vite-node] module ${fsPath} takes over 2s to load.\n${getStack()}`), 2e3);
|
|
161
181
|
try {
|
|
182
|
+
// cached module
|
|
162
183
|
if (mod.promise) return await mod.promise;
|
|
163
184
|
const promise = this.directRequest(id, fsPath, callstack);
|
|
164
185
|
Object.assign(mod, {
|
|
@@ -181,6 +202,7 @@ class ViteNodeRunner {
|
|
|
181
202
|
const { path, exists } = toFilePath(dep, this.root);
|
|
182
203
|
if (!this.options.resolveId || exists) return [dep, path];
|
|
183
204
|
const resolved = await this.options.resolveId(dep, importer);
|
|
205
|
+
// supported since Vite 5-beta.19
|
|
184
206
|
if (resolved === null || resolved === void 0 || (_resolved$meta = resolved.meta) === null || _resolved$meta === void 0 || (_resolved$meta = _resolved$meta["vite:alias"]) === null || _resolved$meta === void 0 ? void 0 : _resolved$meta.noResolved) {
|
|
185
207
|
const error = new Error(`Cannot find module '${id}'${importer ? ` imported from '${importer}'` : ""}.
|
|
186
208
|
|
|
@@ -204,6 +226,7 @@ class ViteNodeRunner {
|
|
|
204
226
|
}
|
|
205
227
|
async resolveUrl(id, importee) {
|
|
206
228
|
const resolveKey = `resolve:${id}`;
|
|
229
|
+
// put info about new import as soon as possible, so we can start tracking it
|
|
207
230
|
this.moduleCache.setByModuleId(resolveKey, { resolving: true });
|
|
208
231
|
try {
|
|
209
232
|
return await this._resolveUrl(id, importee);
|
|
@@ -219,6 +242,7 @@ class ViteNodeRunner {
|
|
|
219
242
|
try {
|
|
220
243
|
return await this.options.fetchModule(id);
|
|
221
244
|
} catch (cause) {
|
|
245
|
+
// rethrow vite error if it cannot load the module because it's not resolved
|
|
222
246
|
if (typeof cause === "object" && cause.code === "ERR_LOAD_URL" || typeof (cause === null || cause === void 0 ? void 0 : cause.message) === "string" && cause.message.includes("Failed to load url")) {
|
|
223
247
|
const error = new Error(`Cannot find ${isBareImport(id) ? "package" : "module"} '${id}'${importer ? ` imported from '${importer}'` : ""}`, { cause });
|
|
224
248
|
error.code = "ERR_MODULE_NOT_FOUND";
|
|
@@ -251,6 +275,7 @@ class ViteNodeRunner {
|
|
|
251
275
|
if (transformed == null) throw new Error(`[vite-node] Failed to load "${id}" imported from ${callstack[callstack.length - 2]}`);
|
|
252
276
|
const { Object, Reflect, Symbol } = this.getContextPrimitives();
|
|
253
277
|
const modulePath = cleanUrl(moduleId);
|
|
278
|
+
// disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710
|
|
254
279
|
const href = pathToFileURL(modulePath).href;
|
|
255
280
|
const __filename = fileURLToPath(href);
|
|
256
281
|
const __dirname = dirname(__filename);
|
|
@@ -268,6 +293,8 @@ class ViteNodeRunner {
|
|
|
268
293
|
});
|
|
269
294
|
const SYMBOL_NOT_DEFINED = Symbol("not defined");
|
|
270
295
|
let moduleExports = SYMBOL_NOT_DEFINED;
|
|
296
|
+
// this proxy is triggered only on exports.{name} and module.exports access
|
|
297
|
+
// inside the module itself. imported module is always "exports"
|
|
271
298
|
const cjsExports = new Proxy(exports, {
|
|
272
299
|
get: (target, p, receiver) => {
|
|
273
300
|
if (Reflect.has(target, p)) return Reflect.get(target, p, receiver);
|
|
@@ -275,12 +302,16 @@ class ViteNodeRunner {
|
|
|
275
302
|
},
|
|
276
303
|
getPrototypeOf: () => Object.prototype,
|
|
277
304
|
set: (_, p, value) => {
|
|
305
|
+
// treat "module.exports =" the same as "exports.default =" to not have nested "default.default",
|
|
306
|
+
// so "exports.default" becomes the actual module
|
|
278
307
|
if (p === "default" && this.shouldInterop(modulePath, { default: value }) && cjsExports !== value) {
|
|
279
308
|
exportAll(cjsExports, value);
|
|
280
309
|
exports.default = value;
|
|
281
310
|
return true;
|
|
282
311
|
}
|
|
283
312
|
if (!Reflect.has(exports, "default")) exports.default = {};
|
|
313
|
+
// returns undefined, when accessing named exports, if default is not an object
|
|
314
|
+
// but is still present inside hasOwnKeys, this is Node behaviour for CJS
|
|
284
315
|
if (moduleExports !== SYMBOL_NOT_DEFINED && isPrimitive(moduleExports)) {
|
|
285
316
|
defineExport(exports, p, () => void 0);
|
|
286
317
|
return true;
|
|
@@ -304,6 +335,7 @@ class ViteNodeRunner {
|
|
|
304
335
|
return cjsExports;
|
|
305
336
|
}
|
|
306
337
|
};
|
|
338
|
+
// Vite hot context
|
|
307
339
|
let hotContext;
|
|
308
340
|
if (this.options.createHotContext) Object.defineProperty(meta, "hot", {
|
|
309
341
|
enumerable: true,
|
|
@@ -316,11 +348,20 @@ class ViteNodeRunner {
|
|
|
316
348
|
hotContext = value;
|
|
317
349
|
}
|
|
318
350
|
});
|
|
351
|
+
// Be careful when changing this
|
|
352
|
+
// changing context will change amount of code added on line :114 (vm.runInThisContext)
|
|
353
|
+
// this messes up sourcemaps for coverage
|
|
354
|
+
// adjust `WRAPPER_LENGTH` variable in packages/coverage-v8/src/provider.ts if you do change this
|
|
319
355
|
const context = this.prepareContext({
|
|
320
356
|
__vite_ssr_import__: request,
|
|
321
357
|
__vite_ssr_dynamic_import__: request,
|
|
322
358
|
__vite_ssr_exports__: exports,
|
|
323
359
|
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
360
|
+
__vite_ssr_exportName__: (name, getter) => Object.defineProperty(exports, name, {
|
|
361
|
+
enumerable: true,
|
|
362
|
+
configurable: true,
|
|
363
|
+
get: getter
|
|
364
|
+
}),
|
|
324
365
|
__vite_ssr_import_meta__: meta,
|
|
325
366
|
require: createRequire(href),
|
|
326
367
|
exports: cjsExports,
|
|
@@ -329,6 +370,7 @@ class ViteNodeRunner {
|
|
|
329
370
|
__dirname
|
|
330
371
|
});
|
|
331
372
|
debugExecute(__filename);
|
|
373
|
+
// remove shebang
|
|
332
374
|
if (transformed[0] === "#") transformed = transformed.replace(/^#!.*/, (s) => " ".repeat(s.length));
|
|
333
375
|
await this.runModule(context, transformed);
|
|
334
376
|
return exports;
|
|
@@ -341,7 +383,7 @@ class ViteNodeRunner {
|
|
|
341
383
|
};
|
|
342
384
|
}
|
|
343
385
|
async runModule(context, transformed) {
|
|
344
|
-
|
|
386
|
+
// add 'use strict' since ESM enables it by default
|
|
345
387
|
const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
|
|
346
388
|
const code = `${codeDefinition}${transformed}\n}}`;
|
|
347
389
|
const options = {
|
|
@@ -349,9 +391,38 @@ class ViteNodeRunner {
|
|
|
349
391
|
lineOffset: 0,
|
|
350
392
|
columnOffset: -codeDefinition.length
|
|
351
393
|
};
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
394
|
+
const finishModuleExecutionInfo = this.startCalculateModuleExecutionInfo(options.filename, codeDefinition.length);
|
|
395
|
+
try {
|
|
396
|
+
const fn = vm.runInThisContext(code, options);
|
|
397
|
+
await fn(...Object.values(context));
|
|
398
|
+
} finally {
|
|
399
|
+
var _this$options$moduleE;
|
|
400
|
+
(_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, finishModuleExecutionInfo());
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Starts calculating the module execution info such as the total duration and self time spent on executing the module.
|
|
405
|
+
* Returns a function to call once the module has finished executing.
|
|
406
|
+
*/
|
|
407
|
+
startCalculateModuleExecutionInfo(filename, startOffset) {
|
|
408
|
+
const startTime = this.performanceNow();
|
|
409
|
+
this.executionStack.push({
|
|
410
|
+
filename,
|
|
411
|
+
startTime,
|
|
412
|
+
subImportTime: 0
|
|
413
|
+
});
|
|
414
|
+
return () => {
|
|
415
|
+
const duration = this.performanceNow() - startTime;
|
|
416
|
+
const currentExecution = this.executionStack.pop();
|
|
417
|
+
if (currentExecution == null) throw new Error("Execution stack is empty, this should never happen");
|
|
418
|
+
const selfTime = duration - currentExecution.subImportTime;
|
|
419
|
+
if (this.executionStack.length > 0) this.executionStack.at(-1).subImportTime += duration;
|
|
420
|
+
return {
|
|
421
|
+
startOffset,
|
|
422
|
+
duration,
|
|
423
|
+
selfTime
|
|
424
|
+
};
|
|
425
|
+
};
|
|
355
426
|
}
|
|
356
427
|
prepareContext(context) {
|
|
357
428
|
return context;
|
|
@@ -362,6 +433,8 @@ class ViteNodeRunner {
|
|
|
362
433
|
*/
|
|
363
434
|
shouldInterop(path, mod) {
|
|
364
435
|
if (this.options.interopDefault === false) return false;
|
|
436
|
+
// never interop ESM modules
|
|
437
|
+
// TODO: should also skip for `.js` with `type="module"`
|
|
365
438
|
return !path.endsWith(".mjs") && "default" in mod;
|
|
366
439
|
}
|
|
367
440
|
importExternalModule(path) {
|
|
@@ -413,6 +486,7 @@ function interopModule(mod) {
|
|
|
413
486
|
defaultExport
|
|
414
487
|
};
|
|
415
488
|
}
|
|
489
|
+
// keep consistency with Vite on how exports are defined
|
|
416
490
|
function defineExport(exports, key, value) {
|
|
417
491
|
Object.defineProperty(exports, key, {
|
|
418
492
|
enumerable: true,
|
|
@@ -421,6 +495,8 @@ function defineExport(exports, key, value) {
|
|
|
421
495
|
});
|
|
422
496
|
}
|
|
423
497
|
function exportAll(exports, sourceModule) {
|
|
498
|
+
// #1120 when a module exports itself it causes
|
|
499
|
+
// call stack error
|
|
424
500
|
if (exports === sourceModule) return;
|
|
425
501
|
if (isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise) return;
|
|
426
502
|
for (const key in sourceModule) if (key !== "default" && !(key in exports)) try {
|
package/dist/hmr.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HMRPayload, Plugin } from 'vite';
|
|
2
2
|
import { EventEmitter } from 'node:events';
|
|
3
|
-
import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index.d-
|
|
3
|
+
import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index.d-DGmxD2U7.js';
|
|
4
4
|
import './trace-mapping.d-DLVdEqOp.js';
|
|
5
5
|
|
|
6
6
|
type EventType = string | symbol;
|
|
@@ -21,6 +21,8 @@ declare module "vite" {
|
|
|
21
21
|
declare function createHmrEmitter(): HMREmitter;
|
|
22
22
|
declare function viteNodeHmrPlugin(): Plugin;
|
|
23
23
|
|
|
24
|
+
/* eslint-disable no-console */
|
|
25
|
+
|
|
24
26
|
type ModuleNamespace = Record<string, any> & {
|
|
25
27
|
[Symbol.toStringTag]: "Module"
|
|
26
28
|
};
|
|
@@ -30,6 +32,7 @@ interface HotModule {
|
|
|
30
32
|
callbacks: HotCallback[];
|
|
31
33
|
}
|
|
32
34
|
interface HotCallback {
|
|
35
|
+
// the dependencies must be fetchable paths
|
|
33
36
|
deps: string[];
|
|
34
37
|
fn: (modules: (ModuleNamespace | undefined)[]) => void;
|
|
35
38
|
}
|
|
@@ -34,6 +34,8 @@ interface Update {
|
|
|
34
34
|
/** @internal */
|
|
35
35
|
isWithinCircularImport?: boolean
|
|
36
36
|
/** @internal */
|
|
37
|
+
firstInvalidatedBy?: string
|
|
38
|
+
/** @internal */
|
|
37
39
|
invalidates?: string[]
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -98,14 +100,20 @@ interface WebSocketConnectionPayload {
|
|
|
98
100
|
interface InvalidatePayload {
|
|
99
101
|
path: string
|
|
100
102
|
message: string | undefined
|
|
103
|
+
firstInvalidatedBy: string
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
/**
|
|
104
|
-
* provides types for built-in Vite events
|
|
107
|
+
* provides types for payloads of built-in Vite events
|
|
105
108
|
*/
|
|
106
109
|
type InferCustomEventPayload<T extends string> =
|
|
107
110
|
T extends keyof CustomEventMap ? CustomEventMap[T] : any
|
|
108
111
|
|
|
112
|
+
/**
|
|
113
|
+
* provides types for names of built-in Vite events
|
|
114
|
+
*/
|
|
115
|
+
type CustomEventName = keyof CustomEventMap | (string & {})
|
|
116
|
+
|
|
109
117
|
type ModuleNamespace = Record<string, any> & {
|
|
110
118
|
[Symbol.toStringTag]: 'Module'
|
|
111
119
|
}
|
|
@@ -130,15 +138,18 @@ interface ViteHotContext {
|
|
|
130
138
|
prune(cb: (data: any) => void): void
|
|
131
139
|
invalidate(message?: string): void
|
|
132
140
|
|
|
133
|
-
on<T extends
|
|
141
|
+
on<T extends CustomEventName>(
|
|
134
142
|
event: T,
|
|
135
143
|
cb: (payload: InferCustomEventPayload<T>) => void,
|
|
136
144
|
): void
|
|
137
|
-
off<T extends
|
|
145
|
+
off<T extends CustomEventName>(
|
|
138
146
|
event: T,
|
|
139
147
|
cb: (payload: InferCustomEventPayload<T>) => void,
|
|
140
148
|
): void
|
|
141
|
-
send<T extends
|
|
149
|
+
send<T extends CustomEventName>(
|
|
150
|
+
event: T,
|
|
151
|
+
data?: InferCustomEventPayload<T>,
|
|
152
|
+
): void
|
|
142
153
|
}
|
|
143
154
|
|
|
144
155
|
declare const DEFAULT_REQUEST_STUBS: Record<string, Record<string, unknown>>;
|
|
@@ -168,9 +179,14 @@ declare class ModuleCacheMap extends Map<string, ModuleCache> {
|
|
|
168
179
|
*/
|
|
169
180
|
getSourceMap(id: string): EncodedSourceMap | null;
|
|
170
181
|
}
|
|
171
|
-
type ModuleExecutionInfo = Map<string,
|
|
172
|
-
|
|
173
|
-
|
|
182
|
+
type ModuleExecutionInfo = Map<string, ModuleExecutionInfoEntry>;
|
|
183
|
+
interface ModuleExecutionInfoEntry {
|
|
184
|
+
startOffset: number;
|
|
185
|
+
/** The duration that was spent executing the module. */
|
|
186
|
+
duration: number;
|
|
187
|
+
/** The time that was spent executing the module itself and externalized imports. */
|
|
188
|
+
selfTime: number;
|
|
189
|
+
}
|
|
174
190
|
declare class ViteNodeRunner {
|
|
175
191
|
options: ViteNodeRunnerOptions;
|
|
176
192
|
root: string;
|
|
@@ -180,6 +196,25 @@ declare class ViteNodeRunner {
|
|
|
180
196
|
* Keys of the map are filepaths, or plain package names
|
|
181
197
|
*/
|
|
182
198
|
moduleCache: ModuleCacheMap;
|
|
199
|
+
/**
|
|
200
|
+
* Tracks the stack of modules being executed for the purpose of calculating import self-time.
|
|
201
|
+
*
|
|
202
|
+
* Note that while in most cases, imports are a linear stack of modules,
|
|
203
|
+
* this is occasionally not the case, for example when you have parallel top-level dynamic imports like so:
|
|
204
|
+
*
|
|
205
|
+
* ```ts
|
|
206
|
+
* await Promise.all([
|
|
207
|
+
* import('./module1'),
|
|
208
|
+
* import('./module2'),
|
|
209
|
+
* ]);
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* In this case, the self time will be reported incorrectly for one of the modules (could go negative).
|
|
213
|
+
* As top-level awaits with dynamic imports like this are uncommon, we don't handle this case specifically.
|
|
214
|
+
*/
|
|
215
|
+
private executionStack;
|
|
216
|
+
// `performance` can be mocked, so make sure we're using the original function
|
|
217
|
+
private performanceNow;
|
|
183
218
|
constructor(options: ViteNodeRunnerOptions);
|
|
184
219
|
executeFile(file: string): Promise<any>;
|
|
185
220
|
executeId(rawId: string): Promise<any>;
|
|
@@ -193,6 +228,11 @@ declare class ViteNodeRunner {
|
|
|
193
228
|
Symbol: SymbolConstructor
|
|
194
229
|
};
|
|
195
230
|
protected runModule(context: Record<string, any>, transformed: string): Promise<void>;
|
|
231
|
+
/**
|
|
232
|
+
* Starts calculating the module execution info such as the total duration and self time spent on executing the module.
|
|
233
|
+
* Returns a function to call once the module has finished executing.
|
|
234
|
+
*/
|
|
235
|
+
protected startCalculateModuleExecutionInfo(filename: string, startOffset: number): () => ModuleExecutionInfoEntry;
|
|
196
236
|
prepareContext(context: Record<string, any>): Record<string, any>;
|
|
197
237
|
/**
|
|
198
238
|
* Define if a module should be interop-ed
|
|
@@ -320,4 +360,4 @@ interface DebuggerOptions {
|
|
|
320
360
|
}
|
|
321
361
|
|
|
322
362
|
export { ModuleCacheMap as M, ViteNodeRunner as a, DEFAULT_REQUEST_STUBS as e };
|
|
323
|
-
export type { Arrayable as A, CustomEventMap as C, DebuggerOptions as D, FetchResult as F, HMRPayload as H, Nullable as N, RawSourceMap as R, StartOfSourceMap as S, ViteNodeServerOptions as V, HotContext as b, DepsHandlingOptions as c, ViteNodeResolveId as d, ModuleExecutionInfo as f,
|
|
363
|
+
export type { Arrayable as A, CustomEventMap as C, DebuggerOptions as D, FetchResult as F, HMRPayload as H, Nullable as N, RawSourceMap as R, StartOfSourceMap as S, ViteNodeServerOptions as V, HotContext as b, DepsHandlingOptions as c, ViteNodeResolveId as d, ModuleExecutionInfo as f, ModuleExecutionInfoEntry as g, Awaitable as h, FetchFunction as i, ResolveIdFunction as j, CreateHotContextFunction as k, ModuleCache as l, ViteNodeRunnerOptions as m, ViteNodeResolveModule as n };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { A as Arrayable,
|
|
1
|
+
export { A as Arrayable, h as Awaitable, k as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, i as FetchFunction, F as FetchResult, b as HotContext, l as ModuleCache, M as ModuleCacheMap, f as ModuleExecutionInfo, N as Nullable, R as RawSourceMap, j as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, n as ViteNodeResolveModule, m as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index.d-DGmxD2U7.js';
|
|
2
2
|
export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-DLVdEqOp.js';
|
package/dist/server.cjs
CHANGED
|
@@ -34,6 +34,7 @@ function _interopNamespaceDefault(e) {
|
|
|
34
34
|
|
|
35
35
|
var esModuleLexer__namespace = /*#__PURE__*/_interopNamespaceDefault(esModuleLexer);
|
|
36
36
|
|
|
37
|
+
/* eslint-disable no-console */
|
|
37
38
|
function hashCode(s) {
|
|
38
39
|
return s.split("").reduce((a, b) => {
|
|
39
40
|
a = (a << 5) - a + b.charCodeAt(0);
|
|
@@ -43,7 +44,7 @@ function hashCode(s) {
|
|
|
43
44
|
class Debugger {
|
|
44
45
|
dumpDir;
|
|
45
46
|
initPromise;
|
|
46
|
-
externalizeMap = new Map();
|
|
47
|
+
externalizeMap = /* @__PURE__ */ new Map();
|
|
47
48
|
constructor(root, options) {
|
|
48
49
|
this.options = options;
|
|
49
50
|
if (options.dumpModules) this.dumpDir = pathe.resolve(root, options.dumpModules === true ? ".vite-node/dump" : options.dumpModules);
|
|
@@ -88,7 +89,7 @@ class Debugger {
|
|
|
88
89
|
async writeInfo() {
|
|
89
90
|
if (!this.dumpDir) return;
|
|
90
91
|
const info = JSON.stringify({
|
|
91
|
-
time: new Date().toLocaleString(),
|
|
92
|
+
time: (/* @__PURE__ */ new Date()).toLocaleString(),
|
|
92
93
|
externalize: Object.fromEntries(this.externalizeMap.entries())
|
|
93
94
|
}, null, 2);
|
|
94
95
|
return fs.promises.writeFile(pathe.join(this.dumpDir, "info.json"), info, "utf-8");
|
|
@@ -128,6 +129,7 @@ function guessCJSversion(id) {
|
|
|
128
129
|
]) if (fs.existsSync(i)) return i;
|
|
129
130
|
}
|
|
130
131
|
}
|
|
132
|
+
// The code from https://github.com/unjs/mlly/blob/c5bcca0cda175921344fd6de1bc0c499e73e5dac/src/syntax.ts#L51-L98
|
|
131
133
|
async function isValidNodeImport(id) {
|
|
132
134
|
const extension = pathe.extname(id);
|
|
133
135
|
if (BUILTIN_EXTENSIONS.has(extension)) return true;
|
|
@@ -145,19 +147,24 @@ async function isValidNodeImport(id) {
|
|
|
145
147
|
return false;
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
|
-
const _defaultExternalizeCache = new Map();
|
|
150
|
+
const _defaultExternalizeCache = /* @__PURE__ */ new Map();
|
|
149
151
|
async function shouldExternalize(id, options, cache = _defaultExternalizeCache) {
|
|
150
152
|
if (!cache.has(id)) cache.set(id, _shouldExternalize(id, options));
|
|
151
153
|
return cache.get(id);
|
|
152
154
|
}
|
|
153
155
|
async function _shouldExternalize(id, options) {
|
|
154
156
|
if (utils.isNodeBuiltin(id)) return id;
|
|
157
|
+
// data: should be processed by native import,
|
|
158
|
+
// since it is a feature of ESM.
|
|
159
|
+
// also externalize network imports since nodejs allows it when --experimental-network-imports
|
|
155
160
|
if (id.startsWith("data:") || /^(?:https?:)?\/\//.test(id)) return id;
|
|
156
161
|
id = patchWindowsImportPath(id);
|
|
157
162
|
const moduleDirectories = (options === null || options === void 0 ? void 0 : options.moduleDirectories) || ["/node_modules/"];
|
|
158
163
|
if (matchExternalizePattern(id, moduleDirectories, options === null || options === void 0 ? void 0 : options.inline)) return false;
|
|
159
164
|
if ((options === null || options === void 0 ? void 0 : options.inlineFiles) && (options === null || options === void 0 ? void 0 : options.inlineFiles.includes(id))) return false;
|
|
160
165
|
if (matchExternalizePattern(id, moduleDirectories, options === null || options === void 0 ? void 0 : options.external)) return id;
|
|
166
|
+
// Unless the user explicitly opted to inline them, externalize Vite deps.
|
|
167
|
+
// They are too big to inline by default.
|
|
161
168
|
if ((options === null || options === void 0 ? void 0 : options.cacheDir) && id.includes(options.cacheDir)) return id;
|
|
162
169
|
const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir));
|
|
163
170
|
const guessCJS = isLibraryModule && (options === null || options === void 0 ? void 0 : options.fallbackCJS);
|
|
@@ -184,33 +191,38 @@ function patchWindowsImportPath(path) {
|
|
|
184
191
|
const debugRequest = createDebug("vite-node:server:request");
|
|
185
192
|
class ViteNodeServer {
|
|
186
193
|
fetchPromiseMap = {
|
|
187
|
-
ssr: new Map(),
|
|
188
|
-
web: new Map()
|
|
194
|
+
ssr: /* @__PURE__ */ new Map(),
|
|
195
|
+
web: /* @__PURE__ */ new Map()
|
|
189
196
|
};
|
|
190
197
|
transformPromiseMap = {
|
|
191
|
-
ssr: new Map(),
|
|
192
|
-
web: new Map()
|
|
198
|
+
ssr: /* @__PURE__ */ new Map(),
|
|
199
|
+
web: /* @__PURE__ */ new Map()
|
|
193
200
|
};
|
|
194
201
|
durations = {
|
|
195
|
-
ssr: new Map(),
|
|
196
|
-
web: new Map()
|
|
202
|
+
ssr: /* @__PURE__ */ new Map(),
|
|
203
|
+
web: /* @__PURE__ */ new Map()
|
|
197
204
|
};
|
|
198
|
-
existingOptimizedDeps = new Set();
|
|
205
|
+
existingOptimizedDeps = /* @__PURE__ */ new Set();
|
|
199
206
|
fetchCaches = {
|
|
200
|
-
ssr: new Map(),
|
|
201
|
-
web: new Map()
|
|
207
|
+
ssr: /* @__PURE__ */ new Map(),
|
|
208
|
+
web: /* @__PURE__ */ new Map()
|
|
202
209
|
};
|
|
203
|
-
fetchCache = new Map();
|
|
204
|
-
externalizeCache = new Map();
|
|
210
|
+
fetchCache = /* @__PURE__ */ new Map();
|
|
211
|
+
externalizeCache = /* @__PURE__ */ new Map();
|
|
205
212
|
debugger;
|
|
206
213
|
constructor(server, options = {}) {
|
|
214
|
+
var _options$deps3;
|
|
207
215
|
this.server = server;
|
|
208
216
|
this.options = options;
|
|
209
|
-
var _options$deps3;
|
|
210
217
|
const ssrOptions = server.config.ssr;
|
|
211
218
|
options.deps ?? (options.deps = {});
|
|
212
219
|
options.deps.cacheDir = pathe.relative(server.config.root, options.deps.cacheDir || server.config.cacheDir);
|
|
213
220
|
if (ssrOptions) {
|
|
221
|
+
// we don't externalize ssr, because it has different semantics in Vite
|
|
222
|
+
// if (ssrOptions.external) {
|
|
223
|
+
// options.deps.external ??= []
|
|
224
|
+
// options.deps.external.push(...ssrOptions.external)
|
|
225
|
+
// }
|
|
214
226
|
if (ssrOptions.noExternal === true) {
|
|
215
227
|
var _options$deps;
|
|
216
228
|
(_options$deps = options.deps).inline ?? (_options$deps.inline = true);
|
|
@@ -240,6 +252,7 @@ class ViteNodeServer {
|
|
|
240
252
|
if (!dir.endsWith("/")) dir += "/";
|
|
241
253
|
return pathe.normalize(dir);
|
|
242
254
|
});
|
|
255
|
+
// always add node_modules as a module directory
|
|
243
256
|
if (!options.deps.moduleDirectories.includes("/node_modules/")) options.deps.moduleDirectories.push("/node_modules/");
|
|
244
257
|
}
|
|
245
258
|
shouldExternalize(id) {
|
|
@@ -293,6 +306,7 @@ class ViteNodeServer {
|
|
|
293
306
|
const moduleId = utils.normalizeModuleId(id);
|
|
294
307
|
this.assertMode(mode);
|
|
295
308
|
const promiseMap = this.fetchPromiseMap[mode];
|
|
309
|
+
// reuse transform for concurrent requests
|
|
296
310
|
if (!promiseMap.has(moduleId)) promiseMap.set(moduleId, this._fetchModule(moduleId, mode).finally(() => {
|
|
297
311
|
promiseMap.delete(moduleId);
|
|
298
312
|
}));
|
|
@@ -302,6 +316,7 @@ class ViteNodeServer {
|
|
|
302
316
|
const mode = transformMode || this.getTransformMode(id);
|
|
303
317
|
this.assertMode(mode);
|
|
304
318
|
const promiseMap = this.transformPromiseMap[mode];
|
|
319
|
+
// reuse transform for concurrent requests
|
|
305
320
|
if (!promiseMap.has(id)) promiseMap.set(id, this._transformRequest(id, filepath, mode).finally(() => {
|
|
306
321
|
promiseMap.delete(id);
|
|
307
322
|
}));
|
|
@@ -327,6 +342,7 @@ class ViteNodeServer {
|
|
|
327
342
|
if (module) return module;
|
|
328
343
|
const _modules = this.server.moduleGraph.getModulesByFile(file);
|
|
329
344
|
if (!_modules || !_modules.size) return null;
|
|
345
|
+
// find the latest changed module
|
|
330
346
|
const modules = [..._modules];
|
|
331
347
|
let mod = modules[0];
|
|
332
348
|
let latestMax = -1;
|
|
@@ -354,6 +370,9 @@ class ViteNodeServer {
|
|
|
354
370
|
const { path: filePath } = utils.toFilePath(id, this.server.config.root);
|
|
355
371
|
const moduleNode = this.getChangedModule(id, filePath);
|
|
356
372
|
const cache = this.fetchCaches[transformMode].get(filePath);
|
|
373
|
+
// lastUpdateTimestamp is the timestamp that marks the last time the module was changed
|
|
374
|
+
// if lastUpdateTimestamp is 0, then the module was not changed since the server started
|
|
375
|
+
// we test "timestamp === 0" for expressiveness, but it's not necessary
|
|
357
376
|
const timestamp = moduleNode ? Math.max(moduleNode.lastHMRTimestamp, moduleNode.lastInvalidationTimestamp) : 0;
|
|
358
377
|
if (cache && (timestamp === 0 || cache.timestamp >= timestamp)) return cache.result;
|
|
359
378
|
const time = Date.now();
|
|
@@ -401,6 +420,8 @@ class ViteNodeServer {
|
|
|
401
420
|
if (result) return result;
|
|
402
421
|
}
|
|
403
422
|
if (transformMode === "web") {
|
|
423
|
+
// for components like Vue, we want to use the client side
|
|
424
|
+
// plugins but then convert the code to be consumed by the server
|
|
404
425
|
result = await this.server.transformRequest(id);
|
|
405
426
|
if (result) result = await this.server.ssrTransform(result.code, result.map, id);
|
|
406
427
|
} else result = await this.server.transformRequest(id, { ssr: true });
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TransformResult, ViteDevServer } from 'vite';
|
|
2
|
-
import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './index.d-
|
|
2
|
+
import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './index.d-DGmxD2U7.js';
|
|
3
3
|
import { E as EncodedSourceMap } from './trace-mapping.d-DLVdEqOp.js';
|
|
4
4
|
|
|
5
5
|
declare class Debugger {
|