vite-node 0.1.20 → 0.1.21
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/client.d.ts +22 -2
- package/dist/cli.cjs +40 -19
- package/dist/cli.js +40 -19
- package/dist/client.cjs +41 -19
- package/dist/client.js +41 -20
- package/index.d.ts +1 -1
- package/package.json +1 -1
package/client.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ interface ViteNodeRunnerOptions {
|
|
|
14
14
|
root: string;
|
|
15
15
|
base?: string;
|
|
16
16
|
moduleCache?: Map<string, ModuleCache>;
|
|
17
|
-
|
|
17
|
+
interopDefault?: boolean;
|
|
18
18
|
requestStubs?: Record<string, any>;
|
|
19
19
|
}
|
|
20
20
|
interface ViteNodeResolveId {
|
|
@@ -25,6 +25,16 @@ interface ViteNodeResolveId {
|
|
|
25
25
|
syntheticNamedExports?: boolean | string | null;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
declare const DEFAULT_REQUEST_STUBS: {
|
|
29
|
+
'/@vite/client': {
|
|
30
|
+
injectQuery: (id: string) => string;
|
|
31
|
+
createHotContext(): {
|
|
32
|
+
accept: () => void;
|
|
33
|
+
prune: () => void;
|
|
34
|
+
};
|
|
35
|
+
updateStyle(): void;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
28
38
|
declare class ViteNodeRunner {
|
|
29
39
|
options: ViteNodeRunnerOptions;
|
|
30
40
|
root: string;
|
|
@@ -37,6 +47,16 @@ declare class ViteNodeRunner {
|
|
|
37
47
|
directRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
|
|
38
48
|
prepareContext(context: Record<string, any>): Record<string, any>;
|
|
39
49
|
setCache(id: string, mod: Partial<ModuleCache>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Define if a module should be interop-ed
|
|
52
|
+
* This function mostly for the ability to override by subclass
|
|
53
|
+
*/
|
|
54
|
+
shouldInterop(path: string, mod: any): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Import a module and interop it
|
|
57
|
+
*/
|
|
58
|
+
interopedImport(path: string): Promise<any>;
|
|
59
|
+
hasNestedDefault(target: any): any;
|
|
40
60
|
}
|
|
41
61
|
|
|
42
|
-
export { ViteNodeRunner };
|
|
62
|
+
export { DEFAULT_REQUEST_STUBS, ViteNodeRunner };
|
package/dist/cli.cjs
CHANGED
|
@@ -202,6 +202,21 @@ async function withInlineSourcemap(result) {
|
|
|
202
202
|
return result;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
const DEFAULT_REQUEST_STUBS = {
|
|
206
|
+
"/@vite/client": {
|
|
207
|
+
injectQuery: (id) => id,
|
|
208
|
+
createHotContext() {
|
|
209
|
+
return {
|
|
210
|
+
accept: () => {
|
|
211
|
+
},
|
|
212
|
+
prune: () => {
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
updateStyle() {
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
205
220
|
class ViteNodeRunner {
|
|
206
221
|
constructor(options) {
|
|
207
222
|
this.options = options;
|
|
@@ -240,11 +255,12 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
240
255
|
}
|
|
241
256
|
return this.cachedRequest(dep, callstack);
|
|
242
257
|
};
|
|
243
|
-
|
|
244
|
-
|
|
258
|
+
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
|
|
259
|
+
if (id in requestStubs)
|
|
260
|
+
return requestStubs[id];
|
|
245
261
|
const { code: transformed, externalize } = await this.options.fetchModule(id);
|
|
246
262
|
if (externalize) {
|
|
247
|
-
const mod = await
|
|
263
|
+
const mod = await this.interopedImport(externalize);
|
|
248
264
|
this.setCache(fsPath, { exports: mod });
|
|
249
265
|
return mod;
|
|
250
266
|
}
|
|
@@ -292,9 +308,27 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
292
308
|
else
|
|
293
309
|
Object.assign(this.moduleCache.get(id), mod);
|
|
294
310
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
311
|
+
shouldInterop(path, mod) {
|
|
312
|
+
if (this.options.interopDefault === false)
|
|
313
|
+
return false;
|
|
314
|
+
return !path.endsWith(".mjs") && "default" in mod;
|
|
315
|
+
}
|
|
316
|
+
async interopedImport(path) {
|
|
317
|
+
const mod = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path);
|
|
318
|
+
if (this.shouldInterop(path, mod)) {
|
|
319
|
+
const tryDefault = this.hasNestedDefault(mod);
|
|
320
|
+
return new Proxy(mod, {
|
|
321
|
+
get: proxyMethod("get", tryDefault),
|
|
322
|
+
set: proxyMethod("set", tryDefault),
|
|
323
|
+
has: proxyMethod("has", tryDefault),
|
|
324
|
+
deleteProperty: proxyMethod("deleteProperty", tryDefault)
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
return mod;
|
|
328
|
+
}
|
|
329
|
+
hasNestedDefault(target) {
|
|
330
|
+
return "__esModule" in target && target.__esModule && "default" in target.default;
|
|
331
|
+
}
|
|
298
332
|
}
|
|
299
333
|
function proxyMethod(name, tryDefault) {
|
|
300
334
|
return function(target, key, ...args) {
|
|
@@ -306,19 +340,6 @@ function proxyMethod(name, tryDefault) {
|
|
|
306
340
|
return result;
|
|
307
341
|
};
|
|
308
342
|
}
|
|
309
|
-
async function interpretedImport(path, interpretDefault) {
|
|
310
|
-
const mod = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path);
|
|
311
|
-
if (interpretDefault && "default" in mod) {
|
|
312
|
-
const tryDefault = hasNestedDefault(mod);
|
|
313
|
-
return new Proxy(mod, {
|
|
314
|
-
get: proxyMethod("get", tryDefault),
|
|
315
|
-
set: proxyMethod("set", tryDefault),
|
|
316
|
-
has: proxyMethod("has", tryDefault),
|
|
317
|
-
deleteProperty: proxyMethod("deleteProperty", tryDefault)
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
return mod;
|
|
321
|
-
}
|
|
322
343
|
function exportAll(exports, sourceModule) {
|
|
323
344
|
for (const key in sourceModule) {
|
|
324
345
|
if (key !== "default") {
|
package/dist/cli.js
CHANGED
|
@@ -177,6 +177,21 @@ async function withInlineSourcemap(result) {
|
|
|
177
177
|
return result;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
const DEFAULT_REQUEST_STUBS = {
|
|
181
|
+
"/@vite/client": {
|
|
182
|
+
injectQuery: (id) => id,
|
|
183
|
+
createHotContext() {
|
|
184
|
+
return {
|
|
185
|
+
accept: () => {
|
|
186
|
+
},
|
|
187
|
+
prune: () => {
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
},
|
|
191
|
+
updateStyle() {
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
180
195
|
class ViteNodeRunner {
|
|
181
196
|
constructor(options) {
|
|
182
197
|
this.options = options;
|
|
@@ -215,11 +230,12 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
215
230
|
}
|
|
216
231
|
return this.cachedRequest(dep, callstack);
|
|
217
232
|
};
|
|
218
|
-
|
|
219
|
-
|
|
233
|
+
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
|
|
234
|
+
if (id in requestStubs)
|
|
235
|
+
return requestStubs[id];
|
|
220
236
|
const { code: transformed, externalize } = await this.options.fetchModule(id);
|
|
221
237
|
if (externalize) {
|
|
222
|
-
const mod = await
|
|
238
|
+
const mod = await this.interopedImport(externalize);
|
|
223
239
|
this.setCache(fsPath, { exports: mod });
|
|
224
240
|
return mod;
|
|
225
241
|
}
|
|
@@ -267,9 +283,27 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
267
283
|
else
|
|
268
284
|
Object.assign(this.moduleCache.get(id), mod);
|
|
269
285
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
286
|
+
shouldInterop(path, mod) {
|
|
287
|
+
if (this.options.interopDefault === false)
|
|
288
|
+
return false;
|
|
289
|
+
return !path.endsWith(".mjs") && "default" in mod;
|
|
290
|
+
}
|
|
291
|
+
async interopedImport(path) {
|
|
292
|
+
const mod = await import(path);
|
|
293
|
+
if (this.shouldInterop(path, mod)) {
|
|
294
|
+
const tryDefault = this.hasNestedDefault(mod);
|
|
295
|
+
return new Proxy(mod, {
|
|
296
|
+
get: proxyMethod("get", tryDefault),
|
|
297
|
+
set: proxyMethod("set", tryDefault),
|
|
298
|
+
has: proxyMethod("has", tryDefault),
|
|
299
|
+
deleteProperty: proxyMethod("deleteProperty", tryDefault)
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return mod;
|
|
303
|
+
}
|
|
304
|
+
hasNestedDefault(target) {
|
|
305
|
+
return "__esModule" in target && target.__esModule && "default" in target.default;
|
|
306
|
+
}
|
|
273
307
|
}
|
|
274
308
|
function proxyMethod(name, tryDefault) {
|
|
275
309
|
return function(target, key, ...args) {
|
|
@@ -281,19 +315,6 @@ function proxyMethod(name, tryDefault) {
|
|
|
281
315
|
return result;
|
|
282
316
|
};
|
|
283
317
|
}
|
|
284
|
-
async function interpretedImport(path, interpretDefault) {
|
|
285
|
-
const mod = await import(path);
|
|
286
|
-
if (interpretDefault && "default" in mod) {
|
|
287
|
-
const tryDefault = hasNestedDefault(mod);
|
|
288
|
-
return new Proxy(mod, {
|
|
289
|
-
get: proxyMethod("get", tryDefault),
|
|
290
|
-
set: proxyMethod("set", tryDefault),
|
|
291
|
-
has: proxyMethod("has", tryDefault),
|
|
292
|
-
deleteProperty: proxyMethod("deleteProperty", tryDefault)
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
return mod;
|
|
296
|
-
}
|
|
297
318
|
function exportAll(exports, sourceModule) {
|
|
298
319
|
for (const key in sourceModule) {
|
|
299
320
|
if (key !== "default") {
|
package/dist/client.cjs
CHANGED
|
@@ -48,6 +48,21 @@ function toFilePath(id, root) {
|
|
|
48
48
|
return isWindows && absolute.startsWith("/") ? url.fileURLToPath(url.pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
const DEFAULT_REQUEST_STUBS = {
|
|
52
|
+
"/@vite/client": {
|
|
53
|
+
injectQuery: (id) => id,
|
|
54
|
+
createHotContext() {
|
|
55
|
+
return {
|
|
56
|
+
accept: () => {
|
|
57
|
+
},
|
|
58
|
+
prune: () => {
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
updateStyle() {
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
51
66
|
class ViteNodeRunner {
|
|
52
67
|
constructor(options) {
|
|
53
68
|
this.options = options;
|
|
@@ -86,11 +101,12 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
86
101
|
}
|
|
87
102
|
return this.cachedRequest(dep, callstack);
|
|
88
103
|
};
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
|
|
105
|
+
if (id in requestStubs)
|
|
106
|
+
return requestStubs[id];
|
|
91
107
|
const { code: transformed, externalize } = await this.options.fetchModule(id);
|
|
92
108
|
if (externalize) {
|
|
93
|
-
const mod = await
|
|
109
|
+
const mod = await this.interopedImport(externalize);
|
|
94
110
|
this.setCache(fsPath, { exports: mod });
|
|
95
111
|
return mod;
|
|
96
112
|
}
|
|
@@ -138,9 +154,27 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
138
154
|
else
|
|
139
155
|
Object.assign(this.moduleCache.get(id), mod);
|
|
140
156
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
157
|
+
shouldInterop(path, mod) {
|
|
158
|
+
if (this.options.interopDefault === false)
|
|
159
|
+
return false;
|
|
160
|
+
return !path.endsWith(".mjs") && "default" in mod;
|
|
161
|
+
}
|
|
162
|
+
async interopedImport(path) {
|
|
163
|
+
const mod = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path);
|
|
164
|
+
if (this.shouldInterop(path, mod)) {
|
|
165
|
+
const tryDefault = this.hasNestedDefault(mod);
|
|
166
|
+
return new Proxy(mod, {
|
|
167
|
+
get: proxyMethod("get", tryDefault),
|
|
168
|
+
set: proxyMethod("set", tryDefault),
|
|
169
|
+
has: proxyMethod("has", tryDefault),
|
|
170
|
+
deleteProperty: proxyMethod("deleteProperty", tryDefault)
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return mod;
|
|
174
|
+
}
|
|
175
|
+
hasNestedDefault(target) {
|
|
176
|
+
return "__esModule" in target && target.__esModule && "default" in target.default;
|
|
177
|
+
}
|
|
144
178
|
}
|
|
145
179
|
function proxyMethod(name, tryDefault) {
|
|
146
180
|
return function(target, key, ...args) {
|
|
@@ -152,19 +186,6 @@ function proxyMethod(name, tryDefault) {
|
|
|
152
186
|
return result;
|
|
153
187
|
};
|
|
154
188
|
}
|
|
155
|
-
async function interpretedImport(path, interpretDefault) {
|
|
156
|
-
const mod = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path);
|
|
157
|
-
if (interpretDefault && "default" in mod) {
|
|
158
|
-
const tryDefault = hasNestedDefault(mod);
|
|
159
|
-
return new Proxy(mod, {
|
|
160
|
-
get: proxyMethod("get", tryDefault),
|
|
161
|
-
set: proxyMethod("set", tryDefault),
|
|
162
|
-
has: proxyMethod("has", tryDefault),
|
|
163
|
-
deleteProperty: proxyMethod("deleteProperty", tryDefault)
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return mod;
|
|
167
|
-
}
|
|
168
189
|
function exportAll(exports, sourceModule) {
|
|
169
190
|
for (const key in sourceModule) {
|
|
170
191
|
if (key !== "default") {
|
|
@@ -182,4 +203,5 @@ function exportAll(exports, sourceModule) {
|
|
|
182
203
|
}
|
|
183
204
|
}
|
|
184
205
|
|
|
206
|
+
exports.DEFAULT_REQUEST_STUBS = DEFAULT_REQUEST_STUBS;
|
|
185
207
|
exports.ViteNodeRunner = ViteNodeRunner;
|
package/dist/client.js
CHANGED
|
@@ -22,6 +22,21 @@ function toFilePath(id, root) {
|
|
|
22
22
|
return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
const DEFAULT_REQUEST_STUBS = {
|
|
26
|
+
"/@vite/client": {
|
|
27
|
+
injectQuery: (id) => id,
|
|
28
|
+
createHotContext() {
|
|
29
|
+
return {
|
|
30
|
+
accept: () => {
|
|
31
|
+
},
|
|
32
|
+
prune: () => {
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
updateStyle() {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
25
40
|
class ViteNodeRunner {
|
|
26
41
|
constructor(options) {
|
|
27
42
|
this.options = options;
|
|
@@ -60,11 +75,12 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
60
75
|
}
|
|
61
76
|
return this.cachedRequest(dep, callstack);
|
|
62
77
|
};
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
|
|
79
|
+
if (id in requestStubs)
|
|
80
|
+
return requestStubs[id];
|
|
65
81
|
const { code: transformed, externalize } = await this.options.fetchModule(id);
|
|
66
82
|
if (externalize) {
|
|
67
|
-
const mod = await
|
|
83
|
+
const mod = await this.interopedImport(externalize);
|
|
68
84
|
this.setCache(fsPath, { exports: mod });
|
|
69
85
|
return mod;
|
|
70
86
|
}
|
|
@@ -112,9 +128,27 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
112
128
|
else
|
|
113
129
|
Object.assign(this.moduleCache.get(id), mod);
|
|
114
130
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
131
|
+
shouldInterop(path, mod) {
|
|
132
|
+
if (this.options.interopDefault === false)
|
|
133
|
+
return false;
|
|
134
|
+
return !path.endsWith(".mjs") && "default" in mod;
|
|
135
|
+
}
|
|
136
|
+
async interopedImport(path) {
|
|
137
|
+
const mod = await import(path);
|
|
138
|
+
if (this.shouldInterop(path, mod)) {
|
|
139
|
+
const tryDefault = this.hasNestedDefault(mod);
|
|
140
|
+
return new Proxy(mod, {
|
|
141
|
+
get: proxyMethod("get", tryDefault),
|
|
142
|
+
set: proxyMethod("set", tryDefault),
|
|
143
|
+
has: proxyMethod("has", tryDefault),
|
|
144
|
+
deleteProperty: proxyMethod("deleteProperty", tryDefault)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return mod;
|
|
148
|
+
}
|
|
149
|
+
hasNestedDefault(target) {
|
|
150
|
+
return "__esModule" in target && target.__esModule && "default" in target.default;
|
|
151
|
+
}
|
|
118
152
|
}
|
|
119
153
|
function proxyMethod(name, tryDefault) {
|
|
120
154
|
return function(target, key, ...args) {
|
|
@@ -126,19 +160,6 @@ function proxyMethod(name, tryDefault) {
|
|
|
126
160
|
return result;
|
|
127
161
|
};
|
|
128
162
|
}
|
|
129
|
-
async function interpretedImport(path, interpretDefault) {
|
|
130
|
-
const mod = await import(path);
|
|
131
|
-
if (interpretDefault && "default" in mod) {
|
|
132
|
-
const tryDefault = hasNestedDefault(mod);
|
|
133
|
-
return new Proxy(mod, {
|
|
134
|
-
get: proxyMethod("get", tryDefault),
|
|
135
|
-
set: proxyMethod("set", tryDefault),
|
|
136
|
-
has: proxyMethod("has", tryDefault),
|
|
137
|
-
deleteProperty: proxyMethod("deleteProperty", tryDefault)
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
return mod;
|
|
141
|
-
}
|
|
142
163
|
function exportAll(exports, sourceModule) {
|
|
143
164
|
for (const key in sourceModule) {
|
|
144
165
|
if (key !== "default") {
|
|
@@ -156,4 +177,4 @@ function exportAll(exports, sourceModule) {
|
|
|
156
177
|
}
|
|
157
178
|
}
|
|
158
179
|
|
|
159
|
-
export { ViteNodeRunner };
|
|
180
|
+
export { DEFAULT_REQUEST_STUBS, ViteNodeRunner };
|
package/index.d.ts
CHANGED