vite-node 0.18.0 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.cjs CHANGED
@@ -2,16 +2,200 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var server = require('./chunk-server.cjs');
6
- require('pathe');
7
- require('debug');
8
- require('fs');
9
- require('mlly');
10
- require('./chunk-utils.cjs');
5
+ var pathe = require('pathe');
6
+ var createDebug = require('debug');
7
+ var fs = require('fs');
8
+ var mlly = require('mlly');
9
+ var utils = require('./utils.cjs');
11
10
  require('url');
12
11
 
12
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
13
 
14
+ var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
14
15
 
15
- exports.ViteNodeServer = server.ViteNodeServer;
16
- exports.guessCJSversion = server.guessCJSversion;
17
- exports.shouldExternalize = server.shouldExternalize;
16
+ const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
17
+ const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
18
+ const defaultInline = [
19
+ /virtual:/,
20
+ /\.[mc]?ts$/
21
+ ];
22
+ const depsExternal = [
23
+ /\.cjs\.js$/,
24
+ /\.mjs$/
25
+ ];
26
+ function guessCJSversion(id) {
27
+ if (id.match(ESM_EXT_RE)) {
28
+ for (const i of [
29
+ id.replace(ESM_EXT_RE, ".mjs"),
30
+ id.replace(ESM_EXT_RE, ".umd.js"),
31
+ id.replace(ESM_EXT_RE, ".cjs.js"),
32
+ id.replace(ESM_EXT_RE, ".js")
33
+ ]) {
34
+ if (fs.existsSync(i))
35
+ return i;
36
+ }
37
+ }
38
+ if (id.match(ESM_FOLDER_RE)) {
39
+ for (const i of [
40
+ id.replace(ESM_FOLDER_RE, "/umd/$1"),
41
+ id.replace(ESM_FOLDER_RE, "/cjs/$1"),
42
+ id.replace(ESM_FOLDER_RE, "/lib/$1"),
43
+ id.replace(ESM_FOLDER_RE, "/$1")
44
+ ]) {
45
+ if (fs.existsSync(i))
46
+ return i;
47
+ }
48
+ }
49
+ }
50
+ async function shouldExternalize(id, options, cache = /* @__PURE__ */ new Map()) {
51
+ if (!cache.has(id))
52
+ cache.set(id, _shouldExternalize(id, options));
53
+ return cache.get(id);
54
+ }
55
+ async function _shouldExternalize(id, options) {
56
+ if (mlly.isNodeBuiltin(id))
57
+ return id;
58
+ if (id.startsWith("data:"))
59
+ return id;
60
+ id = patchWindowsImportPath(id);
61
+ if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
62
+ return false;
63
+ if (matchExternalizePattern(id, options == null ? void 0 : options.external))
64
+ return id;
65
+ const isNodeModule = id.includes("/node_modules/");
66
+ const guessCJS = isNodeModule && (options == null ? void 0 : options.fallbackCJS);
67
+ id = guessCJS ? guessCJSversion(id) || id : id;
68
+ if (matchExternalizePattern(id, defaultInline))
69
+ return false;
70
+ if (matchExternalizePattern(id, depsExternal))
71
+ return id;
72
+ const isDist = id.includes("/dist/");
73
+ if ((isNodeModule || isDist) && await mlly.isValidNodeImport(id))
74
+ return id;
75
+ return false;
76
+ }
77
+ function matchExternalizePattern(id, patterns) {
78
+ if (patterns == null)
79
+ return false;
80
+ if (patterns === true)
81
+ return true;
82
+ for (const ex of patterns) {
83
+ if (typeof ex === "string") {
84
+ if (id.includes(`/node_modules/${ex}/`))
85
+ return true;
86
+ } else {
87
+ if (ex.test(id))
88
+ return true;
89
+ }
90
+ }
91
+ return false;
92
+ }
93
+ function patchWindowsImportPath(path) {
94
+ if (path.match(/^\w:\\/))
95
+ return `file:///${utils.slash(path)}`;
96
+ else if (path.match(/^\w:\//))
97
+ return `file:///${path}`;
98
+ else
99
+ return path;
100
+ }
101
+
102
+ const debugRequest = createDebug__default["default"]("vite-node:server:request");
103
+ const RealDate = Date;
104
+ class ViteNodeServer {
105
+ constructor(server, options = {}) {
106
+ this.server = server;
107
+ this.options = options;
108
+ this.fetchPromiseMap = /* @__PURE__ */ new Map();
109
+ this.transformPromiseMap = /* @__PURE__ */ new Map();
110
+ this.fetchCache = /* @__PURE__ */ new Map();
111
+ var _a, _b;
112
+ const ssrOptions = server.config.ssr;
113
+ if (ssrOptions) {
114
+ options.deps ?? (options.deps = {});
115
+ if (ssrOptions.noExternal === true) {
116
+ (_a = options.deps).inline ?? (_a.inline = true);
117
+ } else if (options.deps.inline !== true) {
118
+ (_b = options.deps).inline ?? (_b.inline = []);
119
+ options.deps.inline.push(...utils.toArray(ssrOptions.noExternal));
120
+ }
121
+ }
122
+ }
123
+ shouldExternalize(id) {
124
+ return shouldExternalize(id, this.options.deps);
125
+ }
126
+ async resolveId(id, importer) {
127
+ if (importer && !importer.startsWith(this.server.config.root))
128
+ importer = pathe.join(this.server.config.root, importer);
129
+ const mode = importer && this.getTransformMode(importer) || "ssr";
130
+ return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
131
+ }
132
+ async fetchModule(id) {
133
+ if (!this.fetchPromiseMap.has(id)) {
134
+ this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => {
135
+ return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
136
+ }).finally(() => {
137
+ this.fetchPromiseMap.delete(id);
138
+ }));
139
+ }
140
+ return this.fetchPromiseMap.get(id);
141
+ }
142
+ async transformRequest(id) {
143
+ if (!this.transformPromiseMap.has(id)) {
144
+ this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
145
+ this.transformPromiseMap.delete(id);
146
+ }));
147
+ }
148
+ return this.transformPromiseMap.get(id);
149
+ }
150
+ getTransformMode(id) {
151
+ var _a, _b, _c, _d;
152
+ const withoutQuery = id.split("?")[0];
153
+ if ((_b = (_a = this.options.transformMode) == null ? void 0 : _a.web) == null ? void 0 : _b.some((r) => withoutQuery.match(r)))
154
+ return "web";
155
+ if ((_d = (_c = this.options.transformMode) == null ? void 0 : _c.ssr) == null ? void 0 : _d.some((r) => withoutQuery.match(r)))
156
+ return "ssr";
157
+ if (withoutQuery.match(/\.([cm]?[jt]sx?|json)$/))
158
+ return "ssr";
159
+ return "web";
160
+ }
161
+ async _fetchModule(id) {
162
+ let result;
163
+ const filePath = utils.toFilePath(id, this.server.config.root);
164
+ const module = this.server.moduleGraph.getModuleById(id);
165
+ const timestamp = (module == null ? void 0 : module.lastHMRTimestamp) || RealDate.now();
166
+ const cache = this.fetchCache.get(filePath);
167
+ if (timestamp && cache && cache.timestamp >= timestamp)
168
+ return cache.result;
169
+ const externalize = await this.shouldExternalize(filePath);
170
+ if (externalize) {
171
+ result = { externalize };
172
+ } else {
173
+ const r = await this._transformRequest(id);
174
+ result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
175
+ }
176
+ this.fetchCache.set(filePath, {
177
+ timestamp,
178
+ result
179
+ });
180
+ return result;
181
+ }
182
+ async _transformRequest(id) {
183
+ debugRequest(id);
184
+ let result = null;
185
+ if (this.getTransformMode(id) === "web") {
186
+ result = await this.server.transformRequest(id);
187
+ if (result)
188
+ result = await this.server.ssrTransform(result.code, result.map, id);
189
+ } else {
190
+ result = await this.server.transformRequest(id, { ssr: true });
191
+ }
192
+ const sourcemap = this.options.sourcemap ?? "inline";
193
+ if (sourcemap === "inline" && result && !id.includes("node_modules"))
194
+ utils.withInlineSourcemap(result);
195
+ return result;
196
+ }
197
+ }
198
+
199
+ exports.ViteNodeServer = ViteNodeServer;
200
+ exports.guessCJSversion = guessCJSversion;
201
+ exports.shouldExternalize = shouldExternalize;
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ViteDevServer, TransformResult } from 'vite';
2
- import { D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './types-b59fb161.js';
2
+ import { D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './types-de894284.js';
3
3
 
4
4
  declare function guessCJSversion(id: string): string | undefined;
5
5
  declare function shouldExternalize(id: string, options?: DepsHandlingOptions, cache?: Map<string, Promise<string | false>>): Promise<string | false>;
package/dist/server.mjs CHANGED
@@ -1,7 +1,191 @@
1
- export { V as ViteNodeServer, g as guessCJSversion, s as shouldExternalize } from './chunk-server.mjs';
2
- import 'pathe';
3
- import 'debug';
4
- import 'fs';
5
- import 'mlly';
6
- import './chunk-utils.mjs';
1
+ import { join } from 'pathe';
2
+ import createDebug from 'debug';
3
+ import { existsSync } from 'fs';
4
+ import { isNodeBuiltin, isValidNodeImport } from 'mlly';
5
+ import { slash, toArray, toFilePath, withInlineSourcemap } from './utils.mjs';
7
6
  import 'url';
7
+
8
+ const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
9
+ const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
10
+ const defaultInline = [
11
+ /virtual:/,
12
+ /\.[mc]?ts$/
13
+ ];
14
+ const depsExternal = [
15
+ /\.cjs\.js$/,
16
+ /\.mjs$/
17
+ ];
18
+ function guessCJSversion(id) {
19
+ if (id.match(ESM_EXT_RE)) {
20
+ for (const i of [
21
+ id.replace(ESM_EXT_RE, ".mjs"),
22
+ id.replace(ESM_EXT_RE, ".umd.js"),
23
+ id.replace(ESM_EXT_RE, ".cjs.js"),
24
+ id.replace(ESM_EXT_RE, ".js")
25
+ ]) {
26
+ if (existsSync(i))
27
+ return i;
28
+ }
29
+ }
30
+ if (id.match(ESM_FOLDER_RE)) {
31
+ for (const i of [
32
+ id.replace(ESM_FOLDER_RE, "/umd/$1"),
33
+ id.replace(ESM_FOLDER_RE, "/cjs/$1"),
34
+ id.replace(ESM_FOLDER_RE, "/lib/$1"),
35
+ id.replace(ESM_FOLDER_RE, "/$1")
36
+ ]) {
37
+ if (existsSync(i))
38
+ return i;
39
+ }
40
+ }
41
+ }
42
+ async function shouldExternalize(id, options, cache = /* @__PURE__ */ new Map()) {
43
+ if (!cache.has(id))
44
+ cache.set(id, _shouldExternalize(id, options));
45
+ return cache.get(id);
46
+ }
47
+ async function _shouldExternalize(id, options) {
48
+ if (isNodeBuiltin(id))
49
+ return id;
50
+ if (id.startsWith("data:"))
51
+ return id;
52
+ id = patchWindowsImportPath(id);
53
+ if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
54
+ return false;
55
+ if (matchExternalizePattern(id, options == null ? void 0 : options.external))
56
+ return id;
57
+ const isNodeModule = id.includes("/node_modules/");
58
+ const guessCJS = isNodeModule && (options == null ? void 0 : options.fallbackCJS);
59
+ id = guessCJS ? guessCJSversion(id) || id : id;
60
+ if (matchExternalizePattern(id, defaultInline))
61
+ return false;
62
+ if (matchExternalizePattern(id, depsExternal))
63
+ return id;
64
+ const isDist = id.includes("/dist/");
65
+ if ((isNodeModule || isDist) && await isValidNodeImport(id))
66
+ return id;
67
+ return false;
68
+ }
69
+ function matchExternalizePattern(id, patterns) {
70
+ if (patterns == null)
71
+ return false;
72
+ if (patterns === true)
73
+ return true;
74
+ for (const ex of patterns) {
75
+ if (typeof ex === "string") {
76
+ if (id.includes(`/node_modules/${ex}/`))
77
+ return true;
78
+ } else {
79
+ if (ex.test(id))
80
+ return true;
81
+ }
82
+ }
83
+ return false;
84
+ }
85
+ function patchWindowsImportPath(path) {
86
+ if (path.match(/^\w:\\/))
87
+ return `file:///${slash(path)}`;
88
+ else if (path.match(/^\w:\//))
89
+ return `file:///${path}`;
90
+ else
91
+ return path;
92
+ }
93
+
94
+ const debugRequest = createDebug("vite-node:server:request");
95
+ const RealDate = Date;
96
+ class ViteNodeServer {
97
+ constructor(server, options = {}) {
98
+ this.server = server;
99
+ this.options = options;
100
+ this.fetchPromiseMap = /* @__PURE__ */ new Map();
101
+ this.transformPromiseMap = /* @__PURE__ */ new Map();
102
+ this.fetchCache = /* @__PURE__ */ new Map();
103
+ var _a, _b;
104
+ const ssrOptions = server.config.ssr;
105
+ if (ssrOptions) {
106
+ options.deps ?? (options.deps = {});
107
+ if (ssrOptions.noExternal === true) {
108
+ (_a = options.deps).inline ?? (_a.inline = true);
109
+ } else if (options.deps.inline !== true) {
110
+ (_b = options.deps).inline ?? (_b.inline = []);
111
+ options.deps.inline.push(...toArray(ssrOptions.noExternal));
112
+ }
113
+ }
114
+ }
115
+ shouldExternalize(id) {
116
+ return shouldExternalize(id, this.options.deps);
117
+ }
118
+ async resolveId(id, importer) {
119
+ if (importer && !importer.startsWith(this.server.config.root))
120
+ importer = join(this.server.config.root, importer);
121
+ const mode = importer && this.getTransformMode(importer) || "ssr";
122
+ return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
123
+ }
124
+ async fetchModule(id) {
125
+ if (!this.fetchPromiseMap.has(id)) {
126
+ this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => {
127
+ return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
128
+ }).finally(() => {
129
+ this.fetchPromiseMap.delete(id);
130
+ }));
131
+ }
132
+ return this.fetchPromiseMap.get(id);
133
+ }
134
+ async transformRequest(id) {
135
+ if (!this.transformPromiseMap.has(id)) {
136
+ this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
137
+ this.transformPromiseMap.delete(id);
138
+ }));
139
+ }
140
+ return this.transformPromiseMap.get(id);
141
+ }
142
+ getTransformMode(id) {
143
+ var _a, _b, _c, _d;
144
+ const withoutQuery = id.split("?")[0];
145
+ if ((_b = (_a = this.options.transformMode) == null ? void 0 : _a.web) == null ? void 0 : _b.some((r) => withoutQuery.match(r)))
146
+ return "web";
147
+ if ((_d = (_c = this.options.transformMode) == null ? void 0 : _c.ssr) == null ? void 0 : _d.some((r) => withoutQuery.match(r)))
148
+ return "ssr";
149
+ if (withoutQuery.match(/\.([cm]?[jt]sx?|json)$/))
150
+ return "ssr";
151
+ return "web";
152
+ }
153
+ async _fetchModule(id) {
154
+ let result;
155
+ const filePath = toFilePath(id, this.server.config.root);
156
+ const module = this.server.moduleGraph.getModuleById(id);
157
+ const timestamp = (module == null ? void 0 : module.lastHMRTimestamp) || RealDate.now();
158
+ const cache = this.fetchCache.get(filePath);
159
+ if (timestamp && cache && cache.timestamp >= timestamp)
160
+ return cache.result;
161
+ const externalize = await this.shouldExternalize(filePath);
162
+ if (externalize) {
163
+ result = { externalize };
164
+ } else {
165
+ const r = await this._transformRequest(id);
166
+ result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
167
+ }
168
+ this.fetchCache.set(filePath, {
169
+ timestamp,
170
+ result
171
+ });
172
+ return result;
173
+ }
174
+ async _transformRequest(id) {
175
+ debugRequest(id);
176
+ let result = null;
177
+ if (this.getTransformMode(id) === "web") {
178
+ result = await this.server.transformRequest(id);
179
+ if (result)
180
+ result = await this.server.ssrTransform(result.code, result.map, id);
181
+ } else {
182
+ result = await this.server.transformRequest(id, { ssr: true });
183
+ }
184
+ const sourcemap = this.options.sourcemap ?? "inline";
185
+ if (sourcemap === "inline" && result && !id.includes("node_modules"))
186
+ withInlineSourcemap(result);
187
+ return result;
188
+ }
189
+ }
190
+
191
+ export { ViteNodeServer, guessCJSversion, shouldExternalize };
@@ -66,26 +66,18 @@ interface CustomEventMap {
66
66
  type InferCustomEventPayload<T extends string> =
67
67
  T extends keyof CustomEventMap ? CustomEventMap[T] : any
68
68
 
69
- type ModuleNamespace = Record<string, any> & {
70
- [Symbol.toStringTag]: 'Module'
71
- }
72
-
73
69
  interface ViteHotContext {
74
70
  readonly data: any
75
71
 
76
72
  accept(): void
77
- accept(cb: (mod: ModuleNamespace | undefined) => void): void
78
- accept(dep: string, cb: (mod: ModuleNamespace | undefined) => void): void
79
- accept(
80
- deps: readonly string[],
81
- cb: (mods: Array<ModuleNamespace | undefined>) => void
82
- ): void
73
+ accept(cb: (mod: any) => void): void
74
+ accept(dep: string, cb: (mod: any) => void): void
75
+ accept(deps: readonly string[], cb: (mods: any[]) => void): void
83
76
 
84
- acceptExports(exportNames: string | readonly string[]): void
85
- acceptExports(
86
- exportNames: string | readonly string[],
87
- cb: (mod: ModuleNamespace | undefined) => void
88
- ): void
77
+ /**
78
+ * @deprecated
79
+ */
80
+ acceptDeps(): never
89
81
 
90
82
  dispose(cb: (data: any) => void): void
91
83
  decline(): void
@@ -109,7 +101,7 @@ declare const DEFAULT_REQUEST_STUBS: {
109
101
  invalidate: () => void;
110
102
  on: () => void;
111
103
  };
112
- updateStyle(): void;
104
+ updateStyle(id: string, css: string): void;
113
105
  };
114
106
  };
