Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use custom source-map-support implementation #2905

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/coverage-c8/src/provider.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading