vite-node 0.18.1 → 0.20.0

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
@@ -29,7 +29,7 @@ npx vite-node -h
29
29
 
30
30
  ### Options via CLI
31
31
 
32
- [All `ViteNodeServer` options](https://github.com/vitest-dev/vitest/blob/main/packages/vite-node/src/types.ts#L61-L78) are supported by the CLI. They may be defined through the dot syntax, as shown below:
32
+ [All `ViteNodeServer` options](https://github.com/vitest-dev/vitest/blob/main/packages/vite-node/src/types.ts#L70-L89) are supported by the CLI. They may be defined through the dot syntax, as shown below:
33
33
 
34
34
  ```bash
35
35
  npx vite-node --options.deps.inline="module-name" --options.deps.external="/module-regexp/" index.ts
@@ -81,6 +81,49 @@ await runner.executeFile('./example.ts')
81
81
  await server.close()
82
82
  ```
83
83
 
84
+ ## Debugging
85
+
86
+ ### Debug Transformation
87
+
88
+ Sometimes you might want to inspect the transformed code to investigate issues. You can set environment variable `VITE_NODE_DEBUG_DUMP=true` to let vite-node write the transformed result of each module under `.vite-node/dump`.
89
+
90
+ If you want to debug by modifying the dumped code, you can change the value of `VITE_NODE_DEBUG_DUMP` to `load` and search for the dumpped files and use them for executing.
91
+
92
+ ```bash
93
+ VITE_NODE_DEBUG_DUMP=load vite-node example.ts
94
+ ```
95
+
96
+ Or programmatically:
97
+
98
+ ```js
99
+ import { ViteNodeServer } from 'vite-node/server'
100
+
101
+ const server = new ViteNodeServer(viteServer, {
102
+ debug: {
103
+ dumpModules: true,
104
+ loadDumppedModules: true,
105
+ }
106
+ })
107
+ ```
108
+
109
+ ### Debug Execution
110
+
111
+ If the process get stuck, it might because there is a unresolvable circular dependencies, you can set `VITE_NODE_DEBUG_RUNNER=true` to vite-node warn about it.
112
+
113
+ ```bash
114
+ VITE_NODE_DEBUG_RUNNER=true vite-node example.ts
115
+ ```
116
+
117
+ Or programmatically:
118
+
119
+ ```js
120
+ import { ViteNodeRunner } from 'vite-node/client'
121
+
122
+ const runner = new ViteNodeRunner({
123
+ debug: true
124
+ })
125
+ ```
126
+
84
127
  ## Credits
85
128
 
86
129
  Based on [@pi0](https://github.com/pi0)'s brilliant idea of having a Vite server as the on-demand transforming service for [Nuxt's Vite SSR](https://github.com/nuxt/vite/pull/201).
package/cli.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ interface CliOptions {
2
+ files?: string[];
3
+ _?: string[];
4
+ root?: string;
5
+ config?: string;
6
+ }
7
+
8
+ export { CliOptions };
package/client.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { ViteNodeRunnerOptions, ModuleCache } from './types.js';
2
+
3
+ declare const DEFAULT_REQUEST_STUBS: {
4
+ '/@vite/client': {
5
+ injectQuery: (id: string) => string;
6
+ createHotContext(): {
7
+ accept: () => void;
8
+ prune: () => void;
9
+ };
10
+ updateStyle(): void;
11
+ };
12
+ };
13
+ declare class ViteNodeRunner {
14
+ options: ViteNodeRunnerOptions;
15
+ root: string;
16
+ moduleCache: Map<string, ModuleCache>;
17
+ constructor(options: ViteNodeRunnerOptions);
18
+ executeFile(file: string): Promise<any>;
19
+ executeId(id: string): Promise<any>;
20
+ cachedRequest(rawId: string, callstack: string[]): Promise<any>;
21
+ directRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
22
+ prepareContext(context: Record<string, any>): Record<string, any>;
23
+ setCache(id: string, mod: Partial<ModuleCache>): void;
24
+ shouldResolveId(dep: string): boolean;
25
+ /**
26
+ * Define if a module should be interop-ed
27
+ * This function mostly for the ability to override by subclass
28
+ */
29
+ shouldInterop(path: string, mod: any): boolean;
30
+ /**
31
+ * Import a module and interop it
32
+ */
33
+ interopedImport(path: string): Promise<any>;
34
+ hasNestedDefault(target: any): any;
35
+ }
36
+
37
+ export { DEFAULT_REQUEST_STUBS, ViteNodeRunner };
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var pathe = require('pathe');
5
+ var picocolors = require('./chunk-picocolors.cjs');
6
+ require('tty');
7
+
8
+ function hashCode(s) {
9
+ return s.split("").reduce((a, b) => {
10
+ a = (a << 5) - a + b.charCodeAt(0);
11
+ return a & a;
12
+ }, 0);
13
+ }
14
+ class Debugger {
15
+ constructor(root, options) {
16
+ this.options = options;
17
+ this.externalizeMap = /* @__PURE__ */ new Map();
18
+ if (options.dumpModules)
19
+ this.dumpDir = pathe.resolve(root, options.dumpModules === true ? ".vite-node/dump" : options.dumpModules);
20
+ if (this.dumpDir) {
21
+ if (options.loadDumppedModules)
22
+ console.info(picocolors.picocolors.exports.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`));
23
+ else
24
+ console.info(picocolors.picocolors.exports.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`));
25
+ }
26
+ this.initPromise = this.clearDump();
27
+ }
28
+ async clearDump() {
29
+ if (!this.dumpDir)
30
+ return;
31
+ if (!this.options.loadDumppedModules && fs.existsSync(this.dumpDir))
32
+ await fs.promises.rm(this.dumpDir, { recursive: true, force: true });
33
+ await fs.promises.mkdir(this.dumpDir, { recursive: true });
34
+ }
35
+ encodeId(id) {
36
+ return `${id.replace(/[^\w@_-]/g, "_").replace(/_+/g, "_")}-${hashCode(id)}.js`;
37
+ }
38
+ async recordExternalize(id, path) {
39
+ if (!this.dumpDir)
40
+ return;
41
+ this.externalizeMap.set(id, path);
42
+ await this.writeInfo();
43
+ }
44
+ async dumpFile(id, result) {
45
+ if (!result || !this.dumpDir)
46
+ return;
47
+ await this.initPromise;
48
+ const name = this.encodeId(id);
49
+ return await fs.promises.writeFile(pathe.join(this.dumpDir, name), `// ${id.replace(/\0/g, "\\0")}
50
+ ${result.code}`, "utf-8");
51
+ }
52
+ async loadDump(id) {
53
+ if (!this.dumpDir)
54
+ return null;
55
+ await this.initPromise;
56
+ const name = this.encodeId(id);
57
+ const path = pathe.join(this.dumpDir, name);
58
+ if (!fs.existsSync(path))
59
+ return null;
60
+ const code = await fs.promises.readFile(path, "utf-8");
61
+ return {
62
+ code: code.replace(/^\/\/.*?\n/, ""),
63
+ map: void 0
64
+ };
65
+ }
66
+ async writeInfo() {
67
+ if (!this.dumpDir)
68
+ return;
69
+ const info = JSON.stringify({
70
+ time: new Date().toLocaleString(),
71
+ externalize: Object.fromEntries(this.externalizeMap.entries())
72
+ }, null, 2);
73
+ return fs.promises.writeFile(pathe.join(this.dumpDir, "info.json"), info, "utf-8");
74
+ }
75
+ }
76
+
77
+ exports.Debugger = Debugger;
@@ -0,0 +1,75 @@
1
+ import { existsSync, promises } from 'fs';
2
+ import { resolve, join } from 'pathe';
3
+ import { p as picocolors } from './chunk-picocolors.mjs';
4
+ import 'tty';
5
+
6
+ function hashCode(s) {
7
+ return s.split("").reduce((a, b) => {
8
+ a = (a << 5) - a + b.charCodeAt(0);
9
+ return a & a;
10
+ }, 0);
11
+ }
12
+ class Debugger {
13
+ constructor(root, options) {
14
+ this.options = options;
15
+ this.externalizeMap = /* @__PURE__ */ new Map();
16
+ if (options.dumpModules)
17
+ this.dumpDir = resolve(root, options.dumpModules === true ? ".vite-node/dump" : options.dumpModules);
18
+ if (this.dumpDir) {
19
+ if (options.loadDumppedModules)
20
+ console.info(picocolors.exports.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`));
21
+ else
22
+ console.info(picocolors.exports.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`));
23
+ }
24
+ this.initPromise = this.clearDump();
25
+ }
26
+ async clearDump() {
27
+ if (!this.dumpDir)
28
+ return;
29
+ if (!this.options.loadDumppedModules && existsSync(this.dumpDir))
30
+ await promises.rm(this.dumpDir, { recursive: true, force: true });
31
+ await promises.mkdir(this.dumpDir, { recursive: true });
32
+ }
33
+ encodeId(id) {
34
+ return `${id.replace(/[^\w@_-]/g, "_").replace(/_+/g, "_")}-${hashCode(id)}.js`;
35
+ }
36
+ async recordExternalize(id, path) {
37
+ if (!this.dumpDir)
38
+ return;
39
+ this.externalizeMap.set(id, path);
40
+ await this.writeInfo();
41
+ }
42
+ async dumpFile(id, result) {
43
+ if (!result || !this.dumpDir)
44
+ return;
45
+ await this.initPromise;
46
+ const name = this.encodeId(id);
47
+ return await promises.writeFile(join(this.dumpDir, name), `// ${id.replace(/\0/g, "\\0")}
48
+ ${result.code}`, "utf-8");
49
+ }
50
+ async loadDump(id) {
51
+ if (!this.dumpDir)
52
+ return null;
53
+ await this.initPromise;
54
+ const name = this.encodeId(id);
55
+ const path = join(this.dumpDir, name);
56
+ if (!existsSync(path))
57
+ return null;
58
+ const code = await promises.readFile(path, "utf-8");
59
+ return {
60
+ code: code.replace(/^\/\/.*?\n/, ""),
61
+ map: void 0
62
+ };
63
+ }
64
+ async writeInfo() {
65
+ if (!this.dumpDir)
66
+ return;
67
+ const info = JSON.stringify({
68
+ time: new Date().toLocaleString(),
69
+ externalize: Object.fromEntries(this.externalizeMap.entries())
70
+ }, null, 2);
71
+ return promises.writeFile(join(this.dumpDir, "info.json"), info, "utf-8");
72
+ }
73
+ }
74
+
75
+ export { Debugger };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var events = require('events');
4
- var kolorist = require('kolorist');
4
+ var picocolors = require('./chunk-picocolors.cjs');
5
5
  var createDebug = require('debug');
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -113,7 +113,7 @@ async function fetchUpdate(runner, { path, acceptedPath }) {
113
113
  for (const { deps, fn } of qualifiedCallbacks)
114
114
  fn(deps.map((dep) => moduleMap.get(dep)));
115
115
  const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
116
- console.log(`${kolorist.cyan("[vite-node]")} hot updated: ${loggedPath}`);
116
+ console.log(`${picocolors.picocolors.exports.cyan("[vite-node]")} hot updated: ${loggedPath}`);
117
117
  };
118
118
  }
