Skip to content

Commit eaefd57

Browse files
authored
Add path to npm registry definition (#1531)
The npm ecosystem is special in that it wants the hostname + path of the URL in the registry key. This updates the updater logic to handle this case.
1 parent 5604642 commit eaefd57

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

__tests__/updater.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,43 @@ describe('Updater', () => {
207207
expect(jobDetails['credentials-metadata']).toEqual([
208208
{
209209
type: 'npm_registry',
210-
registry: 'registry.npmjs.org',
210+
registry: 'registry.npmjs.org/some/path',
211211
url: 'https://registry.npmjs.org/some/path'
212212
}
213213
])
214214
})
215215
})
216216

217+
describe('when given npm_registry credentials with a URL and not a registry with no path', () => {
218+
const jobDetails = {...mockJobDetails}
219+
220+
new Updater(
221+
'MOCK_UPDATER_IMAGE_NAME',
222+
'MOCK_PROXY_IMAGE_NAME',
223+
mockApiClient,
224+
jobDetails,
225+
[
226+
{
227+
type: 'npm_registry',
228+
url: 'https://registry.npmjs.org',
229+
username: 'npm_user',
230+
token: 'npm_token'
231+
}
232+
],
233+
workingDirectory
234+
)
235+
236+
it('generates credentials metadata with the registry from the URL', () => {
237+
expect(jobDetails['credentials-metadata']).toEqual([
238+
{
239+
type: 'npm_registry',
240+
registry: 'registry.npmjs.org/',
241+
url: 'https://registry.npmjs.org'
242+
}
243+
])
244+
})
245+
})
246+
217247
describe('when given docker credentials with a URL and not a registry', () => {
218248
const jobDetails = {...mockJobDetails}
219249

dist/main/index.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/updater.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ export class Updater {
118118

119119
if (!credential.registry && credential.url) {
120120
try {
121-
obj.registry = new URL(credential.url).hostname
121+
const parsedURL = new URL(credential.url)
122+
obj.registry = parsedURL.hostname
123+
if (credential.type === 'npm_registry') {
124+
obj.registry += parsedURL.pathname
125+
}
122126
} catch {
123127
// If the URL is invalid, we skip setting the registry
124128
// as it will fall back to the default registry for the given type (e.g., npm, Docker, or Composer).

0 commit comments

Comments
 (0)