From fef85661f25c85454012d14aba2d75b3df796d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=80=8C=CE=BB=E3=80=8Dxllily?= Date: Mon, 5 Jun 2023 23:03:38 +0800 Subject: [PATCH] feat: Adding publicPath option for npm publishConfig (#1010) * feat: Adding publicPath option for npm publishConfig with docs and tests * feat: Adding publicPath option for npm publishConfig with docs and tests --- .DS_Store | Bin 0 -> 6148 bytes docs/npm.md | 14 ++++++++++++++ lib/plugin/npm/npm.js | 9 ++++++++- test/npm.js | 17 +++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..bcdcacf85c51dd845c35adfafed655c684e6e6d9 GIT binary patch literal 6148 zcmeH~u?oUK42Bc!Ah>jNyv0@U4GyVK&=+tJM34%i&iCm4$pyjcEFym(`7gN(rQgtN zL_{~Y{aU0Ikr~`nmKH{)$QxP7L5_00_m|;x9uBBkeG+GF4R2+%AKMfXAOR8}0TLjA zA0lA)Hf%Pp%18nvKmtz!_I*fj(;Ql=`lkcIM*wJpvK!VuOF)wqpgFWuMFplYJ!rJ5 zk0Dm~c4&%oIkZ%*?V>S!XgpbMih*fu7fncDnq3%3fCNSarZsQv{@=ns&HtkorX)ZD ze?~x?uJ1N@skmF;UeD^gsM@-~p?)0U (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();