summaryrefslogtreecommitdiff
path: root/danger/duplicate_yarn_dependencies/Dangerfile
blob: 492b888d00e5535e0ece3fc8cd88d7e30f2963bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

return unless helper.all_changed_files.include?('yarn.lock')

duplicate = `node_modules/.bin/yarn-deduplicate --list --strategy fewer yarn.lock`
             .split(/$/)
             .map(&:strip)
             .reject(&:empty?)

return if duplicate.empty?

warn 'This merge request has introduced duplicated yarn dependencies.'

if GitlabDanger.new(helper.gitlab_helper).ci?
  markdown(<<~MARKDOWN)
    ## Duplicate yarn dependencies

    The following dependencies should be de-duplicated:

    * #{duplicate.map { |path| "`#{path}`" }.join("\n* ")}

    Please run the following command and commit the changes to `yarn.lock`:

    ```
    node_modules/.bin/yarn-deduplicate --strategy fewer yarn.lock \\
      && yarn install
    ```
  MARKDOWN
end