fix: npm pkg
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
package hubmodule
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/any-hub/any-hub/internal/cache"
|
||||
)
|
||||
import "time"
|
||||
|
||||
// MigrationState 描述模块上线阶段,方便观测端区分 legacy/beta/ga。
|
||||
type MigrationState string
|
||||
@@ -48,5 +44,12 @@ func DefaultModuleKey() string {
|
||||
return defaultModuleKey
|
||||
}
|
||||
|
||||
// Locator 表示模块可用于重写缓存路径的轻量结构体,避免依赖 cache 包。
|
||||
type Locator struct {
|
||||
HubName string
|
||||
Path string
|
||||
HubType string
|
||||
}
|
||||
|
||||
// LocatorRewrite 允许模块根据自身协议调整缓存路径,例如将 npm metadata 写入独立文件。
|
||||
type LocatorRewrite func(cache.Locator) cache.Locator
|
||||
type LocatorRewrite func(Locator) Locator
|
||||
|
||||
@@ -25,6 +25,6 @@ func init() {
|
||||
RequiresMetadataFile: false,
|
||||
SupportsStreamingWrite: true,
|
||||
},
|
||||
LocatorRewrite: rewriteLocator,
|
||||
LocatorRewrite: hubmodule.DefaultLocatorRewrite("npm"),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
package npm
|
||||
package hubmodule
|
||||
|
||||
import (
|
||||
"strings"
|
||||
import "strings"
|
||||
|
||||
"github.com/any-hub/any-hub/internal/cache"
|
||||
)
|
||||
// DefaultLocatorRewrite 针对内置 hub 类型提供缓存路径重写逻辑。
|
||||
func DefaultLocatorRewrite(hubType string) LocatorRewrite {
|
||||
switch hubType {
|
||||
case "npm":
|
||||
return rewriteNPMLocator
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// rewriteLocator 将 npm metadata JSON 落盘至 package.json,避免与 tarball
|
||||
// 路径的 `/-/` 子目录冲突,同时保持 tarball 使用原始路径。
|
||||
func rewriteLocator(loc cache.Locator) cache.Locator {
|
||||
func rewriteNPMLocator(loc Locator) Locator {
|
||||
path := loc.Path
|
||||
if path == "" {
|
||||
return loc
|
||||
Reference in New Issue
Block a user