vite-node 0.19.1 → 0.20.2
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 +44 -1
- package/dist/chunk-debug.cjs +77 -0
- package/dist/chunk-debug.mjs +75 -0
- package/dist/chunk-hmr.cjs +4 -4
- package/dist/chunk-hmr.mjs +4 -4
- package/dist/chunk-picocolors.cjs +70 -0
- package/dist/chunk-picocolors.mjs +64 -0
- package/dist/cli.cjs +6 -5
- package/dist/cli.d.ts +1 -1
- package/dist/cli.mjs +6 -5
- package/dist/client.cjs +2 -7
- package/dist/client.d.ts +1 -1
- package/dist/client.mjs +2 -7
- package/dist/hmr.cjs +2 -1
- package/dist/hmr.d.ts +1 -1
- package/dist/hmr.mjs +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/server.cjs +22 -2
- package/dist/server.d.ts +18 -2
- package/dist/server.mjs +22 -2
- package/dist/{types-de894284.d.ts → types-4f4de592.d.ts} +14 -2
- package/dist/types.d.ts +1 -1
- package/dist/utils.d.ts +1 -1
- package/package.json +2 -2
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#
|
|
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).
|
|
@@ -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 };
|
package/dist/chunk-hmr.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var events = require('events');
|
|
4
|
-
var
|
|
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(`${
|
|
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(`${
|
|
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(`${
|
|
157
|
+
console.error(`${picocolors.picocolors.exports.cyan("[vite-node]")} Internal Server Error
|
|
158
158
|
${err.message}
|
|
159
159
|
${err.stack}`);
|
|
160
160
|
break;
|
package/dist/chunk-hmr.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import {
|
|
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
|
|
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.
|
|
632
|
+
var version = "0.20.2";
|
|
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(
|
|
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
|
|
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,
|
|
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
package/dist/cli.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import {
|
|
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.
|
|
630
|
+
var version = "0.20.2";
|
|
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
|
|
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,
|
|
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
|
@@ -95,7 +95,7 @@ class ViteNodeRunner {
|
|
|
95
95
|
this.options = options;
|
|
96
96
|
this.root = options.root ?? process.cwd();
|
|
97
97
|
this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
|
|
98
|
-
this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.
|
|
98
|
+
this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
|
|
99
99
|
}
|
|
100
100
|
async executeFile(file) {
|
|
101
101
|
return await this.cachedRequest(`/@fs/${utils.slash(pathe.resolve(file))}`, []);
|
|
@@ -126,11 +126,10 @@ ${[...callstack, fsPath2].reverse().map((p) => `- ${p}`).join("\n")}`;
|
|
|
126
126
|
};
|
|
127
127
|
let debugTimer;
|
|
128
128
|
if (this.debug)
|
|
129
|
-
debugTimer = setTimeout(() =>
|
|
129
|
+
debugTimer = setTimeout(() => console.warn(() => `module ${fsPath2} takes over 2s to load.
|
|
130
130
|
${getStack()}`), 2e3);
|
|
131
131
|
try {
|
|
132
132
|
if (callstack.includes(fsPath2)) {
|
|
133
|
-
this.debugLog(() => `circular dependency, ${getStack()}`);
|
|
134
133
|
const depExports = (_a = this.moduleCache.get(fsPath2)) == null ? void 0 : _a.exports;
|
|
135
134
|
if (depExports)
|
|
136
135
|
return depExports;
|
|
@@ -246,10 +245,6 @@ ${getStack()}`), 2e3);
|
|
|
246
245
|
hasNestedDefault(target) {
|
|
247
246
|
return "__esModule" in target && target.__esModule && "default" in target.default;
|
|
248
247
|
}
|
|
249
|
-
debugLog(msg) {
|
|
250
|
-
if (this.debug)
|
|
251
|
-
console.log(`[vite-node] ${msg()}`);
|
|
252
|
-
}
|
|
253
248
|
}
|
|
254
249
|
function proxyMethod(name, tryDefault) {
|
|
255
250
|
return function(target, key, ...args) {
|
package/dist/client.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-4f4de592.js';
|
package/dist/client.mjs
CHANGED
|
@@ -68,7 +68,7 @@ class ViteNodeRunner {
|
|
|
68
68
|
this.options = options;
|
|
69
69
|
this.root = options.root ?? process.cwd();
|
|
70
70
|
this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
|
|
71
|
-
this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.
|
|
71
|
+
this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
|
|
72
72
|
}
|
|
73
73
|
async executeFile(file) {
|
|
74
74
|
return await this.cachedRequest(`/@fs/${slash(resolve(file))}`, []);
|
|
@@ -99,11 +99,10 @@ ${[...callstack, fsPath2].reverse().map((p) => `- ${p}`).join("\n")}`;
|
|
|
99
99
|
};
|
|
100
100
|
let debugTimer;
|
|
101
101
|
if (this.debug)
|
|
102
|
-
debugTimer = setTimeout(() =>
|
|
102
|
+
debugTimer = setTimeout(() => console.warn(() => `module ${fsPath2} takes over 2s to load.
|
|
103
103
|
${getStack()}`), 2e3);
|
|
104
104
|
try {
|
|
105
105
|
if (callstack.includes(fsPath2)) {
|
|
106
|
-
this.debugLog(() => `circular dependency, ${getStack()}`);
|
|
107
106
|
const depExports = (_a = this.moduleCache.get(fsPath2)) == null ? void 0 : _a.exports;
|
|
108
107
|
if (depExports)
|
|
109
108
|
return depExports;
|
|
@@ -219,10 +218,6 @@ ${getStack()}`), 2e3);
|
|
|
219
218
|
hasNestedDefault(target) {
|
|
220
219
|
return "__esModule" in target && target.__esModule && "default" in target.default;
|
|
221
220
|
}
|
|
222
|
-
debugLog(msg) {
|
|
223
|
-
if (this.debug)
|
|
224
|
-
console.log(`[vite-node] ${msg()}`);
|
|
225
|
-
}
|
|
226
221
|
}
|
|
227
222
|
function proxyMethod(name, tryDefault) {
|
|
228
223
|
return function(target, key, ...args) {
|
package/dist/hmr.cjs
CHANGED
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,
|
|
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 '
|
|
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-
|
|
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
|
@@ -47,7 +47,8 @@ function guessCJSversion(id) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
|
|
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 {
|
|
2
|
-
import { D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './types-
|
|
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
|
@@ -39,7 +39,8 @@ function guessCJSversion(id) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
|
|
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
|
}
|
|
@@ -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,
|
|
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-
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.2",
|
|
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": {
|