Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
260c01e1
Commit
260c01e1
authored
Nov 12, 2021
by
Kev
Committed by
Vasilii Iakliushin
Nov 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add yarn as option for package.json dependency manager detection
parent
d8274187
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
7 deletions
+59
-7
app/models/blob_viewer/package_json.rb
app/models/blob_viewer/package_json.rb
+11
-3
spec/models/blob_viewer/package_json_spec.rb
spec/models/blob_viewer/package_json_spec.rb
+48
-4
No files found.
app/models/blob_viewer/package_json.rb
View file @
260c01e1
...
@@ -7,11 +7,15 @@ module BlobViewer
...
@@ -7,11 +7,15 @@ module BlobViewer
self
.
file_types
=
%i(package_json)
self
.
file_types
=
%i(package_json)
def
manager_name
def
manager_name
'npm'
yarn?
?
'yarn'
:
'npm'
end
def
yarn?
json_data
[
'engines'
].
present?
&&
json_data
[
'engines'
][
'yarn'
].
present?
end
end
def
manager_url
def
manager_url
'https://www.npmjs.com/'
yarn?
?
'https://yarnpkg.com/'
:
'https://www.npmjs.com/'
end
end
def
package_name
def
package_name
...
@@ -38,7 +42,11 @@ module BlobViewer
...
@@ -38,7 +42,11 @@ module BlobViewer
end
end
def
npm_url
def
npm_url
if
yarn?
"https://yarnpkg.com/package/
#{
package_name
}
"
else
"https://www.npmjs.com/package/
#{
package_name
}
"
"https://www.npmjs.com/package/
#{
package_name
}
"
end
end
end
end
end
end
end
spec/models/blob_viewer/package_json_spec.rb
View file @
260c01e1
...
@@ -27,14 +27,58 @@ RSpec.describe BlobViewer::PackageJson do
...
@@ -27,14 +27,58 @@ RSpec.describe BlobViewer::PackageJson do
end
end
end
end
context
'yarn'
do
let
(
:data
)
do
<<-
SPEC
.
strip_heredoc
{
"name": "module-name",
"version": "10.3.1",
"engines": {
"yarn": "^2.4.0"
}
}
SPEC
end
let
(
:blob
)
{
fake_blob
(
path:
'package.json'
,
data:
data
)
}
subject
{
described_class
.
new
(
blob
)
}
describe
'#package_url'
do
it
'returns the package URL'
,
:aggregate_failures
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
package_url
).
to
eq
(
"https://yarnpkg.com/package/
#{
subject
.
package_name
}
"
)
end
end
describe
'#manager_url'
do
it
'returns the manager URL'
,
:aggregate_failures
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
manager_url
).
to
eq
(
"https://yarnpkg.com/"
)
end
end
end
context
'npm'
do
describe
'#package_url'
do
describe
'#package_url'
do
it
'returns the package URL'
do
it
'returns the package URL'
,
:aggregate_failures
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
package_url
).
to
eq
(
"https://www.npmjs.com/package/
#{
subject
.
package_name
}
"
)
expect
(
subject
.
package_url
).
to
eq
(
"https://www.npmjs.com/package/
#{
subject
.
package_name
}
"
)
end
end
end
end
describe
'#manager_url'
do
it
'returns the manager URL'
,
:aggregate_failures
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
manager_url
).
to
eq
(
"https://www.npmjs.com/"
)
end
end
end
describe
'#package_type'
do
describe
'#package_type'
do
it
'returns "package"'
do
it
'returns "package"'
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
).
to
receive
(
:prepare!
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment