Fix ?meta listings

Fixes ?meta listings (and other requests) for packages with a root
"directory" entry.

Fixes #210
This commit is contained in:
Michael Jackson 2019-08-01 10:05:05 -07:00
parent e757febc33
commit 88a4213caa
5 changed files with 36 additions and 4 deletions

View File

@ -0,0 +1,32 @@
import request from 'supertest';
import createServer from '../createServer.js';
describe('A request for metadata', () => {
let server;
beforeEach(() => {
server = createServer();
});
it('returns 200', done => {
request(server)
.get('/react@16.8.6/?meta')
.end((err, res) => {
expect(res.statusCode).toBe(200);
expect(res.headers['content-type']).toMatch(/\bapplication\/json\b/);
done();
});
});
describe('with a package that includes a root "directory" entry', () => {
it('returns 200', done => {
request(server)
.get('/sinuous@0.12.9/?meta')
.end((err, res) => {
expect(res.statusCode).toBe(200);
expect(res.headers['content-type']).toMatch(/\bapplication\/json\b/);
done();
});
});
});
});

View File

@ -24,7 +24,7 @@ async function findMatchingEntries(stream, filename) {
// so we shorten that to just `/index.js` here. A few packages use a
// prefix other than `package/`. e.g. the firebase package uses the
// `firebase_npm/` prefix. So we just strip the first dir name.
path: header.name.replace(/^[^/]+/, ''),
path: header.name.replace(/^[^/]+\/?/, '/'),
type: header.type
};

View File

@ -25,7 +25,7 @@ async function findMatchingEntries(stream, filename) {
// so we shorten that to just `/index.js` here. A few packages use a
// prefix other than `package/`. e.g. the firebase package uses the
// `firebase_npm/` prefix. So we just strip the first dir name.
path: header.name.replace(/^[^/]+/, ''),
path: header.name.replace(/^[^/]+\/?/, '/'),
type: header.type
};

View File

@ -27,7 +27,7 @@ async function findEntry(stream, filename) {
// so we shorten that to just `/index.js` here. A few packages use a
// prefix other than `package/`. e.g. the firebase package uses the
// `firebase_npm/` prefix. So we just strip the first dir name.
path: header.name.replace(/^[^/]+/, ''),
path: header.name.replace(/^[^/]+\/?/, '/'),
type: header.type
};

View File

@ -22,7 +22,7 @@ async function findEntry(stream, filename) {
// so we shorten that to just `/index.js` here. A few packages use a
// prefix other than `package/`. e.g. the firebase package uses the
// `firebase_npm/` prefix. So we just strip the first dir name.
path: header.name.replace(/^[^/]+/, ''),
path: header.name.replace(/^[^/]+\/?/, '/'),
type: header.type
};