vite-node 4.0.0-beta.8 → 5.0.0-beta.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/cli.cjs DELETED
@@ -1,114 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('node:path');
4
- var cac = require('cac');
5
- var browser = require('./chunk-browser.cjs');
6
- var vite = require('vite');
7
- var client = require('./client.cjs');
8
- var hmr = require('./chunk-hmr.cjs');
9
- var server = require('./server.cjs');
10
- var sourceMap = require('./source-map.cjs');
11
- var utils = require('./utils.cjs');
12
- require('node:module');
13
- require('node:url');
14
- require('node:vm');
15
- require('debug');
16
- require('pathe');
17
- require('node:fs');
18
- require('node:events');
19
- require('node:assert');
20
- require('node:perf_hooks');
21
- require('es-module-lexer');
22
- require('./constants.cjs');
23
-
24
- var version = "4.0.0-beta.8";
25
-
26
- const cli = cac("vite-node");
27
- if (cli.option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-m, --mode <mode>", "Set env mode").option("-w, --watch", "Restart on file changes, similar to \"nodemon\"").option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command"), cli.command("[...files]").allowUnknownOptions().action(run), cli.parse(process.argv, { run: false }), cli.args.length === 0) cli.runMatchedCommand();
28
- else {
29
- const i = cli.rawArgs.indexOf(cli.args[0]) + 1, scriptArgs = cli.rawArgs.slice(i).filter((it) => it !== "--"), executeArgs = [
30
- ...cli.rawArgs.slice(0, i),
31
- "--",
32
- ...scriptArgs
33
- ];
34
- cli.parse(executeArgs);
35
- }
36
- async function run(files, options = {}) {
37
- var _server$emitter;
38
- if (options.script) files = [files[0]], options = {}, process.argv = [
39
- process.argv[0],
40
- path.resolve(files[0]),
41
- ...process.argv.slice(2).filter((arg) => arg !== "--script" && arg !== files[0])
42
- ];
43
- else process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
44
- if (options.version) cli.version(version), cli.outputVersion(), process.exit(0);
45
- if (options.help) cli.version(version).outputHelp(), process.exit(0);
46
- if (!files.length) console.error(browser.s.red("No files specified.")), cli.version(version).outputHelp(), process.exit(1);
47
- const serverOptions = options.options ? parseServerOptions(options.options) : {}, server$1 = await vite.createServer({
48
- logLevel: "error",
49
- configFile: options.config,
50
- root: options.root,
51
- mode: options.mode,
52
- server: {
53
- hmr: !!options.watch,
54
- watch: options.watch ? void 0 : null
55
- },
56
- plugins: [options.watch && hmr.viteNodeHmrPlugin()]
57
- });
58
- if (Number(vite.version.split(".")[0]) < 6) await server$1.pluginContainer.buildStart({});
59
- else
60
- // directly access client plugin container until https://github.com/vitejs/vite/issues/19607
61
- await server$1.environments.client.pluginContainer.buildStart({});
62
- const env = vite.loadEnv(server$1.config.mode, server$1.config.envDir, "");
63
- for (const key in env) {
64
- var _process$env;
65
- (_process$env = process.env)[key] ?? (_process$env[key] = env[key]);
66
- }
67
- const node = new server.ViteNodeServer(server$1, serverOptions);
68
- sourceMap.installSourcemapsSupport({ getSourceMap: (source) => node.getSourceMap(source) });
69
- const runner = new client.ViteNodeRunner({
70
- root: server$1.config.root,
71
- base: server$1.config.base,
72
- fetchModule(id) {
73
- return node.fetchModule(id);
74
- },
75
- resolveId(id, importer) {
76
- return node.resolveId(id, importer);
77
- },
78
- createHotContext(runner, url) {
79
- return hmr.createHotContext(runner, server$1.emitter, files, url);
80
- }
81
- });
82
- // provide the vite define variable in this context
83
- await runner.executeId("/@vite/env");
84
- for (const file of files) await runner.executeFile(file);
85
- if (!options.watch) await server$1.close();
86
- if ((_server$emitter = server$1.emitter) === null || _server$emitter === void 0 || _server$emitter.on("message", (payload) => {
87
- hmr.handleMessage(runner, server$1.emitter, files, payload);
88
- }), options.watch) process.on("uncaughtException", (err) => {
89
- console.error(browser.s.red("[vite-node] Failed to execute file: \n"), err);
90
- });
91
- }
92
- function parseServerOptions(serverOptions) {
93
- var _serverOptions$deps, _serverOptions$deps2, _serverOptions$deps3, _serverOptions$deps4, _serverOptions$deps5, _serverOptions$deps6, _serverOptions$transf, _serverOptions$transf2;
94
- const inlineOptions = ((_serverOptions$deps = serverOptions.deps) === null || _serverOptions$deps === void 0 ? void 0 : _serverOptions$deps.inline) === true ? true : utils.toArray((_serverOptions$deps2 = serverOptions.deps) === null || _serverOptions$deps2 === void 0 ? void 0 : _serverOptions$deps2.inline);
95
- return {
96
- ...serverOptions,
97
- deps: {
98
- ...serverOptions.deps,
99
- inlineFiles: utils.toArray((_serverOptions$deps3 = serverOptions.deps) === null || _serverOptions$deps3 === void 0 ? void 0 : _serverOptions$deps3.inlineFiles),
100
- inline: inlineOptions !== true ? inlineOptions.map((dep) => {
101
- return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
102
- }) : true,
103
- external: utils.toArray((_serverOptions$deps4 = serverOptions.deps) === null || _serverOptions$deps4 === void 0 ? void 0 : _serverOptions$deps4.external).map((dep) => {
104
- return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
105
- }),
106
- moduleDirectories: ((_serverOptions$deps5 = serverOptions.deps) === null || _serverOptions$deps5 === void 0 ? void 0 : _serverOptions$deps5.moduleDirectories) ? utils.toArray((_serverOptions$deps6 = serverOptions.deps) === null || _serverOptions$deps6 === void 0 ? void 0 : _serverOptions$deps6.moduleDirectories) : void 0
107
- },
108
- transformMode: {
109
- ...serverOptions.transformMode,
110
- ssr: utils.toArray((_serverOptions$transf = serverOptions.transformMode) === null || _serverOptions$transf === void 0 ? void 0 : _serverOptions$transf.ssr).map((dep) => new RegExp(dep)),
111
- web: utils.toArray((_serverOptions$transf2 = serverOptions.transformMode) === null || _serverOptions$transf2 === void 0 ? void 0 : _serverOptions$transf2.web).map((dep) => new RegExp(dep))
112
- }
113
- };
114
- }
package/dist/client.cjs DELETED
@@ -1,447 +0,0 @@
1
- 'use strict';
2
-
3
- var node_module = require('node:module');
4
- var path = require('node:path');
5
- var node_url = require('node:url');
6
- var vm = require('node:vm');
7
- var createDebug = require('debug');
8
- var sourceMap = require('./source-map.cjs');
9
- var utils = require('./utils.cjs');
10
- require('pathe');
11
- require('node:fs');
12
-
13
- const { setTimeout, clearTimeout } = globalThis, debugExecute = createDebug("vite-node:client:execute"), debugNative = createDebug("vite-node:client:native"), clientStub = {
14
- injectQuery: (id) => id,
15
- createHotContext: () => {
16
- return {
17
- accept: () => {},
18
- prune: () => {},
19
- dispose: () => {},
20
- decline: () => {},
21
- invalidate: () => {},
22
- on: () => {},
23
- send: () => {}
24
- };
25
- },
26
- updateStyle: () => {},
27
- removeStyle: () => {}
28
- }, env = utils.createImportMetaEnvProxy();
29
- const DEFAULT_REQUEST_STUBS = {
30
- "/@vite/client": clientStub,
31
- "@vite/client": clientStub
32
- };
33
- class ModuleCacheMap extends Map {
34
- normalizePath(fsPath) {
35
- return utils.normalizeModuleId(fsPath);
36
- }
37
- /**
38
- * Assign partial data to the map
39
- */
40
- update(fsPath, mod) {
41
- if (fsPath = this.normalizePath(fsPath), !super.has(fsPath)) this.setByModuleId(fsPath, mod);
42
- else Object.assign(super.get(fsPath), mod);
43
- return this;
44
- }
45
- setByModuleId(modulePath, mod) {
46
- return super.set(modulePath, mod);
47
- }
48
- set(fsPath, mod) {
49
- return this.setByModuleId(this.normalizePath(fsPath), mod);
50
- }
51
- getByModuleId(modulePath) {
52
- if (!super.has(modulePath)) this.setByModuleId(modulePath, {});
53
- const mod = super.get(modulePath);
54
- if (!mod.imports) Object.assign(mod, {
55
- imports: /* @__PURE__ */ new Set(),
56
- importers: /* @__PURE__ */ new Set()
57
- });
58
- return mod;
59
- }
60
- get(fsPath) {
61
- return this.getByModuleId(this.normalizePath(fsPath));
62
- }
63
- deleteByModuleId(modulePath) {
64
- return super.delete(modulePath);
65
- }
66
- delete(fsPath) {
67
- return this.deleteByModuleId(this.normalizePath(fsPath));
68
- }
69
- invalidateModule(mod) {
70
- var _mod$importers, _mod$imports;
71
- return delete mod.evaluated, delete mod.resolving, delete mod.promise, delete mod.exports, (_mod$importers = mod.importers) === null || _mod$importers === void 0 || _mod$importers.clear(), (_mod$imports = mod.imports) === null || _mod$imports === void 0 || _mod$imports.clear(), true;
72
- }
73
- /**
74
- * Invalidate modules that dependent on the given modules, up to the main entry
75
- */
76
- invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
77
- for (const _id of ids) {
78
- const id = this.normalizePath(_id);
79
- if (invalidated.has(id)) continue;
80
- invalidated.add(id);
81
- const mod = super.get(id);
82
- if (mod === null || mod === void 0 ? void 0 : mod.importers) this.invalidateDepTree(mod.importers, invalidated);
83
- super.delete(id);
84
- }
85
- return invalidated;
86
- }
87
- /**
88
- * Invalidate dependency modules of the given modules, down to the bottom-level dependencies
89
- */
90
- invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
91
- for (const _id of ids) {
92
- const id = this.normalizePath(_id);
93
- if (invalidated.has(id)) continue;
94
- invalidated.add(id);
95
- const subIds = Array.from(super.entries()).filter(([, mod]) => {
96
- var _mod$importers2;
97
- return (_mod$importers2 = mod.importers) === null || _mod$importers2 === void 0 ? void 0 : _mod$importers2.has(id);
98
- }).map(([key]) => key);
99
- if (subIds.length) this.invalidateSubDepTree(subIds, invalidated);
100
- super.delete(id);
101
- }
102
- return invalidated;
103
- }
104
- /**
105
- * Return parsed source map based on inlined source map of the module
106
- */
107
- getSourceMap(id) {
108
- const cache = this.get(id);
109
- if (cache.map) return cache.map;
110
- const map = cache.code && sourceMap.extractSourceMap(cache.code);
111
- return map ? (cache.map = map, map) : null;
112
- }
113
- }
114
- class ViteNodeRunner {
115
- root;
116
- debug;
117
- /**
118
- * Holds the cache of modules
119
- * Keys of the map are filepaths, or plain package names
120
- */
121
- moduleCache;
122
- /**
123
- * Tracks the stack of modules being executed for the purpose of calculating import self-time.
124
- *
125
- * Note that while in most cases, imports are a linear stack of modules,
126
- * this is occasionally not the case, for example when you have parallel top-level dynamic imports like so:
127
- *
128
- * ```ts
129
- * await Promise.all([
130
- * import('./module1'),
131
- * import('./module2'),
132
- * ]);
133
- * ```
134
- *
135
- * In this case, the self time will be reported incorrectly for one of the modules (could go negative).
136
- * As top-level awaits with dynamic imports like this are uncommon, we don't handle this case specifically.
137
- */
138
- executionStack = [];
139
- // `performance` can be mocked, so make sure we're using the original function
140
- performanceNow = performance.now.bind(performance);
141
- constructor(options) {
142
- this.options = options, this.root = options.root ?? process.cwd(), this.moduleCache = options.moduleCache ?? new ModuleCacheMap(), this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
143
- }
144
- async executeFile(file) {
145
- const url = `/@fs/${utils.slash(path.resolve(file))}`;
146
- return await this.cachedRequest(url, url, []);
147
- }
148
- async executeId(rawId) {
149
- const [id, url] = await this.resolveUrl(rawId);
150
- return await this.cachedRequest(id, url, []);
151
- }
152
- /** @internal */
153
- async cachedRequest(id, fsPath, callstack) {
154
- const importee = callstack[callstack.length - 1], mod = this.moduleCache.get(fsPath), { imports, importers } = mod;
155
- if (importee) importers.add(importee);
156
- const getStack = () => `stack:\n${[...callstack, fsPath].reverse().map((p) => ` - ${p}`).join("\n")}`;
157
- // check circular dependency
158
- if (callstack.includes(fsPath) || Array.from(imports.values()).some((i) => importers.has(i))) {
159
- if (mod.exports) return mod.exports;
160
- }
161
- let debugTimer;
162
- if (this.debug) debugTimer = setTimeout(() => console.warn(`[vite-node] module ${fsPath} takes over 2s to load.\n${getStack()}`), 2e3);
163
- try {
164
- // cached module
165
- if (mod.promise) return await mod.promise;
166
- const promise = this.directRequest(id, fsPath, callstack);
167
- return Object.assign(mod, {
168
- promise,
169
- evaluated: false
170
- }), await promise;
171
- } finally {
172
- if (mod.evaluated = true, debugTimer) clearTimeout(debugTimer);
173
- }
174
- }
175
- shouldResolveId(id, _importee) {
176
- return !utils.isInternalRequest(id) && !utils.isNodeBuiltin(id) && !id.startsWith("data:");
177
- }
178
- async _resolveUrl(id, importer) {
179
- var _resolved$meta;
180
- const dep = utils.normalizeRequestId(id, this.options.base);
181
- if (!this.shouldResolveId(dep)) return [dep, dep];
182
- const { path, exists } = utils.toFilePath(dep, this.root);
183
- if (!this.options.resolveId || exists) return [dep, path];
184
- const resolved = await this.options.resolveId(dep, importer);
185
- // supported since Vite 5-beta.19
186
- if (resolved === null || resolved === void 0 || (_resolved$meta = resolved.meta) === null || _resolved$meta === void 0 || (_resolved$meta = _resolved$meta["vite:alias"]) === null || _resolved$meta === void 0 ? void 0 : _resolved$meta.noResolved) {
187
- const error = /* @__PURE__ */ new Error(`Cannot find module '${id}'${importer ? ` imported from '${importer}'` : ""}.
188
-
189
- - If you rely on tsconfig.json's "paths" to resolve modules, please install "vite-tsconfig-paths" plugin to handle module resolution.
190
- - Make sure you don't have relative aliases in your Vitest config. Use absolute paths instead. Read more: https://vitest.dev/guide/common-errors`);
191
- throw Object.defineProperty(error, "code", {
192
- value: "ERR_MODULE_NOT_FOUND",
193
- enumerable: true
194
- }), Object.defineProperty(error, Symbol.for("vitest.error.not_found.data"), {
195
- value: {
196
- id: dep,
197
- importer
198
- },
199
- enumerable: false
200
- }), error;
201
- }
202
- const resolvedId = resolved ? utils.normalizeRequestId(resolved.id, this.options.base) : dep;
203
- return [resolvedId, resolvedId];
204
- }
205
- async resolveUrl(id, importee) {
206
- const resolveKey = `resolve:${id}`;
207
- // put info about new import as soon as possible, so we can start tracking it
208
- this.moduleCache.setByModuleId(resolveKey, { resolving: true });
209
- try {
210
- return await this._resolveUrl(id, importee);
211
- } finally {
212
- this.moduleCache.deleteByModuleId(resolveKey);
213
- }
214
- }
215
- /** @internal */
216
- async dependencyRequest(id, fsPath, callstack) {
217
- return await this.cachedRequest(id, fsPath, callstack);
218
- }
219
- async _fetchModule(id, importer) {
220
- try {
221
- return await this.options.fetchModule(id);
222
- } catch (cause) {
223
- // rethrow vite error if it cannot load the module because it's not resolved
224
- if (typeof cause === "object" && cause.code === "ERR_LOAD_URL" || typeof (cause === null || cause === void 0 ? void 0 : cause.message) === "string" && cause.message.includes("Failed to load url")) {
225
- const error = new Error(`Cannot find ${utils.isBareImport(id) ? "package" : "module"} '${id}'${importer ? ` imported from '${importer}'` : ""}`, { cause });
226
- throw error.code = "ERR_MODULE_NOT_FOUND", error;
227
- }
228
- throw cause;
229
- }
230
- }
231
- /** @internal */
232
- async directRequest(id, fsPath, _callstack) {
233
- const moduleId = utils.normalizeModuleId(fsPath), callstack = [..._callstack, moduleId], mod = this.moduleCache.getByModuleId(moduleId), request = async (dep) => {
234
- const [id, depFsPath] = await this.resolveUrl(String(dep), fsPath), depMod = this.moduleCache.getByModuleId(depFsPath);
235
- return depMod.importers.add(moduleId), mod.imports.add(depFsPath), this.dependencyRequest(id, depFsPath, callstack);
236
- }, requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
237
- if (id in requestStubs) return requestStubs[id];
238
- let { code: transformed, externalize } = await this._fetchModule(id, callstack[callstack.length - 2]);
239
- if (externalize) {
240
- debugNative(externalize);
241
- const exports = await this.interopedImport(externalize);
242
- return mod.exports = exports, exports;
243
- }
244
- if (transformed == null) throw new Error(`[vite-node] Failed to load "${id}" imported from ${callstack[callstack.length - 2]}`);
245
- const { Object, Reflect, Symbol } = this.getContextPrimitives(), modulePath = utils.cleanUrl(moduleId), href = node_url.pathToFileURL(modulePath).href, __filename = node_url.fileURLToPath(href), __dirname = path.dirname(__filename), meta = {
246
- url: href,
247
- env,
248
- filename: __filename,
249
- dirname: __dirname
250
- }, exports = Object.create(null);
251
- Object.defineProperty(exports, Symbol.toStringTag, {
252
- value: "Module",
253
- enumerable: false,
254
- configurable: false
255
- });
256
- const SYMBOL_NOT_DEFINED = Symbol("not defined");
257
- let moduleExports = SYMBOL_NOT_DEFINED;
258
- // this proxy is triggered only on exports.{name} and module.exports access
259
- // inside the module itself. imported module is always "exports"
260
- const cjsExports = new Proxy(exports, {
261
- get: (target, p, receiver) => {
262
- return Reflect.has(target, p) ? Reflect.get(target, p, receiver) : Reflect.get(Object.prototype, p, receiver);
263
- },
264
- getPrototypeOf: () => Object.prototype,
265
- set: (_, p, value) => {
266
- // treat "module.exports =" the same as "exports.default =" to not have nested "default.default",
267
- // so "exports.default" becomes the actual module
268
- if (p === "default" && this.shouldInterop(modulePath, { default: value }) && cjsExports !== value) return exportAll(cjsExports, value), exports.default = value, true;
269
- if (!Reflect.has(exports, "default")) exports.default = {};
270
- // returns undefined, when accessing named exports, if default is not an object
271
- // but is still present inside hasOwnKeys, this is Node behaviour for CJS
272
- if (moduleExports !== SYMBOL_NOT_DEFINED && utils.isPrimitive(moduleExports)) return defineExport(exports, p, () => void 0), true;
273
- if (!utils.isPrimitive(exports.default)) exports.default[p] = value;
274
- if (p !== "default") defineExport(exports, p, () => value);
275
- return true;
276
- }
277
- });
278
- Object.assign(mod, {
279
- code: transformed,
280
- exports
281
- });
282
- const moduleProxy = {
283
- set exports(value) {
284
- exportAll(cjsExports, value), exports.default = value, moduleExports = value;
285
- },
286
- get exports() {
287
- return cjsExports;
288
- }
289
- };
290
- // Vite hot context
291
- let hotContext;
292
- if (this.options.createHotContext) Object.defineProperty(meta, "hot", {
293
- enumerable: true,
294
- get: () => {
295
- var _this$options$createH, _this$options;
296
- return hotContext || (hotContext = (_this$options$createH = (_this$options = this.options).createHotContext) === null || _this$options$createH === void 0 ? void 0 : _this$options$createH.call(_this$options, this, moduleId)), hotContext;
297
- },
298
- set: (value) => {
299
- hotContext = value;
300
- }
301
- });
302
- // Be careful when changing this
303
- // changing context will change amount of code added on line :114 (vm.runInThisContext)
304
- // this messes up sourcemaps for coverage
305
- // adjust `WRAPPER_LENGTH` variable in packages/coverage-v8/src/provider.ts if you do change this
306
- const context = this.prepareContext({
307
- __vite_ssr_import__: request,
308
- __vite_ssr_dynamic_import__: request,
309
- __vite_ssr_exports__: exports,
310
- __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
311
- __vite_ssr_exportName__: (name, getter) => Object.defineProperty(exports, name, {
312
- enumerable: true,
313
- configurable: true,
314
- get: getter
315
- }),
316
- __vite_ssr_import_meta__: meta,
317
- require: node_module.createRequire(href),
318
- exports: cjsExports,
319
- module: moduleProxy,
320
- __filename,
321
- __dirname
322
- });
323
- // remove shebang
324
- if (debugExecute(__filename), transformed[0] === "#") transformed = transformed.replace(/^#!.*/, (s) => " ".repeat(s.length));
325
- return await this.runModule(context, transformed), exports;
326
- }
327
- getContextPrimitives() {
328
- return {
329
- Object,
330
- Reflect,
331
- Symbol
332
- };
333
- }
334
- async runModule(context, transformed) {
335
- // add 'use strict' since ESM enables it by default
336
- const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`, code = `${codeDefinition}${transformed}\n}}`, options = {
337
- filename: context.__filename,
338
- lineOffset: 0,
339
- columnOffset: -codeDefinition.length
340
- }, finishModuleExecutionInfo = this.startCalculateModuleExecutionInfo(options.filename, codeDefinition.length);
341
- try {
342
- const fn = vm.runInThisContext(code, options);
343
- await fn(...Object.values(context));
344
- } finally {
345
- var _this$options$moduleE;
346
- (_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, finishModuleExecutionInfo());
347
- }
348
- }
349
- /**
350
- * Starts calculating the module execution info such as the total duration and self time spent on executing the module.
351
- * Returns a function to call once the module has finished executing.
352
- */
353
- startCalculateModuleExecutionInfo(filename, startOffset) {
354
- const startTime = this.performanceNow();
355
- return this.executionStack.push({
356
- filename,
357
- startTime,
358
- subImportTime: 0
359
- }), () => {
360
- const duration = this.performanceNow() - startTime, currentExecution = this.executionStack.pop();
361
- if (currentExecution == null) throw new Error("Execution stack is empty, this should never happen");
362
- const selfTime = duration - currentExecution.subImportTime;
363
- if (this.executionStack.length > 0) this.executionStack.at(-1).subImportTime += duration;
364
- return {
365
- startOffset,
366
- duration,
367
- selfTime
368
- };
369
- };
370
- }
371
- prepareContext(context) {
372
- return context;
373
- }
374
- /**
375
- * Define if a module should be interop-ed
376
- * This function mostly for the ability to override by subclass
377
- */
378
- shouldInterop(path, mod) {
379
- // never interop ESM modules
380
- // TODO: should also skip for `.js` with `type="module"`
381
- return this.options.interopDefault === false ? false : !path.endsWith(".mjs") && "default" in mod;
382
- }
383
- importExternalModule(path) {
384
- return import(
385
- /* @vite-ignore */
386
- path
387
- );
388
- }
389
- /**
390
- * Import a module and interop it
391
- */
392
- async interopedImport(path) {
393
- const importedModule = await this.importExternalModule(path);
394
- if (!this.shouldInterop(path, importedModule)) return importedModule;
395
- const { mod, defaultExport } = interopModule(importedModule);
396
- return new Proxy(mod, {
397
- get(mod, prop) {
398
- return prop === "default" ? defaultExport : mod[prop] ?? (defaultExport === null || defaultExport === void 0 ? void 0 : defaultExport[prop]);
399
- },
400
- has(mod, prop) {
401
- return prop === "default" ? defaultExport !== void 0 : prop in mod || defaultExport && prop in defaultExport;
402
- },
403
- getOwnPropertyDescriptor(mod, prop) {
404
- const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);
405
- if (descriptor) return descriptor;
406
- if (prop === "default" && defaultExport !== void 0) return {
407
- value: defaultExport,
408
- enumerable: true,
409
- configurable: true
410
- };
411
- }
412
- });
413
- }
414
- }
415
- function interopModule(mod) {
416
- if (utils.isPrimitive(mod)) return {
417
- mod: { default: mod },
418
- defaultExport: mod
419
- };
420
- let defaultExport = "default" in mod ? mod.default : mod;
421
- if (!utils.isPrimitive(defaultExport) && "__esModule" in defaultExport) {
422
- if (mod = defaultExport, "default" in defaultExport) defaultExport = defaultExport.default;
423
- }
424
- return {
425
- mod,
426
- defaultExport
427
- };
428
- }
429
- // keep consistency with Vite on how exports are defined
430
- function defineExport(exports, key, value) {
431
- Object.defineProperty(exports, key, {
432
- enumerable: true,
433
- configurable: true,
434
- get: value
435
- });
436
- }
437
- function exportAll(exports, sourceModule) {
438
- if (exports !== sourceModule && !(utils.isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise)) {
439
- for (const key in sourceModule) if (key !== "default" && !(key in exports)) try {
440
- defineExport(exports, key, () => sourceModule[key]);
441
- } catch {}
442
- }
443
- }
444
-
445
- exports.DEFAULT_REQUEST_STUBS = DEFAULT_REQUEST_STUBS;
446
- exports.ModuleCacheMap = ModuleCacheMap;
447
- exports.ViteNodeRunner = ViteNodeRunner;
@@ -1,36 +0,0 @@
1
- 'use strict';
2
-
3
- const KNOWN_ASSET_TYPES = [
4
- "apng",
5
- "bmp",
6
- "png",
7
- "jpe?g",
8
- "jfif",
9
- "pjpeg",
10
- "pjp",
11
- "gif",
12
- "svg",
13
- "ico",
14
- "webp",
15
- "avif",
16
- "mp4",
17
- "webm",
18
- "ogg",
19
- "mp3",
20
- "wav",
21
- "flac",
22
- "aac",
23
- "woff2?",
24
- "eot",
25
- "ttf",
26
- "otf",
27
- "webmanifest",
28
- "pdf",
29
- "txt"
30
- ];
31
- const KNOWN_ASSET_RE = /* @__PURE__ */ new RegExp(`\\.(${KNOWN_ASSET_TYPES.join("|")})$`);
32
- const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
33
-
34
- exports.CSS_LANGS_RE = CSS_LANGS_RE;
35
- exports.KNOWN_ASSET_RE = KNOWN_ASSET_RE;
36
- exports.KNOWN_ASSET_TYPES = KNOWN_ASSET_TYPES;
package/dist/hmr.cjs DELETED
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- var hmr = require('./chunk-hmr.cjs');
4
- require('node:events');
5
- require('debug');
6
- require('./chunk-browser.cjs');
7
- require('./utils.cjs');
8
- require('node:fs');
9
- require('node:module');
10
- require('node:url');
11
- require('pathe');
12
-
13
-
14
-
15
- exports.createHmrEmitter = hmr.createHmrEmitter;
16
- exports.createHotContext = hmr.createHotContext;
17
- exports.getCache = hmr.getCache;
18
- exports.handleMessage = hmr.handleMessage;
19
- exports.reload = hmr.reload;
20
- exports.sendMessageBuffer = hmr.sendMessageBuffer;
21
- exports.viteNodeHmrPlugin = hmr.viteNodeHmrPlugin;
package/dist/index.cjs DELETED
@@ -1,2 +0,0 @@
1
- 'use strict';
2
-