119
119
  function warnFailedFetch(err, path) {
@@ -137,7 +137,7 @@ async function handleMessage(runner, emitter, files, payload) {
137
137
  if (update.type === "js-update") {
138
138
  queueUpdate(runner, fetchUpdate(runner, update));
139
139
  } else {
140
- console.error(`${kolorist.cyan("[vite-node]")} no support css hmr.}`);
140
+ console.error(`${picocolors.picocolors.exports.cyan("[vite-node]")} no support css hmr.}`);
141
141
  }
142
142
  });
143
143
  break;
@@ -154,7 +154,7 @@ async function handleMessage(runner, emitter, files, payload) {
154
154
  case "error": {
155
155
  notifyListeners(runner, "vite:error", payload);
156
156
  const err = payload.err;
157
- console.error(`${kolorist.cyan("[vite-node]")} Internal Server Error
157
+ console.error(`${picocolors.picocolors.exports.cyan("[vite-node]")} Internal Server Error
158
158
  ${err.message}
159
159
  ${err.stack}`);
160
160
  break;
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'events';
2
- import { cyan } from 'kolorist';
2
+ import { p as picocolors } from './chunk-picocolors.mjs';
3
3
  import createDebug from 'debug';
4
4
 
5
5
  function createHmrEmitter() {
@@ -107,7 +107,7 @@ async function fetchUpdate(runner, { path, acceptedPath }) {
107
107
  for (const { deps, fn } of qualifiedCallbacks)
108
108
  fn(deps.map((dep) => moduleMap.get(dep)));
109
109
  const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
110
- console.log(`${cyan("[vite-node]")} hot updated: ${loggedPath}`);
110
+ console.log(`${picocolors.exports.cyan("[vite-node]")} hot updated: ${loggedPath}`);
111
111
  };
112
112
  }
113
113
  function warnFailedFetch(err, path) {
@@ -131,7 +131,7 @@ async function handleMessage(runner, emitter, files, payload) {
131
131
  if (update.type === "js-update") {
132
132
  queueUpdate(runner, fetchUpdate(runner, update));
133
133
  } else {
134
- console.error(`${cyan("[vite-node]")} no support css hmr.}`);
134
+ console.error(`${picocolors.exports.cyan("[vite-node]")} no support css hmr.}`);
135
135
  }
136
136
  });
137
137
  break;
@@ -148,7 +148,7 @@ async function handleMessage(runner, emitter, files, payload) {
148
148
  case "error": {
149
149
  notifyListeners(runner, "vite:error", payload);
150
150
  const err = payload.err;
151
- console.error(`${cyan("[vite-node]")} Internal Server Error
151
+ console.error(`${picocolors.exports.cyan("[vite-node]")} Internal Server Error
152
152
  ${err.message}
153
153
  ${err.stack}`);
154
154
  break;
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ var require$$0 = require('tty');
4
+
5
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
6
+
7
+ var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
8
+
9
+ var picocolors = {exports: {}};
10
+
11
+ let tty = require$$0__default["default"];
12
+
13
+ let isColorSupported =
14
+ !("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
15
+ ("FORCE_COLOR" in process.env ||
16
+ process.argv.includes("--color") ||
17
+ process.platform === "win32" ||
18
+ (tty.isatty(1) && process.env.TERM !== "dumb") ||
19
+ "CI" in process.env);
20
+
21
+ let formatter =
22
+ (open, close, replace = open) =>
23
+ input => {
24
+ let string = "" + input;
25
+ let index = string.indexOf(close, open.length);
26
+ return ~index
27
+ ? open + replaceClose(string, close, replace, index) + close
28
+ : open + string + close
29
+ };
30
+
31
+ let replaceClose = (string, close, replace, index) => {
32
+ let start = string.substring(0, index) + replace;
33
+ let end = string.substring(index + close.length);
34
+ let nextIndex = end.indexOf(close);
35
+ return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
36
+ };
37
+
38
+ let createColors = (enabled = isColorSupported) => ({
39
+ isColorSupported: enabled,
40
+ reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
41
+ bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
42
+ dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
43
+ italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
44
+ underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
45
+ inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
46
+ hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
47
+ strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
48
+ black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
49
+ red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
50
+ green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
51
+ yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
52
+ blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
53
+ magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
54
+ cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
55
+ white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
56
+ gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
57
+ bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
58
+ bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
59
+ bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
60
+ bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
61
+ bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
62
+ bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
63
+ bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
64
+ bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
65
+ });
66
+
67
+ picocolors.exports = createColors();
68
+ picocolors.exports.createColors = createColors;
69
+
70
+ exports.picocolors = picocolors;
@@ -0,0 +1,64 @@
1
+ import require$$0 from 'tty';
2
+
3
+ var picocolors = {exports: {}};
4
+
5
+ let tty = require$$0;
6
+
7
+ let isColorSupported =
8
+ !("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
9
+ ("FORCE_COLOR" in process.env ||
10
+ process.argv.includes("--color") ||
11
+ process.platform === "win32" ||
12
+ (tty.isatty(1) && process.env.TERM !== "dumb") ||
13
+ "CI" in process.env);
14
+
15
+ let formatter =
16
+ (open, close, replace = open) =>
17
+ input => {
18
+ let string = "" + input;
19
+ let index = string.indexOf(close, open.length);
20
+ return ~index
21
+ ? open + replaceClose(string, close, replace, index) + close
22
+ : open + string + close
23
+ };
24
+
25
+ let replaceClose = (string, close, replace, index) => {
26
+ let start = string.substring(0, index) + replace;
27
+ let end = string.substring(index + close.length);
28
+ let nextIndex = end.indexOf(close);
29
+ return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
30
+ };
31
+
32
+ let createColors = (enabled = isColorSupported) => ({
33
+ isColorSupported: enabled,
34
+ reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
35
+ bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
36
+ dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
37
+ italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
38
+ underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
39
+ inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
40
+ hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
41
+ strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
42
+ black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
43
+ red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
44
+ green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
45
+ yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
46
+ blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
47
+ magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
48
+ cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
49
+ white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
50
+ gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
51
+ bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
52
+ bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
53
+ bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
54
+ bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
55
+ bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
56
+ bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
57
+ bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
58
+ bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
59
+ });
60
+
61
+ picocolors.exports = createColors();
62
+ picocolors.exports.createColors = createColors;
63
+
64
+ export { picocolors as p };
package/dist/cli.cjs CHANGED
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  var events = require('events');
4
- var kolorist = require('kolorist');
4
+ var picocolors = require('./chunk-picocolors.cjs');
5
5
  var vite = require('vite');
6
6
  var server = require('./server.cjs');
7
7
  var client = require('./client.cjs');
8
8
  var utils = require('./utils.cjs');
9
9
  var hmr = require('./chunk-hmr.cjs');
10
+ require('tty');
10
11
  require('pathe');
11
12
  require('debug');
12
13
  require('fs');
@@ -628,7 +629,7 @@ class CAC extends events.EventEmitter {
628
629
 
629
630
  const cac = (name = "") => new CAC(name);
630
631
 
631
- var version = "0.18.1";
632
+ var version = "0.20.0";
632
633
 
633
634
  const cli = cac("vite-node");
634
635
  cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
@@ -637,12 +638,12 @@ cli.parse();
637
638
  async function run(files, options = {}) {
638
639
  var _a;
639
640
  if (!files.length) {
640
- console.error(kolorist.red("No files specified."));
641
+ console.error(picocolors.picocolors.exports.red("No files specified."));
641
642
  cli.outputHelp();
642
643
  process.exit(1);
643
644
  }
644
645
  process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
645
- const parsedServerOptions = options.options ? parseServerOptions(options.options) : void 0;
646
+ const serverOptions = options.options ? parseServerOptions(options.options) : {};
646
647
  const server$1 = await vite.createServer({
647
648
  logLevel: "error",
648
649
  configFile: options.config,
@@ -652,7 +653,7 @@ async function run(files, options = {}) {
652
653
  ]
653
654
  });
654
655
  await server$1.pluginContainer.buildStart({});
655
- const node = new server.ViteNodeServer(server$1, parsedServerOptions);
656
+ const node = new server.ViteNodeServer(server$1, serverOptions);
656
657
  const runner = new client.ViteNodeRunner({
657
658
  root: server$1.config.root,
658
659
  base: server$1.config.base,
package/dist/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { e as ViteNodeServerOptions } from './types-041865e7.js';
1
+ import { e as ViteNodeServerOptions } from './types-4f4de592.js';
2
2
 
3
3
  interface CliOptions {
4
4
  root?: string;
package/dist/cli.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  import { EventEmitter } from 'events';
2
- import { red } from 'kolorist';
2
+ import { p as picocolors } from './chunk-picocolors.mjs';
3
3
  import { createServer } from 'vite';
4
4
  import { ViteNodeServer } from './server.mjs';
5
5
  import { ViteNodeRunner } from './client.mjs';
6
6
  import { toArray } from './utils.mjs';
7
7
  import { v as viteNodeHmrPlugin, c as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
8
+ import 'tty';
8
9
  import 'pathe';
9
10
  import 'debug';
10
11
  import 'fs';
@@ -626,7 +627,7 @@ class CAC extends EventEmitter {
626
627
 
627
628
  const cac = (name = "") => new CAC(name);
628
629
 
629
- var version = "0.18.1";
630
+ var version = "0.20.0";
630
631
 
631
632
  const cli = cac("vite-node");
632
633
  cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
@@ -635,12 +636,12 @@ cli.parse();
635
636
  async function run(files, options = {}) {
636
637
  var _a;
637
638
  if (!files.length) {
638
- console.error(red("No files specified."));
639
+ console.error(picocolors.exports.red("No files specified."));
639
640
  cli.outputHelp();
640
641
  process.exit(1);
641
642
  }
642
643
  process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
643
- const parsedServerOptions = options.options ? parseServerOptions(options.options) : void 0;
644
+ const serverOptions = options.options ? parseServerOptions(options.options) : {};
644
645
  const server = await createServer({
645
646
  logLevel: "error",
646
647
  configFile: options.config,
@@ -650,7 +651,7 @@ async function run(files, options = {}) {
650
651
  ]
651
652
  });
652
653
  await server.pluginContainer.buildStart({});
653
- const node = new ViteNodeServer(server, parsedServerOptions);
654
+ const node = new ViteNodeServer(server, serverOptions);
654
655
  const runner = new ViteNodeRunner({
655
656
  root: server.config.root,
656
657
  base: server.config.base,
package/dist/client.cjs CHANGED
@@ -54,7 +54,18 @@ const DEFAULT_REQUEST_STUBS = {
54
54
  }
55
55
  };
56
56
  },
57
- updateStyle() {
57
+ updateStyle(id, css) {
58
+ if (typeof document === "undefined")
59
+ return;
60
+ const element = document.getElementById(id);
61
+ if (element)
62
+ element.remove();
63
+ const head = document.querySelector("head");
64
+ const style = document.createElement("style");
65
+ style.setAttribute("type", "text/css");
66
+ style.id = id;
67
+ style.innerHTML = css;
68
+ head == null ? void 0 : head.appendChild(style);
58
69
  }
59
70
  }
60
71
  };
@@ -84,7 +95,7 @@ class ViteNodeRunner {
84
95
  this.options = options;
85
96
  this.root = options.root ?? process.cwd();
86
97
  this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
87
- this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG : false);
98
+ this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
88
99
  }
89
100
  async executeFile(file) {
90
101
  return await this.cachedRequest(`/@fs/${utils.slash(pathe.resolve(file))}`, []);
@@ -115,11 +126,10 @@ ${[...callstack, fsPath2].reverse().map((p) => `- ${p}`).join("\n")}`;
115
126
  };
116
127
  let debugTimer;
117
128
  if (this.debug)
118
- debugTimer = setTimeout(() => this.debugLog(() => `module ${fsPath2} takes over 2s to load.
129
+ debugTimer = setTimeout(() => console.warn(() => `module ${fsPath2} takes over 2s to load.
119
130
  ${getStack()}`), 2e3);
120
131
  try {
121
132
  if (callstack.includes(fsPath2)) {
122
- this.debugLog(() => `circular dependency, ${getStack()}`);
123
133
  const depExports = (_a = this.moduleCache.get(fsPath2)) == null ? void 0 : _a.exports;
124
134
  if (depExports)
125
135
  return depExports;
@@ -235,10 +245,6 @@ ${getStack()}`), 2e3);
235
245
  hasNestedDefault(target) {
236
246
  return "__esModule" in target && target.__esModule && "default" in target.default;
237
247
  }
238
- debugLog(msg) {
239
- if (this.debug)
240
- console.log(`[vite-node] ${msg()}`);
241
- }
242
248
  }
243
249
  function proxyMethod(name, tryDefault) {
244
250
  return function(target, key, ...args) {
package/dist/client.d.ts CHANGED
@@ -1 +1 @@
1
- export { i as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, g as ViteNodeRunner } from './types-041865e7.js';
1
+ export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-4f4de592.js';
package/dist/client.mjs CHANGED
@@ -27,7 +27,18 @@ const DEFAULT_REQUEST_STUBS = {
27
27
  }
28
28
  };
29
29
  },
30
- updateStyle() {
30
+ updateStyle(id, css) {
31
+ if (typeof document === "undefined")
32
+ return;
33
+ const element = document.getElementById(id);
34
+ if (element)
35
+ element.remove();
36
+ const head = document.querySelector("head");
37
+ const style = document.createElement("style");
38
+ style.setAttribute("type", "text/css");
39
+ style.id = id;
40
+ style.innerHTML = css;
41
+ head == null ? void 0 : head.appendChild(style);
31
42
  }
32
43
  }
33
44
  };
@@ -57,7 +68,7 @@ class ViteNodeRunner {
57
68
  this.options = options;
58
69
  this.root = options.root ?? process.cwd();
59
70
  this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
60
- this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG : false);
71
+ this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
61
72
  }
62
73
  async executeFile(file) {
63
74
  return await this.cachedRequest(`/@fs/${slash(resolve(file))}`, []);
@@ -88,11 +99,10 @@ ${[...callstack, fsPath2].reverse().map((p) => `- ${p}`).join("\n")}`;
88
99
  };
89
100
  let debugTimer;
90
101
  if (this.debug)
91
- debugTimer = setTimeout(() => this.debugLog(() => `module ${fsPath2} takes over 2s to load.
102
+ debugTimer = setTimeout(() => console.warn(() => `module ${fsPath2} takes over 2s to load.
92
103
  ${getStack()}`), 2e3);
93
104
  try {
94
105
  if (callstack.includes(fsPath2)) {
95
- this.debugLog(() => `circular dependency, ${getStack()}`);
96
106
  const depExports = (_a = this.moduleCache.get(fsPath2)) == null ? void 0 : _a.exports;
97
107
  if (depExports)
98
108
  return depExports;
@@ -208,10 +218,6 @@ ${getStack()}`), 2e3);
208
218
  hasNestedDefault(target) {
209
219
  return "__esModule" in target && target.__esModule && "default" in target.default;
210
220
  }
211
- debugLog(msg) {
212
- if (this.debug)
213
- console.log(`[vite-node] ${msg()}`);
214
- }
215
221
  }
216
222
  function proxyMethod(name, tryDefault) {
217
223
  return function(target, key, ...args) {
package/dist/hmr.cjs CHANGED
@@ -4,7 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var hmr = require('./chunk-hmr.cjs');
6
6
  require('events');
7
- require('kolorist');
7
+ require('./chunk-picocolors.cjs');
8
+ require('tty');
8
9
  require('debug');
9
10
 
10
11
 
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { HMRPayload, Plugin } from 'vite';
3
- import { U as UpdatePayload, P as PrunePayload, f as FullReloadPayload, E as ErrorPayload, g as ViteNodeRunner, h as HMRPayload$1, H as HotContext } from './types-041865e7.js';
3
+ import { U as UpdatePayload, P as PrunePayload, g as FullReloadPayload, E as ErrorPayload, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-4f4de592.js';
4
4
 
5
5
  declare type EventType = string | symbol;
6
6
  declare type Handler<T = unknown> = (event: T) => void;
package/dist/hmr.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  export { a as createHmrEmitter, c as createHotContext, g as getCache, h as handleMessage, r as reload, s as sendMessageBuffer, v as viteNodeHmrPlugin } from './chunk-hmr.mjs';
2
2
  import 'events';
3
- import 'kolorist';
3
+ import './chunk-picocolors.mjs';
4
+ import 'tty';
4
5
  import 'debug';
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { A as Arrayable, C as CreateHotContextFunction, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-041865e7.js';
1
+ export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-4f4de592.js';
package/dist/server.cjs CHANGED
@@ -17,7 +17,7 @@ const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
17
17
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
18
18
  const defaultInline = [
19
19
  /virtual:/,
20
- /\.ts$/
20
+ /\.[mc]?ts$/
21
21
  ];
22
22
  const depsExternal = [
23
23
  /\.cjs\.js$/,
@@ -47,7 +47,8 @@ function guessCJSversion(id) {
47
47
  }
48
48
  }
49
49
  }
50
- async function shouldExternalize(id, options, cache = /* @__PURE__ */ new Map()) {
50
+ const _defaultExternalizeCache = /* @__PURE__ */ new Map();
51
+ async function shouldExternalize(id, options, cache = _defaultExternalizeCache) {
51
52
  if (!cache.has(id))
52
53
  cache.set(id, _shouldExternalize(id, options));
53
54
  return cache.get(id);
@@ -108,6 +109,7 @@ class ViteNodeServer {
108
109
  this.fetchPromiseMap = /* @__PURE__ */ new Map();
109
110
  this.transformPromiseMap = /* @__PURE__ */ new Map();
110
111
  this.fetchCache = /* @__PURE__ */ new Map();
112
+ this.externalizeCache = /* @__PURE__ */ new Map();
111
113
  var _a, _b;
112
114
  const ssrOptions = server.config.ssr;
113
115
  if (ssrOptions) {
@@ -119,9 +121,17 @@ class ViteNodeServer {
119
121
  options.deps.inline.push(...utils.toArray(ssrOptions.noExternal));
120
122
  }
121
123
  }
124
+ if (process.env.VITE_NODE_DEBUG_DUMP) {
125
+ options.debug = Object.assign({
126
+ dumpModules: !!process.env.VITE_NODE_DEBUG_DUMP,
127
+ loadDumppedModules: process.env.VITE_NODE_DEBUG_DUMP === "load"
128
+ }, options.debug ?? {});
129
+ }
130
+ if (options.debug)
131
+ Promise.resolve().then(function () { return require('./chunk-debug.cjs'); }).then((r) => this.debugger = new r.Debugger(server.config.root, options.debug));
122
132
  }
123
133
  shouldExternalize(id) {
124
- return shouldExternalize(id, this.options.deps);
134
+ return shouldExternalize(id, this.options.deps, this.externalizeCache);
125
135
  }
126
136
  async resolveId(id, importer) {
127
137
  if (importer && !importer.startsWith(this.server.config.root))
@@ -159,6 +169,7 @@ class ViteNodeServer {
159
169
  return "web";
160
170
  }
161
171
  async _fetchModule(id) {
172
+ var _a;
162
173
  let result;
163
174
  const filePath = utils.toFilePath(id, this.server.config.root);
164
175
  const module = this.server.moduleGraph.getModuleById(id);
@@ -169,6 +180,7 @@ class ViteNodeServer {
169
180
  const externalize = await this.shouldExternalize(filePath);
170
181
  if (externalize) {
171
182
  result = { externalize };
183
+ (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
172
184
  } else {
173
185
  const r = await this._transformRequest(id);
174
186
  result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
@@ -180,8 +192,14 @@ class ViteNodeServer {
180
192
  return result;
181
193
  }
182
194
  async _transformRequest(id) {
195
+ var _a, _b, _c, _d;
183
196
  debugRequest(id);
184
197
  let result = null;
198
+ if ((_a = this.options.debug) == null ? void 0 : _a.loadDumppedModules) {
199
+ result = await ((_b = this.debugger) == null ? void 0 : _b.loadDump(id)) ?? null;
200
+ if (result)
201
+ return result;
202
+ }
185
203
  if (this.getTransformMode(id) === "web") {
186
204
  result = await this.server.transformRequest(id);
187
205
  if (result)
@@ -192,6 +210,8 @@ class ViteNodeServer {
192
210
  const sourcemap = this.options.sourcemap ?? "inline";
193
211
  if (sourcemap === "inline" && result && !id.includes("node_modules"))
194
212
  utils.withInlineSourcemap(result);
213
+ if ((_c = this.options.debug) == null ? void 0 : _c.dumpModules)
214
+ await ((_d = this.debugger) == null ? void 0 : _d.dumpFile(id, result));
195
215
  return result;
196
216
  }
197
217
  }
package/dist/server.d.ts CHANGED
@@ -1,5 +1,19 @@
1
- import { ViteDevServer, TransformResult } from 'vite';
2
- import { D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './types-041865e7.js';
1
+ import { TransformResult, ViteDevServer } from 'vite';
2
+ import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './types-4f4de592.js';
3
+
4
+ declare class Debugger {
5
+ options: DebuggerOptions;
6
+ dumpDir: string | undefined;
7
+ initPromise: Promise<void> | undefined;
8
+ externalizeMap: Map<string, string>;
9
+ constructor(root: string, options: DebuggerOptions);
10
+ clearDump(): Promise<void>;
11
+ encodeId(id: string): string;
12
+ recordExternalize(id: string, path: string): Promise<void>;
13
+ dumpFile(id: string, result: TransformResult | null): Promise<void>;
14
+ loadDump(id: string): Promise<TransformResult | null>;
15
+ writeInfo(): Promise<void>;
16
+ }
3
17
 
4
18
  declare function guessCJSversion(id: string): string | undefined;
5
19
  declare function shouldExternalize(id: string, options?: DepsHandlingOptions, cache?: Map<string, Promise<string | false>>): Promise<string | false>;
@@ -13,6 +27,8 @@ declare class ViteNodeServer {
13
27
  timestamp: number;
14
28
  result: FetchResult;
15
29
  }>;
30
+ externalizeCache: Map<string, Promise<string | false>>;
31
+ debugger?: Debugger;
16
32
  constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
17
33
  shouldExternalize(id: string): Promise<string | false>;
18
34
  resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
package/dist/server.mjs CHANGED
@@ -9,7 +9,7 @@ const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
9
9
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
10
10
  const defaultInline = [
11
11
  /virtual:/,
12
- /\.ts$/
12
+ /\.[mc]?ts$/
13
13
  ];
14
14
  const depsExternal = [
15
15
  /\.cjs\.js$/,
@@ -39,7 +39,8 @@ function guessCJSversion(id) {
39
39
  }
40
40
  }
41
41
  }
42
- async function shouldExternalize(id, options, cache = /* @__PURE__ */ new Map()) {
42
+ const _defaultExternalizeCache = /* @__PURE__ */ new Map();
43
+ async function shouldExternalize(id, options, cache = _defaultExternalizeCache) {
43
44
  if (!cache.has(id))
44
45
  cache.set(id, _shouldExternalize(id, options));
45
46
  return cache.get(id);
@@ -100,6 +101,7 @@ class ViteNodeServer {
100
101
  this.fetchPromiseMap = /* @__PURE__ */ new Map();
101
102
  this.transformPromiseMap = /* @__PURE__ */ new Map();
102
103
  this.fetchCache = /* @__PURE__ */ new Map();
104
+ this.externalizeCache = /* @__PURE__ */ new Map();
103
105
  var _a, _b;
104
106
  const ssrOptions = server.config.ssr;
105
107
  if (ssrOptions) {
@@ -111,9 +113,17 @@ class ViteNodeServer {
111
113
  options.deps.inline.push(...toArray(ssrOptions.noExternal));
112
114
  }
113
115
  }
116
+ if (process.env.VITE_NODE_DEBUG_DUMP) {
117
+ options.debug = Object.assign({
118
+ dumpModules: !!process.env.VITE_NODE_DEBUG_DUMP,
119
+ loadDumppedModules: process.env.VITE_NODE_DEBUG_DUMP === "load"
120
+ }, options.debug ?? {});
121
+ }
122
+ if (options.debug)
123
+ import('./chunk-debug.mjs').then((r) => this.debugger = new r.Debugger(server.config.root, options.debug));
114
124
  }
115
125
  shouldExternalize(id) {
116
- return shouldExternalize(id, this.options.deps);
126
+ return shouldExternalize(id, this.options.deps, this.externalizeCache);
117
127
  }
118
128
  async resolveId(id, importer) {
119
129
  if (importer && !importer.startsWith(this.server.config.root))
@@ -151,6 +161,7 @@ class ViteNodeServer {
151
161
  return "web";
152
162
  }
153
163
  async _fetchModule(id) {
164
+ var _a;
154
165
  let result;
155
166
  const filePath = toFilePath(id, this.server.config.root);
156
167
  const module = this.server.moduleGraph.getModuleById(id);
@@ -161,6 +172,7 @@ class ViteNodeServer {
161
172
  const externalize = await this.shouldExternalize(filePath);
162
173
  if (externalize) {
163
174
  result = { externalize };
175
+ (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
164
176
  } else {
165
177
  const r = await this._transformRequest(id);
166
178
  result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
@@ -172,8 +184,14 @@ class ViteNodeServer {
172
184
  return result;
173
185
  }
174
186
  async _transformRequest(id) {
187
+ var _a, _b, _c, _d;
175
188
  debugRequest(id);
176
189
  let result = null;
190
+ if ((_a = this.options.debug) == null ? void 0 : _a.loadDumppedModules) {
191
+ result = await ((_b = this.debugger) == null ? void 0 : _b.loadDump(id)) ?? null;
192
+ if (result)
193
+ return result;
194
+ }
177
195
  if (this.getTransformMode(id) === "web") {
178
196
  result = await this.server.transformRequest(id);
179
197
  if (result)
@@ -184,6 +202,8 @@ class ViteNodeServer {
184
202
  const sourcemap = this.options.sourcemap ?? "inline";
185
203
  if (sourcemap === "inline" && result && !id.includes("node_modules"))
186
204
  withInlineSourcemap(result);
205
+ if ((_c = this.options.debug) == null ? void 0 : _c.dumpModules)
206
+ await ((_d = this.debugger) == null ? void 0 : _d.dumpFile(id, result));
187
207
  return result;
188
208
  }
189
209
  }
@@ -101,7 +101,7 @@ declare const DEFAULT_REQUEST_STUBS: {
101
101
  invalidate: () => void;
102
102
  on: () => void;
103
103
  };
104
- updateStyle(): void;
104
+ updateStyle(id: string, css: string): void;
105
105
  };
106
106
  };
107
107
  declare class ModuleCacheMap extends Map<string, ModuleCache> {
@@ -138,7 +138,6 @@ declare class ViteNodeRunner {
138
138
  */
139
139
  interopedImport(path: string): Promise<any>;
140
140
  hasNestedDefault(target: any): any;
141
- private debugLog;
142
141
  }
143
142
 
144
143
  declare type Nullable<T> = T | null | undefined;
@@ -212,6 +211,19 @@ interface ViteNodeServerOptions {
212
211
  ssr?: RegExp[];
213
212
  web?: RegExp[];
214
213
  };
214
+ debug?: DebuggerOptions;
215
+ }
216
+ interface DebuggerOptions {
217
+ /**
218
+ * Dump the transformed module to filesystem
219
+ * Passing a string will dump to the specified path
220
+ */
221
+ dumpModules?: boolean | string;
222
+ /**
223
+ * Read dumpped module from filesystem whenever exists.
224
+ * Useful for debugging by modifying the dump result from the filesystem.
225
+ */
226
+ loadDumppedModules?: boolean;
215
227
  }
216
228
 
217
- export { Arrayable as A, CreateHotContextFunction as C, DepsHandlingOptions as D, ErrorPayload as E, FetchResult as F, HotContext as H, ModuleCacheMap as M, Nullable as N, PrunePayload as P, RawSourceMap as R, StartOfSourceMap as S, UpdatePayload as U, ViteNodeRunnerOptions as V, FetchFunction as a, ResolveIdFunction as b, ModuleCache as c, ViteNodeResolveId as d, ViteNodeServerOptions as e, FullReloadPayload as f, ViteNodeRunner as g, HMRPayload as h, DEFAULT_REQUEST_STUBS as i };
229
+ export { Arrayable as A, CreateHotContextFunction as C, DepsHandlingOptions as D, ErrorPayload as E, FetchResult as F, HotContext as H, ModuleCacheMap as M, Nullable as N, PrunePayload as P, RawSourceMap as R, StartOfSourceMap as S, UpdatePayload as U, ViteNodeRunnerOptions as V, FetchFunction as a, ResolveIdFunction as b, ModuleCache as c, ViteNodeResolveId as d, ViteNodeServerOptions as e, DebuggerOptions as f, FullReloadPayload as g, ViteNodeRunner as h, HMRPayload as i, DEFAULT_REQUEST_STUBS as j };
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- export { A as Arrayable, C as CreateHotContextFunction, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-041865e7.js';
1
+ export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-4f4de592.js';
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TransformResult } from 'vite';
2
- import { N as Nullable, A as Arrayable } from './types-041865e7.js';
2
+ import { N as Nullable, A as Arrayable } from './types-4f4de592.js';
3
3
 
4
4
  declare const isWindows: boolean;
5
5
  declare function slash(str: string): string;
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, RawSourceMap, ResolveIdFunction, StartOfSourceMap, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions } from './types.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.18.1",
3
+ "version": "0.20.0",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -65,7 +65,6 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "debug": "^4.3.4",
68
- "kolorist": "^1.5.1",
69
68
  "mlly": "^0.5.4",
70
69
  "pathe": "^0.2.0",
71
70
  "vite": "^2.9.12 || ^3.0.0-0"
@@ -73,6 +72,7 @@
73
72
  "devDependencies": {
74
73
  "@types/debug": "^4.1.7",
75
74
  "cac": "^6.7.12",
75
+ "picocolors": "^1.0.0",
76
76
  "rollup": "^2.77.0"
77
77
  },
78
78
  "scripts": {
package/server.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { ViteDevServer, TransformResult } from 'vite';
2
+ import { DepsHandlingOptions, ViteNodeServerOptions, FetchResult, ViteNodeResolveId } from './types.js';
3
+
4
+ declare function guessCJSversion(id: string): string | undefined;
5
+ declare function shouldExternalize(id: string, options?: DepsHandlingOptions, cache?: Map<string, Promise<string | false>>): Promise<string | false>;
6
+
7
+ declare class ViteNodeServer {
8
+ server: ViteDevServer;
9
+ options: ViteNodeServerOptions;
10
+ private fetchPromiseMap;
11
+ private transformPromiseMap;
12
+ fetchCache: Map<string, {
13
+ timestamp: number;
14
+ result: FetchResult;
15
+ }>;
16
+ constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
17
+ shouldExternalize(id: string): Promise<string | false>;
18
+ resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
19
+ fetchModule(id: string): Promise<FetchResult>;
20
+ transformRequest(id: string): Promise<TransformResult | null | undefined>;
21
+ getTransformMode(id: string): "web" | "ssr";
22
+ private _fetchModule;
23
+ private _transformRequest;
24
+ }
25
+
26
+ export { ViteNodeServer, guessCJSversion, shouldExternalize };
package/types.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ interface DepsHandlingOptions {
2
+ external?: (string | RegExp)[];
3
+ inline?: (string | RegExp)[];
4
+ /**
5
+ * Try to guess the CJS version of a package when it's invalid ESM
6
+ * @default true
7
+ */
8
+ fallbackCJS?: boolean;
9
+ }
10
+ interface StartOfSourceMap {
11
+ file?: string;
12
+ sourceRoot?: string;
13
+ }
14
+ interface RawSourceMap extends StartOfSourceMap {
15
+ version: string;
16
+ sources: string[];
17
+ names: string[];
18
+ sourcesContent?: string[];
19
+ mappings: string;
20
+ }
21
+ interface FetchResult {
22
+ code?: string;
23
+ externalize?: string;
24
+ map?: RawSourceMap;
25
+ }
26
+ declare type FetchFunction = (id: string) => Promise<FetchResult>;
27
+ declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
28
+ interface ModuleCache {
29
+ promise?: Promise<any>;
30
+ exports?: any;
31
+ code?: string;
32
+ }
33
+ interface ViteNodeRunnerOptions {
34
+ fetchModule: FetchFunction;
35
+ resolveId: ResolveIdFunction;
36
+ root: string;
37
+ base?: string;
38
+ moduleCache?: Map<string, ModuleCache>;
39
+ interopDefault?: boolean;
40
+ requestStubs?: Record<string, any>;
41
+ }
42
+ interface ViteNodeResolveId {
43
+ external?: boolean | 'absolute' | 'relative';
44
+ id: string;
45
+ meta?: Record<string, any> | null;
46
+ moduleSideEffects?: boolean | 'no-treeshake' | null;
47
+ syntheticNamedExports?: boolean | string | null;
48
+ }
49
+ interface ViteNodeServerOptions {
50
+ /**
51
+ * Inject inline sourcemap to modules
52
+ * @default 'inline'
53
+ */
54
+ sourcemap?: 'inline' | boolean;
55
+ /**
56
+ * Deps handling
57
+ */
58
+ deps?: DepsHandlingOptions;
59
+ /**
60
+ * Transform method for modules
61
+ */
62
+ transformMode?: {
63
+ ssr?: RegExp[];
64
+ web?: RegExp[];
65
+ };
66
+ }
67
+
68
+ export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, RawSourceMap, ResolveIdFunction, StartOfSourceMap, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions };
package/utils.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { TransformResult } from 'vite';
2
+
3
+ declare const isWindows: boolean;
4
+ declare function slash(str: string): string;
5
+ declare function normalizeId(id: string, base?: string): string;
6
+ declare function isPrimitive(v: any): boolean;
7
+ declare function toFilePath(id: string, root: string): string;
8
+ declare function withInlineSourcemap(result: TransformResult): Promise<TransformResult>;
9
+
10
+ export { isPrimitive, isWindows, normalizeId, slash, toFilePath, withInlineSourcemap };