npm Mirror: Adding a Plugin Menu in DSH to Manage npm Repositories

Introduction

Directly manage npm mirrors from the “Add Plugin” menu in DSH to adjust installation priority. This capability is useful for developers who need to switch mirror sources or configure multiple repositories.

What Is This

This is a DSH client plugin maintained by dsh-plugins. It is accessible from the “Add Plugin” entry in DSH and allows you to edit the npm mirror list, reorder entries, configure authentication, and bind scopes. The saved mirror order is used for plugin installation and updates under the current profile.

Core Features

  • Modify & Add: Edit existing repositories, or enter a new repository’s name and HTTP(S) URL.

  • Reorder: Drag the item handle or use the up/down arrows. The first entry is written to the host’s registry, and the remaining entries are written sequentially to fallbackRegistries.

  • Configure Authentication: Expand the “Repository Configuration” section for the corresponding mirror, then choose a Bearer token or username/password (Basic).

  • Bind a Scope: Fill in the target scope in the “Repository Configuration” section, for example @example. After saving, pnpm will resolve packages under that scope from this mirror during plugin install and uninstall.

  • Save & Fallback: Use the native configuration editor to update the profile while preserving other plugin-manager settings. Network errors and package-not-found cases fall through to the next repository according to host rules.

  • Install Dialog: DSH remembers the last repository used. To use a new preferred one, expand the repository options in the native install dialog and select the corresponding address.

The plugin reads existing configuration from the current host. The default profile shows the official npm registry and npmmirror. After removing this plugin, the previously saved host configuration continues to take effect.

Credentials are stored in the current profile’s .npmrc, matched by repository host and path. Bearer tokens are stored as plain text, and Basic credentials are stored as Base64-encoded values. The dialog only displays the save status. To clear credentials saved by this panel, select “Use existing npm / pnpm configuration” and save. After modifying a repository address, you will need to re-enter the credentials. Removing a mirror also clears its associated credentials.

Scope mappings are written to the registries section of the current profile’s pnpm-workspace.yaml. Each mirror can be assigned one scope, and the same scope can only be bound to one mirror. When a field is cleared or a mirror is removed, the panel will delete any mappings that still point to the original address. If an identical scope and address already exist, you can manage that mapping in the panel after filling in and saving. If the same scope has already been manually bound to a different address, a conflict warning will appear upon saving.

If the preferred address is a pnpm custom default registry and is not listed in the fallback list, the host will only attempt that address. To let multiple repositories participate in fallback, you can manage the plugin installation order via this plugin while retaining pnpm’s default official source.

Installation & Activation

This plugin requires DSH 0.2.2-rc.3 through 0.2.2-rc.5 or 0.2.3-alpha.2.

Run the following in DSH:

dsh plugin --profile web add @dsh-plugin/dsh-npm-mirror@next

After installation, navigate to the “npm Mirror” panel via “Plugins” → “Add Plugin” (right-side arrow).

Typical Usage

  1. In the “npm Mirror” panel, expand the “Repository Configuration” section of the mirror entry.
  2. Enter the repository name and HTTP(S) URL, or select from the existing list.
  3. Use the up/down arrows to adjust the order, placing the preferred repository at the top.
  4. Expand the “Repository Configuration” for the corresponding mirror, and choose a Bearer token or username/password (Basic) for authentication.
  5. Fill in the target scope in the “Repository Configuration” section, for example @example. After saving, pnpm will use this mirror when installing packages under that scope.
  6. After saving the configuration, DSH writes the mirror order to the host’s registry and fallbackRegistries, and updates the credentials and scope mappings in .npmrc and pnpm-workspace.yaml.

Use Cases & Notes

Suitable for DSH users who need to manage multiple npm mirror sources, configure scope mappings, or adjust installation priority.

The plugin runs with the permissions of the current dsh process. It is recommended to review the source code and license before installation.

Summary

Centrally manage npm mirrors and scope mappings in DSH to simplify the configuration workflow in multi-repository scenarios. For more information, refer to the plugin directory page and the GitHub repository.

  • Directory: https://www.skillhub.cn/plugins/dsh-plugins/dsh-npm-mirror
  • GitHub: https://github.com/dsh-plugins/dsh-npm-mirror
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye