vite-node 0.25.8 → 0.26.1
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/chunk-hmr.cjs +2 -2
- package/dist/chunk-hmr.mjs +1 -1
- package/dist/cli.cjs +4 -2
- package/dist/cli.d.ts +1 -1
- package/dist/cli.mjs +8 -6
- package/dist/client.cjs +101 -97
- package/dist/client.d.ts +1 -1
- package/dist/client.mjs +104 -100
- package/dist/hmr.cjs +1 -1
- package/dist/hmr.d.ts +2 -2
- package/dist/hmr.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.mjs +3 -3
- package/dist/source-map.d.ts +1 -1
- package/dist/{types-fc7e68bc.d.ts → types-57a192bf.d.ts} +6 -4
- package/dist/types.d.ts +1 -1
- package/dist/utils.cjs +10 -17
- package/dist/utils.d.ts +4 -3
- package/dist/utils.mjs +10 -18
- package/package.json +2 -2
package/dist/chunk-hmr.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var node_events = require('node:events');
|
|
4
4
|
var picocolors = require('./chunk-picocolors.cjs');
|
|
5
5
|
var createDebug = require('debug');
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
9
9
|
var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
|
|
10
10
|
|
|
11
11
|
function createHmrEmitter() {
|
|
12
|
-
const emitter = new
|
|
12
|
+
const emitter = new node_events.EventEmitter();
|
|
13
13
|
return emitter;
|
|
14
14
|
}
|
|
15
15
|
function viteNodeHmrPlugin() {
|
package/dist/chunk-hmr.mjs
CHANGED
package/dist/cli.cjs
CHANGED
|
@@ -14,10 +14,12 @@ require('pathe');
|
|
|
14
14
|
require('debug');
|
|
15
15
|
require('fs');
|
|
16
16
|
require('mlly');
|
|
17
|
-
require('url');
|
|
17
|
+
require('node:url');
|
|
18
18
|
require('source-map-support');
|
|
19
19
|
require('module');
|
|
20
|
+
require('path');
|
|
20
21
|
require('vm');
|
|
22
|
+
require('node:events');
|
|
21
23
|
|
|
22
24
|
function toArr(any) {
|
|
23
25
|
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
@@ -632,7 +634,7 @@ class CAC extends events.EventEmitter {
|
|
|
632
634
|
|
|
633
635
|
const cac = (name = "") => new CAC(name);
|
|
634
636
|
|
|
635
|
-
var version = "0.
|
|
637
|
+
var version = "0.26.1";
|
|
636
638
|
|
|
637
639
|
const cli = cac("vite-node");
|
|
638
640
|
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();
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -7,15 +7,17 @@ import { toArray } from './utils.mjs';
|
|
|
7
7
|
import { v as viteNodeHmrPlugin, c as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
|
|
8
8
|
import { installSourcemapsSupport } from './source-map.mjs';
|
|
9
9
|
import 'tty';
|
|
10
|
-
import 'perf_hooks';
|
|
10
|
+
import 'node:perf_hooks';
|
|
11
11
|
import 'pathe';
|
|
12
12
|
import 'debug';
|
|
13
|
-
import 'fs';
|
|
13
|
+
import 'node:fs';
|
|
14
14
|
import 'mlly';
|
|
15
|
-
import 'url';
|
|
15
|
+
import 'node:url';
|
|
16
16
|
import 'source-map-support';
|
|
17
|
-
import 'module';
|
|
18
|
-
import '
|
|
17
|
+
import 'node:module';
|
|
18
|
+
import 'node:path';
|
|
19
|
+
import 'node:vm';
|
|
20
|
+
import 'node:events';
|
|
19
21
|
|
|
20
22
|
function toArr(any) {
|
|
21
23
|
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
@@ -630,7 +632,7 @@ class CAC extends EventEmitter {
|
|
|
630
632
|
|
|
631
633
|
const cac = (name = "") => new CAC(name);
|
|
632
634
|
|
|
633
|
-
var version = "0.
|
|
635
|
+
var version = "0.26.1";
|
|
634
636
|
|
|
635
637
|
const cli = cac("vite-node");
|
|
636
638
|
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();
|
package/dist/client.cjs
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var module$1 = require('module');
|
|
6
|
-
var
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var node_url = require('node:url');
|
|
7
8
|
var vm = require('vm');
|
|
8
|
-
var pathe = require('pathe');
|
|
9
9
|
var mlly = require('mlly');
|
|
10
|
+
var pathe = require('pathe');
|
|
10
11
|
var createDebug = require('debug');
|
|
11
12
|
var utils = require('./utils.cjs');
|
|
12
13
|
var sourceMap = require('./source-map.cjs');
|
|
@@ -146,19 +147,19 @@ class ViteNodeRunner {
|
|
|
146
147
|
this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
|
|
147
148
|
}
|
|
148
149
|
async executeFile(file) {
|
|
149
|
-
|
|
150
|
+
const url = `/@fs/${utils.slash(pathe.resolve(file))}`;
|
|
151
|
+
return await this.cachedRequest(url, url, []);
|
|
150
152
|
}
|
|
151
|
-
async executeId(
|
|
152
|
-
|
|
153
|
+
async executeId(rawId) {
|
|
154
|
+
const [id, url] = await this.resolveUrl(rawId);
|
|
155
|
+
return await this.cachedRequest(id, url, []);
|
|
153
156
|
}
|
|
154
157
|
getSourceMap(id) {
|
|
155
158
|
return this.moduleCache.getSourceMap(id);
|
|
156
159
|
}
|
|
157
|
-
async cachedRequest(
|
|
158
|
-
const id = utils.normalizeRequestId(rawId, this.options.base);
|
|
159
|
-
const fsPath = utils.toFilePath(id, this.root);
|
|
160
|
-
const mod = this.moduleCache.get(fsPath);
|
|
160
|
+
async cachedRequest(id, fsPath, callstack) {
|
|
161
161
|
const importee = callstack[callstack.length - 1];
|
|
162
|
+
const mod = this.moduleCache.get(fsPath);
|
|
162
163
|
if (!mod.importers)
|
|
163
164
|
mod.importers = /* @__PURE__ */ new Set();
|
|
164
165
|
if (importee)
|
|
@@ -175,63 +176,57 @@ class ViteNodeRunner {
|
|
|
175
176
|
mod.evaluated = true;
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return await this.cachedRequest(dep2, callstack);
|
|
200
|
-
} finally {
|
|
201
|
-
if (debugTimer)
|
|
202
|
-
clearTimeout(debugTimer);
|
|
203
|
-
}
|
|
179
|
+
shouldResolveId(id, _importee) {
|
|
180
|
+
return !utils.isInternalRequest(id) && !mlly.isNodeBuiltin(id);
|
|
181
|
+
}
|
|
182
|
+
async resolveUrl(id, importee) {
|
|
183
|
+
if (!this.shouldResolveId(id))
|
|
184
|
+
return [id, id];
|
|
185
|
+
if (importee && id.startsWith(utils.VALID_ID_PREFIX))
|
|
186
|
+
importee = void 0;
|
|
187
|
+
id = utils.normalizeRequestId(id, this.options.base);
|
|
188
|
+
if (!this.options.resolveId)
|
|
189
|
+
return [id, utils.toFilePath(id, this.root)];
|
|
190
|
+
const resolved = await this.options.resolveId(id, importee);
|
|
191
|
+
const resolvedId = resolved ? utils.normalizeRequestId(resolved.id, this.options.base) : id;
|
|
192
|
+
const fsPath = resolved ? resolvedId : utils.toFilePath(id, this.root);
|
|
193
|
+
return [resolvedId, fsPath];
|
|
194
|
+
}
|
|
195
|
+
async dependencyRequest(id, fsPath, callstack) {
|
|
196
|
+
var _a;
|
|
197
|
+
const getStack = () => {
|
|
198
|
+
return `stack:
|
|
199
|
+
${[...callstack, fsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
|
|
204
200
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
201
|
+
let debugTimer;
|
|
202
|
+
if (this.debug)
|
|
203
|
+
debugTimer = setTimeout(() => console.warn(() => `module ${fsPath} takes over 2s to load.
|
|
204
|
+
${getStack()}`), 2e3);
|
|
205
|
+
try {
|
|
206
|
+
if (callstack.includes(fsPath)) {
|
|
207
|
+
const depExports = (_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.exports;
|
|
208
|
+
if (depExports)
|
|
209
|
+
return depExports;
|
|
210
|
+
throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
|
|
215
211
|
}
|
|
216
|
-
return
|
|
212
|
+
return await this.cachedRequest(id, fsPath, callstack);
|
|
213
|
+
} finally {
|
|
214
|
+
if (debugTimer)
|
|
215
|
+
clearTimeout(debugTimer);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async directRequest(id, fsPath, _callstack) {
|
|
219
|
+
const moduleId = utils.normalizeModuleId(fsPath);
|
|
220
|
+
const callstack = [..._callstack, moduleId];
|
|
221
|
+
const mod = this.moduleCache.get(fsPath);
|
|
222
|
+
const request = async (dep) => {
|
|
223
|
+
const [id2, depFsPath] = await this.resolveUrl(dep, fsPath);
|
|
224
|
+
return this.dependencyRequest(id2, depFsPath, callstack);
|
|
217
225
|
};
|
|
218
|
-
const [dep, resolvedId] = await resolveId(id, 2);
|
|
219
226
|
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
|
|
220
227
|
if (id in requestStubs)
|
|
221
228
|
return requestStubs[id];
|
|
222
|
-
let { code: transformed, externalize } = await this.options.fetchModule(
|
|
223
|
-
if (resolvedId && !fsPath.includes("?") && fsPath !== resolvedId) {
|
|
224
|
-
if (this.moduleCache.has(resolvedId)) {
|
|
225
|
-
mod = this.moduleCache.get(resolvedId);
|
|
226
|
-
this.moduleCache.set(fsPath, mod);
|
|
227
|
-
if (mod.promise)
|
|
228
|
-
return mod.promise;
|
|
229
|
-
if (mod.exports)
|
|
230
|
-
return mod.exports;
|
|
231
|
-
} else {
|
|
232
|
-
this.moduleCache.set(resolvedId, mod);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
229
|
+
let { code: transformed, externalize } = await this.options.fetchModule(id);
|
|
235
230
|
if (externalize) {
|
|
236
231
|
debugNative(externalize);
|
|
237
232
|
const exports2 = await this.interopedImport(externalize);
|
|
@@ -239,10 +234,10 @@ ${getStack()}`), 2e3);
|
|
|
239
234
|
return exports2;
|
|
240
235
|
}
|
|
241
236
|
if (transformed == null)
|
|
242
|
-
throw new Error(`[vite-node] Failed to load ${id}`);
|
|
243
|
-
const
|
|
244
|
-
const
|
|
245
|
-
const meta = { url:
|
|
237
|
+
throw new Error(`[vite-node] Failed to load "${id}" imported from ${callstack[callstack.length - 2]}`);
|
|
238
|
+
const modulePath = utils.cleanUrl(moduleId);
|
|
239
|
+
const href = node_url.pathToFileURL(modulePath).href;
|
|
240
|
+
const meta = { url: href };
|
|
246
241
|
const exports = /* @__PURE__ */ Object.create(null);
|
|
247
242
|
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
248
243
|
value: "Module",
|
|
@@ -250,7 +245,12 @@ ${getStack()}`), 2e3);
|
|
|
250
245
|
configurable: false
|
|
251
246
|
});
|
|
252
247
|
const cjsExports = new Proxy(exports, {
|
|
253
|
-
set(_, p, value) {
|
|
248
|
+
set: (_, p, value) => {
|
|
249
|
+
if (p === "default" && this.shouldInterop(modulePath, { default: value })) {
|
|
250
|
+
exportAll(cjsExports, value);
|
|
251
|
+
exports.default = value;
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
254
|
if (!Reflect.has(exports, "default"))
|
|
255
255
|
exports.default = {};
|
|
256
256
|
if (utils.isPrimitive(exports.default)) {
|
|
@@ -264,7 +264,7 @@ ${getStack()}`), 2e3);
|
|
|
264
264
|
}
|
|
265
265
|
});
|
|
266
266
|
Object.assign(mod, { code: transformed, exports });
|
|
267
|
-
const __filename =
|
|
267
|
+
const __filename = node_url.fileURLToPath(href);
|
|
268
268
|
const moduleProxy = {
|
|
269
269
|
set exports(value) {
|
|
270
270
|
exportAll(cjsExports, value);
|
|
@@ -282,6 +282,9 @@ ${getStack()}`), 2e3);
|
|
|
282
282
|
var _a, _b;
|
|
283
283
|
hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
|
|
284
284
|
return hotContext;
|
|
285
|
+
},
|
|
286
|
+
set: (value) => {
|
|
287
|
+
hotContext = value;
|
|
285
288
|
}
|
|
286
289
|
});
|
|
287
290
|
}
|
|
@@ -291,12 +294,11 @@ ${getStack()}`), 2e3);
|
|
|
291
294
|
__vite_ssr_exports__: exports,
|
|
292
295
|
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
293
296
|
__vite_ssr_import_meta__: meta,
|
|
294
|
-
|
|
295
|
-
require: module$1.createRequire(url$1),
|
|
297
|
+
require: module$1.createRequire(href),
|
|
296
298
|
exports: cjsExports,
|
|
297
299
|
module: moduleProxy,
|
|
298
300
|
__filename,
|
|
299
|
-
__dirname:
|
|
301
|
+
__dirname: path.dirname(__filename)
|
|
300
302
|
});
|
|
301
303
|
debugExecute(__filename);
|
|
302
304
|
if (transformed[0] === "#")
|
|
@@ -315,42 +317,44 @@ ${getStack()}`), 2e3);
|
|
|
315
317
|
prepareContext(context) {
|
|
316
318
|
return context;
|
|
317
319
|
}
|
|
318
|
-
shouldResolveId(dep) {
|
|
319
|
-
if (mlly.isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
|
|
320
|
-
return false;
|
|
321
|
-
return !pathe.isAbsolute(dep) || !pathe.extname(dep);
|
|
322
|
-
}
|
|
323
320
|
shouldInterop(path, mod) {
|
|
324
321
|
if (this.options.interopDefault === false)
|
|
325
322
|
return false;
|
|
326
323
|
return !path.endsWith(".mjs") && "default" in mod;
|
|
327
324
|
}
|
|
328
325
|
async interopedImport(path) {
|
|
329
|
-
const
|
|
330
|
-
if (this.shouldInterop(path,
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
326
|
+
const importedModule = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path);
|
|
327
|
+
if (!this.shouldInterop(path, importedModule))
|
|
328
|
+
return importedModule;
|
|
329
|
+
const { mod, defaultExport } = interopModule(importedModule);
|
|
330
|
+
return new Proxy(mod, {
|
|
331
|
+
get(mod2, prop) {
|
|
332
|
+
if (prop === "default")
|
|
333
|
+
return defaultExport;
|
|
334
|
+
return mod2[prop] ?? (defaultExport == null ? void 0 : defaultExport[prop]);
|
|
335
|
+
},
|
|
336
|
+
has(mod2, prop) {
|
|
337
|
+
if (prop === "default")
|
|
338
|
+
return defaultExport !== void 0;
|
|
339
|
+
return prop in mod2 || defaultExport && prop in defaultExport;
|
|
340
|
+
}
|
|
341
|
+
});
|
|
343
342
|
}
|
|
344
343
|
}
|
|
345
|
-
function
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
344
|
+
function interopModule(mod) {
|
|
345
|
+
if (utils.isPrimitive(mod)) {
|
|
346
|
+
return {
|
|
347
|
+
mod: { default: mod },
|
|
348
|
+
defaultExport: mod
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
let defaultExport = "default" in mod ? mod.default : mod;
|
|
352
|
+
if (!utils.isPrimitive(defaultExport) && "__esModule" in defaultExport) {
|
|
353
|
+
mod = defaultExport;
|
|
354
|
+
if ("default" in defaultExport)
|
|
355
|
+
defaultExport = defaultExport.default;
|
|
356
|
+
}
|
|
357
|
+
return { mod, defaultExport };
|
|
354
358
|
}
|
|
355
359
|
function defineExport(exports, key, value) {
|
|
356
360
|
Object.defineProperty(exports, key, {
|
package/dist/client.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-
|
|
1
|
+
export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-57a192bf.js';
|
package/dist/client.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { createRequire } from 'module';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
4
|
+
import vm from 'node:vm';
|
|
5
5
|
import { isNodeBuiltin } from 'mlly';
|
|
6
|
+
import { resolve } from 'pathe';
|
|
6
7
|
import createDebug from 'debug';
|
|
7
|
-
import { normalizeModuleId, slash, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
|
|
8
|
+
import { normalizeModuleId, slash, isInternalRequest, VALID_ID_PREFIX, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
|
|
8
9
|
import { extractSourceMap } from './source-map.mjs';
|
|
9
|
-
import 'fs';
|
|
10
|
+
import 'node:fs';
|
|
10
11
|
import 'source-map-support';
|
|
11
12
|
|
|
12
13
|
const debugExecute = createDebug("vite-node:client:execute");
|
|
@@ -119,19 +120,19 @@ class ViteNodeRunner {
|
|
|
119
120
|
this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
|
|
120
121
|
}
|
|
121
122
|
async executeFile(file) {
|
|
122
|
-
|
|
123
|
+
const url = `/@fs/${slash(resolve(file))}`;
|
|
124
|
+
return await this.cachedRequest(url, url, []);
|
|
123
125
|
}
|
|
124
|
-
async executeId(
|
|
125
|
-
|
|
126
|
+
async executeId(rawId) {
|
|
127
|
+
const [id, url] = await this.resolveUrl(rawId);
|
|
128
|
+
return await this.cachedRequest(id, url, []);
|
|
126
129
|
}
|
|
127
130
|
getSourceMap(id) {
|
|
128
131
|
return this.moduleCache.getSourceMap(id);
|
|
129
132
|
}
|
|
130
|
-
async cachedRequest(
|
|
131
|
-
const id = normalizeRequestId(rawId, this.options.base);
|
|
132
|
-
const fsPath = toFilePath(id, this.root);
|
|
133
|
-
const mod = this.moduleCache.get(fsPath);
|
|
133
|
+
async cachedRequest(id, fsPath, callstack) {
|
|
134
134
|
const importee = callstack[callstack.length - 1];
|
|
135
|
+
const mod = this.moduleCache.get(fsPath);
|
|
135
136
|
if (!mod.importers)
|
|
136
137
|
mod.importers = /* @__PURE__ */ new Set();
|
|
137
138
|
if (importee)
|
|
@@ -148,63 +149,57 @@ class ViteNodeRunner {
|
|
|
148
149
|
mod.evaluated = true;
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return await this.cachedRequest(dep2, callstack);
|
|
173
|
-
} finally {
|
|
174
|
-
if (debugTimer)
|
|
175
|
-
clearTimeout(debugTimer);
|
|
176
|
-
}
|
|
152
|
+
shouldResolveId(id, _importee) {
|
|
153
|
+
return !isInternalRequest(id) && !isNodeBuiltin(id);
|
|
154
|
+
}
|
|
155
|
+
async resolveUrl(id, importee) {
|
|
156
|
+
if (!this.shouldResolveId(id))
|
|
157
|
+
return [id, id];
|
|
158
|
+
if (importee && id.startsWith(VALID_ID_PREFIX))
|
|
159
|
+
importee = void 0;
|
|
160
|
+
id = normalizeRequestId(id, this.options.base);
|
|
161
|
+
if (!this.options.resolveId)
|
|
162
|
+
return [id, toFilePath(id, this.root)];
|
|
163
|
+
const resolved = await this.options.resolveId(id, importee);
|
|
164
|
+
const resolvedId = resolved ? normalizeRequestId(resolved.id, this.options.base) : id;
|
|
165
|
+
const fsPath = resolved ? resolvedId : toFilePath(id, this.root);
|
|
166
|
+
return [resolvedId, fsPath];
|
|
167
|
+
}
|
|
168
|
+
async dependencyRequest(id, fsPath, callstack) {
|
|
169
|
+
var _a;
|
|
170
|
+
const getStack = () => {
|
|
171
|
+
return `stack:
|
|
172
|
+
${[...callstack, fsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
|
|
177
173
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
174
|
+
let debugTimer;
|
|
175
|
+
if (this.debug)
|
|
176
|
+
debugTimer = setTimeout(() => console.warn(() => `module ${fsPath} takes over 2s to load.
|
|
177
|
+
${getStack()}`), 2e3);
|
|
178
|
+
try {
|
|
179
|
+
if (callstack.includes(fsPath)) {
|
|
180
|
+
const depExports = (_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.exports;
|
|
181
|
+
if (depExports)
|
|
182
|
+
return depExports;
|
|
183
|
+
throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
|
|
188
184
|
}
|
|
189
|
-
return
|
|
185
|
+
return await this.cachedRequest(id, fsPath, callstack);
|
|
186
|
+
} finally {
|
|
187
|
+
if (debugTimer)
|
|
188
|
+
clearTimeout(debugTimer);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async directRequest(id, fsPath, _callstack) {
|
|
192
|
+
const moduleId = normalizeModuleId(fsPath);
|
|
193
|
+
const callstack = [..._callstack, moduleId];
|
|
194
|
+
const mod = this.moduleCache.get(fsPath);
|
|
195
|
+
const request = async (dep) => {
|
|
196
|
+
const [id2, depFsPath] = await this.resolveUrl(dep, fsPath);
|
|
197
|
+
return this.dependencyRequest(id2, depFsPath, callstack);
|
|
190
198
|
};
|
|
191
|
-
const [dep, resolvedId] = await resolveId(id, 2);
|
|
192
199
|
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
|
|
193
200
|
if (id in requestStubs)
|
|
194
201
|
return requestStubs[id];
|
|
195
|
-
let { code: transformed, externalize } = await this.options.fetchModule(
|
|
196
|
-
if (resolvedId && !fsPath.includes("?") && fsPath !== resolvedId) {
|
|
197
|
-
if (this.moduleCache.has(resolvedId)) {
|
|
198
|
-
mod = this.moduleCache.get(resolvedId);
|
|
199
|
-
this.moduleCache.set(fsPath, mod);
|
|
200
|
-
if (mod.promise)
|
|
201
|
-
return mod.promise;
|
|
202
|
-
if (mod.exports)
|
|
203
|
-
return mod.exports;
|
|
204
|
-
} else {
|
|
205
|
-
this.moduleCache.set(resolvedId, mod);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
202
|
+
let { code: transformed, externalize } = await this.options.fetchModule(id);
|
|
208
203
|
if (externalize) {
|
|
209
204
|
debugNative(externalize);
|
|
210
205
|
const exports2 = await this.interopedImport(externalize);
|
|
@@ -212,10 +207,10 @@ ${getStack()}`), 2e3);
|
|
|
212
207
|
return exports2;
|
|
213
208
|
}
|
|
214
209
|
if (transformed == null)
|
|
215
|
-
throw new Error(`[vite-node] Failed to load ${id}`);
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
const meta = { url };
|
|
210
|
+
throw new Error(`[vite-node] Failed to load "${id}" imported from ${callstack[callstack.length - 2]}`);
|
|
211
|
+
const modulePath = cleanUrl(moduleId);
|
|
212
|
+
const href = pathToFileURL(modulePath).href;
|
|
213
|
+
const meta = { url: href };
|
|
219
214
|
const exports = /* @__PURE__ */ Object.create(null);
|
|
220
215
|
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
221
216
|
value: "Module",
|
|
@@ -223,7 +218,12 @@ ${getStack()}`), 2e3);
|
|
|
223
218
|
configurable: false
|
|
224
219
|
});
|
|
225
220
|
const cjsExports = new Proxy(exports, {
|
|
226
|
-
set(_, p, value) {
|
|
221
|
+
set: (_, p, value) => {
|
|
222
|
+
if (p === "default" && this.shouldInterop(modulePath, { default: value })) {
|
|
223
|
+
exportAll(cjsExports, value);
|
|
224
|
+
exports.default = value;
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
227
|
if (!Reflect.has(exports, "default"))
|
|
228
228
|
exports.default = {};
|
|
229
229
|
if (isPrimitive(exports.default)) {
|
|
@@ -237,7 +237,7 @@ ${getStack()}`), 2e3);
|
|
|
237
237
|
}
|
|
238
238
|
});
|
|
239
239
|
Object.assign(mod, { code: transformed, exports });
|
|
240
|
-
const __filename = fileURLToPath(
|
|
240
|
+
const __filename = fileURLToPath(href);
|
|
241
241
|
const moduleProxy = {
|
|
242
242
|
set exports(value) {
|
|
243
243
|
exportAll(cjsExports, value);
|
|
@@ -255,6 +255,9 @@ ${getStack()}`), 2e3);
|
|
|
255
255
|
var _a, _b;
|
|
256
256
|
hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
|
|
257
257
|
return hotContext;
|
|
258
|
+
},
|
|
259
|
+
set: (value) => {
|
|
260
|
+
hotContext = value;
|
|
258
261
|
}
|
|
259
262
|
});
|
|
260
263
|
}
|
|
@@ -264,8 +267,7 @@ ${getStack()}`), 2e3);
|
|
|
264
267
|
__vite_ssr_exports__: exports,
|
|
265
268
|
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
266
269
|
__vite_ssr_import_meta__: meta,
|
|
267
|
-
|
|
268
|
-
require: createRequire(url),
|
|
270
|
+
require: createRequire(href),
|
|
269
271
|
exports: cjsExports,
|
|
270
272
|
module: moduleProxy,
|
|
271
273
|
__filename,
|
|
@@ -288,42 +290,44 @@ ${getStack()}`), 2e3);
|
|
|
288
290
|
prepareContext(context) {
|
|
289
291
|
return context;
|
|
290
292
|
}
|
|
291
|
-
shouldResolveId(dep) {
|
|
292
|
-
if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
|
|
293
|
-
return false;
|
|
294
|
-
return !isAbsolute(dep) || !extname(dep);
|
|
295
|
-
}
|
|
296
293
|
shouldInterop(path, mod) {
|
|
297
294
|
if (this.options.interopDefault === false)
|
|
298
295
|
return false;
|
|
299
296
|
return !path.endsWith(".mjs") && "default" in mod;
|
|
300
297
|
}
|
|
301
298
|
async interopedImport(path) {
|
|
302
|
-
const
|
|
303
|
-
if (this.shouldInterop(path,
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
299
|
+
const importedModule = await import(path);
|
|
300
|
+
if (!this.shouldInterop(path, importedModule))
|
|
301
|
+
return importedModule;
|
|
302
|
+
const { mod, defaultExport } = interopModule(importedModule);
|
|
303
|
+
return new Proxy(mod, {
|
|
304
|
+
get(mod2, prop) {
|
|
305
|
+
if (prop === "default")
|
|
306
|
+
return defaultExport;
|
|
307
|
+
return mod2[prop] ?? (defaultExport == null ? void 0 : defaultExport[prop]);
|
|
308
|
+
},
|
|
309
|
+
has(mod2, prop) {
|
|
310
|
+
if (prop === "default")
|
|
311
|
+
return defaultExport !== void 0;
|
|
312
|
+
return prop in mod2 || defaultExport && prop in defaultExport;
|
|
313
|
+
}
|
|
314
|
+
});
|
|
316
315
|
}
|
|
317
316
|
}
|
|
318
|
-
function
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
317
|
+
function interopModule(mod) {
|
|
318
|
+
if (isPrimitive(mod)) {
|
|
319
|
+
return {
|
|
320
|
+
mod: { default: mod },
|
|
321
|
+
defaultExport: mod
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
let defaultExport = "default" in mod ? mod.default : mod;
|
|
325
|
+
if (!isPrimitive(defaultExport) && "__esModule" in defaultExport) {
|
|
326
|
+
mod = defaultExport;
|
|
327
|
+
if ("default" in defaultExport)
|
|
328
|
+
defaultExport = defaultExport.default;
|
|
329
|
+
}
|
|
330
|
+
return { mod, defaultExport };
|
|
327
331
|
}
|
|
328
332
|
function defineExport(exports, key, value) {
|
|
329
333
|
Object.defineProperty(exports, key, {
|
package/dist/hmr.cjs
CHANGED
package/dist/hmr.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
2
|
import { HMRPayload, Plugin } from 'vite';
|
|
3
|
-
import { g as CustomEventMap, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-
|
|
3
|
+
import { g as CustomEventMap, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-57a192bf.js';
|
|
4
4
|
|
|
5
5
|
type EventType = string | symbol;
|
|
6
6
|
type Handler<T = unknown> = (event: T) => void;
|
package/dist/hmr.mjs
CHANGED
|
@@ -1,5 +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
|
-
import 'events';
|
|
2
|
+
import 'node:events';
|
|
3
3
|
import './chunk-picocolors.mjs';
|
|
4
4
|
import 'tty';
|
|
5
5
|
import 'debug';
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
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-
|
|
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-57a192bf.js';
|
package/dist/server.cjs
CHANGED
|
@@ -10,7 +10,7 @@ var mlly = require('mlly');
|
|
|
10
10
|
var utils = require('./utils.cjs');
|
|
11
11
|
var picocolors = require('./chunk-picocolors.cjs');
|
|
12
12
|
var sourceMap = require('./source-map.cjs');
|
|
13
|
-
require('url');
|
|
13
|
+
require('node:url');
|
|
14
14
|
require('tty');
|
|
15
15
|
require('source-map-support');
|
|
16
16
|
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TransformResult, ViteDevServer } from 'vite';
|
|
2
|
-
import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId, R as RawSourceMap } from './types-
|
|
2
|
+
import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId, R as RawSourceMap } from './types-57a192bf.js';
|
|
3
3
|
|
|
4
4
|
declare class Debugger {
|
|
5
5
|
options: DebuggerOptions;
|
package/dist/server.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { performance } from 'perf_hooks';
|
|
1
|
+
import { performance } from 'node:perf_hooks';
|
|
2
2
|
import { resolve, join } from 'pathe';
|
|
3
3
|
import createDebug from 'debug';
|
|
4
|
-
import { existsSync, promises } from 'fs';
|
|
4
|
+
import { existsSync, promises } from 'node:fs';
|
|
5
5
|
import { isNodeBuiltin, isValidNodeImport } from 'mlly';
|
|
6
6
|
import { slash, toArray, normalizeModuleId, toFilePath } from './utils.mjs';
|
|
7
7
|
import { p as picocolors } from './chunk-picocolors.mjs';
|
|
8
8
|
import { withInlineSourcemap } from './source-map.mjs';
|
|
9
|
-
import 'url';
|
|
9
|
+
import 'node:url';
|
|
10
10
|
import 'tty';
|
|
11
11
|
import 'source-map-support';
|
|
12
12
|
|
package/dist/source-map.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TransformResult } from 'vite';
|
|
2
|
-
import { R as RawSourceMap } from './types-
|
|
2
|
+
import { R as RawSourceMap } from './types-57a192bf.js';
|
|
3
3
|
|
|
4
4
|
interface InstallSourceMapSupportOptions {
|
|
5
5
|
getSourceMap: (source: string) => RawSourceMap | null | undefined;
|
|
@@ -155,14 +155,17 @@ declare class ViteNodeRunner {
|
|
|
155
155
|
moduleCache: ModuleCacheMap;
|
|
156
156
|
constructor(options: ViteNodeRunnerOptions);
|
|
157
157
|
executeFile(file: string): Promise<any>;
|
|
158
|
-
executeId(
|
|
158
|
+
executeId(rawId: string): Promise<any>;
|
|
159
159
|
getSourceMap(id: string): RawSourceMap | null;
|
|
160
160
|
/** @internal */
|
|
161
|
-
cachedRequest(
|
|
161
|
+
cachedRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
|
|
162
|
+
shouldResolveId(id: string, _importee?: string): boolean;
|
|
163
|
+
resolveUrl(id: string, importee?: string): Promise<[url: string, fsPath: string]>;
|
|
164
|
+
/** @internal */
|
|
165
|
+
dependencyRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
|
|
162
166
|
/** @internal */
|
|
163
167
|
directRequest(id: string, fsPath: string, _callstack: string[]): Promise<any>;
|
|
164
168
|
prepareContext(context: Record<string, any>): Record<string, any>;
|
|
165
|
-
shouldResolveId(dep: string): boolean;
|
|
166
169
|
/**
|
|
167
170
|
* Define if a module should be interop-ed
|
|
168
171
|
* This function mostly for the ability to override by subclass
|
|
@@ -172,7 +175,6 @@ declare class ViteNodeRunner {
|
|
|
172
175
|
* Import a module and interop it
|
|
173
176
|
*/
|
|
174
177
|
interopedImport(path: string): Promise<any>;
|
|
175
|
-
hasNestedDefault(target: any): any;
|
|
176
178
|
}
|
|
177
179
|
|
|
178
180
|
type Nullable<T> = T | null | undefined;
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
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-
|
|
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-57a192bf.js';
|
package/dist/utils.cjs
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var node_url = require('node:url');
|
|
6
6
|
var fs = require('fs');
|
|
7
7
|
var pathe = require('pathe');
|
|
8
|
-
var mlly = require('mlly');
|
|
9
8
|
|
|
10
9
|
const isWindows = process.platform === "win32";
|
|
11
10
|
function slash(str) {
|
|
@@ -14,31 +13,24 @@ function slash(str) {
|
|
|
14
13
|
function mergeSlashes(str) {
|
|
15
14
|
return str.replace(/\/\//g, "/");
|
|
16
15
|
}
|
|
16
|
+
const VALID_ID_PREFIX = "/@id/";
|
|
17
17
|
function normalizeRequestId(id, base) {
|
|
18
18
|
if (base && id.startsWith(base))
|
|
19
19
|
id = `/${id.slice(base.length)}`;
|
|
20
|
-
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^
|
|
20
|
+
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^file:/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
|
|
21
21
|
}
|
|
22
22
|
const queryRE = /\?.*$/s;
|
|
23
23
|
const hashRE = /#.*$/s;
|
|
24
24
|
const cleanUrl = (url) => url.replace(hashRE, "").replace(queryRE, "");
|
|
25
|
+
const isInternalRequest = (id) => {
|
|
26
|
+
return id.startsWith("/@vite/");
|
|
27
|
+
};
|
|
25
28
|
function normalizeModuleId(id) {
|
|
26
|
-
return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
|
|
29
|
+
return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^file:\//, "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
27
30
|
}
|
|
28
31
|
function isPrimitive(v) {
|
|
29
32
|
return v !== Object(v);
|
|
30
33
|
}
|
|
31
|
-
function pathFromRoot(root, filename) {
|
|
32
|
-
if (mlly.isNodeBuiltin(filename))
|
|
33
|
-
return filename;
|
|
34
|
-
filename = filename.replace(/^\/@fs\//, isWindows ? "" : "/");
|
|
35
|
-
if (!filename.startsWith(root))
|
|
36
|
-
return filename;
|
|
37
|
-
const relativePath = pathe.relative(root, filename);
|
|
38
|
-
const segments = relativePath.split("/");
|
|
39
|
-
const startIndex = segments.findIndex((segment) => segment !== ".." && segment !== ".");
|
|
40
|
-
return `/${segments.slice(startIndex).join("/")}`;
|
|
41
|
-
}
|
|
42
34
|
function toFilePath(id, root) {
|
|
43
35
|
let absolute = (() => {
|
|
44
36
|
if (id.startsWith("/@fs/"))
|
|
@@ -52,7 +44,7 @@ function toFilePath(id, root) {
|
|
|
52
44
|
})();
|
|
53
45
|
if (absolute.startsWith("//"))
|
|
54
46
|
absolute = absolute.slice(1);
|
|
55
|
-
return isWindows && absolute.startsWith("/") ? slash(
|
|
47
|
+
return isWindows && absolute.startsWith("/") ? slash(node_url.fileURLToPath(node_url.pathToFileURL(absolute.slice(1)).href)) : absolute;
|
|
56
48
|
}
|
|
57
49
|
function toArray(array) {
|
|
58
50
|
if (array === null || array === void 0)
|
|
@@ -62,14 +54,15 @@ function toArray(array) {
|
|
|
62
54
|
return [array];
|
|
63
55
|
}
|
|
64
56
|
|
|
57
|
+
exports.VALID_ID_PREFIX = VALID_ID_PREFIX;
|
|
65
58
|
exports.cleanUrl = cleanUrl;
|
|
66
59
|
exports.hashRE = hashRE;
|
|
60
|
+
exports.isInternalRequest = isInternalRequest;
|
|
67
61
|
exports.isPrimitive = isPrimitive;
|
|
68
62
|
exports.isWindows = isWindows;
|
|
69
63
|
exports.mergeSlashes = mergeSlashes;
|
|
70
64
|
exports.normalizeModuleId = normalizeModuleId;
|
|
71
65
|
exports.normalizeRequestId = normalizeRequestId;
|
|
72
|
-
exports.pathFromRoot = pathFromRoot;
|
|
73
66
|
exports.queryRE = queryRE;
|
|
74
67
|
exports.slash = slash;
|
|
75
68
|
exports.toArray = toArray;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { N as Nullable, A as Arrayable } from './types-
|
|
1
|
+
import { N as Nullable, A as Arrayable } from './types-57a192bf.js';
|
|
2
2
|
|
|
3
3
|
declare const isWindows: boolean;
|
|
4
4
|
declare function slash(str: string): string;
|
|
5
5
|
declare function mergeSlashes(str: string): string;
|
|
6
|
+
declare const VALID_ID_PREFIX = "/@id/";
|
|
6
7
|
declare function normalizeRequestId(id: string, base?: string): string;
|
|
7
8
|
declare const queryRE: RegExp;
|
|
8
9
|
declare const hashRE: RegExp;
|
|
9
10
|
declare const cleanUrl: (url: string) => string;
|
|
11
|
+
declare const isInternalRequest: (id: string) => boolean;
|
|
10
12
|
declare function normalizeModuleId(id: string): string;
|
|
11
13
|
declare function isPrimitive(v: any): boolean;
|
|
12
|
-
declare function pathFromRoot(root: string, filename: string): string;
|
|
13
14
|
declare function toFilePath(id: string, root: string): string;
|
|
14
15
|
/**
|
|
15
16
|
* Convert `Arrayable<T>` to `Array<T>`
|
|
@@ -18,4 +19,4 @@ declare function toFilePath(id: string, root: string): string;
|
|
|
18
19
|
*/
|
|
19
20
|
declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
|
|
20
21
|
|
|
21
|
-
export { cleanUrl, hashRE, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId,
|
|
22
|
+
export { VALID_ID_PREFIX, cleanUrl, hashRE, isInternalRequest, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, queryRE, slash, toArray, toFilePath };
|
package/dist/utils.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { fileURLToPath, pathToFileURL } from 'url';
|
|
2
|
-
import { existsSync } from 'fs';
|
|
3
|
-
import {
|
|
4
|
-
import { isNodeBuiltin } from 'mlly';
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'pathe';
|
|
5
4
|
|
|
6
5
|
const isWindows = process.platform === "win32";
|
|
7
6
|
function slash(str) {
|
|
@@ -10,31 +9,24 @@ function slash(str) {
|
|
|
10
9
|
function mergeSlashes(str) {
|
|
11
10
|
return str.replace(/\/\//g, "/");
|
|
12
11
|
}
|
|
12
|
+
const VALID_ID_PREFIX = "/@id/";
|
|
13
13
|
function normalizeRequestId(id, base) {
|
|
14
14
|
if (base && id.startsWith(base))
|
|
15
15
|
id = `/${id.slice(base.length)}`;
|
|
16
|
-
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^
|
|
16
|
+
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^file:/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
|
|
17
17
|
}
|
|
18
18
|
const queryRE = /\?.*$/s;
|
|
19
19
|
const hashRE = /#.*$/s;
|
|
20
20
|
const cleanUrl = (url) => url.replace(hashRE, "").replace(queryRE, "");
|
|
21
|
+
const isInternalRequest = (id) => {
|
|
22
|
+
return id.startsWith("/@vite/");
|
|
23
|
+
};
|
|
21
24
|
function normalizeModuleId(id) {
|
|
22
|
-
return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
|
|
25
|
+
return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^file:\//, "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
23
26
|
}
|
|
24
27
|
function isPrimitive(v) {
|
|
25
28
|
return v !== Object(v);
|
|
26
29
|
}
|
|
27
|
-
function pathFromRoot(root, filename) {
|
|
28
|
-
if (isNodeBuiltin(filename))
|
|
29
|
-
return filename;
|
|
30
|
-
filename = filename.replace(/^\/@fs\//, isWindows ? "" : "/");
|
|
31
|
-
if (!filename.startsWith(root))
|
|
32
|
-
return filename;
|
|
33
|
-
const relativePath = relative(root, filename);
|
|
34
|
-
const segments = relativePath.split("/");
|
|
35
|
-
const startIndex = segments.findIndex((segment) => segment !== ".." && segment !== ".");
|
|
36
|
-
return `/${segments.slice(startIndex).join("/")}`;
|
|
37
|
-
}
|
|
38
30
|
function toFilePath(id, root) {
|
|
39
31
|
let absolute = (() => {
|
|
40
32
|
if (id.startsWith("/@fs/"))
|
|
@@ -58,4 +50,4 @@ function toArray(array) {
|
|
|
58
50
|
return [array];
|
|
59
51
|
}
|
|
60
52
|
|
|
61
|
-
export { cleanUrl, hashRE, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId,
|
|
53
|
+
export { VALID_ID_PREFIX, cleanUrl, hashRE, isInternalRequest, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, queryRE, slash, toArray, toFilePath };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"description": "Vite as Node.js runtime",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"build": "rimraf dist && rollup -c",
|
|
89
|
-
"dev": "rollup -c --watch --watch.include
|
|
89
|
+
"dev": "rollup -c --watch --watch.include 'src/**' -m inline",
|
|
90
90
|
"typecheck": "tsc --noEmit"
|
|
91
91
|
}
|
|
92
92
|
}
|