vite-node 4.0.0-beta.10 → 4.0.0-beta.12

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.
@@ -2,12 +2,11 @@
2
2
 
3
3
  var node_events = require('node:events');
4
4
  var createDebug = require('debug');
5
- var browser = require('./chunk-browser.cjs');
5
+ var index = require('./chunk-index.cjs');
6
6
  var utils = require('./utils.cjs');
7
7
 
8
8
  function createHmrEmitter() {
9
- const emitter = new node_events.EventEmitter();
10
- return emitter;
9
+ return new node_events.EventEmitter();
11
10
  }
12
11
  function viteNodeHmrPlugin() {
13
12
  const emitter = createHmrEmitter();
@@ -58,7 +57,7 @@ async function reload(runner, files) {
58
57
  }), Promise.all(files.map((file) => runner.executeId(file)));
59
58
  }
60
59
  async function notifyListeners(runner, event, data) {
61
- const maps = getCache(runner), cbs = maps.customListenersMap.get(event);
60
+ const cbs = getCache(runner).customListenersMap.get(event);
62
61
  if (cbs) await Promise.all(cbs.map((cb) => cb(data)));
63
62
  }
64
63
  async function queueUpdate(runner, p) {
@@ -93,7 +92,7 @@ async function fetchUpdate(runner, { path, acceptedPath }) {
93
92
  return () => {
94
93
  for (const { deps, fn } of qualifiedCallbacks) fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
95
94
  const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
96
- console.log(`${browser.s.cyan("[vite-node]")} hot updated: ${loggedPath}`);
95
+ console.log(`${index.C.cyan("[vite-node]")} hot updated: ${loggedPath}`);
97
96
  };
98
97
  }
99
98
  function warnFailedFetch(err, path) {
@@ -108,7 +107,7 @@ async function handleMessage(runner, emitter, files, payload) {
108
107
  break;
109
108
  case "update":
110
109
  await notifyListeners(runner, "vite:beforeUpdate", payload), await Promise.all(payload.updates.map((update) => {
111
- return update.type === "js-update" ? queueUpdate(runner, fetchUpdate(runner, update)) : (console.error(`${browser.s.cyan("[vite-node]")} no support css hmr.}`), null);
110
+ return update.type === "js-update" ? queueUpdate(runner, fetchUpdate(runner, update)) : (console.error(`${index.C.cyan("[vite-node]")} no support css hmr.}`), null);
112
111
  })), await notifyListeners(runner, "vite:afterUpdate", payload);
113
112
  break;
114
113
  case "full-reload":
@@ -126,7 +125,7 @@ async function handleMessage(runner, emitter, files, payload) {
126
125
  case "error": {
127
126
  await notifyListeners(runner, "vite:error", payload);
128
127
  const err = payload.err;
129
- console.error(`${browser.s.cyan("[vite-node]")} Internal Server Error\n${err.message}\n${err.stack}`);
128
+ console.error(`${index.C.cyan("[vite-node]")} Internal Server Error\n${err.message}\n${err.stack}`);
130
129
  break;
131
130
  }
132
131
  }
@@ -151,7 +150,7 @@ function createHotContext(runner, emitter, files, ownerPath) {
151
150
  fn: callback
152
151
  }), maps.hotModulesMap.set(ownerPath, mod);
153
152
  }
154
- const hot = {
153
+ return {
155
154
  get data() {
156
155
  return maps.dataMap.get(ownerPath);
157
156
  },
@@ -209,7 +208,6 @@ function createHotContext(runner, emitter, files, ownerPath) {
209
208
  })), sendMessageBuffer(runner, emitter);
210
209
  }
211
210
  };
212
- return hot;
213
211
  }
214
212
 
215
213
  exports.createHmrEmitter = createHmrEmitter;
@@ -1,11 +1,10 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import createDebug from 'debug';
3
- import { s } from './chunk-browser.mjs';
3
+ import { C } from './chunk-index.mjs';
4
4
  import { normalizeRequestId } from './utils.mjs';
5
5
 
6
6
  function createHmrEmitter() {
7
- const emitter = new EventEmitter();
8
- return emitter;
7
+ return new EventEmitter();
9
8
  }
10
9
  function viteNodeHmrPlugin() {
11
10
  const emitter = createHmrEmitter();
@@ -56,7 +55,7 @@ async function reload(runner, files) {
56
55
  }), Promise.all(files.map((file) => runner.executeId(file)));
57
56
  }
58
57
  async function notifyListeners(runner, event, data) {
59
- const maps = getCache(runner), cbs = maps.customListenersMap.get(event);
58
+ const cbs = getCache(runner).customListenersMap.get(event);
60
59
  if (cbs) await Promise.all(cbs.map((cb) => cb(data)));
61
60
  }
