Wiki source code of Pushing npm Packages to Gitea

Last modified by DevOps-as-a-Service Operator on 2025/02/05 11:33

Show last authors
1 This step-by-step guide outlines how to push your npm packages to a Gitea registry.
2
3 {{toc/}}
4
5 (% id="HRequirements" class="anchor anchorWithStickyNavbar_LWe7" %)
6 = Requirements =
7
8 * A package is prepared for publication.
9 * npm (Node Package Manager) is installed on the user's machine.
10 * For npm packages, pushing to the registry is only possible with a token.
11
12 (% style="text-align: left;" %)
13 == Prepare your npm Package ==
14
15 (% style="text-align:left" %)
16 * Ensure your npm package has a {{code language="none"}}package.json{{/code}} file with all the required fields filled out, including {{code language="none"}}"name"{{/code}}, {{code language="none"}}"version"{{/code}}, and any dependencies.
17 * The package name should follow the format {{code language="none"}}@your-scope/package-name{{/code}} if you are using a scope.
18
19 == (% style="color:#0d0d0d" %)Generating a Token for NPM Packages(%%) ==
20
21 (% style="color:#0d0d0d" %)To push packages to Gitea, you must have an access token with read and write permissions. [[doc:Gitea.Creating Access Tokens for Pushing Packages to Gitea.WebHome]] documentation guides you on how to create such a token.
22
23 ----
24
25 = Guide =
26
27 == Configuration ==
28
29 (% style="color:#0d0d0d" %)In your terminal, configure npm to use your Gitea npm registry. Replace (%%)the placeholders {{code language="none"}}{pkey} {{/code}}and {{code language="none"}}{token}{{/code}} with actual values. Replace {{code language="none"}}CUSTOMER{{/code}} with your customer ID.
30
31 {{code language="bash" theme="FadeToGrey"}}
32 npm config set registry https://gitea-CUSTOMER.devops.t-systems.net/api/packages/{pkey}/npm/
33 npm config set -- '//gitea-CUSTOMER.devops.t-systems.net/api/packages/{pkey}/npm/:_authToken' "{token}"
34 {{/code}}
35
36 (% class="wrapped" %)
37 |=(((
38 Parameter
39 )))|=(((
40 Description
41 )))
42 |(((
43 {{{pkey}}}
44 )))|(((
45 Project Key in DevOps Portal refers to Organisation in Gitea
46 )))
47 |(((
48 {{{token}}}
49 )))|(((
50 Your access token.
51 (% style="color:#0d0d0d" %)Refer to [[doc:Gitea.Creating Access Tokens for Pushing Packages to Gitea.WebHome]] for instructions
52 )))
53
54 {{error}}
55 A package always belongs to an organisation, not a repository. To link an (already uploaded) package to a repository, open the settings page on that package and choose a repository to link this package to. The entire package will be linked, not just a single version.
56 {{/error}}
57
58 (% id="HPublishapackage" class="anchor anchorWithStickyNavbar_LWe7" %)
59 == Publish a package ==
60
61 (% style="color:#0d0d0d" %)First, navigate to the directory where your NPM package is located on your local computer. For instance ~:// C:\myuser\myfiles\mypackages\packagetopush. //
62 After navigating to the path, proceed by running the following command to push your package:
63
64 {{code language="py" theme="FadeToGrey"}}
65 npm publish
66 {{/code}}
67
68 {{error}}
69 (% style="color:#0d0d0d" %)If a package of the same name and version already exists, you'll need to delete the existing one before publishing the new version.
70 {{/error}}
71
72 Once published, the package will be accessible within the**// "Packages" //**section of the organization in Gitea.
73 The following picture displays how a package appears in Gitea after being pushed to the package registry.
74 [[image:attach:image-2024-2-9_10-26-37.png||data-xwiki-image-style-border="true" queryparams="effects=drop-shadow" height="250"]]