diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..bcdcacf8 Binary files /dev/null and b/.DS_Store differ diff --git a/docs/npm.md b/docs/npm.md index aeb8ee0d..eecefd59 100644 --- a/docs/npm.md +++ b/docs/npm.md @@ -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 diff --git a/lib/plugin/npm/npm.js b/lib/plugin/npm/npm.js index af86d289..c99ea190 100644 --- a/lib/plugin/npm/npm.js +++ b/lib/plugin/npm/npm.js @@ -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) : []); @@ -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() { @@ -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) { diff --git a/test/npm.js b/test/npm.js index 39516fd2..bb0823c7 100644 --- a/test/npm.js +++ b/test/npm.js @@ -18,6 +18,23 @@ test('should return npm package url (custom registry)', t => { t.is(npmClient.getPackageUrl(), 'https://registry.example.org/package/my-cool-package'); }); +test('should return npm package url (custom publicPath)', t => { + const options = { npm: { name: 'my-cool-package', publishConfig: { publicPath: '/custom/public-path' } } }; + const npmClient = factory(npm, { options }); + t.is(npmClient.getPackageUrl(), 'https://www.npmjs.com/custom/public-path/my-cool-package'); +}); + +test('should return npm package url (custom registry and publicPath)', t => { + const options = { + npm: { + name: 'my-cool-package', + publishConfig: { registry: 'https://registry.example.org/', publicPath: '/custom/public-path' } + } + }; + const npmClient = factory(npm, { options }); + t.is(npmClient.getPackageUrl(), 'https://registry.example.org/custom/public-path/my-cool-package'); +}); + test('should return default tag', async t => { const npmClient = factory(npm); const tag = await npmClient.resolveTag();