vite-node 0.10.3 → 0.11.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/dist/cli.cjs +625 -49
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +625 -45
- package/dist/{client-e24a0d42.js → client-06b06913.js} +25 -9
- package/dist/{client-b20a0596.js → client-da5aac97.js} +25 -9
- package/dist/client.cjs +1 -1
- package/dist/client.js +1 -1
- package/package.json +3 -4
|
@@ -99,15 +99,11 @@ class ViteNodeRunner {
|
|
|
99
99
|
async directRequest(id, fsPath, _callstack) {
|
|
100
100
|
const callstack = [..._callstack, utils.normalizeModuleId(id)];
|
|
101
101
|
const request = async (dep) => {
|
|
102
|
-
var _a
|
|
102
|
+
var _a;
|
|
103
103
|
const getStack = () => {
|
|
104
104
|
return `stack:
|
|
105
105
|
${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`;
|
|
106
106
|
};
|
|
107
|
-
if (this.options.resolveId && this.shouldResolveId(dep)) {
|
|
108
|
-
const resolvedDep = await this.options.resolveId(dep, id);
|
|
109
|
-
dep = ((_a = resolvedDep == null ? void 0 : resolvedDep.id) == null ? void 0 : _a.replace(this.root, "")) || dep;
|
|
110
|
-
}
|
|
111
107
|
let debugTimer;
|
|
112
108
|
if (this.debug)
|
|
113
109
|
debugTimer = setTimeout(() => this.debugLog(() => `module ${dep} takes over 2s to load.
|
|
@@ -115,7 +111,7 @@ ${getStack()}`), 2e3);
|
|
|
115
111
|
try {
|
|
116
112
|
if (callstack.includes(utils.normalizeModuleId(dep))) {
|
|
117
113
|
this.debugLog(() => `circular dependency, ${getStack()}`);
|
|
118
|
-
const depExports = (
|
|
114
|
+
const depExports = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
|
|
119
115
|
if (depExports)
|
|
120
116
|
return depExports;
|
|
121
117
|
throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
|
|
@@ -127,10 +123,22 @@ ${getStack()}`), 2e3);
|
|
|
127
123
|
clearTimeout(debugTimer);
|
|
128
124
|
}
|
|
129
125
|
};
|
|
126
|
+
Object.defineProperty(request, "callstack", { get: () => callstack });
|
|
127
|
+
const resolveId = async (dep, callstackPosition = 1) => {
|
|
128
|
+
if (this.options.resolveId && this.shouldResolveId(dep)) {
|
|
129
|
+
let importer = callstack[callstack.length - callstackPosition];
|
|
130
|
+
if (importer && importer.startsWith("mock:"))
|
|
131
|
+
importer = importer.slice(5);
|
|
132
|
+
const { id: id2 } = await this.options.resolveId(dep, importer) || {};
|
|
133
|
+
dep = id2 && pathe.isAbsolute(id2) ? `/@fs/${id2}` : id2 || dep;
|
|
134
|
+
}
|
|
135
|
+
return dep;
|
|
136
|
+
};
|
|
137
|
+
id = await resolveId(id, 2);
|
|
130
138
|
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
|
|
131
139
|
if (id in requestStubs)
|
|
132
140
|
return requestStubs[id];
|
|
133
|
-
|
|
141
|
+
let { code: transformed, externalize } = await this.options.fetchModule(id);
|
|
134
142
|
if (externalize) {
|
|
135
143
|
const mod = await this.interopedImport(externalize);
|
|
136
144
|
this.moduleCache.set(fsPath, { exports: mod });
|
|
@@ -152,18 +160,26 @@ ${getStack()}`), 2e3);
|
|
|
152
160
|
return exports.default;
|
|
153
161
|
}
|
|
154
162
|
};
|
|
163
|
+
let require;
|
|
155
164
|
const context = this.prepareContext({
|
|
156
165
|
__vite_ssr_import__: request,
|
|
157
166
|
__vite_ssr_dynamic_import__: request,
|
|
158
167
|
__vite_ssr_exports__: exports,
|
|
159
168
|
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
160
169
|
__vite_ssr_import_meta__: { url: url$1 },
|
|
161
|
-
|
|
170
|
+
__vitest_resolve_id__: resolveId,
|
|
171
|
+
require: (path) => {
|
|
172
|
+
if (!require)
|
|
173
|
+
require = module$1.createRequire(url$1);
|
|
174
|
+
return require(path);
|
|
175
|
+
},
|
|
162
176
|
exports,
|
|
163
177
|
module: moduleProxy,
|
|
164
178
|
__filename,
|
|
165
179
|
__dirname: pathe.dirname(__filename)
|
|
166
180
|
});
|
|
181
|
+
if (transformed[0] === "#")
|
|
182
|
+
transformed = transformed.replace(/^\#\!.*/, (s) => " ".repeat(s.length));
|
|
167
183
|
const fn = vm__default["default"].runInThisContext(`'use strict';async (${Object.keys(context).join(",")})=>{{${transformed}
|
|
168
184
|
}}`, {
|
|
169
185
|
filename: fsPath,
|
|
@@ -176,7 +192,7 @@ ${getStack()}`), 2e3);
|
|
|
176
192
|
return context;
|
|
177
193
|
}
|
|
178
194
|
shouldResolveId(dep) {
|
|
179
|
-
if (mlly.isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS))
|
|
195
|
+
if (mlly.isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
|
|
180
196
|
return false;
|
|
181
197
|
return !pathe.isAbsolute(dep) || !pathe.extname(dep);
|
|
182
198
|
}
|
|
@@ -75,15 +75,11 @@ class ViteNodeRunner {
|
|
|
75
75
|
async directRequest(id, fsPath, _callstack) {
|
|
76
76
|
const callstack = [..._callstack, normalizeModuleId(id)];
|
|
77
77
|
const request = async (dep) => {
|
|
78
|
-
var _a
|
|
78
|
+
var _a;
|
|
79
79
|
const getStack = () => {
|
|
80
80
|
return `stack:
|
|
81
81
|
${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`;
|
|
82
82
|
};
|
|
83
|
-
if (this.options.resolveId && this.shouldResolveId(dep)) {
|
|
84
|
-
const resolvedDep = await this.options.resolveId(dep, id);
|
|
85
|
-
dep = ((_a = resolvedDep == null ? void 0 : resolvedDep.id) == null ? void 0 : _a.replace(this.root, "")) || dep;
|
|
86
|
-
}
|
|
87
83
|
let debugTimer;
|
|
88
84
|
if (this.debug)
|
|
89
85
|
debugTimer = setTimeout(() => this.debugLog(() => `module ${dep} takes over 2s to load.
|
|
@@ -91,7 +87,7 @@ ${getStack()}`), 2e3);
|
|
|
91
87
|
try {
|
|
92
88
|
if (callstack.includes(normalizeModuleId(dep))) {
|
|
93
89
|
this.debugLog(() => `circular dependency, ${getStack()}`);
|
|
94
|
-
const depExports = (
|
|
90
|
+
const depExports = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
|
|
95
91
|
if (depExports)
|
|
96
92
|
return depExports;
|
|
97
93
|
throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
|
|
@@ -103,10 +99,22 @@ ${getStack()}`), 2e3);
|
|
|
103
99
|
clearTimeout(debugTimer);
|
|
104
100
|
}
|
|
105
101
|
};
|
|
102
|
+
Object.defineProperty(request, "callstack", { get: () => callstack });
|
|
103
|
+
const resolveId = async (dep, callstackPosition = 1) => {
|
|
104
|
+
if (this.options.resolveId && this.shouldResolveId(dep)) {
|
|
105
|
+
let importer = callstack[callstack.length - callstackPosition];
|
|
106
|
+
if (importer && importer.startsWith("mock:"))
|
|
107
|
+
importer = importer.slice(5);
|
|
108
|
+
const { id: id2 } = await this.options.resolveId(dep, importer) || {};
|
|
109
|
+
dep = id2 && isAbsolute(id2) ? `/@fs/${id2}` : id2 || dep;
|
|
110
|
+
}
|
|
111
|
+
return dep;
|
|
112
|
+
};
|
|
113
|
+
id = await resolveId(id, 2);
|
|
106
114
|
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
|
|
107
115
|
if (id in requestStubs)
|
|
108
116
|
return requestStubs[id];
|
|
109
|
-
|
|
117
|
+
let { code: transformed, externalize } = await this.options.fetchModule(id);
|
|
110
118
|
if (externalize) {
|
|
111
119
|
const mod = await this.interopedImport(externalize);
|
|
112
120
|
this.moduleCache.set(fsPath, { exports: mod });
|
|
@@ -128,18 +136,26 @@ ${getStack()}`), 2e3);
|
|
|
128
136
|
return exports.default;
|
|
129
137
|
}
|
|
130
138
|
};
|
|
139
|
+
let require;
|
|
131
140
|
const context = this.prepareContext({
|
|
132
141
|
__vite_ssr_import__: request,
|
|
133
142
|
__vite_ssr_dynamic_import__: request,
|
|
134
143
|
__vite_ssr_exports__: exports,
|
|
135
144
|
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
136
145
|
__vite_ssr_import_meta__: { url },
|
|
137
|
-
|
|
146
|
+
__vitest_resolve_id__: resolveId,
|
|
147
|
+
require: (path) => {
|
|
148
|
+
if (!require)
|
|
149
|
+
require = createRequire(url);
|
|
150
|
+
return require(path);
|
|
151
|
+
},
|
|
138
152
|
exports,
|
|
139
153
|
module: moduleProxy,
|
|
140
154
|
__filename,
|
|
141
155
|
__dirname: dirname(__filename)
|
|
142
156
|
});
|
|
157
|
+
if (transformed[0] === "#")
|
|
158
|
+
transformed = transformed.replace(/^\#\!.*/, (s) => " ".repeat(s.length));
|
|
143
159
|
const fn = vm.runInThisContext(`'use strict';async (${Object.keys(context).join(",")})=>{{${transformed}
|
|
144
160
|
}}`, {
|
|
145
161
|
filename: fsPath,
|
|
@@ -152,7 +168,7 @@ ${getStack()}`), 2e3);
|
|
|
152
168
|
return context;
|
|
153
169
|
}
|
|
154
170
|
shouldResolveId(dep) {
|
|
155
|
-
if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS))
|
|
171
|
+
if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
|
|
156
172
|
return false;
|
|
157
173
|
return !isAbsolute(dep) || !extname(dep);
|
|
158
174
|
}
|
package/dist/client.cjs
CHANGED
package/dist/client.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"description": "Vite as Node.js runtime",
|
|
6
6
|
"homepage": "https://github.com/vitest-dev/vitest/blob/main/packages/vite-node#readme",
|
|
7
7
|
"bugs": {
|
|
@@ -58,14 +58,13 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"kolorist": "^1.5.1",
|
|
61
|
-
"minimist": "^1.2.6",
|
|
62
61
|
"mlly": "^0.5.2",
|
|
63
62
|
"pathe": "^0.2.0",
|
|
64
63
|
"vite": "^2.9.7"
|
|
65
64
|
},
|
|
66
65
|
"devDependencies": {
|
|
67
|
-
"
|
|
68
|
-
"rollup": "^2.
|
|
66
|
+
"cac": "^6.7.12",
|
|
67
|
+
"rollup": "^2.72.1"
|
|
69
68
|
},
|
|
70
69
|
"engines": {
|
|
71
70
|
"node": ">=v14.16.0"
|