vite-node 2.1.1 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -12,15 +12,15 @@ var hmr = require('./chunk-hmr.cjs');
12
12
  require('node:perf_hooks');
13
13
  require('node:fs');
14
14
  require('node:assert');
15
+ require('node:url');
15
16
  require('pathe');
16
17
  require('debug');
17
18
  require('./constants.cjs');
18
19
  require('node:module');
19
- require('node:url');
20
20
  require('node:vm');
21
21
  require('node:events');
22
22
 
23
- var version = "2.1.1";
23
+ var version = "2.1.3";
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
@@ -10,15 +10,15 @@ import { v as viteNodeHmrPlugin, a as createHotContext, h as handleMessage } fro
10
10
  import 'node:perf_hooks';
11
11
  import 'node:fs';
12
12
  import 'node:assert';
13
+ import 'node:url';
13
14
  import 'pathe';
14
15
  import 'debug';
15
16
  import './constants.mjs';
16
17
  import 'node:module';
17
- import 'node:url';
18
18
  import 'node:vm';
19
19
  import 'node:events';
20
20
 
21
- var version = "2.1.1";
21
+ var version = "2.1.3";
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.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, a as ViteNodeRunner } from './index-CCsqCcr7.js';
1
+ export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, a as ViteNodeRunner } from './index-z0R8hVRu.js';
2
2
  import './trace-mapping.d-DLVdEqOp.js';
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import { HMRPayload, Plugin } from 'vite';
3
- import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index-CCsqCcr7.js';
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;
@@ -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
@@ -3,13 +3,13 @@
3
3
  var node_perf_hooks = require('node:perf_hooks');
4
4
  var fs = require('node:fs');
5
5
  var assert = require('node:assert');
6
+ var node_url = require('node:url');
6
7
  var pathe = require('pathe');
7
8
  var createDebug = require('debug');
8
9
  var utils = require('./utils.cjs');
9
10
  var constants = require('./constants.cjs');
10
11
  var browser = require('./chunk-browser.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
 
@@ -17,6 +17,7 @@ const BUILTIN_EXTENSIONS = /* @__PURE__ */ new Set([".mjs", ".cjs", ".node", ".w
17
17
  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
18
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
19
19
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
20
+ const COMMENT_RE = /\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm;
20
21
  const defaultInline = [
21
22
  /virtual:/,
22
23
  /\.[mc]?ts$/,
@@ -72,7 +73,7 @@ async function isValidNodeImport(id) {
72
73
  return false;
73
74
  }
74
75
  const code = await fs.promises.readFile(id, "utf8").catch(() => "");
75
- return !ESM_SYNTAX_RE.test(code);
76
+ return !ESM_SYNTAX_RE.test(code.replace(COMMENT_RE, ""));
76
77
  }
77
78
  const _defaultExternalizeCache = /* @__PURE__ */ new Map();
78
79
  async function shouldExternalize(id, options, cache = _defaultExternalizeCache) {
@@ -93,6 +94,9 @@ async function _shouldExternalize(id, options) {
93
94
  if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.inline)) {
94
95
  return false;
95
96
  }
97
+ if ((options == null ? void 0 : options.inlineFiles) && (options == null ? void 0 : options.inlineFiles.includes(id))) {
98
+ return false;
99
+ }
96
100
  if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.external)) {
97
101
  return id;
98
102
  }
@@ -277,6 +281,15 @@ class ViteNodeServer {
277
281
  if (options.debug) {
278
282
  this.debugger = new Debugger(server.config.root, options.debug);
279
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
+ }
280
293
  (_c = options.deps).moduleDirectories ?? (_c.moduleDirectories = []);
281
294
  const envValue = process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES || process.env.npm_config_VITE_NODE_DEPS_MODULE_DIRECTORIES;
282
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,13 +1,13 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { existsSync, promises } from 'node:fs';
3
3
  import assert from 'node:assert';
4
+ import { pathToFileURL } from 'node:url';
4
5
  import { join, extname, dirname, resolve, relative, normalize } from 'pathe';
5
6
  import createDebug from 'debug';
6
7
  import { isNodeBuiltin, slash, findNearestPackageData, toArray, withTrailingSlash, normalizeModuleId, toFilePath } from './utils.mjs';
7
8
  import { KNOWN_ASSET_RE } from './constants.mjs';
8
9
  import { f } from './chunk-browser.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
 
@@ -15,6 +15,7 @@ const BUILTIN_EXTENSIONS = /* @__PURE__ */ new Set([".mjs", ".cjs", ".node", ".w
15
15
  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
16
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
17
17
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
18
+ const COMMENT_RE = /\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm;
18
19
  const defaultInline = [
19
20
  /virtual:/,
20
21
  /\.[mc]?ts$/,
@@ -70,7 +71,7 @@ async function isValidNodeImport(id) {
70
71
  return false;
71
72
  }
72
73
  const code = await promises.readFile(id, "utf8").catch(() => "");
73
- return !ESM_SYNTAX_RE.test(code);
74
+ return !ESM_SYNTAX_RE.test(code.replace(COMMENT_RE, ""));
74
75
  }
75
76
  const _defaultExternalizeCache = /* @__PURE__ */ new Map();
76
77
  async function shouldExternalize(id, options, cache = _defaultExternalizeCache) {
@@ -91,6 +92,9 @@ async function _shouldExternalize(id, options) {
91
92
  if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.inline)) {
92
93
  return false;
93
94
  }
95
+ if ((options == null ? void 0 : options.inlineFiles) && (options == null ? void 0 : options.inlineFiles.includes(id))) {
96
+ return false;
97
+ }
94
98
  if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.external)) {
95
99
  return id;
96
100
  }
@@ -275,6 +279,15 @@ class ViteNodeServer {
275
279
  if (options.debug) {
276
280
  this.debugger = new Debugger(server.config.root, options.debug);
277
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
+ }
278
291
  (_c = options.deps).moduleDirectories ?? (_c.moduleDirectories = []);
279
292
  const envValue = process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES || process.env.npm_config_VITE_NODE_DEPS_MODULE_DIRECTORIES;
280
293
  const customModuleDirectories = envValue == null ? void 0 : envValue.split(",");
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';
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/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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "2.1.1",
4
+ "version": "2.1.3",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",