1'use strict' 2const fs = require('fs') 3const path = require('path') 4const test = require('tap').test 5const requireInject = require('require-inject') 6const Tacks = require('tacks') 7const File = Tacks.File 8const Dir = Tacks.Dir 9 10const manifests = { 11 'git-wrap': { 12 name: 'git-wrap', 13 version: '1.0.0', 14 dependencies: { 15 git: 'git+https://example.com/git#semver:1.0' 16 } 17 }, 18 git: { 19 name: 'git', 20 version: '1.0.0' 21 } 22} 23 24const npm = requireInject.installGlobally('../../lib/npm.js', { 25 pacote: { 26 manifest: function (spec) { 27 const manifest = manifests[spec.name] 28 manifest._requested = spec 29 manifest._resolved = spec.saveSpec.replace(/^file:/, '').replace(/(:?#.*)$/, '#0000000000000000000000000000000000000000') 30 manifest._from = spec.rawSpec 31 return Promise.resolve(manifest) 32 } 33 }, 34 '../../lib/utils/output.js': function () { 35 // do not output to stdout 36 } 37}) 38 39const common = require('../common-tap.js') 40const basedir = common.pkg 41const testdir = path.join(basedir, 'testdir') 42const cachedir = common.cache 43const tmpdir = path.join(basedir, 'tmp') 44 45const cwd = process.cwd() 46 47const conf = { 48 cache: cachedir, 49 tmp: tmpdir, 50 loglevel: 'silent', 51 'package-lock-only': true 52} 53 54const fixture = new Tacks(Dir({ 55 cache: Dir(), 56 global: Dir(), 57 tmp: Dir(), 58 testdir: Dir({ 59 'package.json': File({ 60 name: 'fixture', 61 version: '1.0.0', 62 dependencies: { 63 git: 'git+https://example.com/git#semver:1', 64 'git-wrap': 'file:git-wrap-1.0.0.tgz' 65 } 66 }), 67 // Tarball source: 68 // 'git-wrap': Dir({ 69 // 'package.json': File({ 70 // name: 'git-wrap', 71 // version: '1.0.0', 72 // dependencies: { 73 // git: 'git+https://example.com/git#semver:1.0' 74 // } 75 // }) 76 // }), 77 'git-wrap-1.0.0.tgz': File(Buffer.from( 78 '1f8b0800000000000003ed8fcd0ac23010843df729423caaf9c13642df26' + 79 'b44bad9a3434f107a4efeec68aa7de2c8898ef32cb0c3bec3a5d1d7503dc' + 80 '8dca0ebeb38b991142a83c27537e44ee30db164a48a994c01987a210a873' + 81 '1f32c5d907dde3299ff68cbf90b7fe08f78c106ab5015a12dab46173edb5' + 82 'a3ebe85ea0f76d676320996062746b70606bb0550b1ea3b84f9e9baf82d5' + 83 '3e04e74bcee1a68d3b01ab3ac3d15f7a30d8586215c59d211bb26fff9e48' + 84 '2412ffcc034458283d00080000', 85 'hex' 86 )) 87 }) 88})) 89 90function setup () { 91 cleanup() 92 fixture.create(basedir) 93} 94 95function cleanup () { 96 fixture.remove(basedir) 97} 98 99test('setup', function (t) { 100 setup() 101 process.chdir(testdir) 102 npm.load(conf, function (err) { 103 if (err) throw err 104 t.done() 105 }) 106}) 107 108test('dedupe matching git semver ranges', function (t) { 109 npm.commands.install(function (err) { 110 if (err) throw err 111 const packageLock = JSON.parse(fs.readFileSync('package-lock.json')) 112 t.same(packageLock, { 113 name: 'fixture', 114 version: '1.0.0', 115 lockfileVersion: 1, 116 requires: true, 117 dependencies: { 118 git: { 119 from: 'git+https://example.com/git#semver:1', 120 version: 'git+https://example.com/git#0000000000000000000000000000000000000000' 121 }, 122 'git-wrap': { 123 version: 'file:git-wrap-1.0.0.tgz', 124 requires: { 125 git: 'git+https://example.com/git#semver:1' 126 } 127 } 128 } 129 }) 130 t.done() 131 }) 132}) 133 134test('cleanup', function (t) { 135 process.chdir(cwd) 136 cleanup() 137 t.done() 138}) 139