vite-node 0.1.18 → 0.1.22

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/client.js CHANGED
@@ -1,16 +1,47 @@
1
- import { builtinModules, createRequire } from 'module';
2
- import { pathToFileURL, fileURLToPath } from 'url';
1
+ import { createRequire } from 'module';
2
+ import { fileURLToPath, pathToFileURL } from 'url';
3
3
  import vm from 'vm';
4
- import { resolve, dirname } from 'pathe';
5
- import { slash, normalizeId, toFilePath, isPrimitive } from './utils.js';
4
+ import { dirname, resolve } from 'pathe';
6
5
 
6
+ const isWindows = process.platform === "win32";
7
+ function slash(str) {
8
+ return str.replace(/\\/g, "/");
9
+ }
10
+ function normalizeId(id, base) {
11
+ if (base && id.startsWith(base))
12
+ id = `/${id.slice(base.length)}`;
13
+ return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^node:/, "").replace(/[?&]v=\w+/, "?").replace(/\?$/, "");
14
+ }
15
+ function isPrimitive(v) {
16
+ return v !== Object(v);
17
+ }
18
+ function toFilePath(id, root) {
19
+ let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname(root)) && dirname(root) !== "/" ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
20
+ if (absolute.startsWith("//"))
21
+ absolute = absolute.slice(1);
22
+ return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
23
+ }
24
+
25
+ const DEFAULT_REQUEST_STUBS = {
26
+ "/@vite/client": {
27
+ injectQuery: (id) => id,
28
+ createHotContext() {
29
+ return {
30
+ accept: () => {
31
+ },
32
+ prune: () => {
33
+ }
34
+ };
35
+ },
36
+ updateStyle() {
37
+ }
38
+ }
39
+ };
7
40
  class ViteNodeRunner {
8
41
  constructor(options) {
9
42
  this.options = options;
10
43
  this.root = options.root || process.cwd();
11
44
  this.moduleCache = options.moduleCache || new Map();
12
- this.externalCache = new Map();
13
- builtinModules.forEach((m) => this.externalCache.set(m, m));
14
45
  }
15
46
  async executeFile(file) {
16
47
  return await this.cachedRequest(`/@fs/${slash(resolve(file))}`, []);
@@ -21,11 +52,11 @@ class ViteNodeRunner {
21
52
  async cachedRequest(rawId, callstack) {
22
53
  var _a, _b;
23
54
  const id = normalizeId(rawId, this.options.base);
55
+ if ((_a = this.moduleCache.get(id)) == null ? void 0 : _a.promise)
56
+ return (_b = this.moduleCache.get(id)) == null ? void 0 : _b.promise;
24
57
  const fsPath = toFilePath(id, this.root);
25
- if ((_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.promise)
26
- return (_b = this.moduleCache.get(fsPath)) == null ? void 0 : _b.promise;
27
58
  const promise = this.directRequest(id, fsPath, callstack);
28
- this.setCache(fsPath, { promise });
59
+ this.setCache(id, { promise });
29
60
  return await promise;
30
61
  }
31
62
  async directRequest(id, fsPath, callstack) {
@@ -33,28 +64,28 @@ class ViteNodeRunner {
33
64
  const request = async (dep) => {
34
65
  var _a;
35
66
  if (callstack.includes(dep)) {
36
- const cacheKey = toFilePath(dep, this.root);
37
- if (!((_a = this.moduleCache.get(cacheKey)) == null ? void 0 : _a.exports))
38
- throw new Error(`Circular dependency detected
67
+ if (!((_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports))
68
+ throw new Error(`[vite-node] Circular dependency detected
39
69
  Stack:
40
70
  ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
41
- return this.moduleCache.get(cacheKey).exports;
71
+ return this.moduleCache.get(dep).exports;
42
72
  }
43
73
  return this.cachedRequest(dep, callstack);
44
74
  };
45
- if (this.options.requestStubs && id in this.options.requestStubs)
46
- return this.options.requestStubs[id];
75
+ const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
76
+ if (id in requestStubs)
77
+ return requestStubs[id];
47
78
  const { code: transformed, externalize } = await this.options.fetchModule(id);
48
79
  if (externalize) {
49
- const mod = await interpretedImport(externalize, this.options.interpretDefault ?? true);
50
- this.setCache(fsPath, { exports: mod });
80
+ const mod = await this.interopedImport(externalize);
81
+ this.setCache(id, { exports: mod });
51
82
  return mod;
52
83
  }
53
84
  if (transformed == null)
54
- throw new Error(`failed to load ${id}`);
85
+ throw new Error(`[vite-node] Failed to load ${id}`);
55
86
  const url = pathToFileURL(fsPath).href;
56
87
  const exports = {};
57
- this.setCache(fsPath, { code: transformed, exports });
88
+ this.setCache(id, { code: transformed, exports });
58
89
  const __filename = fileURLToPath(url);
59
90
  const moduleProxy = {
60
91
  set exports(value) {
@@ -94,9 +125,27 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
94
125
  else
95
126
  Object.assign(this.moduleCache.get(id), mod);
96
127
  }
97
- }
98
- function hasNestedDefault(target) {
99
- return "__esModule" in target && target.__esModule && "default" in target.default;
128
+ shouldInterop(path, mod) {
129
+ if (this.options.interopDefault === false)
130
+ return false;
131
+ return !path.endsWith(".mjs") && "default" in mod;
132
+ }
133
+ async interopedImport(path) {
134
+ const mod = await import(path);
135
+ if (this.shouldInterop(path, mod)) {
136
+ const tryDefault = this.hasNestedDefault(mod);
137
+ return new Proxy(mod, {
138
+ get: proxyMethod("get", tryDefault),
139
+ set: proxyMethod("set", tryDefault),
140
+ has: proxyMethod("has", tryDefault),
141
+ deleteProperty: proxyMethod("deleteProperty", tryDefault)
142
+ });
143
+ }
144
+ return mod;
145
+ }
146
+ hasNestedDefault(target) {
147
+ return "__esModule" in target && target.__esModule && "default" in target.default;
148
+ }
100
149
  }
101
150
  function proxyMethod(name, tryDefault) {
102
151
  return function(target, key, ...args) {
@@ -108,19 +157,6 @@ function proxyMethod(name, tryDefault) {
108
157
  return result;
109
158
  };
110
159
  }
111
- async function interpretedImport(path, interpretDefault) {
112
- const mod = await import(path);
113
- if (interpretDefault && "default" in mod) {
114
- const tryDefault = hasNestedDefault(mod);
115
- return new Proxy(mod, {
116
- get: proxyMethod("get", tryDefault),
117
- set: proxyMethod("set", tryDefault),
118
- has: proxyMethod("has", tryDefault),
119
- deleteProperty: proxyMethod("deleteProperty", tryDefault)
120
- });
121
- }
122
- return mod;
123
- }
124
160
  function exportAll(exports, sourceModule) {
125
161
  for (const key in sourceModule) {
126
162
  if (key !== "default") {
@@ -138,4 +174,4 @@ function exportAll(exports, sourceModule) {
138
174
  }
139
175
  }
140
176
 
141
- export { ViteNodeRunner };
177
+ export { DEFAULT_REQUEST_STUBS, ViteNodeRunner };
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,174 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var fs = require('fs');
6
+ var mlly = require('mlly');
7
+ var url = require('url');
8
+ var pathe = require('pathe');
9
+
10
+ const isWindows = process.platform === "win32";
11
+ function slash(str) {
12
+ return str.replace(/\\/g, "/");
13
+ }
14
+ function toFilePath(id, root) {
15
+ let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(pathe.dirname(root)) && pathe.dirname(root) !== "/" ? id : id.startsWith("/") ? slash(pathe.resolve(root, id.slice(1))) : id;
16
+ if (absolute.startsWith("//"))
17
+ absolute = absolute.slice(1);
18
+ return isWindows && absolute.startsWith("/") ? url.fileURLToPath(url.pathToFileURL(absolute.slice(1)).href) : absolute;
19
+ }
20
+
21
+ const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
22
+ const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
23
+ const defaultInline = [
24
+ /\/vitest\/dist\//,
25
+ /vitest-virtual-\w+\/dist/,
26
+ /virtual:/,
27
+ /\.ts$/,
28
+ ESM_EXT_RE,
29
+ ESM_FOLDER_RE
30
+ ];
31
+ const depsExternal = [
32
+ /\.cjs.js$/,
33
+ /\.mjs$/
34
+ ];
35
+ function guessCJSversion(id) {
36
+ if (id.match(ESM_EXT_RE)) {
37
+ for (const i of [
38
+ id.replace(ESM_EXT_RE, ".mjs"),
39
+ id.replace(ESM_EXT_RE, ".umd.js"),
40
+ id.replace(ESM_EXT_RE, ".cjs.js"),
41
+ id.replace(ESM_EXT_RE, ".js")
42
+ ]) {
43
+ if (fs.existsSync(i))
44
+ return i;
45
+ }
46
+ }
47
+ if (id.match(ESM_FOLDER_RE)) {
48
+ for (const i of [
49
+ id.replace(ESM_FOLDER_RE, "/umd/$1"),
50
+ id.replace(ESM_FOLDER_RE, "/cjs/$1"),
51
+ id.replace(ESM_FOLDER_RE, "/$1")
52
+ ]) {
53
+ if (fs.existsSync(i))
54
+ return i;
55
+ }
56
+ }
57
+ }
58
+ async function shouldExternalize(id, options, cache = new Map()) {
59
+ if (!cache.has(id))
60
+ cache.set(id, _shouldExternalize(id, options));
61
+ return cache.get(id);
62
+ }
63
+ async function _shouldExternalize(id, options) {
64
+ if (mlly.isNodeBuiltin(id))
65
+ return id;
66
+ id = patchWindowsImportPath(id);
67
+ if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
68
+ return false;
69
+ if (matchExternalizePattern(id, options == null ? void 0 : options.external))
70
+ return id;
71
+ const isNodeModule = id.includes("/node_modules/");
72
+ id = isNodeModule ? guessCJSversion(id) || id : id;
73
+ if (matchExternalizePattern(id, defaultInline))
74
+ return false;
75
+ if (matchExternalizePattern(id, depsExternal))
76
+ return id;
77
+ if (isNodeModule && await mlly.isValidNodeImport(id))
78
+ return id;
79
+ return false;
80
+ }
81
+ function matchExternalizePattern(id, patterns) {
82
+ if (!patterns)
83
+ return false;
84
+ for (const ex of patterns) {
85
+ if (typeof ex === "string") {
86
+ if (id.includes(`/node_modules/${ex}/`))
87
+ return true;
88
+ } else {
89
+ if (ex.test(id))
90
+ return true;
91
+ }
92
+ }
93
+ return false;
94
+ }
95
+ function patchWindowsImportPath(path) {
96
+ if (path.match(/^\w:\\/))
97
+ return `file:///${slash(path)}`;
98
+ else if (path.match(/^\w:\//))
99
+ return `file:///${path}`;
100
+ else
101
+ return path;
102
+ }
103
+
104
+ let SOURCEMAPPING_URL = "sourceMa";
105
+ SOURCEMAPPING_URL += "ppingURL";
106
+ class ViteNodeServer {
107
+ constructor(server, options = {}) {
108
+ this.server = server;
109
+ this.options = options;
110
+ this.promiseMap = new Map();
111
+ }
112
+ shouldExternalize(id) {
113
+ return shouldExternalize(id, this.options.deps);
114
+ }
115
+ async fetchModule(id) {
116
+ const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root));
117
+ if (externalize)
118
+ return { externalize };
119
+ const r = await this.transformRequest(id);
120
+ return { code: r == null ? void 0 : r.code };
121
+ }
122
+ async resolveId(id, importer) {
123
+ return this.server.pluginContainer.resolveId(id, importer, { ssr: true });
124
+ }
125
+ async transformRequest(id) {
126
+ if (!this.promiseMap.has(id)) {
127
+ this.promiseMap.set(id, this._transformRequest(id).finally(() => {
128
+ this.promiseMap.delete(id);
129
+ }));
130
+ }
131
+ return this.promiseMap.get(id);
132
+ }
133
+ getTransformMode(id) {
134
+ var _a, _b, _c, _d;
135
+ const withoutQuery = id.split("?")[0];
136
+ if ((_b = (_a = this.options.transformMode) == null ? void 0 : _a.web) == null ? void 0 : _b.some((r) => withoutQuery.match(r)))
137
+ return "web";
138
+ if ((_d = (_c = this.options.transformMode) == null ? void 0 : _c.ssr) == null ? void 0 : _d.some((r) => withoutQuery.match(r)))
139
+ return "ssr";
140
+ if (withoutQuery.match(/\.([cm]?[jt]sx?|json)$/))
141
+ return "ssr";
142
+ return "web";
143
+ }
144
+ async _transformRequest(id) {
145
+ let result = null;
146
+ const mode = this.getTransformMode(id);
147
+ if (mode === "web") {
148
+ result = await this.server.transformRequest(id);
149
+ if (result)
150
+ result = await this.server.ssrTransform(result.code, result.map, id);
151
+ } else {
152
+ result = await this.server.transformRequest(id, { ssr: true });
153
+ }
154
+ if (this.options.sourcemap !== false && result && !id.includes("node_modules"))
155
+ withInlineSourcemap(result);
156
+ return result;
157
+ }
158
+ }
159
+ async function withInlineSourcemap(result) {
160
+ const { code, map } = result;
161
+ if (code.includes(`${SOURCEMAPPING_URL}=`))
162
+ return result;
163
+ if (map)
164
+ result.code = `${code}
165
+
166
+ //# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
167
+ `;
168
+ return result;
169
+ }
170
+
171
+ exports.ViteNodeServer = ViteNodeServer;
172
+ exports.guessCJSversion = guessCJSversion;
173
+ exports.shouldExternalize = shouldExternalize;
174
+ exports.withInlineSourcemap = withInlineSourcemap;
package/dist/server.js CHANGED
@@ -1,8 +1,18 @@
1
1
  import { existsSync } from 'fs';
2
2
  import { isNodeBuiltin, isValidNodeImport } from 'mlly';
3
- import { slash, toFilePath } from './utils.js';
4
- import 'url';
5
- import 'pathe';
3
+ import { fileURLToPath, pathToFileURL } from 'url';
4
+ import { dirname, resolve } from 'pathe';
5
+
6
+ const isWindows = process.platform === "win32";
7
+ function slash(str) {
8
+ return str.replace(/\\/g, "/");
9
+ }
10
+ function toFilePath(id, root) {
11
+ let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname(root)) && dirname(root) !== "/" ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
12
+ if (absolute.startsWith("//"))
13
+ absolute = absolute.slice(1);
14
+ return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
15
+ }
6
16
 
7
17
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
8
18
  const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
@@ -41,18 +51,18 @@ function guessCJSversion(id) {
41
51
  }
42
52
  }
43
53
  }
44
- async function shouldExternalize(id, config, cache = new Map()) {
54
+ async function shouldExternalize(id, options, cache = new Map()) {
45
55
  if (!cache.has(id))
46
- cache.set(id, _shouldExternalize(id, config));
56
+ cache.set(id, _shouldExternalize(id, options));
47
57
  return cache.get(id);
48
58
  }
49
- async function _shouldExternalize(id, config) {
59
+ async function _shouldExternalize(id, options) {
50
60
  if (isNodeBuiltin(id))
51
61
  return id;
52
62
  id = patchWindowsImportPath(id);
53
- if (matchExternalizePattern(id, config == null ? void 0 : config.inline))
63
+ if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
54
64
  return false;
55
- if (matchExternalizePattern(id, config == null ? void 0 : config.external))
65
+ if (matchExternalizePattern(id, options == null ? void 0 : options.external))
56
66
  return id;
57
67
  const isNodeModule = id.includes("/node_modules/");
58
68
  id = isNodeModule ? guessCJSversion(id) || id : id;
@@ -105,6 +115,9 @@ class ViteNodeServer {
105
115
  const r = await this.transformRequest(id);
106
116
  return { code: r == null ? void 0 : r.code };
107
117
  }
118
+ async resolveId(id, importer) {
119
+ return this.server.pluginContainer.resolveId(id, importer, { ssr: true });
120
+ }
108
121
  async transformRequest(id) {
109
122
  if (!this.promiseMap.has(id)) {
110
123
  this.promiseMap.set(id, this._transformRequest(id).finally(() => {
@@ -134,7 +147,7 @@ class ViteNodeServer {
134
147
  } else {
135
148
  result = await this.server.transformRequest(id, { ssr: true });
136
149
  }
137
- if (result && !id.includes("node_modules"))
150
+ if (this.options.sourcemap !== false && result && !id.includes("node_modules"))
138
151
  withInlineSourcemap(result);
139
152
  return result;
140
153
  }
package/dist/utils.cjs ADDED
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var url = require('url');
6
+ var pathe = require('pathe');
7
+
8
+ const isWindows = process.platform === "win32";
9
+ function slash(str) {
10
+ return str.replace(/\\/g, "/");
11
+ }
12
+ function normalizeId(id, base) {
13
+ if (base && id.startsWith(base))
14
+ id = `/${id.slice(base.length)}`;
15
+ return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^node:/, "").replace(/[?&]v=\w+/, "?").replace(/\?$/, "");
16
+ }
17
+ function isPrimitive(v) {
18
+ return v !== Object(v);
19
+ }
20
+ function toFilePath(id, root) {
21
+ let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(pathe.dirname(root)) && pathe.dirname(root) !== "/" ? id : id.startsWith("/") ? slash(pathe.resolve(root, id.slice(1))) : id;
22
+ if (absolute.startsWith("//"))
23
+ absolute = absolute.slice(1);
24
+ return isWindows && absolute.startsWith("/") ? url.fileURLToPath(url.pathToFileURL(absolute.slice(1)).href) : absolute;
25
+ }
26
+
27
+ exports.isPrimitive = isPrimitive;
28
+ exports.isWindows = isWindows;
29
+ exports.normalizeId = normalizeId;
30
+ exports.slash = slash;
31
+ exports.toFilePath = toFilePath;
package/dist/utils.js CHANGED
@@ -14,7 +14,7 @@ function isPrimitive(v) {
14
14
  return v !== Object(v);
15
15
  }
16
16
  function toFilePath(id, root) {
17
- let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname(root)) ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
17
+ let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname(root)) && dirname(root) !== "/" ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
18
18
  if (absolute.startsWith("//"))
19
19
  absolute = absolute.slice(1);
20
20
  return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
package/index.d.ts CHANGED
@@ -1,12 +1,17 @@
1
- interface ExternalizeOptions {
1
+ interface DepsHandlingOptions {
2
2
  external?: (string | RegExp)[];
3
3
  inline?: (string | RegExp)[];
4
+ /**
5
+ * Try to guess the CJS version of a package when it's invalid ESM
6
+ * @default true
7
+ */
4
8
  fallbackCJS?: boolean;
5
9
  }
6
10
  declare type FetchFunction = (id: string) => Promise<{
7
11
  code?: string;
8
12
  externalize?: string;
9
13
  }>;
14
+ declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
10
15
  interface ModuleCache {
11
16
  promise?: Promise<any>;
12
17
  exports?: any;
@@ -14,18 +19,37 @@ interface ModuleCache {
14
19
  }
15
20
  interface ViteNodeRunnerOptions {
16
21
  fetchModule: FetchFunction;
22
+ resolveId: ResolveIdFunction;
17
23
  root: string;
18
24
  base?: string;
19
25
  moduleCache?: Map<string, ModuleCache>;
20
- interpretDefault?: boolean;
26
+ interopDefault?: boolean;
21
27
  requestStubs?: Record<string, any>;
22
28
  }
29
+ interface ViteNodeResolveId {
30
+ external?: boolean | 'absolute' | 'relative';
31
+ id: string;
32
+ meta?: Record<string, any> | null;
33
+ moduleSideEffects?: boolean | 'no-treeshake' | null;
34
+ syntheticNamedExports?: boolean | string | null;
35
+ }
23
36
  interface ViteNodeServerOptions {
24
- deps?: ExternalizeOptions;
37
+ /**
38
+ * Inject inline sourcemap to modules
39
+ * @default true
40
+ */
41
+ sourcemap?: boolean;
42
+ /**
43
+ * Deps handling
44
+ */
45
+ deps?: DepsHandlingOptions;
46
+ /**
47
+ * Tranform method for modules
48
+ */
25
49
  transformMode?: {
26
50
  ssr?: RegExp[];
27
51
  web?: RegExp[];
28
52
  };
29
53
  }
30
54
 
31
- export { ExternalizeOptions, FetchFunction, ModuleCache, ViteNodeRunnerOptions, ViteNodeServerOptions };
55
+ export { DepsHandlingOptions, FetchFunction, ModuleCache, ResolveIdFunction, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.1.18",
3
+ "version": "0.1.22",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "homepage": "https://github.com/vitest-dev/vitest#readme",
6
6
  "bugs": {
@@ -18,18 +18,22 @@
18
18
  "exports": {
19
19
  ".": {
20
20
  "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs",
21
22
  "types": "./index.d.ts"
22
23
  },
23
24
  "./client": {
24
25
  "import": "./dist/client.js",
26
+ "require": "./dist/client.cjs",
25
27
  "types": "./client.d.ts"
26
28
  },
27
29
  "./server": {
28
30
  "import": "./dist/server.js",
31
+ "require": "./dist/server.cjs",
29
32
  "types": "./server.d.ts"
30
33
  },
31
34
  "./utils": {
32
35
  "import": "./dist/utils.js",
36
+ "require": "./dist/utils.cjs",
33
37
  "types": "./utils.d.ts"
34
38
  }
35
39
  },
@@ -47,13 +51,13 @@
47
51
  "dependencies": {
48
52
  "kolorist": "^1.5.1",
49
53
  "minimist": "^1.2.5",
50
- "mlly": "^0.3.17",
54
+ "mlly": "^0.3.19",
51
55
  "pathe": "^0.2.0",
52
- "vite": "^2.7.12"
56
+ "vite": "^2.7.13"
53
57
  },
54
58
  "devDependencies": {
55
59
  "@types/minimist": "^1.2.2",
56
- "rollup": "^2.63.0"
60
+ "rollup": "^2.64.0"
57
61
  },
58
62
  "engines": {
59
63
  "node": ">=14.14.0"
package/server.d.ts CHANGED
@@ -1,12 +1,34 @@
1
1
  import { ViteDevServer, TransformResult } from 'vite';
2
2
 
3
- interface ExternalizeOptions {
3
+ interface DepsHandlingOptions {
4
4
  external?: (string | RegExp)[];
5
5
  inline?: (string | RegExp)[];
6
+ /**
7
+ * Try to guess the CJS version of a package when it's invalid ESM
8
+ * @default true
9
+ */
6
10
  fallbackCJS?: boolean;
7
11
  }
12
+ interface ViteNodeResolveId {
13
+ external?: boolean | 'absolute' | 'relative';
14
+ id: string;
15
+ meta?: Record<string, any> | null;
16
+ moduleSideEffects?: boolean | 'no-treeshake' | null;
17
+ syntheticNamedExports?: boolean | string | null;
18
+ }
8
19
  interface ViteNodeServerOptions {
9
- deps?: ExternalizeOptions;
20
+ /**
21
+ * Inject inline sourcemap to modules
22
+ * @default true
23
+ */
24
+ sourcemap?: boolean;
25
+ /**
26
+ * Deps handling
27
+ */
28
+ deps?: DepsHandlingOptions;
29
+ /**
30
+ * Tranform method for modules
31
+ */
10
32
  transformMode?: {
11
33
  ssr?: RegExp[];
12
34
  web?: RegExp[];
@@ -14,7 +36,7 @@ interface ViteNodeServerOptions {
14
36
  }
15
37
 
16
38
  declare function guessCJSversion(id: string): string | undefined;
17
- declare function shouldExternalize(id: string, config?: ExternalizeOptions, cache?: Map<string, Promise<string | false>>): Promise<string | false>;
39
+ declare function shouldExternalize(id: string, options?: DepsHandlingOptions, cache?: Map<string, Promise<string | false>>): Promise<string | false>;
18
40
 
19
41
  declare class ViteNodeServer {
20
42
  server: ViteDevServer;
@@ -29,6 +51,7 @@ declare class ViteNodeServer {
29
51
  code: string | undefined;
30
52
  externalize?: undefined;
31
53
  }>;
54
+ resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
32
55
  transformRequest(id: string): Promise<TransformResult | null | undefined>;
33
56
  private getTransformMode;
34
57
  private _transformRequest;