check-peer-dependencies icon indicating copy to clipboard operation
check-peer-dependencies copied to clipboard

[feature] Allow programmatic use that returns an object of data

Open Whoaa512 opened this issue 3 years ago • 4 comments

I'd like to use this within a larger set of CI checks that I currently have in a custom script.

As is I need to spawn this via exec and parse the output, would be great if I could import and call it directly without all the console.logs and get an object back

Whoaa512 avatar Mar 11 '21 22:03 Whoaa512

likewise for use with renovate... there are certain peer dependencies that I would like to skip, and to fail for anything else...

For reference, here is the bash script I'm using at the moment:

#!/bin/bash

set -e

# Set allowed missing peer dependencies
ALLOWED_MISSING=(
    "jquery"
    "popper.js"
)

# Set allowed incorrect peer dependencies
ALLOWED_INCORRECT=(
)

# Perform check for peer dependencies
if ! PEERCHECK=$(yarn check-peer-dependencies --yarn 2>&1); then
    # Gather packages that are not installed
    mapfile -t MISSING < <((grep '❌' <<<"$PEERCHECK") | grep -oP '(?<=\()[^ \(]+(?= is not installed)')
    for PACKAGE in ${!MISSING[*]}; do
        # Check if the missing package is not allowed to be
        if ! [[ ${ALLOWED_MISSING[*]} =~ ${MISSING[$PACKAGE]} ]]; then
            # Show full output and error
            printf "%s\n" "${PEERCHECK[*]}"
            exit 1
        fi
    done
    # Gather packages that are the wrong version
    mapfile -t WRONGVERSION < <((grep '❌' <<<"$PEERCHECK") | grep -oP '(?<= is required by ).+(?=@[^ ]+ \([^ ]+ is installed)')
    for PACKAGE in ${!WRONGVERSION[*]}; do
        # Check if the missing package is not allowed to be
        if ! [[ ${ALLOWED_INCORRECT[*]} =~ ${WRONGVERSION[$PACKAGE]} ]]; then
            # Show full output and error
            printf "%s\n" "${PEERCHECK[*]}"
            exit 1
        fi
    done
fi

Edits: Updating bash script

internalsystemerror avatar May 14 '21 13:05 internalsystemerror

@internalsystemerror

likewise for use with renovate... there are certain peer dependencies that I would like to skip, and to fail for anything else...

I added a cli option --ignore pkg1 --ignore pkg2 in version 4.1.0

christopherthielen avatar Nov 29 '21 18:11 christopherthielen

I added a cli option --ignore pkg1 --ignore pkg2 in version 4.1.0

Oh nice! Thanks I will check it out.

internalsystemerror avatar Nov 30 '21 00:11 internalsystemerror

@christopherthielen That new cli option works for me so I no longer need my bash script. Thanks.

internalsystemerror avatar Dec 13 '21 12:12 internalsystemerror

I'm closing this for now, but would gladly merge a reasonable PR.

christopherthielen avatar Mar 13 '23 19:03 christopherthielen

Hi! Thanks for making and supporting a really useful library!

My use case is somewhat similar to what was originally described, but a little more particular – I'd like to ignore, but also restrict the violations to a specific set of known violations. We're effectively creating an allow-list of exceptions, so we can ratchet down those exceptions over time.

For that I made a custom script that does what was originally described here, but a node API that returned strings and statuses (rather than console.log / process.exit) would be helpful for that purpose. I imagine this use case is a little bit too niche to support as cli arguments, but maybe a node API would be useful for it. I've similarly made do with using exec and parsing the output in the meantime though, so it's not a blocker for us using this library.

jpnelson avatar Feb 02 '24 04:02 jpnelson