vite-node 0.25.3 → 0.25.5

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 CHANGED
@@ -15,9 +15,9 @@ require('debug');
15
15
  require('fs');
16
16
  require('mlly');
17
17
  require('url');
18
+ require('source-map-support');
18
19
  require('module');
19
20
  require('vm');
20
- require('source-map-support');
21
21
 
22
22
  function toArr(any) {
23
23
  return any == null ? [] : Array.isArray(any) ? any : [any];
@@ -632,7 +632,7 @@ class CAC extends events.EventEmitter {
632
632
 
633
633
  const cac = (name = "") => new CAC(name);
634
634
 
635
- var version = "0.25.3";
635
+ var version = "0.25.5";
636
636
 
637
637
  const cli = cac("vite-node");
638
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/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { e as ViteNodeServerOptions } from './types-257c4f87.js';
1
+ import { e as ViteNodeServerOptions } from './types-de49c638.js';
2
2
 
3
3
  interface CliOptions {
4
4
  root?: string;
package/dist/cli.mjs CHANGED
@@ -13,9 +13,9 @@ import 'debug';
13
13
  import 'fs';
14
14
  import 'mlly';
15
15
  import 'url';
16
+ import 'source-map-support';
16
17
  import 'module';
17
18
  import 'vm';
18
- import 'source-map-support';
19
19
 
20
20
  function toArr(any) {
21
21
  return any == null ? [] : Array.isArray(any) ? any : [any];
@@ -630,7 +630,7 @@ class CAC extends EventEmitter {
630
630
 
631
631
  const cac = (name = "") => new CAC(name);
632
632
 
633
- var version = "0.25.3";
633
+ var version = "0.25.5";
634
634
 
635
635
  const cli = cac("vite-node");
636
636
  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
@@ -9,7 +9,9 @@ var pathe = require('pathe');
9
9
  var mlly = require('mlly');
10
10
  var createDebug = require('debug');
11
11
  var utils = require('./utils.cjs');
12
+ var sourceMap = require('./source-map.cjs');
12
13
  require('fs');
14
+ require('source-map-support');
13
15
 
14
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
17
 
@@ -125,14 +127,11 @@ class ModuleCacheMap extends Map {
125
127
  return invalidated;
126
128
  }
127
129
  getSourceMap(id) {
128
- var _a, _b;
129
- const fsPath = this.normalizePath(id);
130
- const cache = this.get(fsPath);
130
+ const cache = this.get(id);
131
131
  if (cache.map)
132
132
  return cache.map;
133
- const mapString = (_b = (_a = cache == null ? void 0 : cache.code) == null ? void 0 : _a.match(/\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,(.+)/)) == null ? void 0 : _b[1];
134
- if (mapString) {
135
- const map = JSON.parse(Buffer.from(mapString, "base64").toString("utf-8"));
133
+ const map = cache.code && sourceMap.extractSourceMap(cache.code);
134
+ if (map) {
136
135
  cache.map = map;
137
136
  return map;
138
137
  }
@@ -169,12 +168,15 @@ class ViteNodeRunner {
169
168
  if (mod.promise)
170
169
  return mod.promise;
171
170
  const promise = this.directRequest(id, fsPath, callstack);
172
- Object.assign(mod, { promise });
171
+ Object.assign(mod, { promise, evaluated: false });
172
+ promise.finally(() => {
173
+ mod.evaluated = true;
174
+ });
173
175
  return await promise;
174
176
  }
175
177
  async directRequest(id, fsPath, _callstack) {
176
178
  const callstack = [..._callstack, fsPath];
177
- const mod = this.moduleCache.get(fsPath);
179
+ let mod = this.moduleCache.get(fsPath);
178
180
  const request = async (dep) => {
179
181
  var _a;
180
182
  const depFsPath = utils.toFilePath(utils.normalizeRequestId(dep, this.options.base), this.root);
@@ -210,11 +212,22 @@ ${getStack()}`), 2e3);
210
212
  }
211
213
  return dep;
212
214
  };
213
- id = await resolveId(id, 2);
214
215
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
215
216
  if (id in requestStubs)
216
217
  return requestStubs[id];
217
- let { code: transformed, externalize } = await this.options.fetchModule(id);
218
+ let { code: transformed, externalize, file } = await this.options.fetchModule(id);
219
+ if (file && !fsPath.includes("?") && fsPath !== file) {
220
+ if (this.moduleCache.has(file)) {
221
+ mod = this.moduleCache.get(file);
222
+ this.moduleCache.set(fsPath, mod);
223
+ if (mod.promise)
224
+ return mod.promise;
225
+ if (mod.exports)
226
+ return mod.exports;
227
+ } else {
228
+ this.moduleCache.set(file, mod);
229
+ }
230
+ }
218
231
  if (externalize) {
219
232
  debugNative(externalize);
220
233
  const exports2 = await this.interopedImport(externalize);
@@ -223,7 +236,7 @@ ${getStack()}`), 2e3);
223
236
  }
224
237
  if (transformed == null)
225
238
  throw new Error(`[vite-node] Failed to load ${id}`);
226
- const url$1 = url.pathToFileURL(fsPath).href;
239
+ const url$1 = url.pathToFileURL(file || fsPath).href;
227
240
  const meta = { url: url$1 };
228
241
  const exports = /* @__PURE__ */ Object.create(null);
229
242
  Object.defineProperty(exports, Symbol.toStringTag, {
@@ -232,9 +245,6 @@ ${getStack()}`), 2e3);
232
245
  configurable: false
233
246
  });
234
247
  const cjsExports = new Proxy(exports, {
235
- get(_, p, receiver) {
236
- return Reflect.get(exports, p, receiver);
237
- },
238
248
  set(_, p, value) {
239
249
  if (!Reflect.has(exports, "default"))
240
250
  exports.default = {};
@@ -290,7 +300,7 @@ ${getStack()}`), 2e3);
290
300
  const code = `${codeDefinition}${transformed}
291
301
  }}`;
292
302
  const fn = vm__default["default"].runInThisContext(code, {
293
- filename: fsPath,
303
+ filename: __filename,
294
304
  lineOffset: 0,
295
305
  columnOffset: -codeDefinition.length
296
306
  });
@@ -347,7 +357,7 @@ function defineExport(exports, key, value) {
347
357
  function exportAll(exports, sourceModule) {
348
358
  if (exports === sourceModule)
349
359
  return;
350
- if (typeof sourceModule !== "object" || Array.isArray(sourceModule) || !sourceModule)
360
+ if (utils.isPrimitive(sourceModule) || Array.isArray(sourceModule))
351
361
  return;
352
362
  for (const key in sourceModule) {
353
363
  if (key !== "default") {
package/dist/client.d.ts CHANGED
@@ -1 +1 @@
1
- export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-257c4f87.js';
1
+ export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-de49c638.js';
package/dist/client.mjs CHANGED
@@ -5,7 +5,9 @@ import { resolve, dirname, isAbsolute, extname } from 'pathe';
5
5
  import { isNodeBuiltin } from 'mlly';
6
6
  import createDebug from 'debug';
7
7
  import { normalizeModuleId, slash, normalizeRequestId, toFilePath, isPrimitive, mergeSlashes } from './utils.mjs';
8
+ import { extractSourceMap } from './source-map.mjs';
8
9
  import 'fs';
10
+ import 'source-map-support';
9
11
 
10
12
  const debugExecute = createDebug("vite-node:client:execute");
11
13
  const debugNative = createDebug("vite-node:client:native");
@@ -98,14 +100,11 @@ class ModuleCacheMap extends Map {
98
100
  return invalidated;
99
101
  }
100
102
  getSourceMap(id) {
101
- var _a, _b;
102
- const fsPath = this.normalizePath(id);
103
- const cache = this.get(fsPath);
103
+ const cache = this.get(id);
104
104
  if (cache.map)
105
105
  return cache.map;
106
- const mapString = (_b = (_a = cache == null ? void 0 : cache.code) == null ? void 0 : _a.match(/\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,(.+)/)) == null ? void 0 : _b[1];
107
- if (mapString) {
108
- const map = JSON.parse(Buffer.from(mapString, "base64").toString("utf-8"));
106
+ const map = cache.code && extractSourceMap(cache.code);
107
+ if (map) {
109
108
  cache.map = map;
110
109
  return map;
111
110
  }
@@ -142,12 +141,15 @@ class ViteNodeRunner {
142
141
  if (mod.promise)
143
142
  return mod.promise;
144
143
  const promise = this.directRequest(id, fsPath, callstack);
145
- Object.assign(mod, { promise });
144
+ Object.assign(mod, { promise, evaluated: false });
145
+ promise.finally(() => {
146
+ mod.evaluated = true;
147
+ });
146
148
  return await promise;
147
149
  }
148
150
  async directRequest(id, fsPath, _callstack) {
149
151
  const callstack = [..._callstack, fsPath];
150
- const mod = this.moduleCache.get(fsPath);
152
+ let mod = this.moduleCache.get(fsPath);
151
153
  const request = async (dep) => {
152
154
  var _a;
153
155
  const depFsPath = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
@@ -183,11 +185,22 @@ ${getStack()}`), 2e3);
183
185
  }
184
186
  return dep;
185
187
  };
186
- id = await resolveId(id, 2);
187
188
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
188
189
  if (id in requestStubs)
189
190
  return requestStubs[id];
190
- let { code: transformed, externalize } = await this.options.fetchModule(id);
191
+ let { code: transformed, externalize, file } = await this.options.fetchModule(id);
192
+ if (file && !fsPath.includes("?") && fsPath !== file) {
193
+ if (this.moduleCache.has(file)) {
194
+ mod = this.moduleCache.get(file);
195
+ this.moduleCache.set(fsPath, mod);
196
+ if (mod.promise)
197
+ return mod.promise;
198
+ if (mod.exports)
199
+ return mod.exports;
200
+ } else {
201
+ this.moduleCache.set(file, mod);
202
+ }
203
+ }
191
204
  if (externalize) {
192
205
  debugNative(externalize);
193
206
  const exports2 = await this.interopedImport(externalize);
@@ -196,7 +209,7 @@ ${getStack()}`), 2e3);
196
209
  }
197
210
  if (transformed == null)
198
211
  throw new Error(`[vite-node] Failed to load ${id}`);
199
- const url = pathToFileURL(fsPath).href;
212
+ const url = pathToFileURL(file || fsPath).href;
200
213
  const meta = { url };
201
214
  const exports = /* @__PURE__ */ Object.create(null);
202
215
  Object.defineProperty(exports, Symbol.toStringTag, {
@@ -205,9 +218,6 @@ ${getStack()}`), 2e3);
205
218
  configurable: false
206
219
  });
207
220
  const cjsExports = new Proxy(exports, {
208
- get(_, p, receiver) {
209
- return Reflect.get(exports, p, receiver);
210
- },
211
221
  set(_, p, value) {
212
222
  if (!Reflect.has(exports, "default"))
213
223
  exports.default = {};
@@ -263,7 +273,7 @@ ${getStack()}`), 2e3);
263
273
  const code = `${codeDefinition}${transformed}
264
274
  }}`;
265
275
  const fn = vm.runInThisContext(code, {
266
- filename: fsPath,
276
+ filename: __filename,
267
277
  lineOffset: 0,
268
278
  columnOffset: -codeDefinition.length
269
279
  });
@@ -320,7 +330,7 @@ function defineExport(exports, key, value) {
320
330
  function exportAll(exports, sourceModule) {
321
331
  if (exports === sourceModule)
322
332
  return;
323
- if (typeof sourceModule !== "object" || Array.isArray(sourceModule) || !sourceModule)
333
+ if (isPrimitive(sourceModule) || Array.isArray(sourceModule))
324
334
  return;
325
335
  for (const key in sourceModule) {
326
336
  if (key !== "default") {
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 { g as CustomEventMap, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-257c4f87.js';
3
+ import { g as CustomEventMap, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-de49c638.js';
4
4
 
5
5
  declare type EventType = string | symbol;
6
6
  declare type Handler<T = unknown> = (event: T) => void;
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-257c4f87.js';
1
+ export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-de49c638.js';
package/dist/server.cjs CHANGED
@@ -9,8 +9,10 @@ var fs = require('fs');
9
9
  var mlly = require('mlly');
10
10
  var utils = require('./utils.cjs');
11
11
  var picocolors = require('./chunk-picocolors.cjs');
12
+ var sourceMap = require('./source-map.cjs');
12
13
  require('url');
13
14
  require('tty');
15
+ require('source-map-support');
14
16
 
15
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
18
 
@@ -173,7 +175,6 @@ ${result.code}`, "utf-8");
173
175
  }
174
176
 
175
177
  const debugRequest = createDebug__default["default"]("vite-node:server:request");
176
- const RealDate = Date;
177
178
  class ViteNodeServer {
178
179
  constructor(server, options = {}) {
179
180
  this.server = server;
@@ -220,6 +221,7 @@ class ViteNodeServer {
220
221
  return (ssrTransformResult == null ? void 0 : ssrTransformResult.map) || null;
221
222
  }
222
223
  async fetchModule(id) {
224
+ id = utils.normalizeModuleId(id);
223
225
  if (!this.fetchPromiseMap.has(id)) {
224
226
  this.fetchPromiseMap.set(
225
227
  id,
@@ -259,24 +261,33 @@ class ViteNodeServer {
259
261
  let result;
260
262
  const filePath = utils.toFilePath(id, this.server.config.root);
261
263
  const module = this.server.moduleGraph.getModuleById(id);
262
- const timestamp = (module == null ? void 0 : module.lastHMRTimestamp) || RealDate.now();
264
+ const timestamp = module ? module.lastHMRTimestamp : null;
263
265
  const cache = this.fetchCache.get(filePath);
264
- if (timestamp && cache && cache.timestamp >= timestamp)
266
+ if (cache == null ? void 0 : cache.result.id)
267
+ id = cache.result.id;
268
+ if (timestamp !== null && cache && cache.timestamp >= timestamp)
265
269
  return cache.result;
270
+ const time = Date.now();
266
271
  const externalize = await this.shouldExternalize(filePath);
267
272
  let duration;
268
273
  if (externalize) {
269
274
  result = { externalize };
270
275
  (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
271
276
  } else {
277
+ let file = module == null ? void 0 : module.file;
278
+ if (!file) {
279
+ const [, resolvedId] = await this.server.moduleGraph.resolveUrl(id, true);
280
+ id = resolvedId;
281
+ file = utils.cleanUrl(resolvedId);
282
+ }
272
283
  const start = perf_hooks.performance.now();
273
284
  const r = await this._transformRequest(id);
274
285
  duration = perf_hooks.performance.now() - start;
275
- result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
286
+ result = { file, id, code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
276
287
  }
277
288
  this.fetchCache.set(filePath, {
278
289
  duration,
279
- timestamp,
290
+ timestamp: time,
280
291
  result
281
292
  });
282
293
  return result;
@@ -299,7 +310,7 @@ class ViteNodeServer {
299
310
  }
300
311
  const sourcemap = this.options.sourcemap ?? "inline";
301
312
  if (sourcemap === "inline" && result && !id.includes("node_modules"))
302
- utils.withInlineSourcemap(result);
313
+ sourceMap.withInlineSourcemap(result);
303
314
  if ((_c = this.options.debug) == null ? void 0 : _c.dumpModules)
304
315
  await ((_d = this.debugger) == null ? void 0 : _d.dumpFile(id, result));
305
316
  return result;
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-257c4f87.js';
2
+ import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId, R as RawSourceMap } from './types-de49c638.js';
3
3
 
4
4
  declare class Debugger {
5
5
  options: DebuggerOptions;
package/dist/server.mjs CHANGED
@@ -3,10 +3,12 @@ import { resolve, join } from 'pathe';
3
3
  import createDebug from 'debug';
4
4
  import { existsSync, promises } from 'fs';
5
5
  import { isNodeBuiltin, isValidNodeImport } from 'mlly';
6
- import { slash, toArray, toFilePath, withInlineSourcemap } from './utils.mjs';
6
+ import { slash, toArray, normalizeModuleId, toFilePath, cleanUrl } from './utils.mjs';
7
7
  import { p as picocolors } from './chunk-picocolors.mjs';
8
+ import { withInlineSourcemap } from './source-map.mjs';
8
9
  import 'url';
9
10
  import 'tty';
11
+ import 'source-map-support';
10
12
 
11
13
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
12
14
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
@@ -165,7 +167,6 @@ ${result.code}`, "utf-8");
165
167
  }
166
168
 
167
169
  const debugRequest = createDebug("vite-node:server:request");
168
- const RealDate = Date;
169
170
  class ViteNodeServer {
170
171
  constructor(server, options = {}) {
171
172
  this.server = server;
@@ -212,6 +213,7 @@ class ViteNodeServer {
212
213
  return (ssrTransformResult == null ? void 0 : ssrTransformResult.map) || null;
213
214
  }
214
215
  async fetchModule(id) {
216
+ id = normalizeModuleId(id);
215
217
  if (!this.fetchPromiseMap.has(id)) {
216
218
  this.fetchPromiseMap.set(
217
219
  id,
@@ -251,24 +253,33 @@ class ViteNodeServer {
251
253
  let result;
252
254
  const filePath = toFilePath(id, this.server.config.root);
253
255
  const module = this.server.moduleGraph.getModuleById(id);
254
- const timestamp = (module == null ? void 0 : module.lastHMRTimestamp) || RealDate.now();
256
+ const timestamp = module ? module.lastHMRTimestamp : null;
255
257
  const cache = this.fetchCache.get(filePath);
256
- if (timestamp && cache && cache.timestamp >= timestamp)
258
+ if (cache == null ? void 0 : cache.result.id)
259
+ id = cache.result.id;
260
+ if (timestamp !== null && cache && cache.timestamp >= timestamp)
257
261
  return cache.result;
262
+ const time = Date.now();
258
263
  const externalize = await this.shouldExternalize(filePath);
259
264
  let duration;
260
265
  if (externalize) {
261
266
  result = { externalize };
262
267
  (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
263
268
  } else {
269
+ let file = module == null ? void 0 : module.file;
270
+ if (!file) {
271
+ const [, resolvedId] = await this.server.moduleGraph.resolveUrl(id, true);
272
+ id = resolvedId;
273
+ file = cleanUrl(resolvedId);
274
+ }
264
275
  const start = performance.now();
265
276
  const r = await this._transformRequest(id);
266
277
  duration = performance.now() - start;
267
- result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
278
+ result = { file, id, code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
268
279
  }
269
280
  this.fetchCache.set(filePath, {
270
281
  duration,
271
- timestamp,
282
+ timestamp: time,
272
283
  result
273
284
  });
274
285
  return result;
@@ -4,6 +4,34 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var sourceMapSupport = require('source-map-support');
6
6
 
7
+ let SOURCEMAPPING_URL = "sourceMa";
8
+ SOURCEMAPPING_URL += "ppingURL";
9
+ const VITE_NODE_SOURCEMAPPING_SOURCE = "//# sourceMappingSource=vite-node";
10
+ const VITE_NODE_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
11
+ const VITE_NODE_SOURCEMAPPING_REGEXP = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`);
12
+ async function withInlineSourcemap(result) {
13
+ const map = result.map;
14
+ let code = result.code;
15
+ if (!map || code.includes(VITE_NODE_SOURCEMAPPING_SOURCE))
16
+ return result;
17
+ const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,(.+)`, "g");
18
+ while (OTHER_SOURCE_MAP_REGEXP.test(code))
19
+ code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
20
+ const sourceMap = Buffer.from(JSON.stringify(map), "utf-8").toString("base64");
21
+ result.code = `${code.trimEnd()}
22
+
23
+ ${VITE_NODE_SOURCEMAPPING_SOURCE}
24
+ //# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}
25
+ `;
26
+ return result;
27
+ }
28
+ function extractSourceMap(code) {
29
+ var _a;
30
+ const mapString = (_a = code.match(VITE_NODE_SOURCEMAPPING_REGEXP)) == null ? void 0 : _a[1];
31
+ if (mapString)
32
+ return JSON.parse(Buffer.from(mapString, "base64").toString("utf-8"));
33
+ return null;
34
+ }
7
35
  function installSourcemapsSupport(options) {
8
36
  sourceMapSupport.install({
9
37
  environment: "node",
@@ -21,4 +49,6 @@ function installSourcemapsSupport(options) {
21
49
  });
22
50
  }
23
51
 
52
+ exports.extractSourceMap = extractSourceMap;
24
53
  exports.installSourcemapsSupport = installSourcemapsSupport;
54
+ exports.withInlineSourcemap = withInlineSourcemap;
@@ -1,8 +1,11 @@
1
- import { R as RawSourceMap } from './types-257c4f87.js';
1
+ import { TransformResult } from 'vite';
2
+ import { R as RawSourceMap } from './types-de49c638.js';
2
3
 
3
4
  interface InstallSourceMapSupportOptions {
4
5
  getSourceMap: (source: string) => RawSourceMap | null | undefined;
5
6
  }
7
+ declare function withInlineSourcemap(result: TransformResult): Promise<TransformResult>;
8
+ declare function extractSourceMap(code: string): RawSourceMap | null;
6
9
  declare function installSourcemapsSupport(options: InstallSourceMapSupportOptions): void;
7
10
 
8
- export { installSourcemapsSupport };
11
+ export { extractSourceMap, installSourcemapsSupport, withInlineSourcemap };
@@ -1,5 +1,33 @@
1
1
  import { install } from 'source-map-support';
2
2
 
3
+ let SOURCEMAPPING_URL = "sourceMa";
4
+ SOURCEMAPPING_URL += "ppingURL";
5
+ const VITE_NODE_SOURCEMAPPING_SOURCE = "//# sourceMappingSource=vite-node";
6
+ const VITE_NODE_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
7
+ const VITE_NODE_SOURCEMAPPING_REGEXP = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`);
8
+ async function withInlineSourcemap(result) {
9
+ const map = result.map;
10
+ let code = result.code;
11
+ if (!map || code.includes(VITE_NODE_SOURCEMAPPING_SOURCE))
12
+ return result;
13
+ const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,(.+)`, "g");
14
+ while (OTHER_SOURCE_MAP_REGEXP.test(code))
15
+ code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
16
+ const sourceMap = Buffer.from(JSON.stringify(map), "utf-8").toString("base64");
17
+ result.code = `${code.trimEnd()}
18
+
19
+ ${VITE_NODE_SOURCEMAPPING_SOURCE}
20
+ //# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}
21
+ `;
22
+ return result;
23
+ }
24
+ function extractSourceMap(code) {
25
+ var _a;
26
+ const mapString = (_a = code.match(VITE_NODE_SOURCEMAPPING_REGEXP)) == null ? void 0 : _a[1];
27
+ if (mapString)
28
+ return JSON.parse(Buffer.from(mapString, "base64").toString("utf-8"));
29
+ return null;
30
+ }
3
31
  function installSourcemapsSupport(options) {
4
32
  install({
5
33
  environment: "node",
@@ -17,4 +45,4 @@ function installSourcemapsSupport(options) {
17
45
  });
18
46
  }
19
47
 
20
- export { installSourcemapsSupport };
48
+ export { extractSourceMap, installSourcemapsSupport, withInlineSourcemap };
@@ -142,7 +142,7 @@ declare class ModuleCacheMap extends Map<string, ModuleCache> {
142
142
  /**
143
143
  * Return parsed source map based on inlined source map of the module
144
144
  */
145
- getSourceMap(id: string): any;
145
+ getSourceMap(id: string): RawSourceMap | null;
146
146
  }
147
147
  declare class ViteNodeRunner {
148
148
  options: ViteNodeRunnerOptions;
@@ -156,7 +156,7 @@ declare class ViteNodeRunner {
156
156
  constructor(options: ViteNodeRunnerOptions);
157
157
  executeFile(file: string): Promise<any>;
158
158
  executeId(id: string): Promise<any>;
159
- getSourceMap(id: string): any;
159
+ getSourceMap(id: string): RawSourceMap | null;
160
160
  /** @internal */
161
161
  cachedRequest(rawId: string, callstack: string[]): Promise<any>;
162
162
  /** @internal */
@@ -201,6 +201,8 @@ interface FetchResult {
201
201
  code?: string;
202
202
  externalize?: string;
203
203
  map?: RawSourceMap;
204
+ id?: string;
205
+ file?: string;
204
206
  }
205
207
  declare type HotContext = Omit<ViteHotContext, 'acceptDeps' | 'decline'>;
206
208
  declare type FetchFunction = (id: string) => Promise<FetchResult>;
@@ -209,6 +211,7 @@ declare type CreateHotContextFunction = (runner: ViteNodeRunner, url: string) =>
209
211
  interface ModuleCache {
210
212
  promise?: Promise<any>;
211
213
  exports?: any;
214
+ evaluated?: boolean;
212
215
  code?: string;
213
216
  map?: RawSourceMap;
214
217
  /**
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-257c4f87.js';
1
+ export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-de49c638.js';
package/dist/utils.cjs CHANGED
@@ -19,6 +19,9 @@ function normalizeRequestId(id, base) {
19
19
  id = `/${id.slice(base.length)}`;
20
20
  return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
21
21
  }
22
+ const queryRE = /\?.*$/s;
23
+ const hashRE = /#.*$/s;
24
+ const cleanUrl = (url) => url.replace(hashRE, "").replace(queryRE, "");
22
25
  function normalizeModuleId(id) {
23
26
  return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
24
27
  }
@@ -51,19 +54,6 @@ function toFilePath(id, root) {
51
54
  absolute = absolute.slice(1);
52
55
  return isWindows && absolute.startsWith("/") ? slash(url.fileURLToPath(url.pathToFileURL(absolute.slice(1)).href)) : absolute;
53
56
  }
54
- let SOURCEMAPPING_URL = "sourceMa";
55
- SOURCEMAPPING_URL += "ppingURL";
56
- async function withInlineSourcemap(result) {
57
- const { code, map } = result;
58
- if (code.includes(`${SOURCEMAPPING_URL}=`))
59
- return result;
60
- if (map)
61
- result.code = `${code}
62
-
63
- //# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
64
- `;
65
- return result;
66
- }
67
57
  function toArray(array) {
68
58
  if (array === null || array === void 0)
69
59
  array = [];
@@ -72,13 +62,15 @@ function toArray(array) {
72
62
  return [array];
73
63
  }
74
64
 
65
+ exports.cleanUrl = cleanUrl;
66
+ exports.hashRE = hashRE;
75
67
  exports.isPrimitive = isPrimitive;
76
68
  exports.isWindows = isWindows;
77
69
  exports.mergeSlashes = mergeSlashes;
78
70
  exports.normalizeModuleId = normalizeModuleId;
79
71
  exports.normalizeRequestId = normalizeRequestId;
80
72
  exports.pathFromRoot = pathFromRoot;
73
+ exports.queryRE = queryRE;
81
74
  exports.slash = slash;
82
75
  exports.toArray = toArray;
83
76
  exports.toFilePath = toFilePath;
84
- exports.withInlineSourcemap = withInlineSourcemap;
package/dist/utils.d.ts CHANGED
@@ -1,15 +1,16 @@
1
- import { TransformResult } from 'vite';
2
- import { N as Nullable, A as Arrayable } from './types-257c4f87.js';
1
+ import { N as Nullable, A as Arrayable } from './types-de49c638.js';
3
2
 
4
3
  declare const isWindows: boolean;
5
4
  declare function slash(str: string): string;
6
5
  declare function mergeSlashes(str: string): string;
7
6
  declare function normalizeRequestId(id: string, base?: string): string;
7
+ declare const queryRE: RegExp;
8
+ declare const hashRE: RegExp;
9
+ declare const cleanUrl: (url: string) => string;
8
10
  declare function normalizeModuleId(id: string): string;
9
11
  declare function isPrimitive(v: any): boolean;
10
12
  declare function pathFromRoot(root: string, filename: string): string;
11
13
  declare function toFilePath(id: string, root: string): string;
12
- declare function withInlineSourcemap(result: TransformResult): Promise<TransformResult>;
13
14
  /**
14
15
  * Convert `Arrayable<T>` to `Array<T>`
15
16
  *
@@ -17,4 +18,4 @@ declare function withInlineSourcemap(result: TransformResult): Promise<Transform
17
18
  */
18
19
  declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
19
20
 
20
- export { isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, pathFromRoot, slash, toArray, toFilePath, withInlineSourcemap };
21
+ export { cleanUrl, hashRE, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, pathFromRoot, queryRE, slash, toArray, toFilePath };
package/dist/utils.mjs CHANGED
@@ -15,6 +15,9 @@ function normalizeRequestId(id, base) {
15
15
  id = `/${id.slice(base.length)}`;
16
16
  return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
17
17
  }
18
+ const queryRE = /\?.*$/s;
19
+ const hashRE = /#.*$/s;
20
+ const cleanUrl = (url) => url.replace(hashRE, "").replace(queryRE, "");
18
21
  function normalizeModuleId(id) {
19
22
  return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
20
23
  }
@@ -47,19 +50,6 @@ function toFilePath(id, root) {
47
50
  absolute = absolute.slice(1);
48
51
  return isWindows && absolute.startsWith("/") ? slash(fileURLToPath(pathToFileURL(absolute.slice(1)).href)) : absolute;
49
52
  }
50
- let SOURCEMAPPING_URL = "sourceMa";
51
- SOURCEMAPPING_URL += "ppingURL";
52
- async function withInlineSourcemap(result) {
53
- const { code, map } = result;
54
- if (code.includes(`${SOURCEMAPPING_URL}=`))
55
- return result;
56
- if (map)
57
- result.code = `${code}
58
-
59
- //# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
60
- `;
61
- return result;
62
- }
63
53
  function toArray(array) {
64
54
  if (array === null || array === void 0)
65
55
  array = [];
@@ -68,4 +58,4 @@ function toArray(array) {
68
58
  return [array];
69
59
  }
70
60
 
71
- export { isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, pathFromRoot, slash, toArray, toFilePath, withInlineSourcemap };
61
+ export { cleanUrl, hashRE, isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, pathFromRoot, queryRE, slash, toArray, toFilePath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.25.3",
3
+ "version": "0.25.5",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",