Skip to content

Instantly share code, notes, and snippets.

@xnuk
Created September 11, 2021 21:10
Show Gist options
  • Save xnuk/bccfac5ed50689812f8f7dd8289fea04 to your computer and use it in GitHub Desktop.
Save xnuk/bccfac5ed50689812f8f7dd8289fea04 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -euf
install_dir=$1
if [ -e "$install_dir" ]; then
printf 'Install path `%s` already exists; use different path.\n' \
"$install_dir" \
1>&2
exit 1
fi
# Note: check latest version by:
# node -pe 'JSON.parse(process.argv.pop()).dist' \
# "$(curl --get https://registry.npmjs.org/corepack/latest/)"
curl https://registry.npmjs.org/corepack/-/corepack-0.9.0.tgz | \
tar -zxvf - \
--strip-components=1 \
package/LICENSE.md \
package/dist/corepack.js \
package/dist/vcc.js \
package/dist/pnpx.js \
"--one-top-level=$install_dir"
cd "$install_dir"
sed -i \
"s/'pnpx'/require('path').basename(process.argv[1]).split('.')[0]/" \
dist/pnpx.js
mv dist/pnpx.js dist/corepack-run
mkdir bin
for name in pnpm pnpx yarn yarnpkg npm npx; do
ln -rs dist/corepack-run "bin/$name"
done
printf '\nDone! Now put `%s` into your favourite $PATH.\n\n' \
"$install_dir/bin/*"\
1>&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment