vite-node 0.34.7 → 1.0.0-beta.1
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/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/server.cjs +37 -22
- package/dist/server.d.ts +12 -7
- package/dist/server.mjs +37 -22
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -20,7 +20,7 @@ require('node:url');
|
|
|
20
20
|
require('node:vm');
|
|
21
21
|
require('node:events');
|
|
22
22
|
|
|
23
|
-
var version = "0.
|
|
23
|
+
var version = "1.0.0-beta.1";
|
|
24
24
|
|
|
25
25
|
const cli = cac("vite-node");
|
|
26
26
|
cli.option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-m, --mode <mode>", "Set env mode").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command");
|
package/dist/cli.mjs
CHANGED
|
@@ -18,7 +18,7 @@ import 'node:url';
|
|
|
18
18
|
import 'node:vm';
|
|
19
19
|
import 'node:events';
|
|
20
20
|
|
|
21
|
-
var version = "0.
|
|
21
|
+
var version = "1.0.0-beta.1";
|
|
22
22
|
|
|
23
23
|
const cli = cac("vite-node");
|
|
24
24
|
cli.option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-m, --mode <mode>", "Set env mode").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command");
|
package/dist/server.cjs
CHANGED
|
@@ -24,8 +24,8 @@ const defaultInline = [
|
|
|
24
24
|
new RegExp(`\\.(${constants.KNOWN_ASSET_TYPES.join("|")})$`)
|
|
25
25
|
];
|
|
26
26
|
const depsExternal = [
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/\/node_modules\/.*\.cjs\.js$/,
|
|
28
|
+
/\/node_modules\/.*\.mjs$/
|
|
29
29
|
];
|
|
30
30
|
function guessCJSversion(id) {
|
|
31
31
|
if (id.match(ESM_EXT_RE)) {
|
|
@@ -217,9 +217,19 @@ class ViteNodeServer {
|
|
|
217
217
|
if (!options.deps.moduleDirectories.includes("/node_modules/"))
|
|
218
218
|
options.deps.moduleDirectories.push("/node_modules/");
|
|
219
219
|
}
|
|
220
|
-
fetchPromiseMap =
|
|
221
|
-
|
|
220
|
+
fetchPromiseMap = {
|
|
221
|
+
ssr: /* @__PURE__ */ new Map(),
|
|
222
|
+
web: /* @__PURE__ */ new Map()
|
|
223
|
+
};
|
|
224
|
+
transformPromiseMap = {
|
|
225
|
+
ssr: /* @__PURE__ */ new Map(),
|
|
226
|
+
web: /* @__PURE__ */ new Map()
|
|
227
|
+
};
|
|
222
228
|
existingOptimizedDeps = /* @__PURE__ */ new Set();
|
|
229
|
+
fetchCaches = {
|
|
230
|
+
ssr: /* @__PURE__ */ new Map(),
|
|
231
|
+
web: /* @__PURE__ */ new Map()
|
|
232
|
+
};
|
|
223
233
|
fetchCache = /* @__PURE__ */ new Map();
|
|
224
234
|
externalizeCache = /* @__PURE__ */ new Map();
|
|
225
235
|
debugger;
|
|
@@ -256,29 +266,33 @@ class ViteNodeServer {
|
|
|
256
266
|
return (ssrTransformResult == null ? void 0 : ssrTransformResult.map) || null;
|
|
257
267
|
}
|
|
258
268
|
async fetchModule(id, transformMode) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
269
|
+
const moduleId = utils.normalizeModuleId(id);
|
|
270
|
+
const mode = transformMode || this.getTransformMode(id);
|
|
271
|
+
const promiseMap = this.fetchPromiseMap[mode];
|
|
272
|
+
if (!promiseMap.has(moduleId)) {
|
|
273
|
+
promiseMap.set(
|
|
274
|
+
moduleId,
|
|
275
|
+
this._fetchModule(moduleId, mode).then((r) => {
|
|
264
276
|
return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
|
|
265
277
|
}).finally(() => {
|
|
266
|
-
|
|
278
|
+
promiseMap.delete(moduleId);
|
|
267
279
|
})
|
|
268
280
|
);
|
|
269
281
|
}
|
|
270
|
-
return
|
|
282
|
+
return promiseMap.get(moduleId);
|
|
271
283
|
}
|
|
272
|
-
async transformRequest(id, filepath = id) {
|
|
273
|
-
|
|
274
|
-
|
|
284
|
+
async transformRequest(id, filepath = id, transformMode) {
|
|
285
|
+
const mode = transformMode || this.getTransformMode(id);
|
|
286
|
+
const promiseMap = this.transformPromiseMap[mode];
|
|
287
|
+
if (!promiseMap.has(id)) {
|
|
288
|
+
promiseMap.set(
|
|
275
289
|
id,
|
|
276
|
-
this._transformRequest(id, filepath).finally(() => {
|
|
277
|
-
|
|
290
|
+
this._transformRequest(id, filepath, mode).finally(() => {
|
|
291
|
+
promiseMap.delete(id);
|
|
278
292
|
})
|
|
279
293
|
);
|
|
280
294
|
}
|
|
281
|
-
return
|
|
295
|
+
return promiseMap.get(id);
|
|
282
296
|
}
|
|
283
297
|
async transformModule(id, transformMode) {
|
|
284
298
|
if (transformMode !== "web")
|
|
@@ -317,7 +331,7 @@ class ViteNodeServer {
|
|
|
317
331
|
const { path: filePath } = utils.toFilePath(id, this.server.config.root);
|
|
318
332
|
const module = this.server.moduleGraph.getModuleById(id);
|
|
319
333
|
const timestamp = module ? module.lastHMRTimestamp : null;
|
|
320
|
-
const cache = this.
|
|
334
|
+
const cache = this.fetchCaches[transformMode].get(filePath);
|
|
321
335
|
if (timestamp && cache && cache.timestamp >= timestamp)
|
|
322
336
|
return cache.result;
|
|
323
337
|
const time = Date.now();
|
|
@@ -332,11 +346,13 @@ class ViteNodeServer {
|
|
|
332
346
|
duration = perf_hooks.performance.now() - start;
|
|
333
347
|
result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
|
|
334
348
|
}
|
|
335
|
-
|
|
349
|
+
const cacheEntry = {
|
|
336
350
|
duration,
|
|
337
351
|
timestamp: time,
|
|
338
352
|
result
|
|
339
|
-
}
|
|
353
|
+
};
|
|
354
|
+
this.fetchCaches[transformMode].set(filePath, cacheEntry);
|
|
355
|
+
this.fetchCache.set(filePath, cacheEntry);
|
|
340
356
|
return result;
|
|
341
357
|
}
|
|
342
358
|
async processTransformResult(filepath, result) {
|
|
@@ -346,7 +362,7 @@ class ViteNodeServer {
|
|
|
346
362
|
root: this.server.config.root
|
|
347
363
|
});
|
|
348
364
|
}
|
|
349
|
-
async _transformRequest(id, filepath,
|
|
365
|
+
async _transformRequest(id, filepath, transformMode) {
|
|
350
366
|
var _a, _b, _c, _d;
|
|
351
367
|
debugRequest(id);
|
|
352
368
|
let result = null;
|
|
@@ -355,7 +371,6 @@ class ViteNodeServer {
|
|
|
355
371
|
if (result)
|
|
356
372
|
return result;
|
|
357
373
|
}
|
|
358
|
-
const transformMode = customTransformMode ?? this.getTransformMode(id);
|
|
359
374
|
if (transformMode === "web") {
|
|
360
375
|
result = await this.server.transformRequest(id);
|
|
361
376
|
if (result)
|
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,
|
|
2
|
+
import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, d as ViteNodeResolveId, F as FetchResult } from './index-6fb787b2.js';
|
|
3
3
|
import { E as EncodedSourceMap } from './trace-mapping.d-e677e8f4.js';
|
|
4
4
|
|
|
5
5
|
declare class Debugger {
|
|
@@ -19,17 +19,22 @@ declare class Debugger {
|
|
|
19
19
|
declare function guessCJSversion(id: string): string | undefined;
|
|
20
20
|
declare function shouldExternalize(id: string, options?: DepsHandlingOptions, cache?: Map<string, Promise<string | false>>): Promise<string | false>;
|
|
21
21
|
|
|
22
|
+
interface FetchCache {
|
|
23
|
+
duration?: number;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
result: FetchResult;
|
|
26
|
+
}
|
|
22
27
|
declare class ViteNodeServer {
|
|
23
28
|
server: ViteDevServer;
|
|
24
29
|
options: ViteNodeServerOptions;
|
|
25
30
|
private fetchPromiseMap;
|
|
26
31
|
private transformPromiseMap;
|
|
27
32
|
private existingOptimizedDeps;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
fetchCaches: {
|
|
34
|
+
ssr: Map<string, FetchCache>;
|
|
35
|
+
web: Map<string, FetchCache>;
|
|
36
|
+
};
|
|
37
|
+
fetchCache: Map<string, FetchCache>;
|
|
33
38
|
externalizeCache: Map<string, Promise<string | false>>;
|
|
34
39
|
debugger?: Debugger;
|
|
35
40
|
constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
|
|
@@ -38,7 +43,7 @@ declare class ViteNodeServer {
|
|
|
38
43
|
resolveId(id: string, importer?: string, transformMode?: 'web' | 'ssr'): Promise<ViteNodeResolveId | null>;
|
|
39
44
|
getSourceMap(source: string): EncodedSourceMap | null;
|
|
40
45
|
fetchModule(id: string, transformMode?: 'web' | 'ssr'): Promise<FetchResult>;
|
|
41
|
-
transformRequest(id: string, filepath?: string): Promise<TransformResult | null | undefined>;
|
|
46
|
+
transformRequest(id: string, filepath?: string, transformMode?: 'web' | 'ssr'): Promise<TransformResult | null | undefined>;
|
|
42
47
|
transformModule(id: string, transformMode?: 'web' | 'ssr'): Promise<{
|
|
43
48
|
code: string | undefined;
|
|
44
49
|
}>;
|
package/dist/server.mjs
CHANGED
|
@@ -22,8 +22,8 @@ const defaultInline = [
|
|
|
22
22
|
new RegExp(`\\.(${KNOWN_ASSET_TYPES.join("|")})$`)
|
|
23
23
|
];
|
|
24
24
|
const depsExternal = [
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
/\/node_modules\/.*\.cjs\.js$/,
|
|
26
|
+
/\/node_modules\/.*\.mjs$/
|
|
27
27
|
];
|
|
28
28
|
function guessCJSversion(id) {
|
|
29
29
|
if (id.match(ESM_EXT_RE)) {
|
|
@@ -215,9 +215,19 @@ class ViteNodeServer {
|
|
|
215
215
|
if (!options.deps.moduleDirectories.includes("/node_modules/"))
|
|
216
216
|
options.deps.moduleDirectories.push("/node_modules/");
|
|
217
217
|
}
|
|
218
|
-
fetchPromiseMap =
|
|
219
|
-
|
|
218
|
+
fetchPromiseMap = {
|
|
219
|
+
ssr: /* @__PURE__ */ new Map(),
|
|
220
|
+
web: /* @__PURE__ */ new Map()
|
|
221
|
+
};
|
|
222
|
+
transformPromiseMap = {
|
|
223
|
+
ssr: /* @__PURE__ */ new Map(),
|
|
224
|
+
web: /* @__PURE__ */ new Map()
|
|
225
|
+
};
|
|
220
226
|
existingOptimizedDeps = /* @__PURE__ */ new Set();
|
|
227
|
+
fetchCaches = {
|
|
228
|
+
ssr: /* @__PURE__ */ new Map(),
|
|
229
|
+
web: /* @__PURE__ */ new Map()
|
|
230
|
+
};
|
|
221
231
|
fetchCache = /* @__PURE__ */ new Map();
|
|
222
232
|
externalizeCache = /* @__PURE__ */ new Map();
|
|
223
233
|
debugger;
|
|
@@ -254,29 +264,33 @@ class ViteNodeServer {
|
|
|
254
264
|
return (ssrTransformResult == null ? void 0 : ssrTransformResult.map) || null;
|
|
255
265
|
}
|
|
256
266
|
async fetchModule(id, transformMode) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
267
|
+
const moduleId = normalizeModuleId(id);
|
|
268
|
+
const mode = transformMode || this.getTransformMode(id);
|
|
269
|
+
const promiseMap = this.fetchPromiseMap[mode];
|
|
270
|
+
if (!promiseMap.has(moduleId)) {
|
|
271
|
+
promiseMap.set(
|
|
272
|
+
moduleId,
|
|
273
|
+
this._fetchModule(moduleId, mode).then((r) => {
|
|
262
274
|
return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
|
|
263
275
|
}).finally(() => {
|
|
264
|
-
|
|
276
|
+
promiseMap.delete(moduleId);
|
|
265
277
|
})
|
|
266
278
|
);
|
|
267
279
|
}
|
|
268
|
-
return
|
|
280
|
+
return promiseMap.get(moduleId);
|
|
269
281
|
}
|
|
270
|
-
async transformRequest(id, filepath = id) {
|
|
271
|
-
|
|
272
|
-
|
|
282
|
+
async transformRequest(id, filepath = id, transformMode) {
|
|
283
|
+
const mode = transformMode || this.getTransformMode(id);
|
|
284
|
+
const promiseMap = this.transformPromiseMap[mode];
|
|
285
|
+
if (!promiseMap.has(id)) {
|
|
286
|
+
promiseMap.set(
|
|
273
287
|
id,
|
|
274
|
-
this._transformRequest(id, filepath).finally(() => {
|
|
275
|
-
|
|
288
|
+
this._transformRequest(id, filepath, mode).finally(() => {
|
|
289
|
+
promiseMap.delete(id);
|
|
276
290
|
})
|
|
277
291
|
);
|
|
278
292
|
}
|
|
279
|
-
return
|
|
293
|
+
return promiseMap.get(id);
|
|
280
294
|
}
|
|
281
295
|
async transformModule(id, transformMode) {
|
|
282
296
|
if (transformMode !== "web")
|
|
@@ -315,7 +329,7 @@ class ViteNodeServer {
|
|
|
315
329
|
const { path: filePath } = toFilePath(id, this.server.config.root);
|
|
316
330
|
const module = this.server.moduleGraph.getModuleById(id);
|
|
317
331
|
const timestamp = module ? module.lastHMRTimestamp : null;
|
|
318
|
-
const cache = this.
|
|
332
|
+
const cache = this.fetchCaches[transformMode].get(filePath);
|
|
319
333
|
if (timestamp && cache && cache.timestamp >= timestamp)
|
|
320
334
|
return cache.result;
|
|
321
335
|
const time = Date.now();
|
|
@@ -330,11 +344,13 @@ class ViteNodeServer {
|
|
|
330
344
|
duration = performance.now() - start;
|
|
331
345
|
result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
|
|
332
346
|
}
|
|
333
|
-
|
|
347
|
+
const cacheEntry = {
|
|
334
348
|
duration,
|
|
335
349
|
timestamp: time,
|
|
336
350
|
result
|
|
337
|
-
}
|
|
351
|
+
};
|
|
352
|
+
this.fetchCaches[transformMode].set(filePath, cacheEntry);
|
|
353
|
+
this.fetchCache.set(filePath, cacheEntry);
|
|
338
354
|
return result;
|
|
339
355
|
}
|
|
340
356
|
async processTransformResult(filepath, result) {
|
|
@@ -344,7 +360,7 @@ class ViteNodeServer {
|
|
|
344
360
|
root: this.server.config.root
|
|
345
361
|
});
|
|
346
362
|
}
|
|
347
|
-
async _transformRequest(id, filepath,
|
|
363
|
+
async _transformRequest(id, filepath, transformMode) {
|
|
348
364
|
var _a, _b, _c, _d;
|
|
349
365
|
debugRequest(id);
|
|
350
366
|
let result = null;
|
|
@@ -353,7 +369,6 @@ class ViteNodeServer {
|
|
|
353
369
|
if (result)
|
|
354
370
|
return result;
|
|
355
371
|
}
|
|
356
|
-
const transformMode = customTransformMode ?? this.getTransformMode(id);
|
|
357
372
|
if (transformMode === "web") {
|
|
358
373
|
result = await this.server.transformRequest(id);
|
|
359
374
|
if (result)
|