Skip to content

Commit 980200b

Browse files
ybiquitousMichael Perrotte
authored and
Michael Perrotte
committed
feat: npm repo support repository.directory field
See #140 PR-URL: #163 Credit: @ybiquitous Close: #163 Reviewed-by: @mikemimik
1 parent 8676429 commit 980200b

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

lib/repo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function getUrlAndOpen (d, cb) {
2727
// XXX remove this when npm@v1.3.10 from node 0.10 is deprecated
2828
// from https://github.com/npm/npm-www/issues/418
2929
const info = hostedGitInfo.fromUrl(r.url)
30-
const url = info ? info.browse() : unknownHostedUrl(r.url)
30+
const url = info ? info.browse(d.repository.directory) : unknownHostedUrl(r.url)
3131

3232
if (!url) return cb(new Error('no repository: could not get url'))
3333

test/tap/repo.js

+73
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,79 @@ test('npm repo test-repo-url-ssh - non-github (ssh://)', function (t) {
168168
})
169169
})
170170

171+
/* ----- Test by new mock registry: BEGIN ----- */
172+
173+
const Tacks = require('tacks')
174+
const mockTar = require('../util/mock-tarball.js')
175+
176+
const { Dir, File } = Tacks
177+
const testDir = path.join(__dirname, path.basename(__filename, '.js'))
178+
179+
let server
180+
test('setup mocked registry', t => {
181+
common.fakeRegistry.compat({}, (err, s) => {
182+
t.ifError(err, 'registry mocked successfully')
183+
server = s
184+
t.end()
185+
})
186+
})
187+
188+
test('npm repo test-repo-with-directory', t => {
189+
const fixture = new Tacks(Dir({
190+
'package.json': File({})
191+
}))
192+
fixture.create(testDir)
193+
const packument = {
194+
name: 'test-repo-with-directory',
195+
'dist-tags': { latest: '1.2.3' },
196+
versions: {
197+
'1.2.3': {
198+
name: 'test-repo-with-directory',
199+
version: '1.2.3',
200+
dist: {
201+
tarball: `${server.registry}/test-repo-with-directory/-/test-repo-with-directory-1.2.3.tgz`
202+
},
203+
repository: {
204+
type: 'git',
205+
url: 'git+https://github.com/foo/test-repo-with-directory.git',
206+
directory: 'some/directory'
207+
}
208+
}
209+
}
210+
}
211+
server.get('/test-repo-with-directory').reply(200, packument)
212+
return mockTar({
213+
'package.json': JSON.stringify({
214+
name: 'test-repo-with-directory',
215+
version: '1.2.3'
216+
})
217+
}).then(tarball => {
218+
server.get('/test-repo-with-directory/-/test-repo-with-directory-1.2.3.tgz').reply(200, tarball)
219+
return common.npm([
220+
'repo', 'test-repo-with-directory',
221+
'--registry=' + server.registry,
222+
'--loglevel=silent',
223+
'--browser=' + fakeBrowser
224+
])
225+
}).then(([code, stdout, stderr]) => {
226+
t.equal(code, 0)
227+
t.comment(stdout)
228+
t.comment(stderr)
229+
230+
const res = fs.readFileSync(outFile, 'ascii')
231+
t.equal(res, 'https://github.com/foo/test-repo-with-directory/tree/master/some/directory\n')
232+
rimraf.sync(outFile)
233+
})
234+
})
235+
236+
test('cleanup mocked registry', t => {
237+
server.close()
238+
rimraf.sync(testDir)
239+
t.end()
240+
})
241+
242+
/* ----- Test by new mock registry: END ----- */
243+
171244
test('cleanup', function (t) {
172245
fs.unlinkSync(fakeBrowser)
173246
t.pass('cleaned up')

0 commit comments

Comments
 (0)