diff options
author | eleith <eleith@users.noreply.github.com> | 2022-10-07 22:24:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-08 13:24:44 +0800 |
commit | bbbf9a4b938a3616e08a854c4b2639863fc54013 (patch) | |
tree | 93732db222a3dba0bce1761a4ba3057bf7b9edd9 /modules | |
parent | 6c53cf852f1b00fbcd5f641ebf4885f78cf1160c (diff) | |
download | gitea-bbbf9a4b938a3616e08a854c4b2639863fc54013.tar.gz gitea-bbbf9a4b938a3616e08a854c4b2639863fc54013.zip |
npm package registry support for `bin` (#21372)
Fix #21303
npm package.json supports binary packaging:
https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bin
the npm registry documents that the binary references will be attached
to the abbreviated version object:
https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md#abbreviated-version-object
unfortunately their api documentation leaves this out:
https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md#abbreviated-version-objectdoc
which is likely to be the reason this was left out in gitea's initial
implementation
this response is critical for npm to install the binary in the `.bin`
folder so as to be included on the users default bin path, resulting in
immediate access to any binaries provided by the package
Diffstat (limited to 'modules')
-rw-r--r-- | modules/packages/npm/creator.go | 5 | ||||
-rw-r--r-- | modules/packages/npm/creator_test.go | 5 | ||||
-rw-r--r-- | modules/packages/npm/metadata.go | 1 |
3 files changed, 10 insertions, 1 deletions
diff --git a/modules/packages/npm/creator.go b/modules/packages/npm/creator.go index 2ed4d26248..16cadefb89 100644 --- a/modules/packages/npm/creator.go +++ b/modules/packages/npm/creator.go @@ -66,7 +66,8 @@ type PackageMetadata struct { License string `json:"license,omitempty"` } -// PackageMetadataVersion https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#version +// PackageMetadataVersion documentation: https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#version +// PackageMetadataVersion response: https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md#abbreviated-version-object type PackageMetadataVersion struct { ID string `json:"_id"` Name string `json:"name"` @@ -80,6 +81,7 @@ type PackageMetadataVersion struct { Dependencies map[string]string `json:"dependencies,omitempty"` DevDependencies map[string]string `json:"devDependencies,omitempty"` PeerDependencies map[string]string `json:"peerDependencies,omitempty"` + Bin map[string]string `json:"bin,omitempty"` OptionalDependencies map[string]string `json:"optionalDependencies,omitempty"` Readme string `json:"readme,omitempty"` Dist PackageDistribution `json:"dist"` @@ -220,6 +222,7 @@ func ParsePackage(r io.Reader) (*Package, error) { DevelopmentDependencies: meta.DevDependencies, PeerDependencies: meta.PeerDependencies, OptionalDependencies: meta.OptionalDependencies, + Bin: meta.Bin, Readme: meta.Readme, }, } diff --git a/modules/packages/npm/creator_test.go b/modules/packages/npm/creator_test.go index 64ae6238f3..2b844f4b0e 100644 --- a/modules/packages/npm/creator_test.go +++ b/modules/packages/npm/creator_test.go @@ -23,6 +23,7 @@ func TestParsePackage(t *testing.T) { packageVersion := "1.0.1-pre" packageTag := "latest" packageAuthor := "KN4CK3R" + packageBin := "gitea" packageDescription := "Test Description" data := "H4sIAAAAAAAA/ytITM5OTE/VL4DQelnF+XkMVAYGBgZmJiYK2MRBwNDcSIHB2NTMwNDQzMwAqA7IMDUxA9LUdgg2UFpcklgEdAql5kD8ogCnhwio5lJQUMpLzE1VslJQcihOzi9I1S9JLS7RhSYIJR2QgrLUouLM/DyQGkM9Az1D3YIiqExKanFyUWZBCVQ2BKhVwQVJDKwosbQkI78IJO/tZ+LsbRykxFXLNdA+HwWjYBSMgpENACgAbtAACAAA" integrity := "sha512-yA4FJsVhetynGfOC1jFf79BuS+jrHbm0fhh+aHzCQkOaOBXKf9oBnC4a6DnLLnEsHQDRLYd00cwj8sCXpC+wIg==" @@ -236,6 +237,9 @@ func TestParsePackage(t *testing.T) { Dependencies: map[string]string{ "package": "1.2.0", }, + Bin: map[string]string{ + "bin": packageBin, + }, Dist: PackageDistribution{ Integrity: integrity, }, @@ -264,6 +268,7 @@ func TestParsePackage(t *testing.T) { assert.Equal(t, packageDescription, p.Metadata.Description) assert.Equal(t, packageDescription, p.Metadata.Readme) assert.Equal(t, packageAuthor, p.Metadata.Author) + assert.Equal(t, packageBin, p.Metadata.Bin["bin"]) assert.Equal(t, "MIT", p.Metadata.License) assert.Equal(t, "https://gitea.io/", p.Metadata.ProjectURL) assert.Contains(t, p.Metadata.Dependencies, "package") diff --git a/modules/packages/npm/metadata.go b/modules/packages/npm/metadata.go index 643a4d344b..44714cd6ea 100644 --- a/modules/packages/npm/metadata.go +++ b/modules/packages/npm/metadata.go @@ -20,5 +20,6 @@ type Metadata struct { DevelopmentDependencies map[string]string `json:"development_dependencies,omitempty"` PeerDependencies map[string]string `json:"peer_dependencies,omitempty"` OptionalDependencies map[string]string `json:"optional_dependencies,omitempty"` + Bin map[string]string `json:"bin,omitempty"` Readme string `json:"readme,omitempty"` } |