From 143a0b9e6a7929368cd3a298b85fa6820d4c1f52 Mon Sep 17 00:00:00 2001 From: nlf Date: Mon, 22 Mar 2021 15:02:26 -0700 Subject: [PATCH] fix: force gzip compression level to 9 (#71) this seems to avoid some platform related optimizations that result in integrity mismatches due to the resulting compressed output not being byte for byte identical. --- lib/util/tar-create-options.js | 8 +++++++- tap-snapshots/test-dir.js-TAP.test.js | 10 +++++----- test/dir.js | 4 +++- test/util/tar-create-options.js | 4 +++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/util/tar-create-options.js b/lib/util/tar-create-options.js index e8abbe17..31ab34c9 100644 --- a/lib/util/tar-create-options.js +++ b/lib/util/tar-create-options.js @@ -4,7 +4,13 @@ const tarCreateOptions = manifest => ({ cwd: manifest._resolved, prefix: 'package/', portable: true, - gzip: true, + gzip: { + // forcing the level to 9 seems to avoid some + // platform specific optimizations that cause + // integrity mismatch errors due to differing + // end results after compression + level: 9 + }, // ensure that package bins are always executable // Note that npm-packlist is already filtering out diff --git a/tap-snapshots/test-dir.js-TAP.test.js b/tap-snapshots/test-dir.js-TAP.test.js index fd3a43cd..4a7a0c63 100644 --- a/tap-snapshots/test-dir.js-TAP.test.js +++ b/tap-snapshots/test-dir.js-TAP.test.js @@ -8,7 +8,7 @@ exports[`test/dir.js TAP basic > extract 1`] = ` Object { "from": "file:test/fixtures/abbrev", - "integrity": "sha512-Ict4yhLfiPOkcX+yjBRSI2QUetKt+A08AXMyLeQbKGYg/OGI/1k47Hu9tWZOx1l4j+M1z07Zxt3IL41TmLkbDw==", + "integrity": "sha512-OCm45DHz7n9f1SEllmg3Bf1zBCzsiOYxMuodMZ5ux+HMoupmkzOftyOCKH07DhAcoyfUlos2VGmYkPHDxH92yg==", "resolved": "\${CWD}/test/fixtures/abbrev", } ` @@ -176,7 +176,7 @@ Object { exports[`test/dir.js TAP make bins executable > results of unpack 1`] = ` Object { "from": "file:test/fixtures/bin-object", - "integrity": "sha512-rlE32nBV7XgKCm0I7YqAewyVPbaRJWUQMZUFLlngGK3imG+som3Hin7d/zPTikWg64tHIxb8VXeeq6u0IRRfmQ==", + "integrity": "sha512-hvYyDtqhAkxg/NF7eOjCpDcIs7ksaZjk9vrBkktxTJ0liITA/FsnEgmbP9l8h3rp+zN1QIvKAUvyTCYRpyCqZQ==", "resolved": "\${CWD}/test/fixtures/bin-object", } ` @@ -184,7 +184,7 @@ Object { exports[`test/dir.js TAP responds to foregroundScripts: true > extract 1`] = ` Object { "from": "file:test/fixtures/prepare-script", - "integrity": "sha512-HTzPAt8wmXNchUdisnGDSCuUgrFee5v8F6GsLc5mQd29VXiNzv4PGz71jjLSIF1wWQSB+UjLTmSJSGznF/s/Lw==", + "integrity": "sha512-+bTA3RvkXgLMM1PIzfcwXkiiSYzCBHT6Jrqo8yt3owZtMhOnBomH1Dc0949tVurdyPk7WcrKitvsRnXRPCD4sQ==", "resolved": "\${CWD}/test/fixtures/prepare-script", } ` @@ -250,7 +250,7 @@ Object { exports[`test/dir.js TAP responds to foregroundScripts: true and log:{level: silent} > extract 1`] = ` Object { "from": "file:test/fixtures/prepare-script", - "integrity": "sha512-HTzPAt8wmXNchUdisnGDSCuUgrFee5v8F6GsLc5mQd29VXiNzv4PGz71jjLSIF1wWQSB+UjLTmSJSGznF/s/Lw==", + "integrity": "sha512-+bTA3RvkXgLMM1PIzfcwXkiiSYzCBHT6Jrqo8yt3owZtMhOnBomH1Dc0949tVurdyPk7WcrKitvsRnXRPCD4sQ==", "resolved": "\${CWD}/test/fixtures/prepare-script", } ` @@ -316,7 +316,7 @@ Object { exports[`test/dir.js TAP with prepare script > extract 1`] = ` Object { "from": "file:test/fixtures/prepare-script", - "integrity": "sha512-HTzPAt8wmXNchUdisnGDSCuUgrFee5v8F6GsLc5mQd29VXiNzv4PGz71jjLSIF1wWQSB+UjLTmSJSGznF/s/Lw==", + "integrity": "sha512-+bTA3RvkXgLMM1PIzfcwXkiiSYzCBHT6Jrqo8yt3owZtMhOnBomH1Dc0949tVurdyPk7WcrKitvsRnXRPCD4sQ==", "resolved": "\${CWD}/test/fixtures/prepare-script", } ` diff --git a/test/dir.js b/test/dir.js index 9bad0bf6..ee662572 100644 --- a/test/dir.js +++ b/test/dir.js @@ -145,7 +145,9 @@ t.test('exposes tarCreateOptions method', async t => { cwd: '/home/foo', prefix: 'package/', portable: true, - gzip: true, + gzip: { + level: 9 + }, mtime: new Date('1985-10-26T08:15:00.000Z'), }, 'should return standard options' diff --git a/test/util/tar-create-options.js b/test/util/tar-create-options.js index c96dbaff..780e1913 100644 --- a/test/util/tar-create-options.js +++ b/test/util/tar-create-options.js @@ -8,7 +8,9 @@ t.match( cwd: '/home/foo', prefix: 'package/', portable: true, - gzip: true, + gzip: { + level: 9 + }, mtime: new Date('1985-10-26T08:15:00.000Z'), }, 'should return standard options'