Skip to content

Commit

Permalink
refactor: move genSourceMapUrl function
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Mar 4, 2022
1 parent b251b6e commit 56aaaee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 8 additions & 1 deletion packages/vite/src/node/server/sourcemap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import { promises as fs } from 'fs'
import type { Logger } from '../logger'
import { createDebugger, genSourceMapUrl } from '../utils'
import { createDebugger } from '../utils'
import type { SourceMap } from 'rollup'

const isDebug = !!process.env.DEBUG
Expand Down Expand Up @@ -59,6 +59,13 @@ export async function injectSourcesContent(
}
}

function genSourceMapUrl(map: SourceMap | string | undefined) {
if (typeof map !== 'string') {
map = JSON.stringify(map)
}
return `data:application/json;base64,${Buffer.from(map).toString('base64')}`
}

export function getCodeWithSourcemap(
type: 'js' | 'css',
code: string,
Expand Down
8 changes: 0 additions & 8 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {
} from '@ampproject/remapping/dist/types/types'
import { performance } from 'perf_hooks'
import { parse as parseUrl, URLSearchParams } from 'url'
import type { SourceMap } from 'rollup'

export function slash(p: string): string {
return p.replace(/\\/g, '/')
Expand Down Expand Up @@ -675,10 +674,3 @@ export function parseRequest(id: string): Record<string, string> | null {
}
return Object.fromEntries(new URLSearchParams(search.slice(1)))
}

export function genSourceMapUrl(map: SourceMap | string | undefined) {
if (typeof map !== 'string') {
map = JSON.stringify(map)
}
return `data:application/json;base64,${Buffer.from(map).toString('base64')}`
}

0 comments on commit 56aaaee

Please sign in to comment.