git ssb

4+

Dominic / scuttlebot



Commit e6f24aead1fb2f4f11eccbdecbd008ab8fbe30af

Make bootstrap.pack deterministic

cel authored on 9/25/2017, 10:51:29 PM
Henry committed on 11/30/2017, 9:46:32 PM
Parent: 53a41420bb71793b685b19ba128638d8bfb59b95

Files changed

plugins/bootstrap.jschanged
plugins/bootstrap.jsView
@@ -1,10 +1,40 @@
1 +var fs = require('fs')
12 var zlib = require('zlib')
23 var pull = require('pull-stream')
34 var tar = require('tar-fs')
45 var toPull = require('stream-to-pull-stream')
56 var path = require('path')
7 +var pkg = require('../package.json')
8 +var Readable = require('stream').Readable
69
10 +var normalizedPkgJsonBuf = Buffer.from(JSON.stringify({
11 + name: pkg.name,
12 + description: pkg.description,
13 + version: pkg.version,
14 + homepage: pkg.homepage,
15 + repository: pkg.repository,
16 + dependencies: pkg.dependencies,
17 + devDependencies: pkg.devDependencies,
18 + bin: pkg.bin,
19 + scripts: pkg.scripts,
20 + author: typeof pkg.author === 'string' ? pkg.author :
21 + pkg.author.name + ' <' + pkg.author.email + '>',
22 + license: pkg.license,
23 + files: pkg.files
24 +}, 0, 2) + '\n')
25 +
26 +function streamOnce(data) {
27 + var done
28 + return new Readable({
29 + read: function (size) {
30 + if (done) return this.push(null)
31 + done = true
32 + this.push(data)
33 + }
34 + })
35 +}
36 +
737 exports.name = 'bootstrap'
838 exports.version = '1.0.0'
939 exports.manifest = {
1040 getPackageLock: 'sync',
@@ -15,17 +45,32 @@
1545 getPackageLock: function () {
1646 return require('../package-lock.json')
1747 },
1848 pack: function () {
19- var pkg = require('../package.json')
2049 var files = pkg.files
2150 if (!files) throw new Error('package.json missing \'files\' property')
2251 var gzip = zlib.createGzip()
2352 tar.pack(path.join(__dirname, '../'), {
2453 entries: files.slice(),
2554 map: function (header) {
2655 header.name = 'package/' + header.name
56 + // deterministicify
57 + header.uid = header.gid = 0
58 + header.uname = header.gname = null
59 + header.mtime = new Date(0)
60 + if (header.name === 'package/package.json') {
61 + header.size = normalizedPkgJsonBuf.length
62 + }
2763 return header
64 + },
65 + mapStream: function (stream, header) {
66 + if (header.name === 'package/package.json') {
67 + // npm changes package.json during install.
68 + // change it back, to make things more deterministic
69 + stream.resume()
70 + return streamOnce(normalizedPkgJsonBuf)
71 + }
72 + return stream
2873 }
2974 }).pipe(gzip)
3075 return toPull.source(gzip)
3176 }

Built with git-ssb-web