| 98 | } |
| 99 | |
| 100 | async fetchFromNetwork(locator, opts) { |
| 101 | // 1980-01-01, like Fedora |
| 102 | const defaultTime = 315532800; |
| 103 | |
| 104 | const parts = parse(locator.reference); |
| 105 | |
| 106 | const releaseBuffer = await httpUtils.get(`https://github.com/${parts.organization}/${parts.repository}/releases/download/${parts.version}/${parts.binary}`, { |
| 107 | configuration: opts.project.configuration, |
| 108 | }); |
| 109 | |
| 110 | const packageName = ppath.join(locator.scope !== null ? '@' + locator.scope : '', locator.name); |
| 111 | |
| 112 | const tmpDir = xfs.mktempSync(); |
| 113 | |
| 114 | const zipFS = new ZipFS(ppath.join(tmpDir, 'release.zip'), { create: true, libzip: await getLibzipPromise() }); |
| 115 | |
| 116 | zipFS.writeFileSync('package.json', `{ "name": "${packageName}", "dependencies": { "@yarnpkg/fslib": "${YARN_FS_VERSION}" } }`); |
| 117 | zipFS.utimesSync('package.json', defaultTime, defaultTime); |
| 118 | |
| 119 | const dir = ppath.join('node_modules', packageName); |
| 120 | zipFS.mkdirSync(dir, { recursive: true }); |
| 121 | |
| 122 | const stubFile = ppath.join(dir, 'exec.js'); |
| 123 | zipFS.writeFileSync(stubFile, `const { xfs } = require('@yarnpkg/fslib'); |
| 124 | const fs = require('fs'); |
| 125 | const path = require('path'); |
| 126 | const os = require('os'); |
| 127 | const { spawn } = require('child_process'); |
| 128 | |
| 129 | const execute = (path, args) => { |
| 130 | const child = spawn(path, args); |
| 131 | |
| 132 | process.stdin.pipe(child.stdin); |
| 133 | child.stdout.pipe(process.stdout); |
| 134 | child.stderr.pipe(process.stderr); |
| 135 | |
| 136 | child.on('error', err => { process.stderr.write(err + '\\n'); process.exit(1) } ); |
| 137 | child.on('exit', status => process.exit(status)); |
| 138 | } |
| 139 | |
| 140 | (async () => { |
| 141 | const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'github-release-binary')); |
| 142 | process.on('exit', () => { |
| 143 | fs.rmdirSync(tmpDir, { recursive: true }); |
| 144 | }) |
| 145 | |
| 146 | const binary = process.argv[1].replace('exec.js', '${parts.binary}'); |
| 147 | const binaryPath = path.join(tmpDir, '${parts.binary}'); |
| 148 | await xfs.copyFilePromise(binary, binaryPath); |
| 149 | await xfs.chmodPromise(binaryPath, 0o755); |
| 150 | execute(binaryPath, process.argv.slice(2)); |
| 151 | })();`); |
| 152 | zipFS.chmodSync(stubFile, 0o755); |
| 153 | zipFS.utimesSync(stubFile, defaultTime, defaultTime); |
| 154 | |
| 155 | const binaryPath = ppath.join(dir, parts.binary); |
| 156 | zipFS.writeFileSync(binaryPath, releaseBuffer); |
| 157 | zipFS.chmodSync(binaryPath, 0o755); |