vite-node 0.12.4 → 0.12.7

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/cli.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ interface CliOptions {
2
+ files?: string[];
3
+ _?: string[];
4
+ root?: string;
5
+ config?: string;
6
+ }
7
+
8
+ export { CliOptions };
package/client.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { ViteNodeRunnerOptions, ModuleCache } from './types.js';
2
+
3
+ declare const DEFAULT_REQUEST_STUBS: {
4
+ '/@vite/client': {
5
+ injectQuery: (id: string) => string;
6
+ createHotContext(): {
7
+ accept: () => void;
8
+ prune: () => void;
9
+ };
10
+ updateStyle(): void;
11
+ };
12
+ };
13
+ declare class ViteNodeRunner {
14
+ options: ViteNodeRunnerOptions;
15
+ root: string;
16
+ moduleCache: Map<string, ModuleCache>;
17
+ constructor(options: ViteNodeRunnerOptions);
18
+ executeFile(file: string): Promise<any>;
19
+ executeId(id: string): Promise<any>;
20
+ cachedRequest(rawId: string, callstack: string[]): Promise<any>;
21
+ directRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
22
+ prepareContext(context: Record<string, any>): Record<string, any>;
23
+ setCache(id: string, mod: Partial<ModuleCache>): void;
24
+ shouldResolveId(dep: string): boolean;
25
+ /**
26
+ * Define if a module should be interop-ed
27
+ * This function mostly for the ability to override by subclass
28
+ */
29
+ shouldInterop(path: string, mod: any): boolean;
30
+ /**
31
+ * Import a module and interop it
32
+ */
33
+ interopedImport(path: string): Promise<any>;
34
+ hasNestedDefault(target: any): any;
35
+ }
36
+
37
+ export { DEFAULT_REQUEST_STUBS, ViteNodeRunner };
package/dist/cli.cjs CHANGED
@@ -3,9 +3,10 @@
3
3
  var events = require('events');
4
4
  var kolorist = require('kolorist');
5
5
  var vite = require('vite');
6
- var server = require('./server-4791181c.js');
7
- var client = require('./client-1992c4bf.js');
6
+ var server = require('./server-c98deede.js');
7
+ var client = require('./client-d42a1094.js');
8
8
  require('pathe');
9
+ require('debug');
9
10
  require('fs');
10
11
  require('mlly');
11
12
  require('./utils-5d86aff6.js');