62
61
  async function queueUpdate(runner, p) {
@@ -91,7 +90,7 @@ async function fetchUpdate(runner, { path, acceptedPath }) {
91
90
  return () => {
92
91
  for (const { deps, fn } of qualifiedCallbacks) fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
93
92
  const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
94
- console.log(`${s.cyan("[vite-node]")} hot updated: ${loggedPath}`);
93
+ console.log(`${C.cyan("[vite-node]")} hot updated: ${loggedPath}`);
95
94
  };
96
95
  }
97
96
  function warnFailedFetch(err, path) {
@@ -106,7 +105,7 @@ async function handleMessage(runner, emitter, files, payload) {
106
105
  break;
107
106
  case "update":
108
107
  await notifyListeners(runner, "vite:beforeUpdate", payload), await Promise.all(payload.updates.map((update) => {
109
- return update.type === "js-update" ? queueUpdate(runner, fetchUpdate(runner, update)) : (console.error(`${s.cyan("[vite-node]")} no support css hmr.}`), null);
108
+ return update.type === "js-update" ? queueUpdate(runner, fetchUpdate(runner, update)) : (console.error(`${C.cyan("[vite-node]")} no support css hmr.}`), null);
110
109
  })), await notifyListeners(runner, "vite:afterUpdate", payload);
111
110
  break;
112
111
  case "full-reload":
@@ -124,7 +123,7 @@ async function handleMessage(runner, emitter, files, payload) {
124
123
  case "error": {
125
124
  await notifyListeners(runner, "vite:error", payload);
126
125
  const err = payload.err;
127
- console.error(`${s.cyan("[vite-node]")} Internal Server Error\n${err.message}\n${err.stack}`);
126
+ console.error(`${C.cyan("[vite-node]")} Internal Server Error\n${err.message}\n${err.stack}`);
128
127
  break;
129
128
  }
130
129
  }
@@ -149,7 +148,7 @@ function createHotContext(runner, emitter, files, ownerPath) {
149
148
  fn: callback
150
149
  }), maps.hotModulesMap.set(ownerPath, mod);
151
150
  }
152
- const hot = {
151
+ return {
153
152
  get data() {
154
153
  return maps.dataMap.get(ownerPath);
155
154
  },
@@ -207,7 +206,6 @@ function createHotContext(runner, emitter, files, ownerPath) {
207
206
  })), sendMessageBuffer(runner, emitter);
208
207
  }
209
208
  };
210
- return hot;
211
209
  }
212
210
 
213
211
  export { createHotContext as a, createHmrEmitter as c, getCache as g, handleMessage as h, reload as r, sendMessageBuffer as s, viteNodeHmrPlugin as v };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  // src/index.ts
