vite-node 0.34.4 → 0.34.6

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.
@@ -1,4 +1,4 @@
1
- import { E as EncodedSourceMap } from './types.d-7442d07f.js';
1
+ import { E as EncodedSourceMap } from './trace-mapping.d-e677e8f4.js';
2
2
 
3
3
  type HMRPayload =
4
4
  | ConnectedPayload
@@ -295,4 +295,4 @@ interface DebuggerOptions {
295
295
  loadDumppedModules?: boolean;
296
296
  }
297
297
 
298
- export { Arrayable as A, CreateHotContextFunction as C, DepsHandlingOptions as D, FetchResult as F, HotContext as H, ModuleCacheMap as M, Nullable as N, RawSourceMap as R, StartOfSourceMap as S, ViteNodeRunnerOptions as V, Awaitable as a, FetchFunction as b, ResolveIdFunction as c, ModuleCache as d, ViteNodeResolveId as e, ViteNodeServerOptions as f, DebuggerOptions as g, CustomEventMap as h, ViteNodeRunner as i, HMRPayload as j, DEFAULT_REQUEST_STUBS as k };
298
+ export { Arrayable as A, CustomEventMap as C, DebuggerOptions as D, FetchResult as F, HMRPayload as H, ModuleCacheMap as M, Nullable as N, RawSourceMap as R, StartOfSourceMap as S, ViteNodeServerOptions as V, ViteNodeRunner as a, HotContext as b, DepsHandlingOptions as c, ViteNodeResolveId as d, DEFAULT_REQUEST_STUBS as e, Awaitable as f, FetchFunction as g, ResolveIdFunction as h, CreateHotContextFunction as i, ModuleCache as j, ViteNodeRunnerOptions as k };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as Arrayable, a as Awaitable, C as CreateHotContextFunction, g as DebuggerOptions, D as DepsHandlingOptions, b as FetchFunction, F as FetchResult, H as HotContext, d as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, c as ResolveIdFunction, S as StartOfSourceMap, e as ViteNodeResolveId, V as ViteNodeRunnerOptions, f as ViteNodeServerOptions } from './types-0f31b933.js';
2
- export { D as DecodedSourceMap, E as EncodedSourceMap } from './types.d-7442d07f.js';
1
+ export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-6fb787b2.js';
2
+ export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-e677e8f4.js';
package/dist/server.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var perf_hooks = require('perf_hooks');
6
4
  var fs = require('fs');
7
5
  var pathe = require('pathe');
@@ -15,11 +13,6 @@ require('node:url');
15
13
  require('module');
16
14
  require('path');
17
15
 
18
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
-
20
- var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
21
- var c__default = /*#__PURE__*/_interopDefaultLegacy(c);
22
-
23
16
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
24
17
  const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
25
18
  const defaultInline = [
@@ -126,9 +119,9 @@ class Debugger {
126
119
  this.dumpDir = pathe.resolve(root, options.dumpModules === true ? ".vite-node/dump" : options.dumpModules);
127
120
  if (this.dumpDir) {
128
121
  if (options.loadDumppedModules)
129
- console.info(c__default["default"].gray(`[vite-node] [debug] load modules from ${this.dumpDir}`));
122
+ console.info(c.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`));
130
123
  else
131
- console.info(c__default["default"].gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`));
124
+ console.info(c.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`));
132
125
  }
133
126
  this.initPromise = this.clearDump();
134
127
  }
@@ -184,7 +177,7 @@ ${result.code}`, "utf-8");
184
177
  }
185
178
  }
186
179
 
