fix(lerna): Return empty lerna packages if 404 for packages/* (#540)

This commit is contained in:
Rhys Arkins 2017-07-27 14:58:26 +02:00 committed by GitHub
parent feffa774d8
commit 434def2bf4
3 changed files with 27 additions and 7 deletions

View file

@ -30,16 +30,21 @@ async function setNpmrc(config) {
}
async function checkForLerna(config) {
const lernaJson = await config.api.getFileContent('lerna.json');
const lernaJson = await config.api.getFileJson('lerna.json');
if (!lernaJson) {
return {};
}
config.logger.debug('Found lerna config');
const lernaPackages = await config.api.getSubDirectories('packages');
if (lernaPackages.length === 0) {
config.logger.debug({ lernaJson }, 'Found lerna config');
try {
const lernaPackages = await config.api.getSubDirectories('packages');
if (lernaPackages.length === 0) {
return {};
}
return { lernaPackages };
} catch (err) {
config.logger.warn('lerna getSubDirectories error');
return {};
}
return { lernaPackages };
}
async function initApis(inputConfig, token) {

View file

@ -11,6 +11,8 @@ Object {
}
`;
exports[`workers/repository/apis checkForLerna(config) swallows lerna 404 1`] = `Object {}`;
exports[`workers/repository/apis detectPackageFiles(config) adds package files to object 1`] = `
Array [
"package.json",

View file

@ -43,10 +43,23 @@ describe('workers/repository/apis', () => {
});
});
describe('checkForLerna(config)', () => {
it('swallows lerna 404', async () => {
const config = {
api: {
getFileJson: jest.fn(() => ({})),
getSubDirectories: jest.fn(() => {
throw new Error('some-error');
}),
},
logger,
};
const res = await apis.checkForLerna(config);
expect(res).toMatchSnapshot();
});
it('ignores zero length lerna', async () => {
const config = {
api: {
getFileContent: jest.fn(() => 'some content'),
getFileJson: jest.fn(() => ({})),
getSubDirectories: jest.fn(() => []),
},
logger,
@ -57,7 +70,7 @@ describe('workers/repository/apis', () => {
it('returns lerna package names', async () => {
const config = {
api: {
getFileContent: jest.fn(() => 'some content'),
getFileJson: jest.fn(() => ({})),
getSubDirectories: jest.fn(() => ['a', 'b']),
},
logger,