Created
February 23, 2021 18:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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