115
107
  declare class ModuleCacheMap extends Map<string, ModuleCache> {
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- export { A as Arrayable, C as CreateHotContextFunction, 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-b59fb161.js';
1
+ export { A as Arrayable, C as CreateHotContextFunction, 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-de894284.js';
package/dist/utils.cjs CHANGED
@@ -2,18 +2,60 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var utils = require('./chunk-utils.cjs');
6
- require('url');
7
- require('pathe');
5
+ var url = require('url');
6
+ var pathe = require('pathe');
8
7
 
8
+ const isWindows = process.platform === "win32";
9
+ function slash(str) {
10
+ return str.replace(/\\/g, "/");
11
+ }
12
+ function mergeSlashes(str) {
13
+ return str.replace(/\/\//g, "/");
14
+ }
15
+ function normalizeRequestId(id, base) {
16
+ if (base && id.startsWith(base))
17
+ id = `/${id.slice(base.length)}`;
18
+ 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(/\?+$/, "");
19
+ }
20
+ function normalizeModuleId(id) {
21
+ return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
22
+ }
23
+ function isPrimitive(v) {
24
+ return v !== Object(v);
25
+ }
26
+ function toFilePath(id, root) {
27
+ let absolute = id.startsWith("/@fs/") ? id.slice(4) : id.startsWith(root) ? id : id.startsWith("/") ? pathe.resolve(root, id.slice(1)) : id;
28
+ if (absolute.startsWith("//"))
29
+ absolute = absolute.slice(1);
30
+ return isWindows && absolute.startsWith("/") ? slash(url.fileURLToPath(url.pathToFileURL(absolute.slice(1)).href)) : absolute;
31
+ }
32
+ let SOURCEMAPPING_URL = "sourceMa";
33
+ SOURCEMAPPING_URL += "ppingURL";
34
+ async function withInlineSourcemap(result) {
35
+ const { code, map } = result;
36
+ if (code.includes(`${SOURCEMAPPING_URL}=`))
37
+ return result;
38
+ if (map)
39
+ result.code = `${code}
9
40
 
41
+ //# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
42
+ `;
43
+ return result;
44
+ }
45
+ function toArray(array) {
46
+ if (array === null || array === void 0)
47
+ array = [];
48
+ if (Array.isArray(array))
49
+ return array;
50
+ return [array];
51
+ }
10
52
 
11
- exports.isPrimitive = utils.isPrimitive;
12
- exports.isWindows = utils.isWindows;
13
- exports.mergeSlashes = utils.mergeSlashes;
14
- exports.normalizeModuleId = utils.normalizeModuleId;
15
- exports.normalizeRequestId = utils.normalizeRequestId;
16
- exports.slash = utils.slash;
17
- exports.toArray = utils.toArray;
18
- exports.toFilePath = utils.toFilePath;
19
- exports.withInlineSourcemap = utils.withInlineSourcemap;
53
+ exports.isPrimitive = isPrimitive;
54
+ exports.isWindows = isWindows;
55
+ exports.mergeSlashes = mergeSlashes;
56
+ exports.normalizeModuleId = normalizeModuleId;
57
+ exports.normalizeRequestId = normalizeRequestId;
58
+ exports.slash = slash;
59
+ exports.toArray = toArray;
60
+ exports.toFilePath = toFilePath;
61
+ exports.withInlineSourcemap = withInlineSourcemap;
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TransformResult } from 'vite';
2
- import { N as Nullable, A as Arrayable } from './types-b59fb161.js';
2
+ import { N as Nullable, A as Arrayable } from './types-de894284.js';
3
3
 
4
4
  declare const isWindows: boolean;
5
5
  declare function slash(str: string): string;
package/dist/utils.mjs CHANGED
@@ -1,3 +1,49 @@
1
- export { i as isPrimitive, c as isWindows, m as mergeSlashes, n as normalizeModuleId, b as normalizeRequestId, s as slash, t as toArray, a as toFilePath, w as withInlineSourcemap } from './chunk-utils.mjs';
2
- import 'url';
3
- import 'pathe';
1
+ import { fileURLToPath, pathToFileURL } from 'url';
2
+ import { resolve } from 'pathe';
3
+
4
+ const isWindows = process.platform === "win32";
5
+ function slash(str) {
6
+ return str.replace(/\\/g, "/");
7
+ }
8
+ function mergeSlashes(str) {
9
+ return str.replace(/\/\//g, "/");
10
+ }
11
+ function normalizeRequestId(id, base) {
12
+ if (base && id.startsWith(base))
13
+ id = `/${id.slice(base.length)}`;
14
+ 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(/\?+$/, "");
15
+ }
16
+ function normalizeModuleId(id) {
17
+ return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
18
+ }
19
+ function isPrimitive(v) {
20
+ return v !== Object(v);
21
+ }
22
+ function toFilePath(id, root) {
23
+ let absolute = id.startsWith("/@fs/") ? id.slice(4) : id.startsWith(root) ? id : id.startsWith("/") ? resolve(root, id.slice(1)) : id;
24
+ if (absolute.startsWith("//"))
25
+ absolute = absolute.slice(1);
26
+ return isWindows && absolute.startsWith("/") ? slash(fileURLToPath(pathToFileURL(absolute.slice(1)).href)) : absolute;
27
+ }
28
+ let SOURCEMAPPING_URL = "sourceMa";
29
+ SOURCEMAPPING_URL += "ppingURL";
30
+ async function withInlineSourcemap(result) {
31
+ const { code, map } = result;
32
+ if (code.includes(`${SOURCEMAPPING_URL}=`))
33
+ return result;
34
+ if (map)
35
+ result.code = `${code}
36
+
37
+ //# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
38
+ `;
39
+ return result;
40
+ }
41
+ function toArray(array) {
42
+ if (array === null || array === void 0)
43
+ array = [];
44
+ if (Array.isArray(array))
45
+ return array;
46
+ return [array];
47
+ }
48
+
49
+ export { isPrimitive, isWindows, mergeSlashes, normalizeModuleId, normalizeRequestId, slash, toArray, toFilePath, withInlineSourcemap };
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,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.18.0",
3
+ "version": "0.19.1",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -66,14 +66,14 @@
66
66
  "dependencies": {
67
67
  "debug": "^4.3.4",
68
68
  "kolorist": "^1.5.1",
69
- "mlly": "^0.5.3",
69
+ "mlly": "^0.5.4",
70
70
  "pathe": "^0.2.0",
71
71
  "vite": "^2.9.12 || ^3.0.0-0"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@types/debug": "^4.1.7",
75
75
  "cac": "^6.7.12",
76
- "rollup": "^2.75.7"
76
+ "rollup": "^2.77.0"
77
77
  },
78
78
  "scripts": {
79
79
  "build": "rimraf dist && rollup -c",
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 };