| 78 | } |
| 79 | |
| 80 | async function syncVersion(storage, pkg, version, data) { |
| 81 | const tarball = pacote.tarball.stream(`${pkg}@${version}`); |
| 82 | const untar = new tar.Parse(); |
| 83 | const files = {}; |
| 84 | const pending = []; |
| 85 | |
| 86 | untar.on('entry', entry => { |
| 87 | if (entry.type === 'File') { |
| 88 | const filename = './' + String(entry.path).replace(/^\/+/g, ''); |
| 89 | const passthrough = new PassThrough(); |
| 90 | passthrough.pause(); |
| 91 | |
| 92 | const stream = entry.pipe(passthrough); |
| 93 | const addFile = storage.add(stream).then(r => { |
| 94 | files[filename] = r; |
| 95 | }); |
| 96 | addFile.catch(() => {}); |
| 97 | pending.push(addFile); |
| 98 | } else { |
| 99 | entry.resume(); |
| 100 | } |
| 101 | }); |
| 102 | |
| 103 | try { |
| 104 | await new Promise((resolve, reject) => { |
| 105 | tarball.on('error', reject); |
| 106 | untar.on('end', resolve).on('error', reject); |
| 107 | tarball.pipe(untar); |
| 108 | }); |
| 109 | } catch { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | await Promise.all(pending); |
| 114 | |
| 115 | return { |
| 116 | version, |
| 117 | signatures: [], |
| 118 | dependencies: data.dependencies || {}, |
| 119 | devDependencies: data.devDependencies || {}, |
| 120 | optionalDependencies: data.optionalDependencies || {}, |
| 121 | peerDependencies: data.peerDependencies || {}, |
| 122 | bundledDependencies: data.bundledDependencies || {}, |
| 123 | files, |
| 124 | derivedFiles: {} |
| 125 | }; |
| 126 | } |