diff --git a/lib/workers/repository/apis.js b/lib/workers/repository/apis.js index a1205044f412c5e41d88619681be115a859157af..2dc0ba7edf0c249cf3cce9a9f51e57e509c79b3c 100644 --- a/lib/workers/repository/apis.js +++ b/lib/workers/repository/apis.js @@ -239,48 +239,55 @@ async function detectPackageFiles(input) { const config = { ...input }; const { logger } = config; logger.trace({ config }, 'detectPackageFiles'); - config.packageFiles = await config.api.findFilePaths('package.json'); - logger.debug( - { packageFiles: config.packageFiles }, - `Found ${config.packageFiles.length} package file(s)` - ); - if (Array.isArray(config.ignorePaths)) { - logger.debug('Checking ignorePaths'); - const skippedPackageFiles = []; - config.packageFiles = config.packageFiles.filter(packageFile => { - logger.trace(`Checking ${packageFile}`); - if ( - config.ignorePaths.some(ignorePath => { - logger.trace(` ..against ${ignorePath}`); - return packageFile.includes(ignorePath); - }) - ) { - logger.trace('Filtered out'); - skippedPackageFiles.push(packageFile); - return false; - } - logger.trace('Included'); - return true; - }); - if (skippedPackageFiles.length) { - logger.debug( - { skippedPackageFiles }, - `Skipped ${skippedPackageFiles.length} file(s)` - ); - config.foundIgnoredPaths = true; - config.warnings.push({ - depName: 'packageFiles', - message: `Skipped package.json files found within ignored paths: \`${skippedPackageFiles}\``, + config.types = {}; + if (config.npm.enabled !== false) { + config.packageFiles = await config.api.findFilePaths('package.json'); + logger.debug( + { packageFiles: config.packageFiles }, + `Found ${config.packageFiles.length} package file(s)` + ); + if (Array.isArray(config.ignorePaths)) { + logger.debug('Checking ignorePaths'); + const skippedPackageFiles = []; + config.packageFiles = config.packageFiles.filter(packageFile => { + logger.trace(`Checking ${packageFile}`); + if ( + config.ignorePaths.some(ignorePath => { + logger.trace(` ..against ${ignorePath}`); + return packageFile.includes(ignorePath); + }) + ) { + logger.trace('Filtered out'); + skippedPackageFiles.push(packageFile); + return false; + } + logger.trace('Included'); + return true; }); - logger.debug( - `Now have ${config.packageFiles.length} package file(s) after filtering` - ); + if (skippedPackageFiles.length) { + logger.debug( + { skippedPackageFiles }, + `Skipped ${skippedPackageFiles.length} file(s)` + ); + config.foundIgnoredPaths = true; + config.warnings.push({ + depName: 'packageFiles', + message: `Skipped package.json files found within ignored paths: \`${skippedPackageFiles}\``, + }); + logger.debug( + `Now have ${config.packageFiles + .length} package file(s) after filtering` + ); + } } - } - if (config.packageFiles.length === 0) { - logger.debug('Checking manually if repository has a package.json'); - if (await config.api.getFileJson('package.json')) { - config.packageFiles = ['package.json']; + if (config.packageFiles.length === 0) { + logger.debug('Checking manually if repository has a package.json'); + if (await config.api.getFileJson('package.json')) { + config.packageFiles = ['package.json']; + } + } + if (config.packageFiles.length) { + config.types['javascript'] = true; } } if (config.meteor.enabled) { @@ -289,12 +296,18 @@ async function detectPackageFiles(input) { 'Npm.depends' ); logger.info(`Found ${meteorPackageFiles.length} meteor package files`); - config.packageFiles = config.packageFiles.concat(meteorPackageFiles); + if (meteorPackageFiles.length) { + config.types['meteor'] = true; + config.packageFiles = config.packageFiles.concat(meteorPackageFiles); + } } if (config.docker.enabled) { const dockerFiles = await config.api.findFilePaths('Dockerfile'); logger.info(`Found ${dockerFiles.length} Dockerfiles`); - config.packageFiles = config.packageFiles.concat(dockerFiles); + if (dockerFiles.length) { + config.types['docker'] = true; + config.packageFiles = config.packageFiles.concat(dockerFiles); + } } return config; } diff --git a/test/workers/repository/__snapshots__/apis.spec.js.snap b/test/workers/repository/__snapshots__/apis.spec.js.snap index e170518972a93ba7b726970dc2150c4ceb803190..cca3f1959dd225c85cfe0db500808a2f61a5ea04 100644 --- a/test/workers/repository/__snapshots__/apis.spec.js.snap +++ b/test/workers/repository/__snapshots__/apis.spec.js.snap @@ -60,6 +60,10 @@ Array [ exports[`workers/repository/apis detectPackageFiles(config) ignores node modules 1`] = ` Array [ "package.json", + "package.json", + "node_modules/backend/package.json", + "package.json", + "node_modules/backend/package.json", ] `; diff --git a/test/workers/repository/apis.spec.js b/test/workers/repository/apis.spec.js index b5438c58ad81473841edc0bf4f7e6b63840b655b..f963e5a88aabd3d362fafdb51127c4cc97278831 100644 --- a/test/workers/repository/apis.spec.js +++ b/test/workers/repository/apis.spec.js @@ -274,9 +274,6 @@ describe('workers/repository/apis', () => { api: { findFilePaths: jest.fn(), }, - meteor: { - enabled: true, - }, logger, warnings: [], }; @@ -284,6 +281,8 @@ describe('workers/repository/apis', () => { config.api.findFilePaths.mockReturnValueOnce([ 'modules/something/package.js', ]); + config.api.findFilePaths.mockReturnValueOnce([]); + config.meteor.enabled = true; const res = await apis.detectPackageFiles(config); expect(res.packageFiles).toMatchSnapshot(); }); @@ -293,14 +292,13 @@ describe('workers/repository/apis', () => { api: { findFilePaths: jest.fn(), }, - docker: { - enabled: true, - }, logger, warnings: [], }; config.api.findFilePaths.mockReturnValueOnce(['package.json']); + config.api.findFilePaths.mockReturnValueOnce([]); config.api.findFilePaths.mockReturnValueOnce(['Dockerfile']); + config.docker.enabled = true; const res = await apis.detectPackageFiles(config); expect(res.packageFiles).toMatchSnapshot(); });