Skip to content

Commit

Permalink
feat: Adding publicPath option for npm publishConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
xllily committed May 31, 2023
1 parent 22bfb01 commit 56b9113
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/npm.md
Expand Up @@ -83,6 +83,20 @@ The default registry is [https://registry.npmjs.org][2]. The publish to another
}
```

## Config public path of registry

The default public path is `/package`. To customize an alternative path, update or set the
`publishConfig`. For example, if a third-party tool such as `Verdaccio` is used to build a private server to proxy
npm registry, then the URL address of the web user interface is `http://{{host}}-/web/detail/{{packageName}}`:

```json
{
"publishConfig": {
"publicPath": "/-/web/detail"
}
}
```

## Yarn

Using Yarn? It adds or overwrites global environment variable(s), causing authentication issues or not being able to
Expand Down
9 changes: 8 additions & 1 deletion lib/plugin/npm/npm.js
Expand Up @@ -13,6 +13,7 @@ const MANIFEST_PATH = './package.json';
const DEFAULT_TAG = 'latest';
const DEFAULT_TAG_PRERELEASE = 'next';
const NPM_BASE_URL = 'https://www.npmjs.com';
const NPM_PUBLIC_PATH = '/package';

const fixArgs = args => (args ? (typeof args === 'string' ? args.split(' ') : args) : []);

Expand Down Expand Up @@ -198,7 +199,8 @@ class npm extends Plugin {

getPackageUrl() {
const baseUrl = this.getRegistry() || NPM_BASE_URL;
return urlJoin(baseUrl, 'package', this.getName());
const publicPath = this.getPublicPath() || NPM_PUBLIC_PATH;
return urlJoin(baseUrl, publicPath, this.getName());
}

getRegistry() {
Expand All @@ -213,6 +215,11 @@ class npm extends Plugin {
return registries[0];
}

getPublicPath() {
const { publishConfig } = this.getContext();
return (publishConfig && publishConfig.publicPath) ?? ''
}

async guessPreReleaseTag() {
const [tag] = await this.getRegistryPreReleaseTags();
if (tag) {
Expand Down

0 comments on commit 56b9113

Please sign in to comment.