vite-node 0.9.4 → 0.10.2

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.cjs CHANGED
@@ -2,239 +2,16 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var module$1 = require('module');
6
- var url = require('url');
7
- var vm = require('vm');
8
- var pathe = require('pathe');
9
- var mlly = require('mlly');
10
- var utils = require('./utils.cjs');
5
+ var client = require('./client-e24a0d42.js');
6
+ require('module');
7
+ require('url');
8
+ require('vm');
9
+ require('pathe');
10
+ require('mlly');
11
+ require('./utils-5d86aff6.js');
11
12
 
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
13
 
14
- function _interopNamespace(e) {
15
- if (e && e.__esModule) return e;
16
- var n = Object.create(null);
17
- if (e) {
18
- Object.keys(e).forEach(function (k) {
19
- if (k !== 'default') {
20
- var d = Object.getOwnPropertyDescriptor(e, k);
21
- Object.defineProperty(n, k, d.get ? d : {
22
- enumerable: true,
23
- get: function () { return e[k]; }
24
- });
25
- }
26
- });
27
- }
28
- n["default"] = e;
29
- return Object.freeze(n);
30
- }
31
14
 
32
- var vm__default = /*#__PURE__*/_interopDefaultLegacy(vm);
33
-
34
- const DEFAULT_REQUEST_STUBS = {
35
- "/@vite/client": {
36
- injectQuery: (id) => id,
37
- createHotContext() {
38
- return {
39
- accept: () => {
40
- },
41
- prune: () => {
42
- },
43
- dispose: () => {
44
- },
45
- decline: () => {
46
- },
47
- invalidate: () => {
48
- },
49
- on: () => {
50
- }
51
- };
52
- },
53
- updateStyle() {
54
- }
55
- }
56
- };
57
- class ModuleCacheMap extends Map {
58
- normalizePath(fsPath) {
59
- return utils.normalizeModuleId(fsPath);
60
- }
61
- set(fsPath, mod) {
62
- fsPath = this.normalizePath(fsPath);
63
- if (!super.has(fsPath))
64
- super.set(fsPath, mod);
65
- else
66
- Object.assign(super.get(fsPath), mod);
67
- return this;
68
- }
69
- get(fsPath) {
70
- fsPath = this.normalizePath(fsPath);
71
- return super.get(fsPath);
72
- }
73
- delete(fsPath) {
74
- fsPath = this.normalizePath(fsPath);
75
- return super.delete(fsPath);
76
- }
77
- }
78
- class ViteNodeRunner {
79
- constructor(options) {
80
- this.options = options;
81
- this.root = options.root ?? process.cwd();
82
- this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
83
- this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG : false);
84
- }
85
- async executeFile(file) {
86
- return await this.cachedRequest(`/@fs/${utils.slash(pathe.resolve(file))}`, []);
87
- }
88
- async executeId(id) {
89
- return await this.cachedRequest(id, []);
90
- }
91
- async cachedRequest(rawId, callstack) {
92
- var _a, _b;
93
- const id = utils.normalizeRequestId(rawId, this.options.base);
94
- const fsPath = utils.toFilePath(id, this.root);
95
- if ((_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.promise)
96
- return (_b = this.moduleCache.get(fsPath)) == null ? void 0 : _b.promise;
97
- const promise = this.directRequest(id, fsPath, callstack);
98
- this.moduleCache.set(fsPath, { promise });
99
- return await promise;
100
- }
101
- async directRequest(id, fsPath, _callstack) {
102
- const callstack = [..._callstack, utils.normalizeModuleId(id)];
103
- const request = async (dep) => {
104
- var _a, _b;
105
- const getStack = () => {
106
- return `stack:
107
- ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`;
108
- };
109
- if (this.options.resolveId && this.shouldResolveId(dep)) {
110
- const resolvedDep = await this.options.resolveId(dep, id);
111
- dep = ((_a = resolvedDep == null ? void 0 : resolvedDep.id) == null ? void 0 : _a.replace(this.root, "")) || dep;
112
- }
113
- let debugTimer;
114
- if (this.debug)
115
- debugTimer = setTimeout(() => this.debugLog(() => `module ${dep} takes over 2s to load.
116
- ${getStack()}`), 2e3);
117
- try {
118
- if (callstack.includes(utils.normalizeModuleId(dep))) {
119
- this.debugLog(() => `circular dependency, ${getStack()}`);
120
- const depExports = (_b = this.moduleCache.get(dep)) == null ? void 0 : _b.exports;
121
- if (depExports)
122
- return depExports;
123
- throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
124
- }
125
- const mod = await this.cachedRequest(dep, callstack);
126
- return mod;
127
- } finally {
128
- if (debugTimer)
129
- clearTimeout(debugTimer);
130
- }
131
- };
132
- const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
133
- if (id in requestStubs)
134
- return requestStubs[id];
135
- const { code: transformed, externalize } = await this.options.fetchModule(id);
136
- if (externalize) {
137
- const mod = await this.interopedImport(externalize);
138
- this.moduleCache.set(fsPath, { exports: mod });
139
- return mod;
140
- }
141
- if (transformed == null)
142
- throw new Error(`[vite-node] Failed to load ${id}`);
143
- const url$1 = url.pathToFileURL(fsPath).href;
144
- const exports = /* @__PURE__ */ Object.create(null);
145
- exports[Symbol.toStringTag] = "Module";
146
- this.moduleCache.set(id, { code: transformed, exports });
147
- const __filename = url.fileURLToPath(url$1);
148
- const moduleProxy = {
149
- set exports(value) {
150
- exportAll(exports, value);
151
- exports.default = value;
152
- },
153
- get exports() {
154
- return exports.default;
155
- }
156
- };
157
- const context = this.prepareContext({
158
- __vite_ssr_import__: request,
159
- __vite_ssr_dynamic_import__: request,
160
- __vite_ssr_exports__: exports,
161
- __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
162
- __vite_ssr_import_meta__: { url: url$1 },
163
- require: module$1.createRequire(url$1),
164
- exports,
165
- module: moduleProxy,
166
- __filename,
167
- __dirname: pathe.dirname(__filename)
168
- });
169
- const fn = vm__default["default"].runInThisContext(`'use strict';async (${Object.keys(context).join(",")})=>{{${transformed}
170
- }}`, {
171
- filename: fsPath,
172
- lineOffset: 0
173
- });
174
- await fn(...Object.values(context));
175
- return exports;
176
- }
177
- prepareContext(context) {
178
- return context;
179
- }
180
- shouldResolveId(dep) {
181
- if (mlly.isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS))
182
- return false;
183
- return !pathe.isAbsolute(dep) || !pathe.extname(dep);
184
- }
185
- shouldInterop(path, mod) {
186
- if (this.options.interopDefault === false)
187
- return false;
188
- return !path.endsWith(".mjs") && "default" in mod;
189
- }
190
- async interopedImport(path) {
191
- const mod = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path);
192
- if (this.shouldInterop(path, mod)) {
193
- const tryDefault = this.hasNestedDefault(mod);
194
- return new Proxy(mod, {
195
- get: proxyMethod("get", tryDefault),
196
- set: proxyMethod("set", tryDefault),
197
- has: proxyMethod("has", tryDefault),
198
- deleteProperty: proxyMethod("deleteProperty", tryDefault)
199
- });
200
- }
201
- return mod;
202
- }
203
- hasNestedDefault(target) {
204
- return "__esModule" in target && target.__esModule && "default" in target.default;
205
- }
206
- debugLog(msg) {
207
- if (this.debug)
208
- console.log(`[vite-node] ${msg()}`);
209
- }
210
- }
211
- function proxyMethod(name, tryDefault) {
212
- return function(target, key, ...args) {
213
- const result = Reflect[name](target, key, ...args);
214
- if (utils.isPrimitive(target.default))
215
- return result;
216
- if (tryDefault && key === "default" || typeof result === "undefined")
217
- return Reflect[name](target.default, key, ...args);
218
- return result;
219
- };
220
- }
221
- function exportAll(exports, sourceModule) {
222
- for (const key in sourceModule) {
223
- if (key !== "default") {
224
- try {
225
- Object.defineProperty(exports, key, {
226
- enumerable: true,
227
- configurable: true,
228
- get() {
229
- return sourceModule[key];
230
- }
231
- });
232
- } catch (_err) {
233
- }
234
- }
235
- }
236
- }
237
-
238
- exports.DEFAULT_REQUEST_STUBS = DEFAULT_REQUEST_STUBS;
239
- exports.ModuleCacheMap = ModuleCacheMap;
240
- exports.ViteNodeRunner = ViteNodeRunner;
15
+ exports.DEFAULT_REQUEST_STUBS = client.DEFAULT_REQUEST_STUBS;
16
+ exports.ModuleCacheMap = client.ModuleCacheMap;
17
+ exports.ViteNodeRunner = client.ViteNodeRunner;
package/dist/client.js CHANGED
@@ -1,212 +1,7 @@
1
- import { createRequire } from 'module';
2
- import { pathToFileURL, fileURLToPath } from 'url';
3
- import vm from 'vm';
4
- import { resolve, dirname, isAbsolute, extname } from 'pathe';
5
- import { isNodeBuiltin } from 'mlly';
6
- import { normalizeModuleId, slash, normalizeRequestId, toFilePath, isPrimitive } from './utils.js';
7
-
8
- const DEFAULT_REQUEST_STUBS = {
9
- "/@vite/client": {
10
- injectQuery: (id) => id,
11
- createHotContext() {
12
- return {
13
- accept: () => {
14
- },
15
- prune: () => {
16
- },
17
- dispose: () => {
18
- },
19
- decline: () => {
20
- },
21
- invalidate: () => {
22
- },
23
- on: () => {
24
- }
25
- };
26
- },
27
- updateStyle() {
28
- }
29
- }
30
- };
31
- class ModuleCacheMap extends Map {
32
- normalizePath(fsPath) {
33
- return normalizeModuleId(fsPath);
34
- }
35
- set(fsPath, mod) {
36
- fsPath = this.normalizePath(fsPath);
37
- if (!super.has(fsPath))
38
- super.set(fsPath, mod);
39
- else
40
- Object.assign(super.get(fsPath), mod);
41
- return this;
42
- }
43
- get(fsPath) {
44
- fsPath = this.normalizePath(fsPath);
45
- return super.get(fsPath);
46
- }
47
- delete(fsPath) {
48
- fsPath = this.normalizePath(fsPath);
49
- return super.delete(fsPath);
50
- }
51
- }
52
- class ViteNodeRunner {
53
- constructor(options) {
54
- this.options = options;
55
- this.root = options.root ?? process.cwd();
56
- this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
57
- this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG : false);
58
- }
59
- async executeFile(file) {
60
- return await this.cachedRequest(`/@fs/${slash(resolve(file))}`, []);
61
- }
62
- async executeId(id) {
63
- return await this.cachedRequest(id, []);
64
- }
65
- async cachedRequest(rawId, callstack) {
66
- var _a, _b;
67
- const id = normalizeRequestId(rawId, this.options.base);
68
- const fsPath = toFilePath(id, this.root);
69
- if ((_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.promise)
70
- return (_b = this.moduleCache.get(fsPath)) == null ? void 0 : _b.promise;
71
- const promise = this.directRequest(id, fsPath, callstack);
72
- this.moduleCache.set(fsPath, { promise });
73
- return await promise;
74
- }
75
- async directRequest(id, fsPath, _callstack) {
76
- const callstack = [..._callstack, normalizeModuleId(id)];
77
- const request = async (dep) => {
78
- var _a, _b;
79
- const getStack = () => {
80
- return `stack:
81
- ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`;
82
- };
83
- if (this.options.resolveId && this.shouldResolveId(dep)) {
84
- const resolvedDep = await this.options.resolveId(dep, id);
85
- dep = ((_a = resolvedDep == null ? void 0 : resolvedDep.id) == null ? void 0 : _a.replace(this.root, "")) || dep;
86
- }
87
- let debugTimer;
88
- if (this.debug)
89
- debugTimer = setTimeout(() => this.debugLog(() => `module ${dep} takes over 2s to load.
90
- ${getStack()}`), 2e3);
91
- try {
92
- if (callstack.includes(normalizeModuleId(dep))) {
93
- this.debugLog(() => `circular dependency, ${getStack()}`);
94
- const depExports = (_b = this.moduleCache.get(dep)) == null ? void 0 : _b.exports;
95
- if (depExports)
96
- return depExports;
97
- throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
98
- }
99
- const mod = await this.cachedRequest(dep, callstack);
100
- return mod;
101
- } finally {
102
- if (debugTimer)
103
- clearTimeout(debugTimer);
104
- }
105
- };
106
- const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
107
- if (id in requestStubs)
108
- return requestStubs[id];
109
- const { code: transformed, externalize } = await this.options.fetchModule(id);
110
- if (externalize) {
111
- const mod = await this.interopedImport(externalize);
112
- this.moduleCache.set(fsPath, { exports: mod });
113
- return mod;
114
- }
115
- if (transformed == null)
116
- throw new Error(`[vite-node] Failed to load ${id}`);
117
- const url = pathToFileURL(fsPath).href;
118
- const exports = /* @__PURE__ */ Object.create(null);
119
- exports[Symbol.toStringTag] = "Module";
120
- this.moduleCache.set(id, { code: transformed, exports });
121
- const __filename = fileURLToPath(url);
122
- const moduleProxy = {
123
- set exports(value) {
124
- exportAll(exports, value);
125
- exports.default = value;
126
- },
127
- get exports() {
128
- return exports.default;
129
- }
130
- };
131
- const context = this.prepareContext({
132
- __vite_ssr_import__: request,
133
- __vite_ssr_dynamic_import__: request,
134
- __vite_ssr_exports__: exports,
135
- __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
136
- __vite_ssr_import_meta__: { url },
137
- require: createRequire(url),
138
- exports,
139
- module: moduleProxy,
140
- __filename,
141
- __dirname: dirname(__filename)
142
- });
143
- const fn = vm.runInThisContext(`'use strict';async (${Object.keys(context).join(",")})=>{{${transformed}
144
- }}`, {
145
- filename: fsPath,
146
- lineOffset: 0
147
- });
148
- await fn(...Object.values(context));
149
- return exports;
150
- }
151
- prepareContext(context) {
152
- return context;
153
- }
154
- shouldResolveId(dep) {
155
- if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS))
156
- return false;
157
- return !isAbsolute(dep) || !extname(dep);
158
- }
159
- shouldInterop(path, mod) {
160
- if (this.options.interopDefault === false)
161
- return false;
162
- return !path.endsWith(".mjs") && "default" in mod;
163
- }
164
- async interopedImport(path) {
165
- const mod = await import(path);
166
- if (this.shouldInterop(path, mod)) {
167
- const tryDefault = this.hasNestedDefault(mod);
168
- return new Proxy(mod, {
169
- get: proxyMethod("get", tryDefault),
170
- set: proxyMethod("set", tryDefault),
171
- has: proxyMethod("has", tryDefault),
172
- deleteProperty: proxyMethod("deleteProperty", tryDefault)
173
- });
174
- }
175
- return mod;
176
- }
177
- hasNestedDefault(target) {
178
- return "__esModule" in target && target.__esModule && "default" in target.default;
179
- }
180
- debugLog(msg) {
181
- if (this.debug)
182
- console.log(`[vite-node] ${msg()}`);
183
- }
184
- }
185
- function proxyMethod(name, tryDefault) {
186
- return function(target, key, ...args) {
187
- const result = Reflect[name](target, key, ...args);
188
- if (isPrimitive(target.default))
189
- return result;
190
- if (tryDefault && key === "default" || typeof result === "undefined")
191
- return Reflect[name](target.default, key, ...args);
192
- return result;
193
- };
194
- }
195
- function exportAll(exports, sourceModule) {
196
- for (const key in sourceModule) {
197
- if (key !== "default") {
198
- try {
199
- Object.defineProperty(exports, key, {
200
- enumerable: true,
201
- configurable: true,
202
- get() {
203
- return sourceModule[key];
204
- }
205
- });
206
- } catch (_err) {
207
- }
208
- }
209
- }
210
- }
211
-
212
- export { DEFAULT_REQUEST_STUBS, ModuleCacheMap, ViteNodeRunner };
1
+ export { D as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, V as ViteNodeRunner } from './client-b20a0596.js';
2
+ import 'module';
3
+ import 'url';
4
+ import 'vm';
5
+ import 'pathe';
6
+ import 'mlly';
7
+ import './utils-0290448b.js';
@@ -0,0 +1,195 @@
1
+ 'use strict';
2
+
3
+ var pathe = require('pathe');
4
+ var fs = require('fs');
5
+ var mlly = require('mlly');
6
+ var utils = require('./utils-5d86aff6.js');
7
+
8
+ const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
9
+ const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
10
+ const defaultInline = [
11
+ /virtual:/,
12
+ /\.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 (fs.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, "/$1")
35
+ ]) {
36
+ if (fs.existsSync(i))
37
+ return i;
38
+ }
39
+ }
40
+ }
41
+ async function shouldExternalize(id, options, cache = /* @__PURE__ */ new Map()) {
42
+ if (!cache.has(id))
43
+ cache.set(id, _shouldExternalize(id, options));
44
+ return cache.get(id);
45
+ }
46
+ async function _shouldExternalize(id, options) {
47
+ if (mlly.isNodeBuiltin(id))
48
+ return id;
49
+ if (id.startsWith("data:"))
50
+ return id;
51
+ id = patchWindowsImportPath(id);
52
+ if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
53
+ return false;
54
+ if (matchExternalizePattern(id, options == null ? void 0 : options.external))
55
+ return id;
56
+ const isNodeModule = id.includes("/node_modules/");
57
+ const guessCJS = isNodeModule && (options == null ? void 0 : options.fallbackCJS);
58
+ id = guessCJS ? guessCJSversion(id) || id : id;
59
+ if (matchExternalizePattern(id, defaultInline))
60
+ return false;
61
+ if (matchExternalizePattern(id, depsExternal))
62
+ return id;
63
+ const isDist = id.includes("/dist/");
64
+ if ((isNodeModule || isDist) && await mlly.isValidNodeImport(id))
65
+ return id;
66
+ return false;
67
+ }
68
+ function matchExternalizePattern(id, patterns) {
69
+ if (!patterns)
70
+ return false;
71
+ for (const ex of patterns) {
72
+ if (typeof ex === "string") {
73
+ if (id.includes(`/node_modules/${ex}/`))
74
+ return true;
75
+ } else {
76
+ if (ex.test(id))
77
+ return true;
78
+ }
79
+ }
80
+ return false;
81
+ }
82
+ function patchWindowsImportPath(path) {
83
+ if (path.match(/^\w:\\/))
84
+ return `file:///${utils.slash(path)}`;
85
+ else if (path.match(/^\w:\//))
86
+ return `file:///${path}`;
87
+ else
88
+ return path;
89
+ }
90
+
91
+ var __defProp = Object.defineProperty;
92
+ var __defProps = Object.defineProperties;
93
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
94
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
95
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
96
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
97
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
98
+ var __spreadValues = (a, b) => {
99
+ for (var prop in b || (b = {}))
100
+ if (__hasOwnProp.call(b, prop))
101
+ __defNormalProp(a, prop, b[prop]);
102
+ if (__getOwnPropSymbols)
103
+ for (var prop of __getOwnPropSymbols(b)) {
104
+ if (__propIsEnum.call(b, prop))
105
+ __defNormalProp(a, prop, b[prop]);
106
+ }
107
+ return a;
108
+ };
109
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
110
+ const RealDate = Date;
111
+ class ViteNodeServer {
112
+ constructor(server, options = {}) {
113
+ this.server = server;
114
+ this.options = options;
115
+ this.fetchPromiseMap = /* @__PURE__ */ new Map();
116
+ this.transformPromiseMap = /* @__PURE__ */ new Map();
117
+ this.fetchCache = /* @__PURE__ */ new Map();
118
+ }
119
+ shouldExternalize(id) {
120
+ return shouldExternalize(id, this.options.deps);
121
+ }
122
+ async resolveId(id, importer) {
123
+ if (importer && !importer.startsWith(this.server.config.root))
124
+ importer = pathe.join(this.server.config.root, importer);
125
+ return this.server.pluginContainer.resolveId(id, importer, { ssr: true });
126
+ }
127
+ async fetchModule(id) {
128
+ if (!this.fetchPromiseMap.has(id)) {
129
+ this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => {
130
+ return this.options.sourcemap !== true ? __spreadProps(__spreadValues({}, r), { map: void 0 }) : r;
131
+ }).finally(() => {
132
+ this.fetchPromiseMap.delete(id);
133
+ }));
134
+ }
135
+ return this.fetchPromiseMap.get(id);
136
+ }
137
+ async transformRequest(id) {
138
+ if (!this.transformPromiseMap.has(id)) {
139
+ this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
140
+ this.transformPromiseMap.delete(id);
141
+ }));
142
+ }
143
+ return this.transformPromiseMap.get(id);
144
+ }
145
+ getTransformMode(id) {
146
+ var _a, _b, _c, _d;
147
+ const withoutQuery = id.split("?")[0];
148
+ if ((_b = (_a = this.options.transformMode) == null ? void 0 : _a.web) == null ? void 0 : _b.some((r) => withoutQuery.match(r)))
149
+ return "web";
150
+ if ((_d = (_c = this.options.transformMode) == null ? void 0 : _c.ssr) == null ? void 0 : _d.some((r) => withoutQuery.match(r)))
151
+ return "ssr";
152
+ if (withoutQuery.match(/\.([cm]?[jt]sx?|json)$/))
153
+ return "ssr";
154
+ return "web";
155
+ }
156
+ async _fetchModule(id) {
157
+ let result;
158
+ const filePath = utils.toFilePath(id, this.server.config.root);
159
+ const module = this.server.moduleGraph.getModuleById(id);
160
+ const timestamp = (module == null ? void 0 : module.lastHMRTimestamp) || RealDate.now();
161
+ const cache = this.fetchCache.get(filePath);
162
+ if (timestamp && cache && cache.timestamp >= timestamp)
163
+ return cache.result;
164
+ const externalize = await this.shouldExternalize(filePath);
165
+ if (externalize) {
166
+ result = { externalize };
167
+ } else {
168
+ const r = await this._transformRequest(id);
169
+ result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
170
+ }
171
+ this.fetchCache.set(filePath, {
172
+ timestamp,
173
+ result
174
+ });
175
+ return result;
176
+ }
177
+ async _transformRequest(id) {
178
+ let result = null;
179
+ if (this.getTransformMode(id) === "web") {
180
+ result = await this.server.transformRequest(id);
181
+ if (result)
182
+ result = await this.server.ssrTransform(result.code, result.map, id);
183
+ } else {
184
+ result = await this.server.transformRequest(id, { ssr: true });
185
+ }
186
+ const sourcemap = this.options.sourcemap ?? "inline";
187
+ if (sourcemap === "inline" && result && !id.includes("node_modules"))
188
+ utils.withInlineSourcemap(result);
189
+ return result;
190
+ }
191
+ }
192
+
193
+ exports.ViteNodeServer = ViteNodeServer;
194
+ exports.guessCJSversion = guessCJSversion;
195
+ exports.shouldExternalize = shouldExternalize;