187
- const debugRequest = createDebug__default["default"]("vite-node:server:request");
180
+ const debugRequest = createDebug("vite-node:server:request");
188
181
  class ViteNodeServer {
189
182
  constructor(server, options = {}) {
190
183
  this.server = server;
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TransformResult, ViteDevServer } from 'vite';
2
- import { E as EncodedSourceMap } from './types.d-7442d07f.js';
3
- import { g as DebuggerOptions, D as DepsHandlingOptions, f as ViteNodeServerOptions, F as FetchResult, e as ViteNodeResolveId } from './types-0f31b933.js';
2
+ import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './index-6fb787b2.js';
3
+ import { E as EncodedSourceMap } from './trace-mapping.d-e677e8f4.js';
4
4
 
5
5
  declare class Debugger {
6
6
  options: DebuggerOptions;
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var pathe = require('pathe');
6
4
  var utils = require('./utils.cjs');
7
5
  var path = require('path');
@@ -9,11 +7,6 @@ var fs = require('fs');
9
7
  require('node:url');
10
8
  require('module');
11
9
 
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
-
14
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
15
- var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
16
-
17
10
  const comma = ','.charCodeAt(0);
18
11
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
19
12
  const intToChar = new Uint8Array(64); // 64 possible chars.
@@ -600,8 +593,8 @@ retrieveFileHandlers.push((path2) => {
600
593
  return fileContentsCache[path2];
601
594
  let contents = "";
602
595
  try {
603
- if (fs__default["default"].existsSync(path2))
604
- contents = fs__default["default"].readFileSync(path2, "utf8");
596
+ if (fs.existsSync(path2))
597
+ contents = fs.readFileSync(path2, "utf8");
605
598
  } catch (er) {
606
599
  }
607
600
  return fileContentsCache[path2] = contents;
@@ -609,15 +602,15 @@ retrieveFileHandlers.push((path2) => {
609
602
  function supportRelativeURL(file, url) {
610
603
  if (!file)
611
604
  return url;
612
- const dir = path__default["default"].dirname(file);
605
+ const dir = path.dirname(file);
613
606
  const match = /^\w+:\/\/[^\/]*/.exec(dir);
614
607
  let protocol = match ? match[0] : "";
615
608
  const startPath = dir.slice(protocol.length);
616
609
  if (protocol && /^\/\w\:/.test(startPath)) {
617
610
  protocol += "/";
618
- return protocol + path__default["default"].resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
611
+ return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
619
612
  }
620
- return protocol + path__default["default"].resolve(dir.slice(protocol.length), url);
613
+ return protocol + path.resolve(dir.slice(protocol.length), url);
621
614
  }
622
615
  function retrieveSourceMapURL(source) {
623
616
  const fileData = retrieveFile(source);
@@ -1,5 +1,5 @@
1
1
  import { TransformResult } from 'vite';
2
- import { E as EncodedSourceMap } from './types.d-7442d07f.js';
2
+ import { E as EncodedSourceMap } from './trace-mapping.d-e677e8f4.js';
3
3
 
4
4
  interface InstallSourceMapSupportOptions {
5
5
  getSourceMap: (source: string) => EncodedSourceMap | null | undefined;
@@ -0,0 +1,54 @@
1
+ declare type GeneratedColumn = number;
2
+ declare type SourcesIndex = number;
3
+ declare type SourceLine = number;
4
+ declare type SourceColumn = number;
5
+ declare type NamesIndex = number;
6
+ declare type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
7
+
8
+ interface SourceMapV3 {
9
+ file?: string | null;
10
+ names: string[];
11
+ sourceRoot?: string;
12
+ sources: (string | null)[];
13
+ sourcesContent?: (string | null)[];
14
+ version: 3;
15
+ }
16
+ interface EncodedSourceMap extends SourceMapV3 {
17
+ mappings: string;
18
+ }
19
+ interface DecodedSourceMap extends SourceMapV3 {
20
+ mappings: SourceMapSegment[][];
21
+ }
22
+ declare type SourceMapInput = string | Ro<EncodedSourceMap> | Ro<DecodedSourceMap> | TraceMap;
23
+ declare abstract class SourceMap {
24
+ version: SourceMapV3['version'];
25
+ file: SourceMapV3['file'];
26
+ names: SourceMapV3['names'];
27
+ sourceRoot: SourceMapV3['sourceRoot'];
28
+ sources: SourceMapV3['sources'];
29
+ sourcesContent: SourceMapV3['sourcesContent'];
30
+ resolvedSources: SourceMapV3['sources'];
31
+ }
32
+ declare type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
33
+ declare type RoArray<T> = Ro<T>[];
34
+ declare type RoObject<T> = {
35
+ [K in keyof T]: T[K] | Ro<T[K]>;
36
+ };
37
+
38
+ declare class TraceMap implements SourceMap {
39
+ version: SourceMapV3['version'];
40
+ file: SourceMapV3['file'];
41
+ names: SourceMapV3['names'];
42
+ sourceRoot: SourceMapV3['sourceRoot'];
43
+ sources: SourceMapV3['sources'];
44
+ sourcesContent: SourceMapV3['sourcesContent'];
45
+ resolvedSources: string[];
46
+ private _encoded;
47
+ private _decoded;
48
+ private _decodedMemo;
49
+ private _bySources;
50
+ private _bySourceMemos;
51
+ constructor(map: SourceMapInput, mapUrl?: string | null);
52
+ }
53
+
54
+ export { DecodedSourceMap as D, EncodedSourceMap as E, SourceMapInput as S };
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as Arrayable, a as Awaitable, C as CreateHotContextFunction, g as DebuggerOptions, D as DepsHandlingOptions, b as FetchFunction, F as FetchResult, H as HotContext, d as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, c as ResolveIdFunction, S as StartOfSourceMap, e as ViteNodeResolveId, V as ViteNodeRunnerOptions, f as ViteNodeServerOptions } from './types-0f31b933.js';
2
- export { D as DecodedSourceMap, E as EncodedSourceMap } from './types.d-7442d07f.js';
1
+ export { A as Arrayable, f as Awaitable, i as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, g as FetchFunction, F as FetchResult, b as HotContext, j as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, h as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, k as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index-6fb787b2.js';
2
+ export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-e677e8f4.js';
package/dist/utils.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var node_url = require('node:url');
6
4
  var module$1 = require('module');
7
5
  var fs = require('fs');
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { N as Nullable, A as Arrayable } from './types-0f31b933.js';
2
- import './types.d-7442d07f.js';
1
+ import { N as Nullable, A as Arrayable } from './index-6fb787b2.js';
2
+ import './trace-mapping.d-e677e8f4.js';
3
3
 
4
4
  declare const isWindows: boolean;
5
5
  declare function slash(str: string): string;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.34.4",
3
+ "type": "module",
4
+ "version": "0.34.6",
4
5
  "description": "Vite as Node.js runtime",
5
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
7
  "license": "MIT",
@@ -81,12 +82,11 @@
81
82
  "mlly": "^1.4.0",
82
83
  "pathe": "^1.1.1",
83
84
  "picocolors": "^1.0.0",
84
- "vite": "^3.0.0 || ^4.0.0"
85
+ "vite": "^3.0.0 || ^4.0.0 || ^5.0.0-0"
85
86
  },
86
87
  "devDependencies": {
87
88
  "@jridgewell/trace-mapping": "^0.3.18",
88
- "@types/debug": "^4.1.8",
89
- "rollup": "^2.79.1"
89
+ "@types/debug": "^4.1.8"
90
90
  },
91
91
  "scripts": {
92
92
  "build": "rimraf dist && rollup -c",
@@ -1,250 +0,0 @@
1
- 'use strict';
2
-
3
- var node_events = require('node:events');
4
- var c = require('picocolors');
5
- var createDebug = require('debug');
6
- var utils = require('./utils.cjs');
7
-
8
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
-
10
- var c__default = /*#__PURE__*/_interopDefaultLegacy(c);
11
- var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
12
-
13
- function createHmrEmitter() {
14
- const emitter = new node_events.EventEmitter();
15
- return emitter;
16
- }
17
- function viteNodeHmrPlugin() {
18
- const emitter = createHmrEmitter();
19
- return {
20
- name: "vite-node:hmr",
21
- config() {
22
- if (process.platform === "darwin" && process.env.VITE_TEST_WATCHER_DEBUG) {
23
- return {
24
- server: {
25
- watch: {
26
- useFsEvents: false,
27
- usePolling: false
28
- }
29
- }
30
- };
31
- }
32
- },
33
- configureServer(server) {
34
- const _send = server.ws.send;
35
- server.emitter = emitter;
36
- server.ws.send = function(payload) {
37
- _send(payload);
38
- emitter.emit("message", payload);
39
- };
40
- if (process.env.VITE_TEST_WATCHER_DEBUG) {
41
- server.watcher.on("ready", () => {
42
- console.log("[debug] watcher is ready");
43
- });
44
- }
45
- }
46
- };
47
- }
48
-
49
- const debugHmr = createDebug__default["default"]("vite-node:hmr");
50
- const cache = /* @__PURE__ */ new WeakMap();
51
- function getCache(runner) {
52
- if (!cache.has(runner)) {
53
- cache.set(runner, {
54
- hotModulesMap: /* @__PURE__ */ new Map(),
55
- dataMap: /* @__PURE__ */ new Map(),
56
- disposeMap: /* @__PURE__ */ new Map(),
57
- pruneMap: /* @__PURE__ */ new Map(),
58
- customListenersMap: /* @__PURE__ */ new Map(),
59
- ctxToListenersMap: /* @__PURE__ */ new Map(),
60
- messageBuffer: [],
61
- isFirstUpdate: false,
62
- pending: false,
63
- queued: []
64
- });
65
- }
66
- return cache.get(runner);
67
- }
68
- function sendMessageBuffer(runner, emitter) {
69
- const maps = getCache(runner);
70
- maps.messageBuffer.forEach((msg) => emitter.emit("custom", msg));
71
- maps.messageBuffer.length = 0;
72
- }
73
- async function reload(runner, files) {
74
- Array.from(runner.moduleCache.keys()).forEach((fsPath) => {
75
- if (!fsPath.includes("node_modules"))
76
- runner.moduleCache.delete(fsPath);
77
- });
78
- return Promise.all(files.map((file) => runner.executeId(file)));
79
- }
80
- async function notifyListeners(runner, event, data) {
81
- const maps = getCache(runner);
82
- const cbs = maps.customListenersMap.get(event);
83
- if (cbs)
84
- await Promise.all(cbs.map((cb) => cb(data)));
85
- }
86
- async function queueUpdate(runner, p) {
87
- const maps = getCache(runner);
88
- maps.queued.push(p);
89
- if (!maps.pending) {
90
- maps.pending = true;
91
- await Promise.resolve();
92
- maps.pending = false;
93
- const loading = [...maps.queued];
94
- maps.queued = [];
95
- (await Promise.all(loading)).forEach((fn) => fn && fn());
96
- }
97
- }
98
- async function fetchUpdate(runner, { path, acceptedPath }) {
99
- path = utils.normalizeRequestId(path);
100
- acceptedPath = utils.normalizeRequestId(acceptedPath);
101
- const maps = getCache(runner);
102
- const mod = maps.hotModulesMap.get(path);
103
- if (!mod) {
104
- return;
105
- }
106
- const isSelfUpdate = path === acceptedPath;
107
- let fetchedModule;
108
- const qualifiedCallbacks = mod.callbacks.filter(
109
- ({ deps }) => deps.includes(acceptedPath)
110
- );
111
- if (isSelfUpdate || qualifiedCallbacks.length > 0) {
112
- const disposer = maps.disposeMap.get(acceptedPath);
113
- if (disposer)
114
- await disposer(maps.dataMap.get(acceptedPath));
115
- try {
116
- [fetchedModule] = await reload(runner, [acceptedPath]);
117
- } catch (e) {
118
- warnFailedFetch(e, acceptedPath);
119
- }
120
- }
121
- return () => {
122
- for (const { deps, fn } of qualifiedCallbacks)
123
- fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
124
- const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
125
- console.log(`${c__default["default"].cyan("[vite-node]")} hot updated: ${loggedPath}`);
126
- };
127
- }
128
- function warnFailedFetch(err, path) {
129
- if (!err.message.match("fetch"))
130
- console.error(err);
131
- console.error(
132
- `[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`
133
- );
134
- }
135
- async function handleMessage(runner, emitter, files, payload) {
136
- const maps = getCache(runner);
137
- switch (payload.type) {
138
- case "connected":
139
- sendMessageBuffer(runner, emitter);
140
- break;
141
- case "update":
142
- await notifyListeners(runner, "vite:beforeUpdate", payload);
143
- await Promise.all(payload.updates.map((update) => {
144
- if (update.type === "js-update")
145
- return queueUpdate(runner, fetchUpdate(runner, update));
146
- console.error(`${c__default["default"].cyan("[vite-node]")} no support css hmr.}`);
147
- return null;
148
- }));
149
- await notifyListeners(runner, "vite:afterUpdate", payload);
150
- break;
151
- case "full-reload":
152
- await notifyListeners(runner, "vite:beforeFullReload", payload);
153
- maps.customListenersMap.delete("vite:beforeFullReload");
154
- await reload(runner, files);
155
- break;
156
- case "custom":
157
- await notifyListeners(runner, payload.event, payload.data);
158
- break;
159
- case "prune":
160
- await notifyListeners(runner, "vite:beforePrune", payload);
161
- payload.paths.forEach((path) => {
162
- const fn = maps.pruneMap.get(path);
163
- if (fn)
164
- fn(maps.dataMap.get(path));
165
- });
166
- break;
167
- case "error": {
168
- await notifyListeners(runner, "vite:error", payload);
169
- const err = payload.err;
170
- console.error(`${c__default["default"].cyan("[vite-node]")} Internal Server Error
171
- ${err.message}
172
- ${err.stack}`);
173
- break;
174
- }
175
- }
176
- }
177
- function createHotContext(runner, emitter, files, ownerPath) {
178
- debugHmr("createHotContext", ownerPath);
179
- const maps = getCache(runner);
180
- if (!maps.dataMap.has(ownerPath))
181
- maps.dataMap.set(ownerPath, {});
182
- const mod = maps.hotModulesMap.get(ownerPath);
183
- if (mod)
184
- mod.callbacks = [];
185
- const newListeners = /* @__PURE__ */ new Map();
186
- maps.ctxToListenersMap.set(ownerPath, newListeners);
187
- function acceptDeps(deps, callback = () => {
188
- }) {
189
- const mod2 = maps.hotModulesMap.get(ownerPath) || {
190
- id: ownerPath,
191
- callbacks: []
192
- };
193
- mod2.callbacks.push({
194
- deps,
195
- fn: callback
196
- });
197
- maps.hotModulesMap.set(ownerPath, mod2);
198
- }
199
- const hot = {
200
- get data() {
201
- return maps.dataMap.get(ownerPath);
202
- },
203
- acceptExports(_, callback) {
204
- acceptDeps([ownerPath], callback && (([mod2]) => callback(mod2)));
205
- },
206
- accept(deps, callback) {
207
- if (typeof deps === "function" || !deps) {
208
- acceptDeps([ownerPath], ([mod2]) => deps && deps(mod2));
209
- } else if (typeof deps === "string") {
210
- acceptDeps([deps], ([mod2]) => callback && callback(mod2));
211
- } else if (Array.isArray(deps)) {
212
- acceptDeps(deps, callback);
213
- } else {
214
- throw new TypeError("invalid hot.accept() usage.");
215
- }
216
- },
217
- dispose(cb) {
218
- maps.disposeMap.set(ownerPath, cb);
219
- },
220
- prune(cb) {
221
- maps.pruneMap.set(ownerPath, cb);
222
- },
223
- invalidate() {
224
- notifyListeners(runner, "vite:invalidate", { path: ownerPath, message: void 0 });
225
- return reload(runner, files);
226
- },
227
- on(event, cb) {
228
- const addToMap = (map) => {
229
- const existing = map.get(event) || [];
230
- existing.push(cb);
231
- map.set(event, existing);
232
- };
233
- addToMap(maps.customListenersMap);
234
- addToMap(newListeners);
235
- },
236
- send(event, data) {
237
- maps.messageBuffer.push(JSON.stringify({ type: "custom", event, data }));
238
- sendMessageBuffer(runner, emitter);
239
- }
240
- };
241
- return hot;
242
- }
243
-
244
- exports.createHmrEmitter = createHmrEmitter;
245
- exports.createHotContext = createHotContext;
246
- exports.getCache = getCache;
247
- exports.handleMessage = handleMessage;
248
- exports.reload = reload;
249
- exports.sendMessageBuffer = sendMessageBuffer;
250
- exports.viteNodeHmrPlugin = viteNodeHmrPlugin;