vite-node 4.0.0-beta.5 → 4.0.0-beta.6

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021-Present Vitest Team
3
+ Copyright (c) 2021-Present VoidZero Inc. and Vitest contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -19,24 +19,20 @@ function viteNodeHmrPlugin() {
19
19
  },
20
20
  configureServer(server) {
21
21
  const _send = server.ws.send;
22
- server.emitter = emitter;
23
- server.ws.send = function(payload) {
24
- _send(payload);
25
- emitter.emit("message", payload);
22
+ server.emitter = emitter, server.ws.send = function(payload) {
23
+ _send(payload), emitter.emit("message", payload);
26
24
  };
27
25
  // eslint-disable-next-line ts/ban-ts-comment
28
26
  // @ts-ignore Vite 6 compat
29
27
  const environments = server.environments;
30
28
  if (environments) environments.ssr.hot.send = function(payload) {
31
- _send(payload);
32
- emitter.emit("message", payload);
29
+ _send(payload), emitter.emit("message", payload);
33
30
  };
34
31
  }
35
32
  };
36
33
  }
37
34
 
38
- const debugHmr = createDebug("vite-node:hmr");
39
- const cache = /* @__PURE__ */ new WeakMap();
35
+ const debugHmr = createDebug("vite-node:hmr"), cache = /* @__PURE__ */ new WeakMap();
40
36
  function getCache(runner) {
41
37
  if (!cache.has(runner)) cache.set(runner, {
42
38
  hotModulesMap: /* @__PURE__ */ new Map(),
@@ -54,38 +50,28 @@ function getCache(runner) {
54
50
  }
55
51
  function sendMessageBuffer(runner, emitter) {
56
52
  const maps = getCache(runner);
57
- maps.messageBuffer.forEach((msg) => emitter.emit("custom", msg));
58
- maps.messageBuffer.length = 0;
53
+ maps.messageBuffer.forEach((msg) => emitter.emit("custom", msg)), maps.messageBuffer.length = 0;
59
54
  }
60
55
  async function reload(runner, files) {
61
- // invalidate module cache but not node_modules
62
- Array.from(runner.moduleCache.keys()).forEach((fsPath) => {
56
+ return Array.from(runner.moduleCache.keys()).forEach((fsPath) => {
63
57
  if (!fsPath.includes("node_modules")) runner.moduleCache.delete(fsPath);
64
- });
65
- return Promise.all(files.map((file) => runner.executeId(file)));
58
+ }), Promise.all(files.map((file) => runner.executeId(file)));
66
59
  }
67
60
  async function notifyListeners(runner, event, data) {
68
- const maps = getCache(runner);
69
- const cbs = maps.customListenersMap.get(event);
61
+ const maps = getCache(runner), cbs = maps.customListenersMap.get(event);
70
62
  if (cbs) await Promise.all(cbs.map((cb) => cb(data)));
71
63
  }
72
64
  async function queueUpdate(runner, p) {
73
65
  const maps = getCache(runner);
74
- maps.queued.push(p);
75
- if (!maps.pending) {
76
- maps.pending = true;
77
- await Promise.resolve();
78
- maps.pending = false;
66
+ if (maps.queued.push(p), !maps.pending) {
67
+ maps.pending = true, await Promise.resolve(), maps.pending = false;
79
68
  const loading = [...maps.queued];
80
- maps.queued = [];
81
- (await Promise.all(loading)).forEach((fn) => fn && fn());
69
+ maps.queued = [], (await Promise.all(loading)).forEach((fn) => fn && fn());
82
70
  }
83
71
  }
84
72
  async function fetchUpdate(runner, { path, acceptedPath }) {
85
- path = utils.normalizeRequestId(path);
86
- acceptedPath = utils.normalizeRequestId(acceptedPath);
87
- const maps = getCache(runner);
88
- const mod = maps.hotModulesMap.get(path);
73
+ path = utils.normalizeRequestId(path), acceptedPath = utils.normalizeRequestId(acceptedPath);
74
+ const maps = getCache(runner), mod = maps.hotModulesMap.get(path);
89
75
  if (!mod)
90
76
  // In a code-splitting project,
91
77
  // it is common that the hot-updating module is not loaded yet.
@@ -121,26 +107,18 @@ async function handleMessage(runner, emitter, files, payload) {
121
107
  sendMessageBuffer(runner, emitter);
122
108
  break;
123
109
  case "update":
124
- await notifyListeners(runner, "vite:beforeUpdate", payload);
125
- await Promise.all(payload.updates.map((update) => {
126
- if (update.type === "js-update") return queueUpdate(runner, fetchUpdate(runner, update));
127
- // css-update
128
- console.error(`${browser.s.cyan("[vite-node]")} no support css hmr.}`);
129
- return null;
130
- }));
131
- await notifyListeners(runner, "vite:afterUpdate", payload);
110
+ 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);
112
+ })), await notifyListeners(runner, "vite:afterUpdate", payload);
132
113
  break;
133
114
  case "full-reload":
134
- await notifyListeners(runner, "vite:beforeFullReload", payload);
135
- maps.customListenersMap.delete("vite:beforeFullReload");
136
- await reload(runner, files);
115
+ await notifyListeners(runner, "vite:beforeFullReload", payload), maps.customListenersMap.delete("vite:beforeFullReload"), await reload(runner, files);
137
116
  break;
138
117
  case "custom":
139
118
  await notifyListeners(runner, payload.event, payload.data);
140
119
  break;
141
120
  case "prune":
142
- await notifyListeners(runner, "vite:beforePrune", payload);
143
- payload.paths.forEach((path) => {
121
+ await notifyListeners(runner, "vite:beforePrune", payload), payload.paths.forEach((path) => {
144
122
  const fn = maps.pruneMap.get(path);
145
123
  if (fn) fn(maps.dataMap.get(path));
146
124
  });
@@ -171,8 +149,7 @@ function createHotContext(runner, emitter, files, ownerPath) {
171
149
  mod.callbacks.push({
172
150
  deps,
173
151
  fn: callback
174
- });
175
- maps.hotModulesMap.set(ownerPath, mod);
152
+ }), maps.hotModulesMap.set(ownerPath, mod);
176
153
  }
177
154
  const hot = {
178
155
  get data() {
@@ -198,21 +175,18 @@ function createHotContext(runner, emitter, files, ownerPath) {
198
175
  maps.pruneMap.set(ownerPath, cb);
199
176
  },
200
177
  invalidate() {
201
- notifyListeners(runner, "vite:invalidate", {
178
+ return notifyListeners(runner, "vite:invalidate", {
202
179
  path: ownerPath,
203
180
  message: void 0,
204
181
  firstInvalidatedBy: ownerPath
205
- });
206
- return reload(runner, files);
182
+ }), reload(runner, files);
207
183
  },
208
184
  on(event, cb) {
209
185
  const addToMap = (map) => {
210
186
  const existing = map.get(event) || [];
211
- existing.push(cb);
212
- map.set(event, existing);
187
+ existing.push(cb), map.set(event, existing);
213
188
  };
214
- addToMap(maps.customListenersMap);
215
- addToMap(newListeners);
189
+ addToMap(maps.customListenersMap), addToMap(newListeners);
216
190
  },
217
191
  off(event, cb) {
218
192
  const removeFromMap = (map) => {
@@ -225,16 +199,14 @@ function createHotContext(runner, emitter, files, ownerPath) {
225
199
  }
226
200
  map.set(event, pruned);
227
201
  };
228
- removeFromMap(maps.customListenersMap);
229
- removeFromMap(newListeners);
202
+ removeFromMap(maps.customListenersMap), removeFromMap(newListeners);
230
203
  },
231
204
  send(event, data) {
232
205
  maps.messageBuffer.push(JSON.stringify({
233
206
  type: "custom",
234
207
  event,
235
208
  data
236
- }));
237
- sendMessageBuffer(runner, emitter);
209
+ })), sendMessageBuffer(runner, emitter);
238
210
  }
239
211
  };