4
- var f = {
4
+ var d = {
5
5
  reset: [0, 0],
6
6
  bold: [1, 22, "\x1B[22m\x1B[1m"],
7
7
  dim: [2, 22, "\x1B[22m\x1B[2m"],
@@ -43,41 +43,42 @@ var f = {
43
43
  bgMagentaBright: [105, 49],
44
44
  bgCyanBright: [106, 49],
45
45
  bgWhiteBright: [107, 49]
46
- }, h = Object.entries(f);
47
- function a(n) {
48
- return String(n);
46
+ };
47
+ function g(e) {
48
+ return String(e);
49
49
  }
50
- a.open = "";
51
- a.close = "";
52
- function C(n = false) {
53
- let e = typeof process != "undefined" ? process : void 0, i = (e == null ? void 0 : e.env) || {}, g = (e == null ? void 0 : e.argv) || [];
54
- return !("NO_COLOR" in i || g.includes("--no-color")) && ("FORCE_COLOR" in i || g.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || n && i.TERM !== "dumb" || "CI" in i) || typeof window != "undefined" && !!window.chrome;
50
+ g.open = "";
51
+ g.close = "";
52
+ function h() {
53
+ let e = typeof process != "undefined" ? process : void 0, n = (e == null ? void 0 : e.env) || {}, a = n.FORCE_TTY !== "false", i = (e == null ? void 0 : e.argv) || [];
54
+ return !("NO_COLOR" in n || i.includes("--no-color")) && ("FORCE_COLOR" in n || i.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || a && n.TERM !== "dumb" || "CI" in n) || typeof window != "undefined" && !!window.chrome;
55
55
  }
56
- function p(n = false) {
57
- let e = C(n), i = (r, t, c, o) => {
56
+ function f() {
57
+ let e = h(), n = (r, t, u, o) => {
58
58
  let l = "", s = 0;
59
59
  do
60
- l += r.substring(s, o) + c, s = o + t.length, o = r.indexOf(t, s);
60
+ l += r.substring(s, o) + u, s = o + t.length, o = r.indexOf(t, s);
61
61
  while (~o);
62
62
  return l + r.substring(s);
63
- }, g = (r, t, c = r) => {
63
+ }, a = (r, t, u = r) => {
64
64
  let o = (l) => {
65
65
  let s = String(l), b = s.indexOf(t, r.length);
66
- return ~b ? r + i(s, t, c, b) + t : r + s + t;
66
+ return ~b ? r + n(s, t, u, b) + t : r + s + t;
67
67
  };
68
68
  return o.open = r, o.close = t, o;
69
- }, u = {
69
+ }, i = {
70
70
  isColorSupported: e
71
- }, d = (r) => `\x1B[${r}m`;
72
- for (let [r, t] of h)
73
- u[r] = e ? g(
74
- d(t[0]),
75
- d(t[1]),
71
+ }, c = (r) => `\x1B[${r}m`;
72
+ for (let r in d) {
73
+ let t = d[r];
74
+ i[r] = e ? a(
75
+ c(t[0]),
76
+ c(t[1]),
76
77
  t[2]
77
- ) : a;
78
- return u;
78
+ ) : g;
79
+ }
80
+ return i;
79
81
  }
82
+ var C = f();
80
83
 
81
- var s = p();
82
-
83
- exports.s = s;
84
+ exports.C = C;
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- var f = {
2
+ var d = {
3
3
  reset: [0, 0],
4
4
  bold: [1, 22, "\x1B[22m\x1B[1m"],
5
5
  dim: [2, 22, "\x1B[22m\x1B[2m"],
@@ -41,41 +41,42 @@ var f = {
41
41
  bgMagentaBright: [105, 49],
42
42
  bgCyanBright: [106, 49],
43
43
  bgWhiteBright: [107, 49]
44
- }, h = Object.entries(f);
45
- function a(n) {
46
- return String(n);
44
+ };
45
+ function g(e) {
46
+ return String(e);
47
47
  }
48
- a.open = "";
49
- a.close = "";
50
- function C(n = false) {
51
- let e = typeof process != "undefined" ? process : void 0, i = (e == null ? void 0 : e.env) || {}, g = (e == null ? void 0 : e.argv) || [];
52
- return !("NO_COLOR" in i || g.includes("--no-color")) && ("FORCE_COLOR" in i || g.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || n && i.TERM !== "dumb" || "CI" in i) || typeof window != "undefined" && !!window.chrome;
48
+ g.open = "";
49
+ g.close = "";
50
+ function h() {
51
+ let e = typeof process != "undefined" ? process : void 0, n = (e == null ? void 0 : e.env) || {}, a = n.FORCE_TTY !== "false", i = (e == null ? void 0 : e.argv) || [];
52
+ return !("NO_COLOR" in n || i.includes("--no-color")) && ("FORCE_COLOR" in n || i.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || a && n.TERM !== "dumb" || "CI" in n) || typeof window != "undefined" && !!window.chrome;
53
53
  }
54
- function p(n = false) {
55
- let e = C(n), i = (r, t, c, o) => {
54
+ function f() {
55
+ let e = h(), n = (r, t, u, o) => {
56
56
  let l = "", s = 0;
57
57
  do
58
- l += r.substring(s, o) + c, s = o + t.length, o = r.indexOf(t, s);
58
+ l += r.substring(s, o) + u, s = o + t.length, o = r.indexOf(t, s);
59
59
  while (~o);
60
60
  return l + r.substring(s);
61
- }, g = (r, t, c = r) => {
61
+ }, a = (r, t, u = r) => {
62
62
  let o = (l) => {
63
63
  let s = String(l), b = s.indexOf(t, r.length);
64
- return ~b ? r + i(s, t, c, b) + t : r + s + t;
64
+ return ~b ? r + n(s, t, u, b) + t : r + s + t;
65
65
  };
66
66
  return o.open = r, o.close = t, o;
67
- }, u = {
67
+ }, i = {
68
68
  isColorSupported: e
69
- }, d = (r) => `\x1B[${r}m`;
70
- for (let [r, t] of h)
71
- u[r] = e ? g(
72
- d(t[0]),
73
- d(t[1]),
69
+ }, c = (r) => `\x1B[${r}m`;
70
+ for (let r in d) {
71
+ let t = d[r];
72
+ i[r] = e ? a(
73
+ c(t[0]),
74
+ c(t[1]),
74
75
  t[2]
75
- ) : a;
76
- return u;
76
+ ) : g;
77
+ }
78
+ return i;
77
79
  }
80
+ var C = f();
78
81
 
79
- var s = p();
80
-
81
- export { s };
82
+ export { C };
package/dist/cli.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  var path = require('node:path');
4
4
  var cac = require('cac');
5
- var browser = require('./chunk-browser.cjs');
5
+ var index = require('./chunk-index.cjs');
6
6
  var vite = require('vite');
7
7
  var client = require('./client.cjs');
8
8
  var hmr = require('./chunk-hmr.cjs');
@@ -21,7 +21,7 @@ require('node:perf_hooks');
21
21
  require('es-module-lexer');
22
22
  require('./constants.cjs');
23
23
 
24
- var version = "4.0.0-beta.10";
24
+ var version = "4.0.0-beta.12";
25
25
 
26
26
  const cli = cac("vite-node");
27
27
  if (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"), cli.command("[...files]").allowUnknownOptions().action(run), cli.parse(process.argv, { run: false }), cli.args.length === 0) cli.runMatchedCommand();
@@ -43,7 +43,7 @@ async function run(files, options = {}) {
43
43
  else process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
44
44
  if (options.version) cli.version(version), cli.outputVersion(), process.exit(0);
45
45
  if (options.help) cli.version(version).outputHelp(), process.exit(0);
46
- if (!files.length) console.error(browser.s.red("No files specified.")), cli.version(version).outputHelp(), process.exit(1);
46
+ if (!files.length) console.error(index.C.red("No files specified.")), cli.version(version).outputHelp(), process.exit(1);
47
47
  const serverOptions = options.options ? parseServerOptions(options.options) : {}, server$1 = await vite.createServer({
48
48
  logLevel: "error",
49
49
  configFile: options.config,
@@ -86,7 +86,7 @@ async function run(files, options = {}) {
86
86
  if ((_server$emitter = server$1.emitter) === null || _server$emitter === void 0 || _server$emitter.on("message", (payload) => {
87
87
  hmr.handleMessage(runner, server$1.emitter, files, payload);
88
88
  }), options.watch) process.on("uncaughtException", (err) => {
89
- console.error(browser.s.red("[vite-node] Failed to execute file: \n"), err);
89
+ console.error(index.C.red("[vite-node] Failed to execute file: \n"), err);
90
90
  });
91
91
  }
92
92
  function parseServerOptions(serverOptions) {
@@ -98,10 +98,10 @@ function parseServerOptions(serverOptions) {
98
98
  ...serverOptions.deps,
99
99
  inlineFiles: utils.toArray((_serverOptions$deps3 = serverOptions.deps) === null || _serverOptions$deps3 === void 0 ? void 0 : _serverOptions$deps3.inlineFiles),
100
100
  inline: inlineOptions !== true ? inlineOptions.map((dep) => {
101
- return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
101
+ return dep[0] === "/" && dep.endsWith("/") ? new RegExp(dep) : dep;
102
102
  }) : true,
103
103
  external: utils.toArray((_serverOptions$deps4 = serverOptions.deps) === null || _serverOptions$deps4 === void 0 ? void 0 : _serverOptions$deps4.external).map((dep) => {
104
- return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
104
+ return dep[0] === "/" && dep.endsWith("/") ? new RegExp(dep) : dep;
105
105
  }),
106
106
  moduleDirectories: ((_serverOptions$deps5 = serverOptions.deps) === null || _serverOptions$deps5 === void 0 ? void 0 : _serverOptions$deps5.moduleDirectories) ? utils.toArray((_serverOptions$deps6 = serverOptions.deps) === null || _serverOptions$deps6 === void 0 ? void 0 : _serverOptions$deps6.moduleDirectories) : void 0
107
107
  },
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { resolve } from 'node:path';
2
2
  import cac from 'cac';
3
- import { s } from './chunk-browser.mjs';
3
+ import { C } from './chunk-index.mjs';
4
4
  import { createServer, version as version$1, loadEnv } from 'vite';
5
5
  import { ViteNodeRunner } from './client.mjs';
6
6
  import { v as viteNodeHmrPlugin, a as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
@@ -19,7 +19,7 @@ import 'node:perf_hooks';
19
19
  import 'es-module-lexer';
20
20
  import './constants.mjs';
21
21
 
22
- var version = "4.0.0-beta.10";
22
+ var version = "4.0.0-beta.12";
23
23
 
24
24
  const cli = cac("vite-node");
25
25
  if (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"), cli.command("[...files]").allowUnknownOptions().action(run), cli.parse(process.argv, { run: false }), cli.args.length === 0) cli.runMatchedCommand();
@@ -41,7 +41,7 @@ async function run(files, options = {}) {
41
41
  else process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
42
42
  if (options.version) cli.version(version), cli.outputVersion(), process.exit(0);
43
43
  if (options.help) cli.version(version).outputHelp(), process.exit(0);
44
- if (!files.length) console.error(s.red("No files specified.")), cli.version(version).outputHelp(), process.exit(1);
44
+ if (!files.length) console.error(C.red("No files specified.")), cli.version(version).outputHelp(), process.exit(1);
45
45
  const serverOptions = options.options ? parseServerOptions(options.options) : {}, server = await createServer({
46
46
  logLevel: "error",
47
47
  configFile: options.config,
@@ -84,7 +84,7 @@ async function run(files, options = {}) {
84
84
  if ((_server$emitter = server.emitter) === null || _server$emitter === void 0 || _server$emitter.on("message", (payload) => {
85
85
  handleMessage(runner, server.emitter, files, payload);
86
86
  }), options.watch) process.on("uncaughtException", (err) => {
87
- console.error(s.red("[vite-node] Failed to execute file: \n"), err);
87
+ console.error(C.red("[vite-node] Failed to execute file: \n"), err);
88
88
  });
89
89
  }
90
90
  function parseServerOptions(serverOptions) {
@@ -96,10 +96,10 @@ function parseServerOptions(serverOptions) {
96
96
  ...serverOptions.deps,
97
97
  inlineFiles: toArray((_serverOptions$deps3 = serverOptions.deps) === null || _serverOptions$deps3 === void 0 ? void 0 : _serverOptions$deps3.inlineFiles),
98
98
  inline: inlineOptions !== true ? inlineOptions.map((dep) => {
99
- return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
99
+ return dep[0] === "/" && dep.endsWith("/") ? new RegExp(dep) : dep;
100
100
  }) : true,
101
101
  external: toArray((_serverOptions$deps4 = serverOptions.deps) === null || _serverOptions$deps4 === void 0 ? void 0 : _serverOptions$deps4.external).map((dep) => {
102
- return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
102
+ return dep[0] === "/" && dep.endsWith("/") ? new RegExp(dep) : dep;
103
103
  }),
104
104
  moduleDirectories: ((_serverOptions$deps5 = serverOptions.deps) === null || _serverOptions$deps5 === void 0 ? void 0 : _serverOptions$deps5.moduleDirectories) ? toArray((_serverOptions$deps6 = serverOptions.deps) === null || _serverOptions$deps6 === void 0 ? void 0 : _serverOptions$deps6.moduleDirectories) : void 0
105
105
  },
package/dist/client.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var node_module = require('node:module');
3
+ var nodeModule = require('node:module');
4
4
  var path = require('node:path');
5
5
  var node_url = require('node:url');
6
6
  var vm = require('node:vm');
@@ -231,8 +231,8 @@ class ViteNodeRunner {
231
231
  /** @internal */
232
232
  async directRequest(id, fsPath, _callstack) {
233
233
  const moduleId = utils.normalizeModuleId(fsPath), callstack = [..._callstack, moduleId], mod = this.moduleCache.getByModuleId(moduleId), request = async (dep) => {
234
- const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath), depMod = this.moduleCache.getByModuleId(depFsPath);
235
- return depMod.importers.add(moduleId), mod.imports.add(depFsPath), this.dependencyRequest(id, depFsPath, callstack);
234
+ const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath);
235
+ return this.moduleCache.getByModuleId(depFsPath).importers.add(moduleId), mod.imports.add(depFsPath), this.dependencyRequest(id, depFsPath, callstack);
236
236
  }, requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
237
237
  if (id in requestStubs) return requestStubs[id];
238
238
  let { code: transformed, externalize } = await this._fetchModule(id, callstack[callstack.length - 2]);
@@ -314,7 +314,7 @@ class ViteNodeRunner {
314
314
  get: getter
315
315
  }),
316
316
  __vite_ssr_import_meta__: meta,
317
- require: node_module.createRequire(href),
317
+ require: nodeModule.createRequire(href),
318
318
  exports: cjsExports,
319
319
  module: moduleProxy,
320
320
  __filename,
@@ -339,8 +339,7 @@ class ViteNodeRunner {
339
339
  columnOffset: -codeDefinition.length
340
340
  }, finishModuleExecutionInfo = this.startCalculateModuleExecutionInfo(options.filename, codeDefinition.length);
341
341
  try {
342
- const fn = vm.runInThisContext(code, options);
343
- await fn(...Object.values(context));
342
+ await vm.runInThisContext(code, options)(...Object.values(context));
344
343
  } finally {
345
344
  var _this$options$moduleE;
346
345
  (_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, finishModuleExecutionInfo());
package/dist/client.mjs CHANGED
@@ -229,8 +229,8 @@ class ViteNodeRunner {
229
229
  /** @internal */
230
230
  async directRequest(id, fsPath, _callstack) {
231
231
  const moduleId = normalizeModuleId(fsPath), callstack = [..._callstack, moduleId], mod = this.moduleCache.getByModuleId(moduleId), request = async (dep) => {
232
- const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath), depMod = this.moduleCache.getByModuleId(depFsPath);
233
- return depMod.importers.add(moduleId), mod.imports.add(depFsPath), this.dependencyRequest(id, depFsPath, callstack);
232
+ const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath);
233
+ return this.moduleCache.getByModuleId(depFsPath).importers.add(moduleId), mod.imports.add(depFsPath), this.dependencyRequest(id, depFsPath, callstack);
234
234
  }, requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
235
235
  if (id in requestStubs) return requestStubs[id];
236
236
  let { code: transformed, externalize } = await this._fetchModule(id, callstack[callstack.length - 2]);
@@ -337,8 +337,7 @@ class ViteNodeRunner {
337
337
  columnOffset: -codeDefinition.length
338
338
  }, finishModuleExecutionInfo = this.startCalculateModuleExecutionInfo(options.filename, codeDefinition.length);
339
339
  try {
340
- const fn = vm.runInThisContext(code, options);
341
- await fn(...Object.values(context));
340
+ await vm.runInThisContext(code, options)(...Object.values(context));
342
341
  } finally {
343
342
  var _this$options$moduleE;
344
343
  (_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, finishModuleExecutionInfo());
package/dist/hmr.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  var hmr = require('./chunk-hmr.cjs');
4
4
  require('node:events');
5
5
  require('debug');
6
- require('./chunk-browser.cjs');
6
+ require('./chunk-index.cjs');
7
7
  require('./utils.cjs');
8
8
  require('node:fs');
9
9
  require('node:module');
package/dist/hmr.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  export { c as createHmrEmitter, a as createHotContext, g as getCache, h as handleMessage, r as reload, s as sendMessageBuffer, v as viteNodeHmrPlugin } from './chunk-hmr.mjs';
2
2
  import 'node:events';
3
3
  import 'debug';
4
- import './chunk-browser.mjs';
4
+ import './chunk-index.mjs';
5
5
  import './utils.mjs';
6
6
  import 'node:fs';
7
7
  import 'node:module';
package/dist/server.cjs CHANGED
@@ -7,7 +7,7 @@ var node_url = require('node:url');
7
7
  var createDebug = require('debug');
8
8
  var pathe = require('pathe');
9
9
  var vite = require('vite');
10
- var browser = require('./chunk-browser.cjs');
10
+ var index = require('./chunk-index.cjs');
11
11
  var esModuleLexer = require('es-module-lexer');
12
12
  var constants = require('./constants.cjs');
13
13
  var utils = require('./utils.cjs');
@@ -46,8 +46,8 @@ class Debugger {
46
46
  externalizeMap = /* @__PURE__ */ new Map();
47
47
  constructor(root, options) {
48
48
  if (this.options = options, options.dumpModules) this.dumpDir = pathe.resolve(root, options.dumpModules === true ? ".vite-node/dump" : options.dumpModules);
49
- if (this.dumpDir) if (options.loadDumppedModules) console.info(browser.s.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`));
50
- else console.info(browser.s.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`));
49
+ if (this.dumpDir) if (options.loadDumppedModules) console.info(index.C.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`));
50
+ else console.info(index.C.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`));
51
51
  this.initPromise = this.clearDump();
52
52
  }
53
53
  async clearDump() {
@@ -75,12 +75,10 @@ class Debugger {
75
75
  if (!this.dumpDir) return null;
76
76
  await this.initPromise;
77
77
  const name = this.encodeId(id), path = pathe.join(this.dumpDir, name);
78
- if (!fs.existsSync(path)) return null;
79
- const code = await fs.promises.readFile(path, "utf-8");
80
- return {
81
- code: code.replace(/^\/\/.*\n/, ""),
78
+ return fs.existsSync(path) ? {
79
+ code: (await fs.promises.readFile(path, "utf-8")).replace(/^\/\/.*\n/, ""),
82
80
  map: void 0
83
- };
81
+ } : null;
84
82
  }
85
83
  async writeInfo() {
86
84
  if (!this.dumpDir) return;
@@ -126,9 +124,7 @@ async function isValidNodeImport(id) {
126
124
  const extension = pathe.extname(id);
127
125
  if (BUILTIN_EXTENSIONS.has(extension)) return true;
128
126
  if (extension !== ".js") return false;
129
- id = id.replace("file:///", "");
130
- const package_ = await utils.findNearestPackageData(pathe.dirname(id));
131
- if (package_.type === "module") return true;
127
+ if (id = id.replace("file:///", ""), (await utils.findNearestPackageData(pathe.dirname(id))).type === "module") return true;
132
128
  if (/\.(?:\w+-)?esm?(?:-\w+)?\.js$|\/esm?\//.test(id)) return false;
133
129
  try {
134
130
  await esModuleLexer__namespace.init;
@@ -154,8 +150,8 @@ async function _shouldExternalize(id, options) {
154
150
  // Unless the user explicitly opted to inline them, externalize Vite deps.
155
151
  // They are too big to inline by default.
156
152
  if (matchExternalizePattern(id, moduleDirectories, options === null || options === void 0 ? void 0 : options.external) || (options === null || options === void 0 ? void 0 : options.cacheDir) && id.includes(options.cacheDir)) return id;
157
- const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir)), guessCJS = isLibraryModule && (options === null || options === void 0 ? void 0 : options.fallbackCJS);
158
- return id = guessCJS ? guessCJSversion(id) || id : id, matchExternalizePattern(id, moduleDirectories, defaultInline) ? false : matchExternalizePattern(id, moduleDirectories, depsExternal) || isLibraryModule && await isValidNodeImport(id) ? id : false;
153
+ const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir));
154
+ return id = isLibraryModule && (options === null || options === void 0 ? void 0 : options.fallbackCJS) ? guessCJSversion(id) || id : id, matchExternalizePattern(id, moduleDirectories, defaultInline) ? false : matchExternalizePattern(id, moduleDirectories, depsExternal) || isLibraryModule && await isValidNodeImport(id) ? id : false;
159
155
  }
160
156
  function matchExternalizePattern(id, moduleDirectories, patterns) {
161
157
  if (patterns == null) return false;
@@ -226,7 +222,7 @@ class ViteNodeServer {
226
222
  if (customModuleDirectories) options.deps.moduleDirectories.push(...customModuleDirectories);
227
223
  // always add node_modules as a module directory
228
224
  if (options.deps.moduleDirectories = options.deps.moduleDirectories.map((dir) => {
229
- if (!dir.startsWith("/")) dir = `/${dir}`;
225
+ if (dir[0] !== "/") dir = `/${dir}`;
230
226
  if (!dir.endsWith("/")) dir += "/";
231
227
  return pathe.normalize(dir);
232
228
  }), !options.deps.moduleDirectories.includes("/node_modules/")) options.deps.moduleDirectories.push("/node_modules/");
@@ -307,9 +303,7 @@ class ViteNodeServer {
307
303
  if (module) return module;
308
304
  const _modules = this.server.moduleGraph.getModulesByFile(file);
309
305
  if (!_modules || !_modules.size) return null;
310
- // find the latest changed module
311
- const modules = [..._modules];
312
- let mod = modules[0], latestMax = -1;
306
+ let mod = [..._modules][0], latestMax = -1;
313
307
  for (const m of _modules) {
314
308
  const timestamp = Math.max(m.lastHMRTimestamp, m.lastInvalidationTimestamp);
315
309
  if (timestamp > latestMax) latestMax = timestamp, mod = m;
@@ -367,8 +361,7 @@ class ViteNodeServer {
367
361
  if (transformMode === "web") {
368
362
  if (result = await this.server.transformRequest(id), result) result = await this.server.ssrTransform(result.code, result.map, id);
369
363
  } else result = await this.server.transformRequest(id, { ssr: true });
370
- const sourcemap = this.options.sourcemap ?? "inline";
371
- if (sourcemap === "inline" && result) result = await this.processTransformResult(filepath, result);
364
+ if ((this.options.sourcemap ?? "inline") === "inline" && result) result = await this.processTransformResult(filepath, result);
372
365
  if ((_this$options$debug2 = this.options.debug) === null || _this$options$debug2 === void 0 ? void 0 : _this$options$debug2.dumpModules) {
373
366
  var _this$debugger3;
374
367
  await ((_this$debugger3 = this.debugger) === null || _this$debugger3 === void 0 ? void 0 : _this$debugger3.dumpFile(id, result));
package/dist/server.mjs CHANGED
@@ -5,7 +5,7 @@ import { pathToFileURL } from 'node:url';
5
5
  import createDebug from 'debug';
6
6
  import { resolve, join, extname, dirname, relative, normalize } from 'pathe';
7
7
  import { version } from 'vite';
8
- import { s } from './chunk-browser.mjs';
8
+ import { C } from './chunk-index.mjs';
9
9
  import * as esModuleLexer from 'es-module-lexer';
10
10
  import { KNOWN_ASSET_RE } from './constants.mjs';
11
11
  import { isNodeBuiltin, slash, findNearestPackageData, toArray, withTrailingSlash, normalizeModuleId, toFilePath } from './utils.mjs';
@@ -25,8 +25,8 @@ class Debugger {
25
25
  externalizeMap = /* @__PURE__ */ new Map();
26
26
  constructor(root, options) {
27
27
  if (this.options = options, options.dumpModules) this.dumpDir = resolve(root, options.dumpModules === true ? ".vite-node/dump" : options.dumpModules);
28
- if (this.dumpDir) if (options.loadDumppedModules) console.info(s.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`));
29
- else console.info(s.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`));
28
+ if (this.dumpDir) if (options.loadDumppedModules) console.info(C.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`));
29
+ else console.info(C.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`));
30
30
  this.initPromise = this.clearDump();
31
31
  }
32
32
  async clearDump() {
@@ -54,12 +54,10 @@ class Debugger {
54
54
  if (!this.dumpDir) return null;
55
55
  await this.initPromise;
56
56
  const name = this.encodeId(id), path = join(this.dumpDir, name);
57
- if (!existsSync(path)) return null;
58
- const code = await promises.readFile(path, "utf-8");
59
- return {
60
- code: code.replace(/^\/\/.*\n/, ""),
57
+ return existsSync(path) ? {
58
+ code: (await promises.readFile(path, "utf-8")).replace(/^\/\/.*\n/, ""),
61
59
  map: void 0
62
- };
60
+ } : null;
63
61
  }
64
62
  async writeInfo() {
65
63
  if (!this.dumpDir) return;
@@ -105,9 +103,7 @@ async function isValidNodeImport(id) {
105
103
  const extension = extname(id);
106
104
  if (BUILTIN_EXTENSIONS.has(extension)) return true;
107
105
  if (extension !== ".js") return false;
108
- id = id.replace("file:///", "");
109
- const package_ = await findNearestPackageData(dirname(id));
110
- if (package_.type === "module") return true;
106
+ if (id = id.replace("file:///", ""), (await findNearestPackageData(dirname(id))).type === "module") return true;
111
107
  if (/\.(?:\w+-)?esm?(?:-\w+)?\.js$|\/esm?\//.test(id)) return false;
112
108
  try {
113
109
  await esModuleLexer.init;
@@ -133,8 +129,8 @@ async function _shouldExternalize(id, options) {
133
129
  // Unless the user explicitly opted to inline them, externalize Vite deps.
134
130
  // They are too big to inline by default.
135
131
  if (matchExternalizePattern(id, moduleDirectories, options === null || options === void 0 ? void 0 : options.external) || (options === null || options === void 0 ? void 0 : options.cacheDir) && id.includes(options.cacheDir)) return id;
136
- const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir)), guessCJS = isLibraryModule && (options === null || options === void 0 ? void 0 : options.fallbackCJS);
137
- return id = guessCJS ? guessCJSversion(id) || id : id, matchExternalizePattern(id, moduleDirectories, defaultInline) ? false : matchExternalizePattern(id, moduleDirectories, depsExternal) || isLibraryModule && await isValidNodeImport(id) ? id : false;
132
+ const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir));
133
+ return id = isLibraryModule && (options === null || options === void 0 ? void 0 : options.fallbackCJS) ? guessCJSversion(id) || id : id, matchExternalizePattern(id, moduleDirectories, defaultInline) ? false : matchExternalizePattern(id, moduleDirectories, depsExternal) || isLibraryModule && await isValidNodeImport(id) ? id : false;
138
134
  }
139
135
  function matchExternalizePattern(id, moduleDirectories, patterns) {
140
136
  if (patterns == null) return false;
@@ -205,7 +201,7 @@ class ViteNodeServer {
205
201
  if (customModuleDirectories) options.deps.moduleDirectories.push(...customModuleDirectories);
206
202
  // always add node_modules as a module directory
207
203
  if (options.deps.moduleDirectories = options.deps.moduleDirectories.map((dir) => {
208
- if (!dir.startsWith("/")) dir = `/${dir}`;
204
+ if (dir[0] !== "/") dir = `/${dir}`;
209
205
  if (!dir.endsWith("/")) dir += "/";
210
206
  return normalize(dir);
211
207
  }), !options.deps.moduleDirectories.includes("/node_modules/")) options.deps.moduleDirectories.push("/node_modules/");
@@ -286,9 +282,7 @@ class ViteNodeServer {
286
282
  if (module) return module;
287
283
  const _modules = this.server.moduleGraph.getModulesByFile(file);
288
284
  if (!_modules || !_modules.size) return null;
289
- // find the latest changed module
290
- const modules = [..._modules];
291
- let mod = modules[0], latestMax = -1;
285
+ let mod = [..._modules][0], latestMax = -1;
292
286
  for (const m of _modules) {
293
287
  const timestamp = Math.max(m.lastHMRTimestamp, m.lastInvalidationTimestamp);
294
288
  if (timestamp > latestMax) latestMax = timestamp, mod = m;
@@ -346,8 +340,7 @@ class ViteNodeServer {
346
340
  if (transformMode === "web") {
347
341
  if (result = await this.server.transformRequest(id), result) result = await this.server.ssrTransform(result.code, result.map, id);
348
342
  } else result = await this.server.transformRequest(id, { ssr: true });
349
- const sourcemap = this.options.sourcemap ?? "inline";
350
- if (sourcemap === "inline" && result) result = await this.processTransformResult(filepath, result);
343
+ if ((this.options.sourcemap ?? "inline") === "inline" && result) result = await this.processTransformResult(filepath, result);
351
344
  if ((_this$options$debug2 = this.options.debug) === null || _this$options$debug2 === void 0 ? void 0 : _this$options$debug2.dumpModules) {
352
345
  var _this$debugger3;
353
346
  await ((_this$debugger3 = this.debugger) === null || _this$debugger3 === void 0 ? void 0 : _this$debugger3.dumpFile(id, result));