Working with the npm registry
パッケージを作成する
Before you can publish and install a package from the npm registry, you will need to create a package in Bitbucket first:
上部のナビゲーション バーで [作成] を選択し、[作成] ドロップダウン メニューを開きます。
[作成] ドロップダウンから [パッケージ] を選択します。
Select npm from the Package type dropdown.
Provide a package name for the package. We recommend including a scope, for example
@my-scope/my-packageSelect the Repository to link to dropdown and select the repository that you want to link the package to. Note: The package inherits the permissions of the repository which then grants users the same permissions to access the package.
[送信] を選択し、パッケージを作成します。
Package manager support
We support npm versions bundled with Node v20+ and yarn v2+. Other package managers may work with the registry but aren’t officially supported.
認証
Interacting with the Packages registry requires you to authenticate your client with an Atlassian API token.
npm
Add the following to your .npmrc file. Create the file in your project directory if one doesn’t exist.
<package-scope>:registry=https://npm.apkg.io/<workspace-slug>/
//npm.apkg.io/<workspace-slug>/:username=<atlassian-email>
//npm.apkg.io/<workspace-slug>/:_password=<base64-encoded-atlassian-api-token>Ensure your base64-encoded API token does not contain any whitespace characters, for example:
echo -n '<atlassian-api-token>' | base64 -w 0Yarn
Add the following to your .yarnrc.yml file. Create the file in your project directory if one doesn’t exist.
npmRegistries:
https://npm.apkg.io/<workspace-slug>/:
npmAlwaysAuth: true
npmAuthIdent: <base64-encoded-email-and-api-token>
npmScopes:
<workspace-slug>:
npmRegistryServer: https://npm.apkg.io/<workspace-slug>/
npmPublishRegistry: https://npm.apkg.io/<workspace-slug>/
npmAlwaysAuth: true
npmAuthIdent: <base64-encoded-email-and-api-token>
Where <base64-encoded-email-and-api-token> is a base64-encoded HTTP basic authentication string, to be more specific <atlassian-email>:<atlassian-api-token>. Ensure this string contains no whitespace characters, for example:
echo -n '<atlassian-email>:<atlassian-api-token>' | base64 -w 0Bitbucket pipelines
Alternatively, if publishing from Bitbucket Pipelines, you can use BITBUCKET_PACKAGES_USERNAME and BITBUCKET_PACKAGES_TOKEN environment variables available to each step in your Bitbucket Pipeline runs:
image: node:24
pipelines:
default:
- step:
name: Publish NPM package
script:
- export ENCODED_PACKAGES_TOKEN=$(echo -n "$BITBUCKET_PACKAGES_TOKEN" | base64 -w 0)
- echo '@<package-scope>:registry=https://npm.apkg.io/<workspace-slug>/' >> .npmrc
- echo "//npm.apkg.io/<workspace-slug>/:username=$BITBUCKET_PACKAGES_USERNAME" >> .npmrc
- echo "//npm.apkg.io/<workspace-slug>/:_password=$ENCODED_PACKAGES_TOKEN" >> .npmrc
- npm publishSupported npm commands
We support the following npm CLI commands:
npm install- Install a package.npm ci- Install a project with a clean slatenpm publish- Publish a packagenpm view- View registry infonpm dist-tag add- Add a package distribution tagnpm dist-tag ls- List package distribution tagsnpm dist-tag rm- Remove a package distribution tagnpm audit signatures- Verify registry signatures
Publishing an npm package to the registry
Update the publishConfig field in your package.json:
{
"name": "@my-scope/my-package",
"version": "1.0.0",
"publishConfig": {
"registry": "https://npm.apkg.io/<workspace_slug>/"
}
}npm
Publish the package.
npm publishYarn
Publish the package.
yarn npm publishInstalling an npm package
Add the package to the dependencies field in your package.json.
{
"name": "my-project",
"version": "1.0.0",
"dependencies": {
"@my-scope/my-package": "1.0.0"
}
}npm
Install the dependency.
npm installYarn
Install the dependency.
yarn installViewing npm packages
The npm packages within your registry can be viewed from the workspace, project, and repository. You will see a list of npm packages along with other package types that have been published to your workspace, project, or repository.
To view the npm packages within the workspace, select Packages on the left sidebar. This opens the Packages page which lists all the npm packages within the workspace.
To view the npm packages within a project, select Packages on the left sidebar from within the project in which you want to see a list of npm packages.
To view the npm packages within a repository, select Packages on the left sidebar within the repository in which you want to see a list of npm packages.
Viewing npm package details
Display a package: Select the npm package name from the list of packages to see details about that npm package.
Display a version: Select the version to see details specific to that version.
Delete an npm package and version
In Bitbucket Cloud, you can delete either a npm version, or the entire npm package, including all of its versions.
Delete an npm version
Only users with repository write permission can delete an npm version.
Deleting an npm version permanently removes it from Bitbucket Cloud. Once it is deleted, the version can no longer be installed and storage will be freed up soon after. To delete an npm version:
From the packages list view under the workspace, project, or repository, select the npm package containing the version you want to delete.
Find the version you want to delete in the versions list view, and open the Actions menu.
Select Delete version, then select Delete.
Delete an npm package
Only users with repository admin permission can delete an npm package.
Deleting an npm package permanently removes it and all of its versions from Packages. Once deleted, the npm package and all its versions can no longer be installed and storage will be freed up soon after. To delete an npm package:
From the packages list view under the workspace, project, or repository, select the npm package you want to delete.
Find the package you want to delete in the versions list view, and open the Actions menu
Select Delete package, then select Delete.
この内容はお役に立ちましたか?