Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 9e84d38

Browse files
author
Je
committed
refactor: add target for esm.sh automatically
1 parent fe0c029 commit 9e84d38

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

project.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -724,12 +724,13 @@ export default class Project {
724724
return _
725725
})
726726
}
727-
if (this.isDev && url.startsWith('https://esm.sh/')) {
727+
if (url.startsWith('https://esm.sh/')) {
728728
const u = new URL(dlUrl)
729-
if (!u.searchParams.has('dev')) {
730-
u.searchParams.set('env', 'development')
729+
u.searchParams.set('target', this.config.buildTarget)
730+
if (this.isDev && !u.searchParams.has('dev')) {
731+
u.searchParams.set('dev', '')
731732
}
732-
dlUrl = u.toString()
733+
dlUrl = u.toString().replace(/=(&|$)/, '$1')
733734
}
734735
if (mod.sourceHash === '') {
735736
log.info('Download', url, dlUrl != url ? colors.dim(`• ${dlUrl}`) : '')
@@ -1078,8 +1079,9 @@ function renameImportUrl(importUrl: string): string {
10781079
const url = new URL(isRemote ? importUrl : 'file://' + path.resolve('/', importUrl))
10791080
const ext = path.extname(path.basename(url.pathname)) || '.js'
10801081
let pathname = util.trimSuffix(url.pathname, ext)
1081-
if (url.search) {
1082-
pathname += '@' + btoa(url.search).replace(/\//g, '_').replace(/=/g, '')
1082+
let search = Array.from(url.searchParams.entries()).map(([key, value]) => value ? `${key}=${value}` : key)
1083+
if (search.length > 0) {
1084+
pathname += '@' + search.join(',')
10831085
}
10841086
if (isRemote) {
10851087
return '/-/' + url.hostname + (url.port ? '/' + url.port : '') + pathname + ext

0 commit comments

Comments
 (0)