diff options
author | Lukas Eipert <leipert@gitlab.com> | 2018-09-07 13:20:06 +0200 |
---|---|---|
committer | Lukas Eipert <leipert@gitlab.com> | 2018-12-17 09:58:39 +0100 |
commit | 243bd56f9db95a29deaec9ff093b2ff8d02f82ee (patch) | |
tree | 437d20ccde414ff8e9650283276bca0b6279a494 /danger | |
parent | 8b4602041cf2c4a8738a4796d78720017249249f (diff) | |
download | gitlab-ce-243bd56f9db95a29deaec9ff093b2ff8d02f82ee.tar.gz |
Add danger check for duplicate yarn dependencies
This danger check utilises `yarn-deduplicate` in order to show duplicate
dependencies in the yarn.lock dependency tree.
Often when introducing new dependencies or updating existing ones, yarn
does not seem to build the most optimal dependency tree.
In order to prevent those unnecessary dependency updates we are nudging
developers and maintainers to resolve these issues in MRs. Automating
this with danger especially helps, as yarn.lock files are not that easy
to review.
Diffstat (limited to 'danger')
-rw-r--r-- | danger/duplicate_yarn_dependencies/Dangerfile | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/danger/duplicate_yarn_dependencies/Dangerfile b/danger/duplicate_yarn_dependencies/Dangerfile new file mode 100644 index 00000000000..25f81ec86a4 --- /dev/null +++ b/danger/duplicate_yarn_dependencies/Dangerfile @@ -0,0 +1,27 @@ +# 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.' + +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 |