vite-node 1.0.0-beta.0 → 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 CHANGED
@@ -20,7 +20,7 @@ require('node:url');
20
20
  require('node:vm');
21
21
  require('node:events');
22
22
 
23
- var version = "1.0.0-beta.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 = "1.0.0-beta.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
- /\.cjs\.js$/,
28
- /\.mjs$/
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 = /* @__PURE__ */ new Map();
221
- transformPromiseMap = /* @__PURE__ */ new Map();
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
- id = utils.normalizeModuleId(id);
260
- if (!this.fetchPromiseMap.has(id)) {
261
- this.fetchPromiseMap.set(
262
- id,
263
- this._fetchModule(id, transformMode).then((r) => {
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
- this.fetchPromiseMap.delete(id);
278
+ promiseMap.delete(moduleId);
267
279
  })
268
280
  );
269
281
  }
270
- return this.fetchPromiseMap.get(id);
282
+ return promiseMap.get(moduleId);
271
283
  }
272
- async transformRequest(id, filepath = id) {
273
- if (!this.transformPromiseMap.has(id)) {
274
- this.transformPromiseMap.set(
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
- this.transformPromiseMap.delete(id);
290
+ this._transformRequest(id, filepath, mode).finally(() => {
291
+ promiseMap.delete(id);
278
292
  })
279
293
  );
280
294
  }
281
- return this.transformPromiseMap.get(id);
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.fetchCache.get(filePath);
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
- this.fetchCache.set(filePath, {
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, customTransformMode) {
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, F as FetchResult, d as ViteNodeResolveId } from './index-6fb787b2.js';
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
- fetchCache: Map<string, {
29
- duration?: number | undefined;
30
- timestamp: number;
31
- result: FetchResult;
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
- /\.cjs\.js$/,
26
- /\.mjs$/
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 = /* @__PURE__ */ new Map();
219
- transformPromiseMap = /* @__PURE__ */ new Map();
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
- id = normalizeModuleId(id);
258
- if (!this.fetchPromiseMap.has(id)) {
259
- this.fetchPromiseMap.set(
260
- id,
261
- this._fetchModule(id, transformMode).then((r) => {
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
- this.fetchPromiseMap.delete(id);
276
+ promiseMap.delete(moduleId);
265
277
  })
266
278
  );
267
279
  }
268
- return this.fetchPromiseMap.get(id);
280
+ return promiseMap.get(moduleId);
269
281
  }
270
- async transformRequest(id, filepath = id) {
271
- if (!this.transformPromiseMap.has(id)) {
272
- this.transformPromiseMap.set(
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
- this.transformPromiseMap.delete(id);
288
+ this._transformRequest(id, filepath, mode).finally(() => {
289
+ promiseMap.delete(id);
276
290
  })
277
291
  );
278
292
  }
279
- return this.transformPromiseMap.get(id);
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.fetchCache.get(filePath);
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
- this.fetchCache.set(filePath, {
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, customTransformMode) {
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)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.0",
4
+ "version": "1.0.0-beta.1",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",