Skip to content

Commit

Permalink
feat(manifest): include _shasum for legacy compat
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Apr 29, 2017
1 parent 4595ab2 commit b3a7eed
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/fetchers/registry/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function pickMem (opts) {
function annotateManifest (uri, registry, manifest) {
const shasum = manifest.dist && manifest.dist.shasum
manifest._integrity = manifest.dist && manifest.dist.integrity
manifest._shasum = shasum
if (!manifest._integrity && shasum) {
// Use legacy dist.shasum field if available.
manifest._integrity = ssri.fromHex(shasum, 'sha1').toString()
Expand Down
1 change: 1 addition & 0 deletions lib/finalize-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function Manifest (pkg, fromTarball, fullMetadata) {
// and if they don't, we need to extract and read the tarball ourselves.
// These are details required by the installer.
this._integrity = pkg._integrity || fromTarball._integrity
this._shasum = pkg._shasum
this._shrinkwrap = pkg._shrinkwrap || fromTarball._shrinkwrap || null
this.bin = pkg.bin || fromTarball.bin || null

Expand Down
1 change: 1 addition & 0 deletions test/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ test('supports directory deps', t => {
peerDependencies: {},
deprecated: false,
_resolved: path.resolve(PKG).replace(/\\/g, '/'),
_shasum: null,
_integrity: null,
_shrinkwrap: sr,
bin: { mybin: path.join('x', 'mybin') },
Expand Down
5 changes: 5 additions & 0 deletions test/finalize-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ test('returns a manifest with the right fields', t => {
bin: './foo.js',
_resolved: 'resolved.to.this',
_integrity: 'sha1-deadbeefc0ffeebad1dea',
_shasum: 'deadbeef1',
_hasShrinkwrap: false,
deprecated: 'foo'
}
Expand All @@ -60,6 +61,7 @@ test('returns a manifest with the right fields', t => {
bin: {
testing: './foo.js'
},
_shasum: 'deadbeef1',
_resolved: 'resolved.to.this',
_integrity: 'sha1-deadbeefc0ffeebad1dea',
_shrinkwrap: null,
Expand All @@ -73,6 +75,7 @@ test('defaults all field to expected types + values', t => {
const base = {
name: 'testing',
version: '1.2.3',
_shasum: 'deadbeef',
_resolved: 'resolved.to.this',
_integrity: 'sha1-deadbeefc0ffeebad1dea',
_hasShrinkwrap: false
Expand All @@ -92,6 +95,7 @@ test('defaults all field to expected types + values', t => {
bin: null,
_resolved: base._resolved,
_integrity: base._integrity,
_shasum: base._shasum,
_shrinkwrap: null,
deprecated: false,
_id: 'testing@1.2.3'
Expand Down Expand Up @@ -250,6 +254,7 @@ test('uses package.json as base if passed null', t => {
_resolved: OPTS.registry + tarballPath,
deprecated: false,
_integrity: ssri.fromData(tarData, {algorithms: ['sha1']}).toString(),
_shasum: null, // shasums are only when provided
_shrinkwrap: sr,
bin: { 'x': path.join('foo', 'x') },
_id: 'testing@1.2.3'
Expand Down
4 changes: 3 additions & 1 deletion test/prefetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const PKG = {

test('setup integrity', t => {
return mockTar(PKG).then(tarData => {
BASE.dist.integrity = BASE._integrity = ssri.fromData(tarData, {algorithms: ['sha1']}).toString()
const integrity = ssri.fromData(tarData, {algorithms: ['sha1']})
BASE.dist.integrity = BASE._integrity = integrity.toString()
BASE.dist.shasum = BASE._shasum = integrity.hexDigest()
return 'lol ok'
})
})
Expand Down
1 change: 1 addition & 0 deletions test/registry.manifest.cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const PKG = new Manifest({
name: 'foo',
version: '1.2.3',
_hasShrinkwrap: false,
_shasum: BASE.dist.shasum,
_integrity: BASE.dist.integrity,
_resolved: BASE.dist.tarball
})
Expand Down

0 comments on commit b3a7eed

Please sign in to comment.