Skip to content

Instantly share code, notes, and snippets.

@cspotcode
Created February 23, 2021 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cspotcode/8a34ff62de82d183af583b744adc8c70 to your computer and use it in GitHub Desktop.
Save cspotcode/8a34ff62de82d183af583b744adc8c70 to your computer and use it in GitHub Desktop.
yarn 2 bootstrap downloader, when you don't want to commit yarn's binary to git
const target = './releases/yarn-berry.cjs';
// Change URL to refer to specific commit if you want version to be locked
const url = 'https://github.com/yarnpkg/berry/raw/master/packages/berry-cli/bin/berry.js';
const Path = require('path')
const fs = require('fs')
const targetPath = Path.join(__dirname, target)
if(fs.existsSync(targetPath)) {
require(targetPath)
} else {
const https = require('https')
const util = require('util')
https.get(url).on('response', r => {
https.get(r.headers.location).on('response', r => {
const buffers = []
r.on('data', d => {
buffers.push(d)
}).on('end', () => {
fs.writeFileSync(targetPath, Buffer.concat(buffers));
require(target)
})
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment