forwarded 886277 https://github.com/then/promise/pull/148
thanks

Hi.

Updated patch attached and noting the new upstream pull request at:

  https://github.com/then/promise/pull/148


Regards,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      la...@debian.org / chris-lamb.co.uk
       `-
From a6d0176784d16315a89ae12b2abe5395255b963d Mon Sep 17 00:00:00 2001
From: Chris Lamb <ch...@chris-lamb.co.uk>
Date: Sun, 11 Feb 2018 16:39:00 +0000
Subject: [PATCH] Make the build reproducible

Whilst working on the Reproducible Builds effort [0], we noticed
that node-promise could not be built reproducibly as it uses
random numbers as throwaway identifiers.

This patch uses a determinstic suffix for these identifiers based
on the contents of the src/ directory.

This was filed in @Debian as https://bugs.debian.org/886277. There was
also a previous aborted attempt in #146.

 [0] https://reproducible-builds.org/
 [1] https://github.com/then/promise/pull/146

Signed-off-by: Chris Lamb <ch...@chris-lamb.co.uk>
---
 build.js | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/build.js b/build.js
index 1e028e9..eb984d8 100644
--- a/build.js
+++ b/build.js
@@ -4,19 +4,17 @@ var fs = require('fs');
 var rimraf = require('rimraf');
 var acorn = require('acorn');
 var walk = require('acorn/dist/walk');
+var crypto = require('crypto');
 
-var ids = [];
-var names = {};
+var shasum = crypto.createHash('sha512');
+fs.readdirSync(__dirname + '/src').forEach(function (filename) {
+  shasum.update(fs.readFileSync(__dirname + '/src/' + filename, 'utf8'));
+});
+var salt = shasum.digest('hex');
 
+// Deterministic 4 char suffix seeded from contents of src
 function getIdFor(name) {
-  if (name in names) return names[name];
-  var id;
-  do {
-    id = '_' + Math.floor(Math.random() * 100);
-  } while (ids.indexOf(id) !== -1)
-  ids.push(id);
-  names[name] = id;
-  return id;
+  return '_' + crypto.pbkdf2Sync(name, salt, 0, 2, 'sha512').toString('hex');
 }
 
 function fixup(src) {

Reply via email to