Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
a1f9d7b5
Commit
a1f9d7b5
authored
7 years ago
by
Rhys Arkins
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: catch registry url error and default to npm (#769)
parent
bae9ae05
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/api/npm.js
+8
-3
8 additions, 3 deletions
lib/api/npm.js
test/api/__snapshots__/npm.spec.js.snap
+28
-3
28 additions, 3 deletions
test/api/__snapshots__/npm.spec.js.snap
test/api/npm.spec.js
+8
-0
8 additions, 0 deletions
test/api/npm.spec.js
with
44 additions
and
6 deletions
lib/api/npm.js
+
8
−
3
View file @
a1f9d7b5
...
...
@@ -27,7 +27,12 @@ async function setNpmrc(input) {
async
function
getDependency
(
name
,
logger
)
{
logger
.
debug
(
`getDependency(
${
name
}
)`
);
const
scope
=
name
.
split
(
'
/
'
)[
0
];
const
regUrl
=
getRegistryUrl
(
scope
,
npmrc
);
let
regUrl
;
try
{
regUrl
=
getRegistryUrl
(
scope
,
npmrc
);
}
catch
(
err
)
{
regUrl
=
'
https://registry.npmjs.org
'
;
}
const
pkgUrl
=
url
.
resolve
(
regUrl
,
encodeURIComponent
(
name
).
replace
(
/^%40/
,
'
@
'
)
...
...
@@ -35,9 +40,9 @@ async function getDependency(name, logger) {
const
authInfo
=
registryAuthToken
(
regUrl
,
{
npmrc
});
const
headers
=
{};
if
(
authInfo
)
{
if
(
authInfo
&&
authInfo
.
type
&&
authInfo
.
token
)
{
headers
.
authorization
=
`
${
authInfo
.
type
}
${
authInfo
.
token
}
`
;
}
else
if
(
process
.
env
.
NPM_TOKEN
)
{
}
else
if
(
process
.
env
.
NPM_TOKEN
&&
process
.
env
.
NPM_TOKEN
!==
'
undefined
'
)
{
headers
.
authorization
=
`Bearer
${
process
.
env
.
NPM_TOKEN
}
`
;
}
...
...
This diff is collapsed.
Click to expand it.
test/api/__snapshots__/npm.spec.js.snap
+
28
−
3
View file @
a1f9d7b5
...
...
@@ -21,9 +21,7 @@ exports[`api/npm should fetch package info from custom registry 2`] = `
Array [
"https://npm.mycustomregistry.com/foobar",
Object {
"headers": Object {
"authorization": "Bearer undefined",
},
"headers": Object {},
"json": true,
},
]
...
...
@@ -114,6 +112,33 @@ Array [
]
`;
exports[`api/npm should use default registry if missing from npmrc 1`] = `
Object {
"dist-tags": Object {
"latest": "0.0.1",
},
"homepage": "https://google.com",
"name": undefined,
"renovate-config": undefined,
"repositoryUrl": "https://google.com",
"versions": Object {
"0.0.1": Object {
"time": "",
},
},
}
`;
exports[`api/npm should use default registry if missing from npmrc 2`] = `
Array [
"https://registry.npmjs.org/foobar",
Object {
"headers": Object {},
"json": true,
},
]
`;
exports[`api/npm should use homepage 1`] = `
Object {
"dist-tags": Object {
...
...
This diff is collapsed.
Click to expand it.
test/api/npm.spec.js
+
8
−
0
View file @
a1f9d7b5
...
...
@@ -92,4 +92,12 @@ describe('api/npm', () => {
const
call
=
got
.
mock
.
calls
[
0
];
expect
(
call
).
toMatchSnapshot
();
});
it
(
'
should use default registry if missing from npmrc
'
,
async
()
=>
{
got
.
mockImplementation
(()
=>
Promise
.
resolve
(
npmResponse
));
npm
.
setNpmrc
(
'
foo=bar
'
);
const
res
=
await
npm
.
getDependency
(
'
foobar
'
,
logger
);
expect
(
res
).
toMatchSnapshot
();
const
call
=
got
.
mock
.
calls
[
0
];
expect
(
call
).
toMatchSnapshot
();
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment