sfmc-devtools icon indicating copy to clipboard operation
sfmc-devtools copied to clipboard

[FEATURE] ensure project users install same npm dependencies

Open JoernBerkefeld opened this issue 1 year ago • 1 comments

during mcdev upgrade we install the latest dependencies image

however, if you just pull from the repo, mcdev does not force you run that. instead it only enforces using the same mcdev version.

going forward, dependency versions in package.json should be cross checked with versions actually installed to ensure things work smoothly.

how to

From: https://dev.to/zirkelc/automatically-install-npm-dependencies-on-git-pull-bg0

The following file is going to be executed by Husky as post-merge hook.

#!/bin/zsh
. "$(dirname "$0")/_/husky.sh"

IFS=$'\n'
# regex supports mono-repos with a package.json at root-level and at package-level
PACKAGE_LOCK_REGEX="(^packages\/.*\/package-lock\.json)|(^package-lock\.json)"
# extract all paths to package-lock.json files 
PACKAGES=("$(git diff --name-only HEAD@{1} HEAD | grep -E "$PACKAGE_LOCK_REGEX")")

if [[ ${PACKAGES[@]} ]]; then
  for package in $PACKAGES; do
    echo "📦 $package was changed. Running npm install to update your dependencies..."
    DIR=$(dirname package)
    cd "$DIR" && npm install
  done
fi

The file must be saved as post-merge (no .sh extension) inside the .husky folder. I'm running on macOS with zsh as default shell (see shebang #!/bin/zsh) and it's working. However, I didn't test it with bash, so there might be some changes necessary if you run a different shell.

JoernBerkefeld avatar May 05 '23 13:05 JoernBerkefeld

check final solution in #912 / pr #913!

JoernBerkefeld avatar May 31 '23 08:05 JoernBerkefeld