Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] ensure project users install same npm dependencies #894

Open
JoernBerkefeld opened this issue May 5, 2023 · 1 comment
Open
Assignees
Labels
enhancement New feature or request; requires increasing the minor version of mcdev. Jira issue-type "Story"
Milestone

Comments

@JoernBerkefeld
Copy link
Contributor

JoernBerkefeld commented May 5, 2023

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 JoernBerkefeld added enhancement New feature or request; requires increasing the minor version of mcdev. Jira issue-type "Story" NEW not yet analyzed new issues get this label labels May 5, 2023
@JoernBerkefeld JoernBerkefeld added this to the 5.1.0 milestone May 5, 2023
@JoernBerkefeld JoernBerkefeld self-assigned this May 5, 2023
@JoernBerkefeld JoernBerkefeld removed the NEW not yet analyzed new issues get this label label May 8, 2023
@JoernBerkefeld
Copy link
Contributor Author

check final solution in #912 / pr #913!

@JoernBerkefeld JoernBerkefeld changed the title [FEATURE] ensure collaborators install same npm dependencies [FEATURE] ensure project users install same npm dependencies Jun 5, 2023
@JoernBerkefeld JoernBerkefeld modified the milestones: 5.1.0, 5.2.0 Jun 5, 2023
@JoernBerkefeld JoernBerkefeld modified the milestones: 5.2.0, 5.3.0 Jul 13, 2023
@JoernBerkefeld JoernBerkefeld modified the milestones: 5.3.0, 5.4.0 Aug 23, 2023
@JoernBerkefeld JoernBerkefeld modified the milestones: 6.2.0, 6.3.0 May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request; requires increasing the minor version of mcdev. Jira issue-type "Story"
Projects
None yet
Development

No branches or pull requests

1 participant