Fix ?meta listings
Fixes ?meta listings (and other requests) for packages with a root "directory" entry. Fixes #210
This commit is contained in:
parent
e757febc33
commit
88a4213caa
|
@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -24,7 +24,7 @@ async function findMatchingEntries(stream, filename) {
|
||||||
// so we shorten that to just `/index.js` here. A few packages use a
|
// 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
|
// prefix other than `package/`. e.g. the firebase package uses the
|
||||||
// `firebase_npm/` prefix. So we just strip the first dir name.
|
// `firebase_npm/` prefix. So we just strip the first dir name.
|
||||||
path: header.name.replace(/^[^/]+/, ''),
|
path: header.name.replace(/^[^/]+\/?/, '/'),
|
||||||
type: header.type
|
type: header.type
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ async function findMatchingEntries(stream, filename) {
|
||||||
// so we shorten that to just `/index.js` here. A few packages use a
|
// 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
|
// prefix other than `package/`. e.g. the firebase package uses the
|
||||||
// `firebase_npm/` prefix. So we just strip the first dir name.
|
// `firebase_npm/` prefix. So we just strip the first dir name.
|
||||||
path: header.name.replace(/^[^/]+/, ''),
|
path: header.name.replace(/^[^/]+\/?/, '/'),
|
||||||
type: header.type
|
type: header.type
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ async function findEntry(stream, filename) {
|
||||||
// so we shorten that to just `/index.js` here. A few packages use a
|
// 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
|
// prefix other than `package/`. e.g. the firebase package uses the
|
||||||
// `firebase_npm/` prefix. So we just strip the first dir name.
|
// `firebase_npm/` prefix. So we just strip the first dir name.
|
||||||
path: header.name.replace(/^[^/]+/, ''),
|
path: header.name.replace(/^[^/]+\/?/, '/'),
|
||||||
type: header.type
|
type: header.type
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ async function findEntry(stream, filename) {
|
||||||
// so we shorten that to just `/index.js` here. A few packages use a
|
// 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
|
// prefix other than `package/`. e.g. the firebase package uses the
|
||||||
// `firebase_npm/` prefix. So we just strip the first dir name.
|
// `firebase_npm/` prefix. So we just strip the first dir name.
|
||||||
path: header.name.replace(/^[^/]+/, ''),
|
path: header.name.replace(/^[^/]+\/?/, '/'),
|
||||||
type: header.type
|
type: header.type
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue