List possible patterns for preinstall script here and update docs once clear winners emerge.
Current front-runner, worryingly:
using npm to install enforce:
"preinstall": "ENFORCE_VERSION=1.0.0; ENFORCE_DIR=\"$HOME/.npm/enforce/$ENFORCE_VERSION\"; [ -x \"$ENFORCE_DIR/bin/enforce-yarn\" ] || npm i -g --prefix=\"$ENFORCE_DIR\" @blackpepper/enforce@$ENFORCE_VERSION || exit 1; PATH=\"$ENFORCE_DIR/bin:$PATH\"; enforce-yarn --prohibit"
using yarn to install enforce:
"preinstall": "ENFORCE_VERSION=1.0.0; ENFORCE_DIR=\"$HOME/.npm/enforce/$ENFORCE_VERSION\"; [ -x \"$ENFORCE_DIR/bin/enforce-yarn\" ] || yarn global add --prefix=\"$ENFORCE_DIR\" @blackpepper/enforce@$ENFORCE_VERSION || exit 1; PATH=\"$ENFORCE_DIR/bin:$PATH\"; enforce-yarn"
Thoughts:
- do linux home dirs always contain no whitespace? If so we can replace
$HOME with ~ and lose all the escaped double quotes
- could make a new executable in the package e.g.
enforce or enforce-check which always returns 0 to remove the [ -x ... ]
- what does any of this look like on Windows/cross-platform? On Windows it looks like you're best off delegating to e.g. Git bash and double-escaping quotes - even when npm is launched from Git bash, the script is executed by the Windows command interpreter, so
"" must be used to safely escape args in the sh argument line:
"preinstall": "sh -c \"ENFORCE_VERSION=1.0.0; ENFORCE_DIR=\"\"$HOME/.npm/enforce/$ENFORCE_VERSION\"\"; [ -x \"\"$ENFORCE_DIR/bin/enforce-yarn\"\" ] || npm i -g --prefix=\"\"$ENFORCE_DIR\"\" @blackpepper/enforce@$ENFORCE_VERSION || exit 1; PATH=\"\"$ENFORCE_DIR/bin:$PATH\"\"; enforce-yarn --prohibit\""
Previous bad ideas:
yarn: ((type $(yarn global bin)/enforce-yarn &> /dev/null && yarn global upgrade -s @blackpepper/enforce) || yarn global add -s @blackpepper/enforce) && enforce-yarn
- doesn't seem to work from frontend-maven-plugin called from
maven:3.6-jdk-8 image
- command -v probably better than type
- always upgrades; slow, horrible
List possible patterns for preinstall script here and update docs once clear winners emerge.
Current front-runner, worryingly:
using npm to install enforce:
"preinstall": "ENFORCE_VERSION=1.0.0; ENFORCE_DIR=\"$HOME/.npm/enforce/$ENFORCE_VERSION\"; [ -x \"$ENFORCE_DIR/bin/enforce-yarn\" ] || npm i -g --prefix=\"$ENFORCE_DIR\" @blackpepper/enforce@$ENFORCE_VERSION || exit 1; PATH=\"$ENFORCE_DIR/bin:$PATH\"; enforce-yarn --prohibit"using yarn to install enforce:
"preinstall": "ENFORCE_VERSION=1.0.0; ENFORCE_DIR=\"$HOME/.npm/enforce/$ENFORCE_VERSION\"; [ -x \"$ENFORCE_DIR/bin/enforce-yarn\" ] || yarn global add --prefix=\"$ENFORCE_DIR\" @blackpepper/enforce@$ENFORCE_VERSION || exit 1; PATH=\"$ENFORCE_DIR/bin:$PATH\"; enforce-yarn"Thoughts:
$HOMEwith~and lose all the escaped double quotesenforceorenforce-checkwhich always returns0to remove the[ -x ... ]""must be used to safely escape args in theshargument line:"preinstall": "sh -c \"ENFORCE_VERSION=1.0.0; ENFORCE_DIR=\"\"$HOME/.npm/enforce/$ENFORCE_VERSION\"\"; [ -x \"\"$ENFORCE_DIR/bin/enforce-yarn\"\" ] || npm i -g --prefix=\"\"$ENFORCE_DIR\"\" @blackpepper/enforce@$ENFORCE_VERSION || exit 1; PATH=\"\"$ENFORCE_DIR/bin:$PATH\"\"; enforce-yarn --prohibit\""Previous bad ideas:
yarn:
((type $(yarn global bin)/enforce-yarn &> /dev/null && yarn global upgrade -s @blackpepper/enforce) || yarn global add -s @blackpepper/enforce) && enforce-yarnmaven:3.6-jdk-8image