vite-node 2.1.2 → 2.1.4

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/README.md CHANGED
@@ -83,8 +83,8 @@ In Vite Node, the server and runner (client) are separated, so you can integrate
83
83
 
84
84
  ```ts
85
85
  import { createServer } from 'vite'
86
- import { ViteNodeServer } from 'vite-node/server'
87
86
  import { ViteNodeRunner } from 'vite-node/client'
87
+ import { ViteNodeServer } from 'vite-node/server'
88
88
  import { installSourcemapsSupport } from 'vite-node/source-map'
89
89
 
90
90
  // create vite server
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var node_events = require('node:events');
4
- var browser = require('./chunk-browser.cjs');
5
4
  var createDebug = require('debug');
5
+ var browser = require('./chunk-browser.cjs');
6
6
  var utils = require('./utils.cjs');
7
7
 
8
8
  function createHmrEmitter() {
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import { f } from './chunk-browser.mjs';
3
2
  import createDebug from 'debug';
3
+ import { f } from './chunk-browser.mjs';
4
4
  import { normalizeRequestId } from './utils.mjs';
5
5
 
6
6
  function createHmrEmitter() {
package/dist/cli.cjs CHANGED
@@ -4,23 +4,23 @@ var path = require('node:path');
4
4
  var cac = require('cac');
5
5
  var browser = require('./chunk-browser.cjs');
6
6
  var vite = require('vite');
7
- var server = require('./server.cjs');
8
7
  var client = require('./client.cjs');
9
- var utils = require('./utils.cjs');
8
+ var server = require('./server.cjs');
10
9
  var sourceMap = require('./source-map.cjs');
10
+ var utils = require('./utils.cjs');
11
11
  var hmr = require('./chunk-hmr.cjs');
12
- require('node:perf_hooks');
13
- require('node:fs');
14
- require('node:assert');
15
- require('pathe');
16
- require('debug');
17
- require('./constants.cjs');
18
12
  require('node:module');
19
13
  require('node:url');
20
14
  require('node:vm');
15
+ require('debug');
16
+ require('pathe');
17
+ require('node:fs');
18
+ require('node:assert');
19
+ require('node:perf_hooks');
20
+ require('./constants.cjs');
21
21
  require('node:events');
22
22
 
23
- var version = "2.1.2";
23
+ var version = "2.1.4";
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");
@@ -112,26 +112,27 @@ async function run(files, options = {}) {
112
112
  }
113
113
  }
114
114
  function parseServerOptions(serverOptions) {
115
- var _a, _b, _c, _d, _e, _f, _g;
115
+ var _a, _b, _c, _d, _e, _f, _g, _h;
116
116
  const inlineOptions = ((_a = serverOptions.deps) == null ? void 0 : _a.inline) === true ? true : utils.toArray((_b = serverOptions.deps) == null ? void 0 : _b.inline);
117
117
  return {
118
118
  ...serverOptions,
119
119
  deps: {
120
120
  ...serverOptions.deps,
121
+ inlineFiles: utils.toArray((_c = serverOptions.deps) == null ? void 0 : _c.inlineFiles),
121
122
  inline: inlineOptions !== true ? inlineOptions.map((dep) => {
122
123
  return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
123
124
  }) : true,
124
- external: utils.toArray((_c = serverOptions.deps) == null ? void 0 : _c.external).map((dep) => {
125
+ external: utils.toArray((_d = serverOptions.deps) == null ? void 0 : _d.external).map((dep) => {
125
126
  return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
126
127
  }),
127
- moduleDirectories: ((_d = serverOptions.deps) == null ? void 0 : _d.moduleDirectories) ? utils.toArray((_e = serverOptions.deps) == null ? void 0 : _e.moduleDirectories) : void 0
128
+ moduleDirectories: ((_e = serverOptions.deps) == null ? void 0 : _e.moduleDirectories) ? utils.toArray((_f = serverOptions.deps) == null ? void 0 : _f.moduleDirectories) : void 0
128
129
  },
129
130
  transformMode: {
130
131
  ...serverOptions.transformMode,
131
- ssr: utils.toArray((_f = serverOptions.transformMode) == null ? void 0 : _f.ssr).map(
132
+ ssr: utils.toArray((_g = serverOptions.transformMode) == null ? void 0 : _g.ssr).map(
132
133
  (dep) => new RegExp(dep)
133
134
  ),
134
- web: utils.toArray((_g = serverOptions.transformMode) == null ? void 0 : _g.web).map(
135
+ web: utils.toArray((_h = serverOptions.transformMode) == null ? void 0 : _h.web).map(
135
136
  (dep) => new RegExp(dep)
136
137
  )
137
138
  }
package/dist/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { V as ViteNodeServerOptions } from './index-CCsqCcr7.js';
1
+ import { V as ViteNodeServerOptions } from './index-z0R8hVRu.js';
2
2
  import './trace-mapping.d-DLVdEqOp.js';
3
3
 
4
4
  interface CliOptions {
package/dist/cli.mjs CHANGED
@@ -2,23 +2,23 @@ import { resolve } from 'node:path';
2
2
  import cac from 'cac';
3
3
  import { f } from './chunk-browser.mjs';
4
4
  import { createServer, loadEnv } from 'vite';
5
- import { ViteNodeServer } from './server.mjs';
6
5
  import { ViteNodeRunner } from './client.mjs';
7
- import { toArray } from './utils.mjs';
6
+ import { ViteNodeServer } from './server.mjs';
8
7
  import { installSourcemapsSupport } from './source-map.mjs';
8
+ import { toArray } from './utils.mjs';
9
9
  import { v as viteNodeHmrPlugin, a as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
10
- import 'node:perf_hooks';
11
- import 'node:fs';
12
- import 'node:assert';
13
- import 'pathe';
14
- import 'debug';
15
- import './constants.mjs';
16
10
  import 'node:module';
17
11
  import 'node:url';
18
12
  import 'node:vm';
13
+ import 'debug';
14
+ import 'pathe';
15
+ import 'node:fs';
16
+ import 'node:assert';
17
+ import 'node:perf_hooks';
18
+ import './constants.mjs';
19
19
  import 'node:events';
20
20
 
21
- var version = "2.1.2";
21
+ var version = "2.1.4";
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");
@@ -110,26 +110,27 @@ async function run(files, options = {}) {
110
110
  }
111
111
  }
112
112
  function parseServerOptions(serverOptions) {
113
- var _a, _b, _c, _d, _e, _f, _g;
113
+ var _a, _b, _c, _d, _e, _f, _g, _h;
114
114
  const inlineOptions = ((_a = serverOptions.deps) == null ? void 0 : _a.inline) === true ? true : toArray((_b = serverOptions.deps) == null ? void 0 : _b.inline);
115
115
  return {
116
116
  ...serverOptions,
117
117
  deps: {
118
118
  ...serverOptions.deps,
119
+ inlineFiles: toArray((_c = serverOptions.deps) == null ? void 0 : _c.inlineFiles),
119
120
  inline: inlineOptions !== true ? inlineOptions.map((dep) => {
120
121
  return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
121
122
  }) : true,
122
- external: toArray((_c = serverOptions.deps) == null ? void 0 : _c.external).map((dep) => {
123
+ external: toArray((_d = serverOptions.deps) == null ? void 0 : _d.external).map((dep) => {
123
124
  return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
124
125
  }),
125
- moduleDirectories: ((_d = serverOptions.deps) == null ? void 0 : _d.moduleDirectories) ? toArray((_e = serverOptions.deps) == null ? void 0 : _e.moduleDirectories) : void 0
126
+ moduleDirectories: ((_e = serverOptions.deps) == null ? void 0 : _e.moduleDirectories) ? toArray((_f = serverOptions.deps) == null ? void 0 : _f.moduleDirectories) : void 0
126
127
  },
127
128
  transformMode: {
128
129
  ...serverOptions.transformMode,
129
- ssr: toArray((_f = serverOptions.transformMode) == null ? void 0 : _f.ssr).map(
130
+ ssr: toArray((_g = serverOptions.transformMode) == null ? void 0 : _g.ssr).map(
130
131
  (dep) => new RegExp(dep)
131
132
  ),
132
- web: toArray((_g = serverOptions.transformMode) == null ? void 0 : _g.web).map(
133
+ web: toArray((_h = serverOptions.transformMode) == null ? void 0 : _h.web).map(
133
134
  (dep) => new RegExp(dep)
134
135
  )
135
136
  }
package/dist/client.cjs CHANGED
@@ -4,10 +4,10 @@ var node_module = 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');
7
- var pathe = require('pathe');
8
7
  var createDebug = require('debug');
9
- var utils = require('./utils.cjs');
10
8
  var sourceMap = require('./source-map.cjs');
9
+ var utils = require('./utils.cjs');
10
+ require('pathe');
11
11
  require('node:fs');
12
12
 
13
13
  const { setTimeout, clearTimeout } = globalThis;
@@ -167,7 +167,7 @@ class ViteNodeRunner {
167
167
  */
168
168
  moduleCache;
169
169
  async executeFile(file) {
170
- const url = `/@fs/${utils.slash(pathe.resolve(file))}`;
170
+ const url = `/@fs/${utils.slash(path.resolve(file))}`;
171
171
  return await this.cachedRequest(url, url, []);
172
172
  }
173
173
  async executeId(rawId) {
package/dist/client.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, a as ViteNodeRunner } from './index-CCsqCcr7.js';
2
1
  import './trace-mapping.d-DLVdEqOp.js';
2
+ export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, a as ViteNodeRunner } from './index-z0R8hVRu.js';
package/dist/client.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  import { createRequire } from 'node:module';
2
- import { dirname } from 'node:path';
2
+ import { resolve, dirname } from 'node:path';
3
3
  import { pathToFileURL, fileURLToPath } from 'node:url';
4
4
  import vm from 'node:vm';
5
- import { resolve } from 'pathe';
6
5
  import createDebug from 'debug';
7
- import { createImportMetaEnvProxy, normalizeModuleId, slash, isInternalRequest, isNodeBuiltin, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
8
6
  import { extractSourceMap } from './source-map.mjs';
7
+ import { createImportMetaEnvProxy, normalizeModuleId, slash, isInternalRequest, isNodeBuiltin, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
8
+ import 'pathe';
9
9
  import 'node:fs';
10
10
 
11
11
  const { setTimeout, clearTimeout } = globalThis;
package/dist/hmr.cjs CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  var hmr = require('./chunk-hmr.cjs');
4
4
  require('node:events');
5
- require('./chunk-browser.cjs');
6
5
  require('debug');
6
+ require('./chunk-browser.cjs');
7
7
  require('./utils.cjs');
8
- require('node:url');
9
- require('node:module');
10
8
  require('node:fs');
9
+ require('node:module');
10
+ require('node:url');
11
11
  require('pathe');
12
12
 
13
13
 
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { EventEmitter } from 'node:events';
2
1
  import { HMRPayload, Plugin } from 'vite';
3
- import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index-CCsqCcr7.js';
2
+ import { EventEmitter } from 'node:events';
3
+ import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index-z0R8hVRu.js';
4
4
  import './trace-mapping.d-DLVdEqOp.js';
5
5
 
6
6
  type EventType = string | symbol;
package/dist/hmr.mjs CHANGED
@@ -1,9 +1,9 @@
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
- import './chunk-browser.mjs';
4
3
  import 'debug';
4
+ import './chunk-browser.mjs';
5
5
  import './utils.mjs';
6
- import 'node:url';
7
- import 'node:module';
8
6
  import 'node:fs';
7
+ import 'node:module';
8
+ import 'node:url';
9
9
  import 'pathe';
@@ -207,6 +207,7 @@ type Awaitable<T> = T | PromiseLike<T>;
207
207
  interface DepsHandlingOptions {
208
208
  external?: (string | RegExp)[];
209
209
  inline?: (string | RegExp)[] | true;
210
+ inlineFiles?: string[];
210
211
  /**
211
212
  * A list of directories that are considered to hold Node.js modules
212
213
  * Have to include "/" at the start and end of the path
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, l as ViteNodeResolveModule, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-CCsqCcr7.js';
1
+ export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, l as ViteNodeResolveModule, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-z0R8hVRu.js';
2
2
  export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-DLVdEqOp.js';
package/dist/server.cjs CHANGED
@@ -1,18 +1,115 @@
1
1
  'use strict';
2
2
 
3
- var node_perf_hooks = require('node:perf_hooks');
4
- var fs = require('node:fs');
5
3
  var assert = require('node:assert');
6
- var pathe = require('pathe');
4
+ var fs = require('node:fs');
5
+ var node_perf_hooks = require('node:perf_hooks');
6
+ var node_url = require('node:url');
7
7
  var createDebug = require('debug');
8
- var utils = require('./utils.cjs');
9
- var constants = require('./constants.cjs');
8
+ var pathe = require('pathe');
10
9
  var browser = require('./chunk-browser.cjs');
10
+ var constants = require('./constants.cjs');
11
+ var utils = require('./utils.cjs');
11
12
  var sourceMap = require('./source-map.cjs');
12
- require('node:url');
13
13
  require('node:module');
14
14
  require('node:path');
15
15
 
16
+ function hashCode(s) {
17
+ return s.split("").reduce((a, b) => {
18
+ a = (a << 5) - a + b.charCodeAt(0);
19
+ return a & a;
20
+ }, 0);
21
+ }
22
+ class Debugger {
23
+ constructor(root, options) {
24
+ this.options = options;
25
+ if (options.dumpModules) {
26
+ this.dumpDir = pathe.resolve(
27
+ root,
28
+ options.dumpModules === true ? ".vite-node/dump" : options.dumpModules
29
+ );
30
+ }
31
+ if (this.dumpDir) {
32
+ if (options.loadDumppedModules) {
33
+ console.info(
34
+ browser.f.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`)
35
+ );
36
+ } else {
37
+ console.info(
38
+ browser.f.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`)
39
+ );
40
+ }
41
+ }
42
+ this.initPromise = this.clearDump();
43
+ }
44
+ dumpDir;
45
+ initPromise;
46
+ externalizeMap = /* @__PURE__ */ new Map();
47
+ async clearDump() {
48
+ if (!this.dumpDir) {
49
+ return;
50
+ }
51
+ if (!this.options.loadDumppedModules && fs.existsSync(this.dumpDir)) {
52
+ await fs.promises.rm(this.dumpDir, { recursive: true, force: true });
53
+ }
54
+ await fs.promises.mkdir(this.dumpDir, { recursive: true });
55
+ }
56
+ encodeId(id) {
57
+ return `${id.replace(/[^\w@\-]/g, "_").replace(/_+/g, "_")}-${hashCode(
58
+ id
59
+ )}.js`;
60
+ }
61
+ async recordExternalize(id, path) {
62
+ if (!this.dumpDir) {
63
+ return;
64
+ }
65
+ this.externalizeMap.set(id, path);
66
+ await this.writeInfo();
67
+ }
68
+ async dumpFile(id, result) {
69
+ if (!result || !this.dumpDir) {
70
+ return;
71
+ }
72
+ await this.initPromise;
73
+ const name = this.encodeId(id);
74
+ return await fs.promises.writeFile(
75
+ pathe.join(this.dumpDir, name),
76
+ `// ${id.replace(/\0/g, "\\0")}
77
+ ${result.code}`,
78
+ "utf-8"
79
+ );
80
+ }
81
+ async loadDump(id) {
82
+ if (!this.dumpDir) {
83
+ return null;
84
+ }
85
+ await this.initPromise;
86
+ const name = this.encodeId(id);
87
+ const path = pathe.join(this.dumpDir, name);
88
+ if (!fs.existsSync(path)) {
89
+ return null;
90
+ }
91
+ const code = await fs.promises.readFile(path, "utf-8");
92
+ return {
93
+ code: code.replace(/^\/\/.*\n/, ""),
94
+ map: void 0
95
+ };
96
+ }
97
+ async writeInfo() {
98
+ if (!this.dumpDir) {
99
+ return;
100
+ }
101
+ const info = JSON.stringify(
102
+ {
103
+ time: (/* @__PURE__ */ new Date()).toLocaleString(),
104
+ externalize: Object.fromEntries(this.externalizeMap.entries())
105
+ },
106
+ null,
107
+ 2
108
+ );
109
+ return fs.promises.writeFile(pathe.join(this.dumpDir, "info.json"), info, "utf-8");
110
+ }
111
+ }
112
+
16
113
  const BUILTIN_EXTENSIONS = /* @__PURE__ */ new Set([".mjs", ".cjs", ".node", ".wasm"]);
17
114
  const ESM_SYNTAX_RE = /(?:[\s;]|^)(?:import[\s\w*,{}]*from|import\s*["'*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
18
115
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
@@ -94,6 +191,9 @@ async function _shouldExternalize(id, options) {
94
191
  if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.inline)) {
95
192
  return false;
96
193
  }
194
+ if ((options == null ? void 0 : options.inlineFiles) && (options == null ? void 0 : options.inlineFiles.includes(id))) {
195
+ return false;
196
+ }
97
197
  if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.external)) {
98
198
  return id;
99
199
  }
@@ -144,103 +244,6 @@ function patchWindowsImportPath(path) {
144
244
  }
145
245
  }
146
246
 
147
- function hashCode(s) {
148
- return s.split("").reduce((a, b) => {
149
- a = (a << 5) - a + b.charCodeAt(0);
150
- return a & a;
151
- }, 0);
152
- }
153
- class Debugger {
154
- constructor(root, options) {
155
- this.options = options;
156
- if (options.dumpModules) {
157
- this.dumpDir = pathe.resolve(
158
- root,
159
- options.dumpModules === true ? ".vite-node/dump" : options.dumpModules
160
- );
161
- }
162
- if (this.dumpDir) {
163
- if (options.loadDumppedModules) {
164
- console.info(
165
- browser.f.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`)
166
- );
167
- } else {
168
- console.info(
169
- browser.f.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`)
170
- );
171
- }
172
- }
173
- this.initPromise = this.clearDump();
174
- }
175
- dumpDir;
176
- initPromise;
177
- externalizeMap = /* @__PURE__ */ new Map();
178
- async clearDump() {
179
- if (!this.dumpDir) {
180
- return;
181
- }
182
- if (!this.options.loadDumppedModules && fs.existsSync(this.dumpDir)) {
183
- await fs.promises.rm(this.dumpDir, { recursive: true, force: true });
184
- }
185
- await fs.promises.mkdir(this.dumpDir, { recursive: true });
186
- }
187
- encodeId(id) {
188
- return `${id.replace(/[^\w@\-]/g, "_").replace(/_+/g, "_")}-${hashCode(
189
- id
190
- )}.js`;
191
- }
192
- async recordExternalize(id, path) {
193
- if (!this.dumpDir) {
194
- return;
195
- }
196
- this.externalizeMap.set(id, path);
197
- await this.writeInfo();
198
- }
199
- async dumpFile(id, result) {
200
- if (!result || !this.dumpDir) {
201
- return;
202
- }
203
- await this.initPromise;
204
- const name = this.encodeId(id);
205
- return await fs.promises.writeFile(
206
- pathe.join(this.dumpDir, name),
207
- `// ${id.replace(/\0/g, "\\0")}
208
- ${result.code}`,
209
- "utf-8"
210
- );
211
- }
212
- async loadDump(id) {
213
- if (!this.dumpDir) {
214
- return null;
215
- }
216
- await this.initPromise;
217
- const name = this.encodeId(id);
218
- const path = pathe.join(this.dumpDir, name);
219
- if (!fs.existsSync(path)) {
220
- return null;
221
- }
222
- const code = await fs.promises.readFile(path, "utf-8");
223
- return {
224
- code: code.replace(/^\/\/.*\n/, ""),
225
- map: void 0
226
- };
227
- }
228
- async writeInfo() {
229
- if (!this.dumpDir) {
230
- return;
231
- }
232
- const info = JSON.stringify(
233
- {
234
- time: (/* @__PURE__ */ new Date()).toLocaleString(),
235
- externalize: Object.fromEntries(this.externalizeMap.entries())
236
- },
237
- null,
238
- 2
239
- );
240
- return fs.promises.writeFile(pathe.join(this.dumpDir, "info.json"), info, "utf-8");
241
- }
242
- }
243
-
244
247
  const debugRequest = createDebug("vite-node:server:request");
245
248
  class ViteNodeServer {
246
249
  constructor(server, options = {}) {
@@ -278,6 +281,15 @@ class ViteNodeServer {
278
281
  if (options.debug) {
279
282
  this.debugger = new Debugger(server.config.root, options.debug);
280
283
  }
284
+ if (options.deps.inlineFiles) {
285
+ options.deps.inlineFiles = options.deps.inlineFiles.flatMap((file) => {
286
+ if (file.startsWith("file://")) {
287
+ return file;
288
+ }
289
+ const resolvedId = pathe.resolve(file);
290
+ return [resolvedId, node_url.pathToFileURL(resolvedId).href];
291
+ });
292
+ }
281
293
  (_c = options.deps).moduleDirectories ?? (_c.moduleDirectories = []);
282
294
  const envValue = process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES || process.env.npm_config_VITE_NODE_DEPS_MODULE_DIRECTORIES;
283
295
  const customModuleDirectories = envValue == null ? void 0 : envValue.split(",");
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, d as ViteNodeResolveId, F as FetchResult } from './index-CCsqCcr7.js';
2
+ import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, d as ViteNodeResolveId, F as FetchResult } from './index-z0R8hVRu.js';
3
3
  import { E as EncodedSourceMap } from './trace-mapping.d-DLVdEqOp.js';
4
4
 
5
5
  declare class Debugger {
package/dist/server.mjs CHANGED
@@ -1,16 +1,113 @@
1
- import { performance } from 'node:perf_hooks';
2
- import { existsSync, promises } from 'node:fs';
3
1
  import assert from 'node:assert';
4
- import { join, extname, dirname, resolve, relative, normalize } from 'pathe';
2
+ import { existsSync, promises } from 'node:fs';
3
+ import { performance } from 'node:perf_hooks';
4
+ import { pathToFileURL } from 'node:url';
5
5
  import createDebug from 'debug';
6
- import { isNodeBuiltin, slash, findNearestPackageData, toArray, withTrailingSlash, normalizeModuleId, toFilePath } from './utils.mjs';
7
- import { KNOWN_ASSET_RE } from './constants.mjs';
6
+ import { resolve, join, extname, dirname, relative, normalize } from 'pathe';
8
7
  import { f } from './chunk-browser.mjs';
8
+ import { KNOWN_ASSET_RE } from './constants.mjs';
9
+ import { isNodeBuiltin, slash, findNearestPackageData, toArray, withTrailingSlash, normalizeModuleId, toFilePath } from './utils.mjs';
9
10
  import { withInlineSourcemap } from './source-map.mjs';
10
- import 'node:url';
11
11
  import 'node:module';
12
12
  import 'node:path';
13
13
 
14
+ function hashCode(s) {
15
+ return s.split("").reduce((a, b) => {
16
+ a = (a << 5) - a + b.charCodeAt(0);
17
+ return a & a;
18
+ }, 0);
19
+ }
20
+ class Debugger {
21
+ constructor(root, options) {
22
+ this.options = options;
23
+ if (options.dumpModules) {
24
+ this.dumpDir = resolve(
25
+ root,
26
+ options.dumpModules === true ? ".vite-node/dump" : options.dumpModules
27
+ );
28
+ }
29
+ if (this.dumpDir) {
30
+ if (options.loadDumppedModules) {
31
+ console.info(
32
+ f.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`)
33
+ );
34
+ } else {
35
+ console.info(
36
+ f.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`)
37
+ );
38
+ }
39
+ }
40
+ this.initPromise = this.clearDump();
41
+ }
42
+ dumpDir;
43
+ initPromise;
44
+ externalizeMap = /* @__PURE__ */ new Map();
45
+ async clearDump() {
46
+ if (!this.dumpDir) {
47
+ return;
48
+ }
49
+ if (!this.options.loadDumppedModules && existsSync(this.dumpDir)) {
50
+ await promises.rm(this.dumpDir, { recursive: true, force: true });
51
+ }
52
+ await promises.mkdir(this.dumpDir, { recursive: true });
53
+ }
54
+ encodeId(id) {
55
+ return `${id.replace(/[^\w@\-]/g, "_").replace(/_+/g, "_")}-${hashCode(
56
+ id
57
+ )}.js`;
58
+ }
59
+ async recordExternalize(id, path) {
60
+ if (!this.dumpDir) {
61
+ return;
62
+ }
63
+ this.externalizeMap.set(id, path);
64
+ await this.writeInfo();
65
+ }
66
+ async dumpFile(id, result) {
67
+ if (!result || !this.dumpDir) {
68
+ return;
69
+ }
70
+ await this.initPromise;
71
+ const name = this.encodeId(id);
72
+ return await promises.writeFile(
73
+ join(this.dumpDir, name),
74
+ `// ${id.replace(/\0/g, "\\0")}
75
+ ${result.code}`,
76
+ "utf-8"
77
+ );
78
+ }
79
+ async loadDump(id) {
80
+ if (!this.dumpDir) {
81
+ return null;
82
+ }
83
+ await this.initPromise;
84
+ const name = this.encodeId(id);
85
+ const path = join(this.dumpDir, name);
86
+ if (!existsSync(path)) {
87
+ return null;
88
+ }
89
+ const code = await promises.readFile(path, "utf-8");
90
+ return {
91
+ code: code.replace(/^\/\/.*\n/, ""),
92
+ map: void 0
93
+ };
94
+ }
95
+ async writeInfo() {
96
+ if (!this.dumpDir) {
97
+ return;
98
+ }
99
+ const info = JSON.stringify(
100
+ {
101
+ time: (/* @__PURE__ */ new Date()).toLocaleString(),
102
+ externalize: Object.fromEntries(this.externalizeMap.entries())
103
+ },
104
+ null,
105
+ 2
106
+ );
107
+ return promises.writeFile(join(this.dumpDir, "info.json"), info, "utf-8");
108
+ }
109
+ }
110
+
14
111
  const BUILTIN_EXTENSIONS = /* @__PURE__ */ new Set([".mjs", ".cjs", ".node", ".wasm"]);
15
112
  const ESM_SYNTAX_RE = /(?:[\s;]|^)(?:import[\s\w*,{}]*from|import\s*["'*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
16
113
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
@@ -92,6 +189,9 @@ async function _shouldExternalize(id, options) {
92
189
  if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.inline)) {
93
190
  return false;
94
191
  }
192
+ if ((options == null ? void 0 : options.inlineFiles) && (options == null ? void 0 : options.inlineFiles.includes(id))) {
193
+ return false;
194
+ }
95
195
  if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.external)) {
96
196
  return id;
97
197
  }
@@ -142,103 +242,6 @@ function patchWindowsImportPath(path) {
142
242
  }
143
243
  }
144
244
 
145
- function hashCode(s) {
146
- return s.split("").reduce((a, b) => {
147
- a = (a << 5) - a + b.charCodeAt(0);
148
- return a & a;
149
- }, 0);
150
- }
151
- class Debugger {
152
- constructor(root, options) {
153
- this.options = options;
154
- if (options.dumpModules) {
155
- this.dumpDir = resolve(
156
- root,
157
- options.dumpModules === true ? ".vite-node/dump" : options.dumpModules
158
- );
159
- }
160
- if (this.dumpDir) {
161
- if (options.loadDumppedModules) {
162
- console.info(
163
- f.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`)
164
- );
165
- } else {
166
- console.info(
167
- f.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`)
168
- );
169
- }
170
- }
171
- this.initPromise = this.clearDump();
172
- }
173
- dumpDir;
174
- initPromise;
175
- externalizeMap = /* @__PURE__ */ new Map();
176
- async clearDump() {
177
- if (!this.dumpDir) {
178
- return;
179
- }
180
- if (!this.options.loadDumppedModules && existsSync(this.dumpDir)) {
181
- await promises.rm(this.dumpDir, { recursive: true, force: true });
182
- }
183
- await promises.mkdir(this.dumpDir, { recursive: true });
184
- }
185
- encodeId(id) {
186
- return `${id.replace(/[^\w@\-]/g, "_").replace(/_+/g, "_")}-${hashCode(
187
- id
188
- )}.js`;
189
- }
190
- async recordExternalize(id, path) {
191
- if (!this.dumpDir) {
192
- return;
193
- }
194
- this.externalizeMap.set(id, path);
195
- await this.writeInfo();
196
- }
197
- async dumpFile(id, result) {
198
- if (!result || !this.dumpDir) {
199
- return;
200
- }
201
- await this.initPromise;
202
- const name = this.encodeId(id);
203
- return await promises.writeFile(
204
- join(this.dumpDir, name),
205
- `// ${id.replace(/\0/g, "\\0")}
206
- ${result.code}`,
207
- "utf-8"
208
- );
209
- }
210
- async loadDump(id) {
211
- if (!this.dumpDir) {
212
- return null;
213
- }
214
- await this.initPromise;
215
- const name = this.encodeId(id);
216
- const path = join(this.dumpDir, name);
217
- if (!existsSync(path)) {
218
- return null;
219
- }
220
- const code = await promises.readFile(path, "utf-8");
221
- return {
222
- code: code.replace(/^\/\/.*\n/, ""),
223
- map: void 0
224
- };
225
- }
226
- async writeInfo() {
227
- if (!this.dumpDir) {
228
- return;
229
- }
230
- const info = JSON.stringify(
231
- {
232
- time: (/* @__PURE__ */ new Date()).toLocaleString(),
233
- externalize: Object.fromEntries(this.externalizeMap.entries())
234
- },
235
- null,
236
- 2
237
- );
238
- return promises.writeFile(join(this.dumpDir, "info.json"), info, "utf-8");
239
- }
240
- }
241
-
242
245
  const debugRequest = createDebug("vite-node:server:request");
243
246
  class ViteNodeServer {
244
247
  constructor(server, options = {}) {
@@ -276,6 +279,15 @@ class ViteNodeServer {
276
279
  if (options.debug) {
277
280
  this.debugger = new Debugger(server.config.root, options.debug);
278
281
  }
282
+ if (options.deps.inlineFiles) {
283
+ options.deps.inlineFiles = options.deps.inlineFiles.flatMap((file) => {
284
+ if (file.startsWith("file://")) {
285
+ return file;
286
+ }
287
+ const resolvedId = resolve(file);
288
+ return [resolvedId, pathToFileURL(resolvedId).href];
289
+ });
290
+ }
279
291
  (_c = options.deps).moduleDirectories ?? (_c.moduleDirectories = []);
280
292
  const envValue = process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES || process.env.npm_config_VITE_NODE_DEPS_MODULE_DIRECTORIES;
281
293
  const customModuleDirectories = envValue == null ? void 0 : envValue.split(",");
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var pathe = require('pathe');
4
- var utils = require('./utils.cjs');
5
- var path = require('node:path');
6
4
  var fs = require('node:fs');
7
- require('node:url');
5
+ var path = require('node:path');
6
+ var utils = require('./utils.cjs');
8
7
  require('node:module');
8
+ require('node:url');
9
9
 
10
10
  const comma = ','.charCodeAt(0);
11
11
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@@ -1,9 +1,9 @@
1
1
  import { isAbsolute, resolve as resolve$2, relative, dirname } from 'pathe';
2
- import { withTrailingSlash } from './utils.mjs';
3
- import path from 'node:path';
4
2
  import fs from 'node:fs';
5
- import 'node:url';
3
+ import path from 'node:path';
4
+ import { withTrailingSlash } from './utils.mjs';
6
5
  import 'node:module';
6
+ import 'node:url';
7
7
 
8
8
  const comma = ','.charCodeAt(0);
9
9
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, l as ViteNodeResolveModule, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-CCsqCcr7.js';
2
1
  export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-DLVdEqOp.js';
2
+ export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, l as ViteNodeResolveModule, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-z0R8hVRu.js';
package/dist/utils.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var node_url = require('node:url');
4
- var node_module = require('node:module');
5
3
  var fs = require('node:fs');
4
+ var node_module = require('node:module');
5
+ var node_url = require('node:url');
6
6
  var pathe = require('pathe');
7
7
 
8
8
  const isWindows = process.platform === "win32";
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { N as Nullable, A as Arrayable } from './index-CCsqCcr7.js';
1
+ import { N as Nullable, A as Arrayable } from './index-z0R8hVRu.js';
2
2
  import './trace-mapping.d-DLVdEqOp.js';
3
3
 
4
4
  declare const isWindows: boolean;
package/dist/utils.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { fileURLToPath, pathToFileURL } from 'node:url';
2
- import { builtinModules } from 'node:module';
3
1
  import { existsSync, promises } from 'node:fs';
2
+ import { builtinModules } from 'node:module';
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
4
  import { resolve, dirname, join } from 'pathe';
5
5
 
6
6
  const isWindows = process.platform === "win32";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "2.1.2",
4
+ "version": "2.1.4",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -78,7 +78,7 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "cac": "^6.7.14",
81
- "debug": "^4.3.6",
81
+ "debug": "^4.3.7",
82
82
  "pathe": "^1.1.2",
83
83
  "vite": "^5.0.0"
84
84
  },