Refactor package (routes and error handling, npm peer dependency) (#33111)
This commit is contained in:
parent
ef736b7e27
commit
80e4f4c4eb
28 changed files with 153 additions and 244 deletions
|
@ -81,6 +81,7 @@ type PackageMetadataVersion struct {
|
|||
BundleDependencies []string `json:"bundleDependencies,omitempty"`
|
||||
DevDependencies map[string]string `json:"devDependencies,omitempty"`
|
||||
PeerDependencies map[string]string `json:"peerDependencies,omitempty"`
|
||||
PeerDependenciesMeta map[string]any `json:"peerDependenciesMeta,omitempty"`
|
||||
Bin map[string]string `json:"bin,omitempty"`
|
||||
OptionalDependencies map[string]string `json:"optionalDependencies,omitempty"`
|
||||
Readme string `json:"readme,omitempty"`
|
||||
|
@ -222,6 +223,7 @@ func ParsePackage(r io.Reader) (*Package, error) {
|
|||
BundleDependencies: meta.BundleDependencies,
|
||||
DevelopmentDependencies: meta.DevDependencies,
|
||||
PeerDependencies: meta.PeerDependencies,
|
||||
PeerDependenciesMeta: meta.PeerDependenciesMeta,
|
||||
OptionalDependencies: meta.OptionalDependencies,
|
||||
Bin: meta.Bin,
|
||||
Readme: meta.Readme,
|
||||
|
|
|
@ -19,6 +19,7 @@ type Metadata struct {
|
|||
BundleDependencies []string `json:"bundleDependencies,omitempty"`
|
||||
DevelopmentDependencies map[string]string `json:"development_dependencies,omitempty"`
|
||||
PeerDependencies map[string]string `json:"peer_dependencies,omitempty"`
|
||||
PeerDependenciesMeta map[string]any `json:"peer_dependencies_meta,omitempty"`
|
||||
OptionalDependencies map[string]string `json:"optional_dependencies,omitempty"`
|
||||
Bin map[string]string `json:"bin,omitempty"`
|
||||
Readme string `json:"readme,omitempty"`
|
||||
|
|
|
@ -89,11 +89,23 @@ func (p *routerPathMatcher) matchPath(chiCtx *chi.Context, path string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func isValidMethod(name string) bool {
|
||||
switch name {
|
||||
case http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodHead, http.MethodOptions, http.MethodConnect, http.MethodTrace:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func newRouterPathMatcher(methods, pattern string, h ...any) *routerPathMatcher {
|
||||
middlewares, handlerFunc := wrapMiddlewareAndHandler(nil, h)
|
||||
p := &routerPathMatcher{methods: make(container.Set[string]), middlewares: middlewares, handlerFunc: handlerFunc}
|
||||
for _, method := range strings.Split(methods, ",") {
|
||||
p.methods.Add(strings.TrimSpace(method))
|
||||
method = strings.TrimSpace(method)
|
||||
if !isValidMethod(method) {
|
||||
panic(fmt.Sprintf("invalid HTTP method: %s", method))
|
||||
}
|
||||
p.methods.Add(method)
|
||||
}
|
||||
re := []byte{'^'}
|
||||
lastEnd := 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue