diff --git a/lib/hash.js b/lib/hash.js index 8d7d3fd..fea3c53 100644 --- a/lib/hash.js +++ b/lib/hash.js @@ -9,11 +9,18 @@ import { readFile } from 'fs-promise'; */ export default async function hashes (files) { - const entries = await Promise.all(files.map(async (name) => { + const map = new Map(); + await Promise.all(files.map(async (name) => { const data = await readFile(name); - return [hash(data), { name, data }]; + const h = hash(data); + const entry = map.get(h); + if (entry) { + entry.names.push(name); + } else { + map.set(hash(data), { names: [name], data }); + } })); - return new Map(entries); + return map; } /** diff --git a/lib/index.js b/lib/index.js index c85588b..8906500 100644 --- a/lib/index.js +++ b/lib/index.js @@ -82,13 +82,15 @@ export default class Now extends EventEmitter { forceSync, name: pkg.name || basename(path), description: pkg.description, - files: Array.from(this._files).map(([sha, { data, name }]) => { - return { - sha, - size: data.length, - file: toRelative(name, this._path) - }; - }) + files: [].concat.apply([], Array.from(this._files).map(([sha, { data, names }]) => { + return names.map((name) => { + return { + sha, + size: data.length, + file: toRelative(name, this._path) + }; + }); + })) } }); if (this._debug) console.timeEnd('> [debug] /create'); @@ -127,9 +129,9 @@ export default class Now extends EventEmitter { const uploadChunk = () => { Promise.all(parts.shift().map((sha) => retry(async (bail) => { const file = this._files.get(sha); - const { data, name } = file; + const { data, names } = file; - if (this._debug) console.time(`> [debug] /sync ${name}`); + if (this._debug) console.time(`> [debug] /sync ${names.join(' ')}`); const stream = resumer().queue(data).end(); const res = await this._fetch('/sync', { @@ -139,12 +141,12 @@ export default class Now extends EventEmitter { 'Content-Length': data.length, 'x-now-deployment-id': this._id, 'x-now-sha': sha, - 'x-now-file': toRelative(name, this._path), + 'x-now-file': names.map((name) => toRelative(name, this._path)).join(','), 'x-now-size': data.length }, body: stream }); - if (this._debug) console.timeEnd(`> [debug] /sync ${name}`); + if (this._debug) console.timeEnd(`> [debug] /sync ${names.join(' ')}`); // no retry on 4xx if (200 !== res.status && (400 <= res.status || 500 > res.status)) {