Skip to content

Commit

Permalink
feat: use custom source-map-support implementation (#2905)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Feb 23, 2023
1 parent 855047d commit 6ff6c6e
Show file tree
Hide file tree
Showing 9 changed files with 549 additions and 97 deletions.
4 changes: 2 additions & 2 deletions packages/coverage-c8/src/provider.ts
Expand Up @@ -4,7 +4,7 @@ import type { Profiler } from 'inspector'
import { extname, resolve } from 'pathe'
import c from 'picocolors'
import { provider } from 'std-env'
import type { RawSourceMap } from 'vite-node'
import type { EncodedSourceMap } from 'vite-node'
import { coverageConfigDefaults } from 'vitest/config'
// eslint-disable-next-line no-restricted-imports
import type { AfterSuiteRunMeta, CoverageC8Options, CoverageProvider, ReportContext, ResolvedCoverageOptions } from 'vitest'
Expand Down Expand Up @@ -67,7 +67,7 @@ export class C8CoverageProvider implements CoverageProvider {
// Overwrite C8's loader as results are in memory instead of file system
report._loadReports = () => this.coverages

interface MapAndSource { map: RawSourceMap; source: string | undefined }
interface MapAndSource { map: EncodedSourceMap; source: string | undefined }
type SourceMapMeta = { url: string; filepath: string } & MapAndSource

// add source maps
Expand Down
5 changes: 1 addition & 4 deletions packages/vite-node/package.json
Expand Up @@ -81,14 +81,11 @@
"mlly": "^1.1.0",
"pathe": "^1.1.0",
"picocolors": "^1.0.0",
"source-map": "^0.6.1",
"source-map-support": "^0.5.21",
"vite": "^3.0.0 || ^4.0.0"
},
"devDependencies": {
"@jridgewell/trace-mapping": "^0.3.17",
"@types/debug": "^4.1.7",
"@types/source-map": "^0.5.7",
"@types/source-map-support": "^0.5.6",
"rollup": "^2.79.1"
}
}
4 changes: 0 additions & 4 deletions packages/vite-node/src/client.ts
Expand Up @@ -170,10 +170,6 @@ export class ViteNodeRunner {
return await this.cachedRequest(id, url, [])
}

getSourceMap(id: string) {
return this.moduleCache.getSourceMap(id)
}

/** @internal */
async cachedRequest(id: string, fsPath: string, callstack: string[]) {
const importee = callstack[callstack.length - 1]
Expand Down
7 changes: 4 additions & 3 deletions packages/vite-node/src/server.ts
Expand Up @@ -2,7 +2,8 @@ import { performance } from 'node:perf_hooks'
import { resolve } from 'pathe'
import type { TransformResult, ViteDevServer } from 'vite'
import createDebug from 'debug'
import type { DebuggerOptions, FetchResult, RawSourceMap, ViteNodeResolveId, ViteNodeServerOptions } from './types'
import type { EncodedSourceMap } from '@jridgewell/trace-mapping'
import type { DebuggerOptions, FetchResult, ViteNodeResolveId, ViteNodeServerOptions } from './types'
import { shouldExternalize } from './externalize'
import { normalizeModuleId, toArray, toFilePath } from './utils'
import { Debugger } from './debug'
Expand Down Expand Up @@ -76,7 +77,7 @@ export class ViteNodeServer {
if (fetchResult?.map)
return fetchResult.map
const ssrTransformResult = this.server.moduleGraph.getModuleById(source)?.ssrTransformResult
return (ssrTransformResult?.map || null) as unknown as RawSourceMap | null
return (ssrTransformResult?.map || null) as unknown as EncodedSourceMap | null
}

async fetchModule(id: string): Promise<FetchResult> {
Expand Down Expand Up @@ -144,7 +145,7 @@ export class ViteNodeServer {
const start = performance.now()
const r = await this._transformRequest(id)
duration = performance.now() - start
result = { code: r?.code, map: r?.map as unknown as RawSourceMap }
result = { code: r?.code, map: r?.map as any }
}

this.fetchCache.set(filePath, {
Expand Down

0 comments on commit 6ff6c6e

Please sign in to comment.