240
212
  return hot;
@@ -17,24 +17,20 @@ function viteNodeHmrPlugin() {
17
17
  },
18
18
  configureServer(server) {
19
19
  const _send = server.ws.send;
20
- server.emitter = emitter;
21
- server.ws.send = function(payload) {
22
- _send(payload);
23
- emitter.emit("message", payload);
20
+ server.emitter = emitter, server.ws.send = function(payload) {
21
+ _send(payload), emitter.emit("message", payload);
24
22
  };
25
23
  // eslint-disable-next-line ts/ban-ts-comment
26
24
  // @ts-ignore Vite 6 compat
27
25
  const environments = server.environments;
28
26
  if (environments) environments.ssr.hot.send = function(payload) {
29
- _send(payload);
30
- emitter.emit("message", payload);
27
+ _send(payload), emitter.emit("message", payload);
31
28
  };
32
29
  }
33
30
  };
34
31
  }
35
32
 
36
- const debugHmr = createDebug("vite-node:hmr");
37
- const cache = /* @__PURE__ */ new WeakMap();
33
+ const debugHmr = createDebug("vite-node:hmr"), cache = /* @__PURE__ */ new WeakMap();
38
34
  function getCache(runner) {
39
35
  if (!cache.has(runner)) cache.set(runner, {
40
36
  hotModulesMap: /* @__PURE__ */ new Map(),
@@ -52,38 +48,28 @@ function getCache(runner) {
52
48
  }
53
49
  function sendMessageBuffer(runner, emitter) {
54
50
  const maps = getCache(runner);
55
- maps.messageBuffer.forEach((msg) => emitter.emit("custom", msg));
56
- maps.messageBuffer.length = 0;
51
+ maps.messageBuffer.forEach((msg) => emitter.emit("custom", msg)), maps.messageBuffer.length = 0;
57
52
  }
58
53
  async function reload(runner, files) {
59
- // invalidate module cache but not node_modules
60
- Array.from(runner.moduleCache.keys()).forEach((fsPath) => {
54
+ return Array.from(runner.moduleCache.keys()).forEach((fsPath) => {
61
55
  if (!fsPath.includes("node_modules")) runner.moduleCache.delete(fsPath);
62
- });
63
- return Promise.all(files.map((file) => runner.executeId(file)));
56
+ }), Promise.all(files.map((file) => runner.executeId(file)));
64
57
  }
65
58
  async function notifyListeners(runner, event, data) {
66
- const maps = getCache(runner);
67
- const cbs = maps.customListenersMap.get(event);
59
+ const maps = getCache(runner), cbs = maps.customListenersMap.get(event);
68
60
  if (cbs) await Promise.all(cbs.map((cb) => cb(data)));
69
61
  }
70
62
  async function queueUpdate(runner, p) {
71
63
  const maps = getCache(runner);
72
- maps.queued.push(p);
73
- if (!maps.pending) {
74
- maps.pending = true;
75
- await Promise.resolve();
76
- maps.pending = false;
64
+ if (maps.queued.push(p), !maps.pending) {
65
+ maps.pending = true, await Promise.resolve(), maps.pending = false;
77
66
  const loading = [...maps.queued];
78
- maps.queued = [];
79
- (await Promise.all(loading)).forEach((fn) => fn && fn());
67
+ maps.queued = [], (await Promise.all(loading)).forEach((fn) => fn && fn());
80
68
  }
81
69
  }
82
70
  async function fetchUpdate(runner, { path, acceptedPath }) {
83
- path = normalizeRequestId(path);
84
- acceptedPath = normalizeRequestId(acceptedPath);
85
- const maps = getCache(runner);
86
- const mod = maps.hotModulesMap.get(path);
71
+ path = normalizeRequestId(path), acceptedPath = normalizeRequestId(acceptedPath);
72
+ const maps = getCache(runner), mod = maps.hotModulesMap.get(path);
87
73
  if (!mod)
88
74
  // In a code-splitting project,
89
75
  // it is common that the hot-updating module is not loaded yet.
@@ -119,26 +105,18 @@ async function handleMessage(runner, emitter, files, payload) {
119
105
  sendMessageBuffer(runner, emitter);
120
106
  break;
121
107
  case "update":
122
- await notifyListeners(runner, "vite:beforeUpdate", payload);
123
- await Promise.all(payload.updates.map((update) => {
124
- if (update.type === "js-update") return queueUpdate(runner, fetchUpdate(runner, update));
125
- // css-update
126
- console.error(`${s.cyan("[vite-node]")} no support css hmr.}`);
127
- return null;
128
- }));
129
- await notifyListeners(runner, "vite:afterUpdate", payload);
108
+ 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);
110
+ })), await notifyListeners(runner, "vite:afterUpdate", payload);
130
111
  break;
131
112
  case "full-reload":
132
- await notifyListeners(runner, "vite:beforeFullReload", payload);
133
- maps.customListenersMap.delete("vite:beforeFullReload");
134
- await reload(runner, files);
113
+ await notifyListeners(runner, "vite:beforeFullReload", payload), maps.customListenersMap.delete("vite:beforeFullReload"), await reload(runner, files);
135
114
  break;
136
115
  case "custom":
137
116
  await notifyListeners(runner, payload.event, payload.data);
138
117
  break;
139
118
  case "prune":
140
- await notifyListeners(runner, "vite:beforePrune", payload);
141
- payload.paths.forEach((path) => {
119
+ await notifyListeners(runner, "vite:beforePrune", payload), payload.paths.forEach((path) => {
142
120
  const fn = maps.pruneMap.get(path);
143
121
  if (fn) fn(maps.dataMap.get(path));
144
122
  });
@@ -169,8 +147,7 @@ function createHotContext(runner, emitter, files, ownerPath) {
169
147
  mod.callbacks.push({
170
148
  deps,
171
149
  fn: callback
172
- });
173
- maps.hotModulesMap.set(ownerPath, mod);
150
+ }), maps.hotModulesMap.set(ownerPath, mod);
174
151
  }
175
152
  const hot = {
176
153
  get data() {
@@ -196,21 +173,18 @@ function createHotContext(runner, emitter, files, ownerPath) {
196
173
  maps.pruneMap.set(ownerPath, cb);
197
174
  },
198
175
  invalidate() {
199
- notifyListeners(runner, "vite:invalidate", {
176
+ return notifyListeners(runner, "vite:invalidate", {
200
177
  path: ownerPath,
201
178
  message: void 0,
202
179
  firstInvalidatedBy: ownerPath
203
- });
204
- return reload(runner, files);
180
+ }), reload(runner, files);
205
181
  },
206
182
  on(event, cb) {
207
183
  const addToMap = (map) => {
208
184
  const existing = map.get(event) || [];
209
- existing.push(cb);
210
- map.set(event, existing);
185
+ existing.push(cb), map.set(event, existing);
211
186
  };
212
- addToMap(maps.customListenersMap);
213
- addToMap(newListeners);
187
+ addToMap(maps.customListenersMap), addToMap(newListeners);
214
188
  },
215
189
  off(event, cb) {
216
190
  const removeFromMap = (map) => {
@@ -223,16 +197,14 @@ function createHotContext(runner, emitter, files, ownerPath) {
223
197
  }
224
198
  map.set(event, pruned);
225
199
  };
226
- removeFromMap(maps.customListenersMap);
227
- removeFromMap(newListeners);
200
+ removeFromMap(maps.customListenersMap), removeFromMap(newListeners);
228
201
  },
229
202
  send(event, data) {
230
203
  maps.messageBuffer.push(JSON.stringify({
231
204
  type: "custom",
232
205
  event,
233
206
  data
234
- }));
235
- sendMessageBuffer(runner, emitter);
207
+ })), sendMessageBuffer(runner, emitter);
236
208
  }
237
209
  };