@@ -626,7 +627,7 @@ class CAC extends events.EventEmitter {
626
627
 
627
628
  const cac = (name = "") => new CAC(name);
628
629
 
629
- var version = "0.12.4";
630
+ var version = "0.12.7";
630
631
 
631
632
  const cli = cac("vite-node");
632
633
  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"').help();
@@ -661,8 +662,8 @@ async function run(files, options = {}) {
661
662
  await runner.executeFile(file);
662
663
  if (!options.watch)
663
664
  await server$1.close();
664
- server$1.watcher.on("change", async (eventName, path) => {
665
- console.log(kolorist.dim(`[${eventName}] ${path}`));
665
+ server$1.watcher.on("change", async (path) => {
666
+ console.log(`${kolorist.cyan("[vite-node]")} File change detected. ${kolorist.dim(path)}`);
666
667
  Array.from(runner.moduleCache.keys()).forEach((i) => {
667
668
  if (!i.includes("node_modules"))
668
669
  runner.moduleCache.delete(i);
package/dist/cli.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { EventEmitter } from 'events';
2
- import { red, dim } from 'kolorist';
2
+ import { red, cyan, dim } from 'kolorist';
3
3
  import { createServer } from 'vite';
4
- import { V as ViteNodeServer } from './server-d9fc65e0.js';
5
- import { V as ViteNodeRunner } from './client-162aebb2.js';
4
+ import { V as ViteNodeServer } from './server-e4d25388.js';
5
+ import { V as ViteNodeRunner } from './client-aa28334b.js';
6
6
  import 'pathe';
7
+ import 'debug';
7
8
  import 'fs';
8
9
  import 'mlly';
9
10
  import './utils-0290448b.js';
@@ -624,7 +625,7 @@ class CAC extends EventEmitter {
624
625
 
625
626
  const cac = (name = "") => new CAC(name);
626
627
 
627
- var version = "0.12.4";
628
+ var version = "0.12.7";
628
629
 
629
630
  const cli = cac("vite-node");
630
631
  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"').help();
@@ -659,8 +660,8 @@ async function run(files, options = {}) {
659
660
  await runner.executeFile(file);
660
661
  if (!options.watch)
661
662
  await server.close();
662
- server.watcher.on("change", async (eventName, path) => {
663
- console.log(dim(`[${eventName}] ${path}`));
663
+ server.watcher.on("change", async (path) => {
664
+ console.log(`${cyan("[vite-node]")} File change detected. ${dim(path)}`);
664
665
  Array.from(runner.moduleCache.keys()).forEach((i) => {
665
666
  if (!i.includes("node_modules"))
666
667
  runner.moduleCache.delete(i);
@@ -3,8 +3,11 @@ import { pathToFileURL, fileURLToPath } from 'url';
3
3
  import vm from 'vm';
4
4
  import { resolve, dirname, isAbsolute, extname } from 'pathe';
5
5
  import { isNodeBuiltin } from 'mlly';
6
+ import createDebug from 'debug';
6
7
  import { n as normalizeModuleId, s as slash, a as normalizeRequestId, t as toFilePath, i as isPrimitive } from './utils-0290448b.js';
7
8
 
9
+ const debugExecute = createDebug("vite-node:client:execute");
10
+ const debugNative = createDebug("vite-node:client:native");
8
11
  const DEFAULT_REQUEST_STUBS = {
9
12
  "/@vite/client": {
10
13
  injectQuery: (id) => id,
@@ -116,6 +119,7 @@ ${getStack()}`), 2e3);
116
119
  return requestStubs[id];
117
120
  let { code: transformed, externalize } = await this.options.fetchModule(id);
118
121
  if (externalize) {
122
+ debugNative(externalize);
119
123
  const mod = await this.interopedImport(externalize);
120
124
  this.moduleCache.set(fsPath, { exports: mod });
121
125
  return mod;
@@ -149,6 +153,7 @@ ${getStack()}`), 2e3);
149
153
  __filename,
150
154
  __dirname: dirname(__filename)
151
155
  });
156
+ debugExecute(__filename);
152
157
  if (transformed[0] === "#")
153
158
  transformed = transformed.replace(/^\#\!.*/, (s) => " ".repeat(s.length));
154
159
  const fn = vm.runInThisContext(`'use strict';async (${Object.keys(context).join(",")})=>{{${transformed}
@@ -5,6 +5,7 @@ var url = require('url');
5
5
  var vm = require('vm');
6
6
  var pathe = require('pathe');
7
7
  var mlly = require('mlly');
8
+ var createDebug = require('debug');
8
9
  var utils = require('./utils-5d86aff6.js');
9
10
 
10
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -28,7 +29,10 @@ function _interopNamespace(e) {
28
29
  }
29
30
 
30
31
  var vm__default = /*#__PURE__*/_interopDefaultLegacy(vm);
32
+ var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
31
33
 
34
+ const debugExecute = createDebug__default["default"]("vite-node:client:execute");
35
+ const debugNative = createDebug__default["default"]("vite-node:client:native");
32
36
  const DEFAULT_REQUEST_STUBS = {
33
37
  "/@vite/client": {
34
38
  injectQuery: (id) => id,
@@ -140,6 +144,7 @@ ${getStack()}`), 2e3);
140
144
  return requestStubs[id];
141
145
  let { code: transformed, externalize } = await this.options.fetchModule(id);
142
146
  if (externalize) {
147
+ debugNative(externalize);
143
148
  const mod = await this.interopedImport(externalize);
144
149
  this.moduleCache.set(fsPath, { exports: mod });
145
150
  return mod;
@@ -173,6 +178,7 @@ ${getStack()}`), 2e3);
173
178
  __filename,
174
179
  __dirname: pathe.dirname(__filename)
175
180
  });
181
+ debugExecute(__filename);
176
182
  if (transformed[0] === "#")
177
183
  transformed = transformed.replace(/^\#\!.*/, (s) => " ".repeat(s.length));
178
184
  const fn = vm__default["default"].runInThisContext(`'use strict';async (${Object.keys(context).join(",")})=>{{${transformed}
package/dist/client.cjs CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var client = require('./client-1992c4bf.js');
5
+ var client = require('./client-d42a1094.js');
6
6
  require('module');
7
7
  require('url');
8
8
  require('vm');
9
9
  require('pathe');
10
10
  require('mlly');
11
+ require('debug');
11
12
  require('./utils-5d86aff6.js');
12
13
 
13
14
 
package/dist/client.js CHANGED
@@ -1,7 +1,8 @@
1
- export { D as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, V as ViteNodeRunner } from './client-162aebb2.js';
1
+ export { D as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, V as ViteNodeRunner } from './client-aa28334b.js';
2
2
  import 'module';
3
3
  import 'url';
4
4
  import 'vm';
5
5
  import 'pathe';
6
6
  import 'mlly';
7
+ import 'debug';
7
8
  import './utils-0290448b.js';
@@ -1,10 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  var pathe = require('pathe');
4
+ var createDebug = require('debug');
4
5
  var fs = require('fs');
5
6
  var mlly = require('mlly');
6
7
  var utils = require('./utils-5d86aff6.js');
7
8
 
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
12
+
8
13
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
9
14
  const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
10
15
  const defaultInline = [
@@ -107,6 +112,7 @@ var __spreadValues = (a, b) => {
107
112
  return a;
108
113
  };
109
114
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
115
+ const debugRequest = createDebug__default["default"]("vite-node:server:request");
110
116
  const RealDate = Date;
111
117
  class ViteNodeServer {
112
118
  constructor(server, options = {}) {
@@ -175,6 +181,7 @@ class ViteNodeServer {
175
181
  return result;
176
182
  }
177
183
  async _transformRequest(id) {
184
+ debugRequest(id);
178
185
  let result = null;
179
186
  if (this.getTransformMode(id) === "web") {
180
187
  result = await this.server.transformRequest(id);
@@ -1,4 +1,5 @@
1
1
  import { join } from 'pathe';
2
+ import createDebug from 'debug';
2
3
  import { existsSync } from 'fs';
3
4
  import { isNodeBuiltin, isValidNodeImport } from 'mlly';
4
5
  import { s as slash, t as toFilePath, w as withInlineSourcemap } from './utils-0290448b.js';
@@ -105,6 +106,7 @@ var __spreadValues = (a, b) => {
105
106
  return a;
106
107
  };
107
108
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
109
+ const debugRequest = createDebug("vite-node:server:request");
108
110
  const RealDate = Date;
109
111
  class ViteNodeServer {
110
112
  constructor(server, options = {}) {
@@ -173,6 +175,7 @@ class ViteNodeServer {
173
175
  return result;
174
176
  }
175
177
  async _transformRequest(id) {
178
+ debugRequest(id);
176
179
  let result = null;
177
180
  if (this.getTransformMode(id) === "web") {
178
181
  result = await this.server.transformRequest(id);
package/dist/server.cjs CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var server = require('./server-4791181c.js');
5
+ var server = require('./server-c98deede.js');
6
6
  require('pathe');
7
+ require('debug');
7
8
  require('fs');
8
9
  require('mlly');
9
10
  require('./utils-5d86aff6.js');
package/dist/server.js CHANGED
@@ -1,5 +1,6 @@
1
- export { V as ViteNodeServer, g as guessCJSversion, s as shouldExternalize } from './server-d9fc65e0.js';
1
+ export { V as ViteNodeServer, g as guessCJSversion, s as shouldExternalize } from './server-e4d25388.js';
2
2
  import 'pathe';
3
+ import 'debug';
3
4
  import 'fs';
4
5
  import 'mlly';
5
6
  import './utils-0290448b.js';
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, RawSourceMap, ResolveIdFunction, StartOfSourceMap, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions } from './types.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "0.12.4",
4
+ "version": "0.12.7",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "homepage": "https://github.com/vitest-dev/vitest/blob/main/packages/vite-node#readme",
7
7
  "bugs": {
@@ -57,14 +57,16 @@
57
57
  }
58
58
  },
59
59
  "dependencies": {
60
+ "debug": "^4.3.4",
60
61
  "kolorist": "^1.5.1",
61
62
  "mlly": "^0.5.2",
62
63
  "pathe": "^0.2.0",
63
64
  "vite": "^2.9.8"
64
65
  },
65
66
  "devDependencies": {
67
+ "@types/debug": "^4.1.7",
66
68
  "cac": "^6.7.12",
67
- "rollup": "^2.72.1"
69
+ "rollup": "^2.73.0"
68
70
  },
69
71
  "engines": {
70
72
  "node": ">=v14.16.0"
package/server.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { ViteDevServer, TransformResult } from 'vite';
2
+ import { DepsHandlingOptions, ViteNodeServerOptions, FetchResult, ViteNodeResolveId } from './types.js';
3
+
4
+ declare function guessCJSversion(id: string): string | undefined;
5
+ declare function shouldExternalize(id: string, options?: DepsHandlingOptions, cache?: Map<string, Promise<string | false>>): Promise<string | false>;
6
+
7
+ declare class ViteNodeServer {
8
+ server: ViteDevServer;
9
+ options: ViteNodeServerOptions;
10
+ private fetchPromiseMap;
11
+ private transformPromiseMap;
12
+ fetchCache: Map<string, {
13
+ timestamp: number;
14
+ result: FetchResult;
15
+ }>;
16
+ constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
17
+ shouldExternalize(id: string): Promise<string | false>;
18
+ resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
19
+ fetchModule(id: string): Promise<FetchResult>;
20
+ transformRequest(id: string): Promise<TransformResult | null | undefined>;
21
+ getTransformMode(id: string): "web" | "ssr";
22
+ private _fetchModule;
23
+ private _transformRequest;
24
+ }
25
+
26
+ export { ViteNodeServer, guessCJSversion, shouldExternalize };
package/types.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ interface DepsHandlingOptions {
2
+ external?: (string | RegExp)[];
3
+ inline?: (string | RegExp)[];
4
+ /**
5
+ * Try to guess the CJS version of a package when it's invalid ESM
6
+ * @default true
7
+ */
8
+ fallbackCJS?: boolean;
9
+ }
10
+ interface StartOfSourceMap {
11
+ file?: string;
12
+ sourceRoot?: string;
13
+ }
14
+ interface RawSourceMap extends StartOfSourceMap {
15
+ version: string;
16
+ sources: string[];
17
+ names: string[];
18
+ sourcesContent?: string[];
19
+ mappings: string;
20
+ }
21
+ interface FetchResult {
22
+ code?: string;
23
+ externalize?: string;
24
+ map?: RawSourceMap;
25
+ }
26
+ declare type FetchFunction = (id: string) => Promise<FetchResult>;
27
+ declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
28
+ interface ModuleCache {
29
+ promise?: Promise<any>;
30
+ exports?: any;
31
+ code?: string;
32
+ }
33
+ interface ViteNodeRunnerOptions {
34
+ fetchModule: FetchFunction;
35
+ resolveId: ResolveIdFunction;
36
+ root: string;
37
+ base?: string;
38
+ moduleCache?: Map<string, ModuleCache>;
39
+ interopDefault?: boolean;
40
+ requestStubs?: Record<string, any>;
41
+ }
42
+ interface ViteNodeResolveId {
43
+ external?: boolean | 'absolute' | 'relative';
44
+ id: string;
45
+ meta?: Record<string, any> | null;
46
+ moduleSideEffects?: boolean | 'no-treeshake' | null;
47
+ syntheticNamedExports?: boolean | string | null;
48
+ }
49
+ interface ViteNodeServerOptions {
50
+ /**
51
+ * Inject inline sourcemap to modules
52
+ * @default 'inline'
53
+ */
54
+ sourcemap?: 'inline' | boolean;
55
+ /**
56
+ * Deps handling
57
+ */
58
+ deps?: DepsHandlingOptions;
59
+ /**
60
+ * Transform method for modules
61
+ */
62
+ transformMode?: {
63
+ ssr?: RegExp[];
64
+ web?: RegExp[];
65
+ };
66
+ }
67
+
68
+ export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, RawSourceMap, ResolveIdFunction, StartOfSourceMap, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions };
package/utils.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { TransformResult } from 'vite';
2
+
3
+ declare const isWindows: boolean;
4
+ declare function slash(str: string): string;
5
+ declare function normalizeId(id: string, base?: string): string;
6
+ declare function isPrimitive(v: any): boolean;
7
+ declare function toFilePath(id: string, root: string): string;
8
+ declare function withInlineSourcemap(result: TransformResult): Promise<TransformResult>;
9
+
10
+ export { isPrimitive, isWindows, normalizeId, slash, toFilePath, withInlineSourcemap };