vite-node
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -0,7 +1,18 @@ | ||
interface StartOfSourceMap { | ||
file?: string; | ||
sourceRoot?: string; | ||
} | ||
interface RawSourceMap extends StartOfSourceMap { | ||
version: string; | ||
sources: string[]; | ||
names: string[]; | ||
sourcesContent?: string[]; | ||
mappings: string; | ||
} | ||
interface FetchResult { | ||
code?: string; | ||
externalize?: string; | ||
map?: RawSourceMap; | ||
} | ||
declare type FetchFunction = (id: string) => Promise<FetchResult>; | ||
declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>; | ||
interface ModuleCache { | ||
@@ -14,3 +25,2 @@ promise?: Promise<any>; | ||
fetchModule: FetchFunction; | ||
resolveId: ResolveIdFunction; | ||
root: string; | ||
@@ -22,9 +32,2 @@ base?: string; | ||
} | ||
interface ViteNodeResolveId { | ||
external?: boolean | 'absolute' | 'relative'; | ||
id: string; | ||
meta?: Record<string, any> | null; | ||
moduleSideEffects?: boolean | 'no-treeshake' | null; | ||
syntheticNamedExports?: boolean | string | null; | ||
} | ||
@@ -31,0 +34,0 @@ declare const DEFAULT_REQUEST_STUBS: { |
@@ -126,2 +126,21 @@ import minimist from 'minimist'; | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
class ViteNodeServer { | ||
@@ -143,3 +162,5 @@ constructor(server, options = {}) { | ||
if (!this.fetchPromiseMap.has(id)) { | ||
this.fetchPromiseMap.set(id, this._fetchModule(id).finally(() => { | ||
this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => { | ||
return this.options.sourcemap !== true ? __spreadProps(__spreadValues({}, r), { map: void 0 }) : r; | ||
}).finally(() => { | ||
this.fetchPromiseMap.delete(id); | ||
@@ -170,9 +191,10 @@ })); | ||
async _fetchModule(id) { | ||
var _a; | ||
let result; | ||
const timestamp = (_a = this.server.moduleGraph.getModuleById(id)) == null ? void 0 : _a.lastHMRTimestamp; | ||
const cache = this.fetchCache.get(id); | ||
const filePath = toFilePath(id, this.server.config.root); | ||
const module = this.server.moduleGraph.getModuleById(id); | ||
const timestamp = (module == null ? void 0 : module.lastHMRTimestamp) || Date.now(); | ||
const cache = this.fetchCache.get(filePath); | ||
if (timestamp && cache && cache.timestamp >= timestamp) | ||
return cache.result; | ||
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root)); | ||
const externalize = await this.shouldExternalize(filePath); | ||
if (externalize) { | ||
@@ -182,10 +204,8 @@ result = { externalize }; | ||
const r = await this._transformRequest(id); | ||
result = { code: r == null ? void 0 : r.code }; | ||
result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map }; | ||
} | ||
if (timestamp) { | ||
this.fetchCache.set(id, { | ||
timestamp, | ||
result | ||
}); | ||
} | ||
this.fetchCache.set(filePath, { | ||
timestamp, | ||
result | ||
}); | ||
return result; | ||
@@ -202,3 +222,4 @@ } | ||
} | ||
if (this.options.sourcemap !== false && result && !id.includes("node_modules")) | ||
const sourcemap = this.options.sourcemap ?? "inline"; | ||
if (sourcemap === "inline" && result && !id.includes("node_modules")) | ||
withInlineSourcemap(result); | ||
@@ -420,5 +441,2 @@ return result; | ||
return node.fetchModule(id); | ||
}, | ||
resolveId(id, importer) { | ||
return node.resolveId(id, importer); | ||
} | ||
@@ -425,0 +443,0 @@ }); |
@@ -113,2 +113,21 @@ import { existsSync } from 'fs'; | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
class ViteNodeServer { | ||
@@ -130,3 +149,5 @@ constructor(server, options = {}) { | ||
if (!this.fetchPromiseMap.has(id)) { | ||
this.fetchPromiseMap.set(id, this._fetchModule(id).finally(() => { | ||
this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => { | ||
return this.options.sourcemap !== true ? __spreadProps(__spreadValues({}, r), { map: void 0 }) : r; | ||
}).finally(() => { | ||
this.fetchPromiseMap.delete(id); | ||
@@ -157,9 +178,10 @@ })); | ||
async _fetchModule(id) { | ||
var _a; | ||
let result; | ||
const timestamp = (_a = this.server.moduleGraph.getModuleById(id)) == null ? void 0 : _a.lastHMRTimestamp; | ||
const cache = this.fetchCache.get(id); | ||
const filePath = toFilePath(id, this.server.config.root); | ||
const module = this.server.moduleGraph.getModuleById(id); | ||
const timestamp = (module == null ? void 0 : module.lastHMRTimestamp) || Date.now(); | ||
const cache = this.fetchCache.get(filePath); | ||
if (timestamp && cache && cache.timestamp >= timestamp) | ||
return cache.result; | ||
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root)); | ||
const externalize = await this.shouldExternalize(filePath); | ||
if (externalize) { | ||
@@ -169,10 +191,8 @@ result = { externalize }; | ||
const r = await this._transformRequest(id); | ||
result = { code: r == null ? void 0 : r.code }; | ||
result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map }; | ||
} | ||
if (timestamp) { | ||
this.fetchCache.set(id, { | ||
timestamp, | ||
result | ||
}); | ||
} | ||
this.fetchCache.set(filePath, { | ||
timestamp, | ||
result | ||
}); | ||
return result; | ||
@@ -189,3 +209,4 @@ } | ||
} | ||
if (this.options.sourcemap !== false && result && !id.includes("node_modules")) | ||
const sourcemap = this.options.sourcemap ?? "inline"; | ||
if (sourcemap === "inline" && result && !id.includes("node_modules")) | ||
withInlineSourcemap(result); | ||
@@ -192,0 +213,0 @@ return result; |
@@ -10,8 +10,19 @@ interface DepsHandlingOptions { | ||
} | ||
interface StartOfSourceMap { | ||
file?: string; | ||
sourceRoot?: string; | ||
} | ||
interface RawSourceMap extends StartOfSourceMap { | ||
version: string; | ||
sources: string[]; | ||
names: string[]; | ||
sourcesContent?: string[]; | ||
mappings: string; | ||
} | ||
interface FetchResult { | ||
code?: string; | ||
externalize?: string; | ||
map?: RawSourceMap; | ||
} | ||
declare type FetchFunction = (id: string) => Promise<FetchResult>; | ||
declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>; | ||
interface ModuleCache { | ||
@@ -24,3 +35,2 @@ promise?: Promise<any>; | ||
fetchModule: FetchFunction; | ||
resolveId: ResolveIdFunction; | ||
root: string; | ||
@@ -42,5 +52,5 @@ base?: string; | ||
* Inject inline sourcemap to modules | ||
* @default true | ||
* @default 'inline' | ||
*/ | ||
sourcemap?: boolean; | ||
sourcemap?: 'inline' | boolean; | ||
/** | ||
@@ -59,2 +69,2 @@ * Deps handling | ||
export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, ResolveIdFunction, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions }; | ||
export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, RawSourceMap, StartOfSourceMap, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions }; |
{ | ||
"name": "vite-node", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "Vite as Node.js runtime", | ||
@@ -60,3 +60,3 @@ "homepage": "https://github.com/vitest-dev/vitest#readme", | ||
"@types/minimist": "^1.2.2", | ||
"rollup": "^2.66.1" | ||
"rollup": "^2.67.0" | ||
}, | ||
@@ -63,0 +63,0 @@ "engines": { |
import { ViteDevServer, TransformResult } from 'vite'; | ||
interface FetchResult { | ||
code?: string; | ||
externalize?: string; | ||
} | ||
interface DepsHandlingOptions { | ||
@@ -17,2 +12,18 @@ external?: (string | RegExp)[]; | ||
} | ||
interface StartOfSourceMap { | ||
file?: string; | ||
sourceRoot?: string; | ||
} | ||
interface RawSourceMap extends StartOfSourceMap { | ||
version: string; | ||
sources: string[]; | ||
names: string[]; | ||
sourcesContent?: string[]; | ||
mappings: string; | ||
} | ||
interface FetchResult { | ||
code?: string; | ||
externalize?: string; | ||
map?: RawSourceMap; | ||
} | ||
interface ViteNodeResolveId { | ||
@@ -28,5 +39,5 @@ external?: boolean | 'absolute' | 'relative'; | ||
* Inject inline sourcemap to modules | ||
* @default true | ||
* @default 'inline' | ||
*/ | ||
sourcemap?: boolean; | ||
sourcemap?: 'inline' | boolean; | ||
/** | ||
@@ -53,3 +64,6 @@ * Deps handling | ||
private transformPromiseMap; | ||
private fetchCache; | ||
fetchCache: Map<string, { | ||
timestamp: number; | ||
result: FetchResult; | ||
}>; | ||
constructor(server: ViteDevServer, options?: ViteNodeServerOptions); | ||
@@ -56,0 +70,0 @@ shouldExternalize(id: string): Promise<string | false>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71847
1968