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

refactor: replace parse with splitFileAndPostfix #18185

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Changes from 4 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
12 changes: 9 additions & 3 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path'
import { parse as parseUrl } from 'node:url'
import { URL } from 'node:url'
import fsp from 'node:fs/promises'
import { Buffer } from 'node:buffer'
import * as mrmime from 'mrmime'
@@ -371,8 +371,14 @@ async function fileToBuiltUrl(
}
} else {
// emit as asset
const { search, hash } = parseUrl(id)
const postfix = (search || '') + (hash || '')
// On Mac or Linux platforms, the path resolution is considered an invalid URL by the new URL and an error will be thrown.
// So it will be converted into a valid URL.
let { search, hash } = new URL(id, 'http://vitejs.dev')
if (!search && id.includes('?')) {
// When the string structure is like `woff2?#iefix`, the search value obtained by parsing the new URL is an empty string
search = '?'
}
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
const postfix = search + hash

const originalFileName = normalizePath(
path.relative(environment.config.root, file),