vite-node
Advanced tools
Comparing version 0.1.21 to 0.1.22
@@ -41,3 +41,2 @@ declare type FetchFunction = (id: string) => Promise<{ | ||
root: string; | ||
externalCache: Map<string, string | Promise<false | string>>; | ||
moduleCache: Map<string, ModuleCache>; | ||
@@ -44,0 +43,0 @@ constructor(options: ViteNodeRunnerOptions); |
@@ -8,3 +8,3 @@ import minimist from 'minimist'; | ||
import { dirname, resolve } from 'pathe'; | ||
import { builtinModules, createRequire } from 'module'; | ||
import { createRequire } from 'module'; | ||
import vm from 'vm'; | ||
@@ -201,4 +201,2 @@ | ||
this.moduleCache = options.moduleCache || new Map(); | ||
this.externalCache = new Map(); | ||
builtinModules.forEach((m) => this.externalCache.set(m, m)); | ||
} | ||
@@ -214,7 +212,7 @@ async executeFile(file) { | ||
const id = normalizeId(rawId, this.options.base); | ||
if ((_a = this.moduleCache.get(id)) == null ? void 0 : _a.promise) | ||
return (_b = this.moduleCache.get(id)) == null ? void 0 : _b.promise; | ||
const fsPath = toFilePath(id, this.root); | ||
if ((_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.promise) | ||
return (_b = this.moduleCache.get(fsPath)) == null ? void 0 : _b.promise; | ||
const promise = this.directRequest(id, fsPath, callstack); | ||
this.setCache(fsPath, { promise }); | ||
this.setCache(id, { promise }); | ||
return await promise; | ||
@@ -227,8 +225,7 @@ } | ||
if (callstack.includes(dep)) { | ||
const cacheKey = toFilePath(dep, this.root); | ||
if (!((_a = this.moduleCache.get(cacheKey)) == null ? void 0 : _a.exports)) | ||
throw new Error(`Circular dependency detected | ||
if (!((_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports)) | ||
throw new Error(`[vite-node] Circular dependency detected | ||
Stack: | ||
${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`); | ||
return this.moduleCache.get(cacheKey).exports; | ||
return this.moduleCache.get(dep).exports; | ||
} | ||
@@ -243,10 +240,10 @@ return this.cachedRequest(dep, callstack); | ||
const mod = await this.interopedImport(externalize); | ||
this.setCache(fsPath, { exports: mod }); | ||
this.setCache(id, { exports: mod }); | ||
return mod; | ||
} | ||
if (transformed == null) | ||
throw new Error(`failed to load ${id}`); | ||
throw new Error(`[vite-node] Failed to load ${id}`); | ||
const url = pathToFileURL(fsPath).href; | ||
const exports = {}; | ||
this.setCache(fsPath, { code: transformed, exports }); | ||
this.setCache(id, { code: transformed, exports }); | ||
const __filename = fileURLToPath(url); | ||
@@ -253,0 +250,0 @@ const moduleProxy = { |
@@ -1,2 +0,2 @@ | ||
import { builtinModules, createRequire } from 'module'; | ||
import { createRequire } from 'module'; | ||
import { fileURLToPath, pathToFileURL } from 'url'; | ||
@@ -45,4 +45,2 @@ import vm from 'vm'; | ||
this.moduleCache = options.moduleCache || new Map(); | ||
this.externalCache = new Map(); | ||
builtinModules.forEach((m) => this.externalCache.set(m, m)); | ||
} | ||
@@ -58,7 +56,7 @@ async executeFile(file) { | ||
const id = normalizeId(rawId, this.options.base); | ||
if ((_a = this.moduleCache.get(id)) == null ? void 0 : _a.promise) | ||
return (_b = this.moduleCache.get(id)) == null ? void 0 : _b.promise; | ||
const fsPath = toFilePath(id, this.root); | ||
if ((_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.promise) | ||
return (_b = this.moduleCache.get(fsPath)) == null ? void 0 : _b.promise; | ||
const promise = this.directRequest(id, fsPath, callstack); | ||
this.setCache(fsPath, { promise }); | ||
this.setCache(id, { promise }); | ||
return await promise; | ||
@@ -71,8 +69,7 @@ } | ||
if (callstack.includes(dep)) { | ||
const cacheKey = toFilePath(dep, this.root); | ||
if (!((_a = this.moduleCache.get(cacheKey)) == null ? void 0 : _a.exports)) | ||
throw new Error(`Circular dependency detected | ||
if (!((_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports)) | ||
throw new Error(`[vite-node] Circular dependency detected | ||
Stack: | ||
${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`); | ||
return this.moduleCache.get(cacheKey).exports; | ||
return this.moduleCache.get(dep).exports; | ||
} | ||
@@ -87,10 +84,10 @@ return this.cachedRequest(dep, callstack); | ||
const mod = await this.interopedImport(externalize); | ||
this.setCache(fsPath, { exports: mod }); | ||
this.setCache(id, { exports: mod }); | ||
return mod; | ||
} | ||
if (transformed == null) | ||
throw new Error(`failed to load ${id}`); | ||
throw new Error(`[vite-node] Failed to load ${id}`); | ||
const url = pathToFileURL(fsPath).href; | ||
const exports = {}; | ||
this.setCache(fsPath, { code: transformed, exports }); | ||
this.setCache(id, { code: transformed, exports }); | ||
const __filename = fileURLToPath(url); | ||
@@ -97,0 +94,0 @@ const moduleProxy = { |
{ | ||
"name": "vite-node", | ||
"version": "0.1.21", | ||
"version": "0.1.22", | ||
"description": "Vite as Node.js runtime", | ||
@@ -54,9 +54,9 @@ "homepage": "https://github.com/vitest-dev/vitest#readme", | ||
"minimist": "^1.2.5", | ||
"mlly": "^0.3.17", | ||
"mlly": "^0.3.19", | ||
"pathe": "^0.2.0", | ||
"vite": "^2.7.12" | ||
"vite": "^2.7.13" | ||
}, | ||
"devDependencies": { | ||
"@types/minimist": "^1.2.2", | ||
"rollup": "^2.63.0" | ||
"rollup": "^2.64.0" | ||
}, | ||
@@ -63,0 +63,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
63244
1738
Updatedmlly@^0.3.19
Updatedvite@^2.7.13