ecommerce-integration-boilerplate
ecommerce-integration-boilerplate copied to clipboard
[Bug]: yarn prepare doesn't work when on a git submodule
Expected Behavior
yarn prepare linking $GIT_DIR/hooks to .husky when present
Actual Behavior
yarn prepare fails because .git is a file instead of a directory and still claims success
Possible Solution
use git rev-parse --git-dir instead of assuming .git/, and use negative logic instead of || true
diff --git a/package.json b/package.json
index 0235c08..a1a8e59 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,7 @@
"docs:dev": "cd docs && yarn dev",
"docs:install": "cd docs && yarn",
"lint": "eslint . --ext .ts,.vue",
- "prepare": "[ -d '.husky' ] && (husky install && shx rm -rf .git/hooks && shx ln -s ../.husky .git/hooks) || true",
+ "prepare": "[ ! -d '.husky' ] || (GIT_DIR=$(git rev-parse --git-dir); husky install && shx rm -rf \"$GIT_DIR/hooks\" && shx ln -s $(realpath --relative-to=\"$GIT_DIR\" .husky) \"$GIT_DIR/hooks\")",
"publish:api-client": "node ./scripts/publishApi.js",
"publish:composables": "node ./scripts/publishComposable.js",
"start": "cd packages/theme && yarn start",
unfortunately realpath doesn't seem to be available on macOS and I don't know how to handle that without making the script call way more complex.,,
Steps to reproduce
mkdir foo
cd foo
git init
git submodule add https://github.com/vuestorefront/ecommerce-integration-boilerplate
cd ecommerce-integration-boilerplate
yarn
What version of replace_me integration are you using?
9148bd7 (main's HEAD)
What version of Node.js are you using?
v16.13.1
What browser (and version) are you using?
None
What operating system (and version) are you using?
Ubuntu 21.10
Relevant log output
# BEFORE
#
$ yarn prepare
yarn run v1.22.17
$ set -x; [ -d '.husky' ] && (husky install && shx rm -rf .git/hooks && shx ln -s ../.husky .git/hooks) || true
+ [ -d .husky ]
+ husky install
husky - Git hooks installed
+ shx rm -rf .git/hooks
+ shx ln -s ../.husky .git/hooks
ln: ENOTDIR: not a directory, symlink '../.husky' -> '/home/amery/projects/go-nuxt/src/github.com/goshop-project/vuestorefront/.git/hooks'
+ true
Done in 0.19s.
# AFTER
#
$ yarn prepare
yarn run v1.22.17
$ set -x; [ ! -d '.husky' ] || (GIT_DIR=$(git rev-parse --git-dir); husky install && shx rm -rf "$GIT_DIR/hooks" && shx ln -s $(realpath --relative-to="$GIT_DIR" .husky) "$GIT_DIR/hooks")
+ [ ! -d .husky ]
+ git rev-parse --git-dir
+ GIT_DIR=/home/amery/projects/go-nuxt/.git/modules/src/github.com/goshop-project/vuestorefront
+ husky install
husky - Git hooks installed
+ shx rm -rf /home/amery/projects/go-nuxt/.git/modules/src/github.com/goshop-project/vuestorefront/hooks
+ realpath --relative-to=/home/amery/projects/go-nuxt/.git/modules/src/github.com/goshop-project/vuestorefront .husky
+ shx ln -s ../../../../../../src/github.com/goshop-project/vuestorefront/.husky /home/amery/projects/go-nuxt/.git/modules/src/github.com/goshop-project/vuestorefront/hooks
Done in 0.21s
Code of Conduct
- [X] I agree to follow this project's Code of Conduct