From 40d102728a23fe406f2672c239e33b1fab89535f Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Thu, 2 Feb 2017 15:57:14 -0800 Subject: [PATCH] Add flag for TypeScript modules --- config/elasticsearch/npms.json5 | 1 + lib/analyze/collect/source.js | 10 ++++++---- lib/scoring/score.js | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config/elasticsearch/npms.json5 b/config/elasticsearch/npms.json5 index c18df093..500a991a 100644 --- a/config/elasticsearch/npms.json5 +++ b/config/elasticsearch/npms.json5 @@ -341,6 +341,7 @@ "deprecated": { "type": "string", "index": "not_analyzed" }, "insecure": { "type": "integer" }, "unstable": { "type": "boolean" }, + "dts": { "type": "boolean" }, }, }, "evaluation": { diff --git a/lib/analyze/collect/source.js b/lib/analyze/collect/source.js index 773f9ed9..4a404a3b 100644 --- a/lib/analyze/collect/source.js +++ b/lib/analyze/collect/source.js @@ -23,17 +23,19 @@ const log = logger.child({ module: 'collect/source' }); /** * Inspects important files, such as the tests and README file sizes. * - * @param {object} data The package data - * @param {string} dir The package directory + * @param {object} data The package data + * @param {string} dir The package directory + * @param {object} packageJson The latest package.json data (normalized) * * @return {Promise} The promise for the inspection result */ -function inspectFiles(data, dir) { +function inspectFiles(data, dir, packageJson) { return Promise.props({ readmeSize: data.readmeFilename ? fileSize(`${dir}/${data.readmeFilename}`) : 0, testsSize: detectRepoTestFiles(dir).then((files) => fileSize(files)), hasNpmIgnore: isRegularFile(`${dir}/.npmignore`).then((is) => is || null), hasShrinkwrap: isRegularFile(`${dir}/npm-shrinkwrap.json`).then((is) => is || null), + hasTypeScriptDeclaration: isRegularFile(path.join(dir, String(packageJson.typings || packageJson.types || 'index.d.ts'))).then((is) => is || null), hasChangelog: detectRepoChangelog(dir).then((file) => !!file).then((is) => is || null), }); } @@ -183,7 +185,7 @@ function source(data, packageJson, downloaded, options) { // Analyze source first because the external tools add files to the directory return promisePropsSettled({ - files: inspectFiles(data, downloaded.dir), + files: inspectFiles(data, downloaded.dir, packageJson), repositorySize: fileSize.dir(downloaded.dir), linters: detectRepoLinters(downloaded.dir), coverage: fetchCodeCoverage(packageJson, badges), diff --git a/lib/scoring/score.js b/lib/scoring/score.js index 21eb71c4..581c338d 100644 --- a/lib/scoring/score.js +++ b/lib/scoring/score.js @@ -158,6 +158,7 @@ function buildScore(analysis, aggregation) { deprecated: collected.metadata.deprecated, insecure: collected.source && collected.source.vulnerabilities ? collected.source.vulnerabilities.length : null, unstable: semver.lt(collected.metadata.version, '1.0.0', true) ? true : null, + dts: collected.source && collected.source.hasTypeScriptDeclaration, }, evaluation, score: {