238
210
  return hot;
package/dist/cli.cjs CHANGED
@@ -21,17 +21,12 @@ require('node:perf_hooks');
21
21
  require('es-module-lexer');
22
22
  require('./constants.cjs');
23
23
 
24
- var version = "4.0.0-beta.5";
24
+ var version = "4.0.0-beta.6";
25
25
 
26
26
  const cli = cac("vite-node");
27
- 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");
28
- cli.command("[...files]").allowUnknownOptions().action(run);
29
- cli.parse(process.argv, { run: false });
30
- if (cli.args.length === 0) cli.runMatchedCommand();
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();
31
28
  else {
32
- const i = cli.rawArgs.indexOf(cli.args[0]) + 1;
33
- const scriptArgs = cli.rawArgs.slice(i).filter((it) => it !== "--");
34
- const executeArgs = [
29
+ const i = cli.rawArgs.indexOf(cli.args[0]) + 1, scriptArgs = cli.rawArgs.slice(i).filter((it) => it !== "--"), executeArgs = [
35
30
  ...cli.rawArgs.slice(0, i),
36
31
  "--",
37
32
  ...scriptArgs
@@ -40,31 +35,16 @@ else {
40
35
  }
41
36
  async function run(files, options = {}) {
42
37
  var _server$emitter;
43
- if (options.script) {
44
- files = [files[0]];
45
- options = {};
46
- process.argv = [
47
- process.argv[0],
48
- path.resolve(files[0]),
49
- ...process.argv.slice(2).filter((arg) => arg !== "--script" && arg !== files[0])
50
- ];
51
- } else process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
52
- if (options.version) {
53
- cli.version(version);
54
- cli.outputVersion();
55
- process.exit(0);
56
- }
57
- if (options.help) {
58
- cli.version(version).outputHelp();
59
- process.exit(0);
60
- }
61
- if (!files.length) {
62
- console.error(browser.s.red("No files specified."));
63
- cli.version(version).outputHelp();
64
- process.exit(1);
65
- }
66
- const serverOptions = options.options ? parseServerOptions(options.options) : {};
67
- const server$1 = await vite.createServer({
38
+ if (options.script) files = [files[0]], options = {}, process.argv = [
39
+ process.argv[0],
40
+ path.resolve(files[0]),
41
+ ...process.argv.slice(2).filter((arg) => arg !== "--script" && arg !== files[0])
42
+ ];
43
+ else process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
44
+ if (options.version) cli.version(version), cli.outputVersion(), process.exit(0);
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);
47
+ const serverOptions = options.options ? parseServerOptions(options.options) : {}, server$1 = await vite.createServer({
68
48
  logLevel: "error",
69
49
  configFile: options.config,
70
50
  root: options.root,
@@ -103,10 +83,9 @@ async function run(files, options = {}) {
103
83
  await runner.executeId("/@vite/env");
104
84
  for (const file of files) await runner.executeFile(file);
105
85
  if (!options.watch) await server$1.close();
106
- (_server$emitter = server$1.emitter) === null || _server$emitter === void 0 || _server$emitter.on("message", (payload) => {
86
+ if ((_server$emitter = server$1.emitter) === null || _server$emitter === void 0 || _server$emitter.on("message", (payload) => {
107
87
  hmr.handleMessage(runner, server$1.emitter, files, payload);
108
- });
109
- if (options.watch) process.on("uncaughtException", (err) => {
88
+ }), options.watch) process.on("uncaughtException", (err) => {
110
89
  console.error(browser.s.red("[vite-node] Failed to execute file: \n"), err);
111
90
  });
112
91
  }
package/dist/cli.mjs CHANGED
@@ -3,33 +3,28 @@ import cac from 'cac';
3
3
  import { s } from './chunk-browser.mjs';
4
4
  import { createServer, version as version$1, loadEnv } from 'vite';
5
5
  import { ViteNodeRunner } from './client.mjs';
6
- import { v as viteNodeHmrPlugin, a as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
7
6
  import { ViteNodeServer } from './server.mjs';
8
7
  import { installSourcemapsSupport } from './source-map.mjs';
9
8
  import { toArray } from './utils.mjs';
9
+ import { v as viteNodeHmrPlugin, a as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
10
10
  import 'node:module';
11
11
  import 'node:url';
12
12
  import 'node:vm';
13
13
  import 'debug';
14
14
  import 'pathe';
15
15
  import 'node:fs';
16
- import 'node:events';
17
16
  import 'node:assert';
18
17
  import 'node:perf_hooks';
19
18
  import 'es-module-lexer';
20
19
  import './constants.mjs';
20
+ import 'node:events';
21
21
 
22
- var version = "4.0.0-beta.5";
22
+ var version = "4.0.0-beta.6";
23
23
 
24
24
  const cli = cac("vite-node");
25
- 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");
26
- cli.command("[...files]").allowUnknownOptions().action(run);
27
- cli.parse(process.argv, { run: false });
28
- if (cli.args.length === 0) cli.runMatchedCommand();
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();
29
26
  else {
30
- const i = cli.rawArgs.indexOf(cli.args[0]) + 1;
31
- const scriptArgs = cli.rawArgs.slice(i).filter((it) => it !== "--");
32
- const executeArgs = [
27
+ const i = cli.rawArgs.indexOf(cli.args[0]) + 1, scriptArgs = cli.rawArgs.slice(i).filter((it) => it !== "--"), executeArgs = [
33
28
  ...cli.rawArgs.slice(0, i),
34
29
  "--",
35
30
  ...scriptArgs
@@ -38,31 +33,16 @@ else {
38
33
  }
39
34
  async function run(files, options = {}) {
40
35
  var _server$emitter;
41
- if (options.script) {
42
- files = [files[0]];
43
- options = {};
44
- process.argv = [
45
- process.argv[0],
46
- resolve(files[0]),
47
- ...process.argv.slice(2).filter((arg) => arg !== "--script" && arg !== files[0])
48
- ];
49
- } else process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
50
- if (options.version) {
51
- cli.version(version);
52
- cli.outputVersion();
53
- process.exit(0);
54
- }
55
- if (options.help) {
56
- cli.version(version).outputHelp();
57
- process.exit(0);
58
- }
59
- if (!files.length) {
60
- console.error(s.red("No files specified."));
61
- cli.version(version).outputHelp();
62
- process.exit(1);
63
- }
64
- const serverOptions = options.options ? parseServerOptions(options.options) : {};
65
- const server = await createServer({
36
+ if (options.script) files = [files[0]], options = {}, process.argv = [
37
+ process.argv[0],
38
+ resolve(files[0]),
39
+ ...process.argv.slice(2).filter((arg) => arg !== "--script" && arg !== files[0])
40
+ ];
41
+ else process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
42
+ if (options.version) cli.version(version), cli.outputVersion(), process.exit(0);
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);
45
+ const serverOptions = options.options ? parseServerOptions(options.options) : {}, server = await createServer({
66
46
  logLevel: "error",
67
47
  configFile: options.config,
68
48
  root: options.root,
@@ -101,10 +81,9 @@ async function run(files, options = {}) {
101
81
  await runner.executeId("/@vite/env");
102
82
  for (const file of files) await runner.executeFile(file);
103
83
  if (!options.watch) await server.close();
104
- (_server$emitter = server.emitter) === null || _server$emitter === void 0 || _server$emitter.on("message", (payload) => {
84
+ if ((_server$emitter = server.emitter) === null || _server$emitter === void 0 || _server$emitter.on("message", (payload) => {
105
85
  handleMessage(runner, server.emitter, files, payload);
106
- });
107
- if (options.watch) process.on("uncaughtException", (err) => {
86
+ }), options.watch) process.on("uncaughtException", (err) => {
108
87
  console.error(s.red("[vite-node] Failed to execute file: \n"), err);
109
88
  });
110
89
  }