mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
refactor: replace parse
with splitFileAndPostfix
(#18185)
This commit is contained in:
parent
c8aea5ae0a
commit
6f030ec15f
@ -1,5 +1,4 @@
|
||||
import path from 'node:path'
|
||||
import { parse as parseUrl } from 'node:url'
|
||||
import fsp from 'node:fs/promises'
|
||||
import { Buffer } from 'node:buffer'
|
||||
import * as mrmime from 'mrmime'
|
||||
@ -25,7 +24,11 @@ import {
|
||||
urlRE,
|
||||
} from '../utils'
|
||||
import { DEFAULT_ASSETS_INLINE_LIMIT, FS_PREFIX } from '../constants'
|
||||
import { cleanUrl, withTrailingSlash } from '../../shared/utils'
|
||||
import {
|
||||
cleanUrl,
|
||||
splitFileAndPostfix,
|
||||
withTrailingSlash,
|
||||
} from '../../shared/utils'
|
||||
import type { Environment } from '../environment'
|
||||
|
||||
// referenceId is base64url but replaces - with $
|
||||
@ -351,7 +354,7 @@ async function fileToBuiltUrl(
|
||||
return cached
|
||||
}
|
||||
|
||||
const file = cleanUrl(id)
|
||||
const { file, postfix } = splitFileAndPostfix(id)
|
||||
const content = await fsp.readFile(file)
|
||||
|
||||
let url: string
|
||||
@ -371,9 +374,6 @@ async function fileToBuiltUrl(
|
||||
}
|
||||
} else {
|
||||
// emit as asset
|
||||
const { search, hash } = parseUrl(id)
|
||||
const postfix = (search || '') + (hash || '')
|
||||
|
||||
const originalFileName = normalizePath(
|
||||
path.relative(environment.config.root, file),
|
||||
)
|
||||
|
@ -53,6 +53,7 @@ import {
|
||||
cleanUrl,
|
||||
isWindows,
|
||||
slash,
|
||||
splitFileAndPostfix,
|
||||
withTrailingSlash,
|
||||
} from '../../shared/utils'
|
||||
|
||||
@ -589,11 +590,6 @@ function ensureVersionQuery(
|
||||
return resolved
|
||||
}
|
||||
|
||||
function splitFileAndPostfix(path: string) {
|
||||
const file = cleanUrl(path)
|
||||
return { file, postfix: path.slice(file.length) }
|
||||
}
|
||||
|
||||
export function tryFsResolve(
|
||||
fsPath: string,
|
||||
options: InternalResolveOptions,
|
||||
|
@ -33,6 +33,14 @@ export function cleanUrl(url: string): string {
|
||||
return url.replace(postfixRE, '')
|
||||
}
|
||||
|
||||
export function splitFileAndPostfix(path: string): {
|
||||
file: string
|
||||
postfix: string
|
||||
} {
|
||||
const file = cleanUrl(path)
|
||||
return { file, postfix: path.slice(file.length) }
|
||||
}
|
||||
|
||||
export function isPrimitive(value: unknown): boolean {
|
||||
return !value || (typeof value !== 'object' && typeof value !== 'function')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user