vite-node
Advanced tools
Comparing version 0.1.27 to 0.2.0
@@ -1,5 +0,6 @@ | ||
declare type FetchFunction = (id: string) => Promise<{ | ||
interface FetchResult { | ||
code?: string; | ||
externalize?: string; | ||
}>; | ||
} | ||
declare type FetchFunction = (id: string) => Promise<FetchResult>; | ||
declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>; | ||
@@ -6,0 +7,0 @@ interface ModuleCache { |
@@ -29,3 +29,16 @@ import minimist from 'minimist'; | ||
} | ||
let SOURCEMAPPING_URL = "sourceMa"; | ||
SOURCEMAPPING_URL += "ppingURL"; | ||
async function withInlineSourcemap(result) { | ||
const { code, map } = result; | ||
if (code.includes(`${SOURCEMAPPING_URL}=`)) | ||
return result; | ||
if (map) | ||
result.code = `${code} | ||
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")} | ||
`; | ||
return result; | ||
} | ||
const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/; | ||
@@ -114,4 +127,2 @@ const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/; | ||
let SOURCEMAPPING_URL = "sourceMa"; | ||
SOURCEMAPPING_URL += "ppingURL"; | ||
class ViteNodeServer { | ||
@@ -121,3 +132,5 @@ constructor(server, options = {}) { | ||
this.options = options; | ||
this.promiseMap = new Map(); | ||
this.fetchPromiseMap = new Map(); | ||
this.transformPromiseMap = new Map(); | ||
this.fetchCache = new Map(); | ||
} | ||
@@ -127,19 +140,20 @@ shouldExternalize(id) { | ||
} | ||
async fetchModule(id) { | ||
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root)); | ||
if (externalize) | ||
return { externalize }; | ||
const r = await this.transformRequest(id); | ||
return { code: r == null ? void 0 : r.code }; | ||
} | ||
async resolveId(id, importer) { | ||
return this.server.pluginContainer.resolveId(id, importer, { ssr: true }); | ||
} | ||
async fetchModule(id) { | ||
if (!this.fetchPromiseMap.has(id)) { | ||
this.fetchPromiseMap.set(id, this._fetchModule(id).finally(() => { | ||
this.fetchPromiseMap.delete(id); | ||
})); | ||
} | ||
return this.fetchPromiseMap.get(id); | ||
} | ||
async transformRequest(id) { | ||
if (!this.promiseMap.has(id)) { | ||
this.promiseMap.set(id, this._transformRequest(id).finally(() => { | ||
this.promiseMap.delete(id); | ||
if (!this.transformPromiseMap.has(id)) { | ||
this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => { | ||
this.transformPromiseMap.delete(id); | ||
})); | ||
} | ||
return this.promiseMap.get(id); | ||
return this.transformPromiseMap.get(id); | ||
} | ||
@@ -157,6 +171,27 @@ getTransformMode(id) { | ||
} | ||
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); | ||
if (timestamp && cache && cache.timestamp >= timestamp) | ||
return cache.result; | ||
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root)); | ||
if (externalize) { | ||
result = { externalize }; | ||
} else { | ||
const r = await this._transformRequest(id); | ||
result = { code: r == null ? void 0 : r.code }; | ||
} | ||
if (timestamp) { | ||
this.fetchCache.set(id, { | ||
timestamp, | ||
result | ||
}); | ||
} | ||
return result; | ||
} | ||
async _transformRequest(id) { | ||
let result = null; | ||
const mode = this.getTransformMode(id); | ||
if (mode === "web") { | ||
if (this.getTransformMode(id) === "web") { | ||
result = await this.server.transformRequest(id); | ||
@@ -173,14 +208,3 @@ if (result) | ||
} | ||
async function withInlineSourcemap(result) { | ||
const { code, map } = result; | ||
if (code.includes(`${SOURCEMAPPING_URL}=`)) | ||
return result; | ||
if (map) | ||
result.code = `${code} | ||
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")} | ||
`; | ||
return result; | ||
} | ||
const DEFAULT_REQUEST_STUBS = { | ||
@@ -187,0 +211,0 @@ "/@vite/client": { |
@@ -16,3 +16,16 @@ import { existsSync } from 'fs'; | ||
} | ||
let SOURCEMAPPING_URL = "sourceMa"; | ||
SOURCEMAPPING_URL += "ppingURL"; | ||
async function withInlineSourcemap(result) { | ||
const { code, map } = result; | ||
if (code.includes(`${SOURCEMAPPING_URL}=`)) | ||
return result; | ||
if (map) | ||
result.code = `${code} | ||
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")} | ||
`; | ||
return result; | ||
} | ||
const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/; | ||
@@ -101,4 +114,2 @@ const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/; | ||
let SOURCEMAPPING_URL = "sourceMa"; | ||
SOURCEMAPPING_URL += "ppingURL"; | ||
class ViteNodeServer { | ||
@@ -108,3 +119,5 @@ constructor(server, options = {}) { | ||
this.options = options; | ||
this.promiseMap = new Map(); | ||
this.fetchPromiseMap = new Map(); | ||
this.transformPromiseMap = new Map(); | ||
this.fetchCache = new Map(); | ||
} | ||
@@ -114,19 +127,20 @@ shouldExternalize(id) { | ||
} | ||
async fetchModule(id) { | ||
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root)); | ||
if (externalize) | ||
return { externalize }; | ||
const r = await this.transformRequest(id); | ||
return { code: r == null ? void 0 : r.code }; | ||
} | ||
async resolveId(id, importer) { | ||
return this.server.pluginContainer.resolveId(id, importer, { ssr: true }); | ||
} | ||
async fetchModule(id) { | ||
if (!this.fetchPromiseMap.has(id)) { | ||
this.fetchPromiseMap.set(id, this._fetchModule(id).finally(() => { | ||
this.fetchPromiseMap.delete(id); | ||
})); | ||
} | ||
return this.fetchPromiseMap.get(id); | ||
} | ||
async transformRequest(id) { | ||
if (!this.promiseMap.has(id)) { | ||
this.promiseMap.set(id, this._transformRequest(id).finally(() => { | ||
this.promiseMap.delete(id); | ||
if (!this.transformPromiseMap.has(id)) { | ||
this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => { | ||
this.transformPromiseMap.delete(id); | ||
})); | ||
} | ||
return this.promiseMap.get(id); | ||
return this.transformPromiseMap.get(id); | ||
} | ||
@@ -144,6 +158,27 @@ getTransformMode(id) { | ||
} | ||
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); | ||
if (timestamp && cache && cache.timestamp >= timestamp) | ||
return cache.result; | ||
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root)); | ||
if (externalize) { | ||
result = { externalize }; | ||
} else { | ||
const r = await this._transformRequest(id); | ||
result = { code: r == null ? void 0 : r.code }; | ||
} | ||
if (timestamp) { | ||
this.fetchCache.set(id, { | ||
timestamp, | ||
result | ||
}); | ||
} | ||
return result; | ||
} | ||
async _transformRequest(id) { | ||
let result = null; | ||
const mode = this.getTransformMode(id); | ||
if (mode === "web") { | ||
if (this.getTransformMode(id) === "web") { | ||
result = await this.server.transformRequest(id); | ||
@@ -160,14 +195,3 @@ if (result) | ||
} | ||
async function withInlineSourcemap(result) { | ||
const { code, map } = result; | ||
if (code.includes(`${SOURCEMAPPING_URL}=`)) | ||
return result; | ||
if (map) | ||
result.code = `${code} | ||
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")} | ||
`; | ||
return result; | ||
} | ||
export { ViteNodeServer, guessCJSversion, shouldExternalize, withInlineSourcemap }; | ||
export { ViteNodeServer, guessCJSversion, shouldExternalize }; |
@@ -22,3 +22,16 @@ import { fileURLToPath, pathToFileURL } from 'url'; | ||
} | ||
let SOURCEMAPPING_URL = "sourceMa"; | ||
SOURCEMAPPING_URL += "ppingURL"; | ||
async function withInlineSourcemap(result) { | ||
const { code, map } = result; | ||
if (code.includes(`${SOURCEMAPPING_URL}=`)) | ||
return result; | ||
if (map) | ||
result.code = `${code} | ||
export { isPrimitive, isWindows, normalizeId, slash, toFilePath }; | ||
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")} | ||
`; | ||
return result; | ||
} | ||
export { isPrimitive, isWindows, normalizeId, slash, toFilePath, withInlineSourcemap }; |
@@ -10,6 +10,7 @@ interface DepsHandlingOptions { | ||
} | ||
declare type FetchFunction = (id: string) => Promise<{ | ||
interface FetchResult { | ||
code?: string; | ||
externalize?: string; | ||
}>; | ||
} | ||
declare type FetchFunction = (id: string) => Promise<FetchResult>; | ||
declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>; | ||
@@ -56,2 +57,2 @@ interface ModuleCache { | ||
export { DepsHandlingOptions, FetchFunction, ModuleCache, ResolveIdFunction, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions }; | ||
export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, ResolveIdFunction, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions }; |
{ | ||
"name": "vite-node", | ||
"version": "0.1.27", | ||
"version": "0.2.0", | ||
"description": "Vite as Node.js runtime", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/vitest-dev/vitest#readme", |
import { ViteDevServer, TransformResult } from 'vite'; | ||
interface FetchResult { | ||
code?: string; | ||
externalize?: string; | ||
} | ||
interface DepsHandlingOptions { | ||
@@ -44,19 +49,15 @@ external?: (string | RegExp)[]; | ||
options: ViteNodeServerOptions; | ||
promiseMap: Map<string, Promise<TransformResult | null | undefined>>; | ||
private fetchPromiseMap; | ||
private transformPromiseMap; | ||
private fetchCache; | ||
constructor(server: ViteDevServer, options?: ViteNodeServerOptions); | ||
shouldExternalize(id: string): Promise<string | false>; | ||
fetchModule(id: string): Promise<{ | ||
externalize: string; | ||
code?: undefined; | ||
} | { | ||
code: string | undefined; | ||
externalize?: undefined; | ||
}>; | ||
resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>; | ||
fetchModule(id: string): Promise<FetchResult>; | ||
transformRequest(id: string): Promise<TransformResult | null | undefined>; | ||
private getTransformMode; | ||
getTransformMode(id: string): "web" | "ssr"; | ||
private _fetchModule; | ||
private _transformRequest; | ||
} | ||
declare function withInlineSourcemap(result: TransformResult): Promise<TransformResult>; | ||
export { ViteNodeServer, guessCJSversion, shouldExternalize, withInlineSourcemap }; | ||
export { ViteNodeServer, guessCJSversion, shouldExternalize }; |
@@ -0,1 +1,3 @@ | ||
import { TransformResult } from 'vite'; | ||
declare const isWindows: boolean; | ||
@@ -6,3 +8,4 @@ declare function slash(str: string): string; | ||
declare function toFilePath(id: string, root: string): string; | ||
declare function withInlineSourcemap(result: TransformResult): Promise<TransformResult>; | ||
export { isPrimitive, isWindows, normalizeId, slash, toFilePath }; | ||
export { isPrimitive, isWindows, normalizeId, slash, toFilePath, withInlineSourcemap }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
67206
1862