Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Determine best pattern for preinstall script #2

Open
hdpe opened this issue May 22, 2019 · 0 comments
Open

Determine best pattern for preinstall script #2

hdpe opened this issue May 22, 2019 · 0 comments

Comments

@hdpe
Copy link
Contributor

hdpe commented May 22, 2019

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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant