diff --git a/src/main/scopes/npm/find-installers-from-tree.ts b/src/main/scopes/npm/find-installers-from-tree.ts index 9e16f08b..b52c9d3e 100644 --- a/src/main/scopes/npm/find-installers-from-tree.ts +++ b/src/main/scopes/npm/find-installers-from-tree.ts @@ -52,15 +52,16 @@ export function findInstallersFromTree( packageName, packageVersion ]) + let results: InstallingPackage[] = [] + // Matches come back as something like: [..., parentPkgName, dependencies, instrumentedPackage] const matches = findNestedDeps(dependencyTree, packageName, packageVersion) - let result: InstallingPackage[] = [] if (matches.length >= 1) { // We want to ignore last 2 pieces to get the parent's info, not the child's - result = matches.map((match) => getPackageSubTree(dependencyTree, match.slice(0, -2))) + results = matches.map((match) => getPackageSubTree(dependencyTree, match.slice(0, -2))) } - logger.traceExit('find-installers-from-tree', 'findInstallersFromTree', result) - return result + logger.traceExit('find-installers-from-tree', 'findInstallersFromTree', results) + return results } diff --git a/src/main/scopes/npm/metrics/dependency-metric.ts b/src/main/scopes/npm/metrics/dependency-metric.ts index a209bc61..db4e1108 100644 --- a/src/main/scopes/npm/metrics/dependency-metric.ts +++ b/src/main/scopes/npm/metrics/dependency-metric.ts @@ -62,7 +62,7 @@ export class DependencyMetric extends ScopeMetric { 'version.major': major.toString(), 'version.minor': minor.toString(), 'version.patch': patch.toString(), - 'version.preRelease': preRelease.join('.'), + 'version.preRelease': preRelease?.join('.'), 'installer.raw': this.data.installerName, 'installer.owner': installerOwner, 'installer.name': installerName, @@ -70,7 +70,7 @@ export class DependencyMetric extends ScopeMetric { 'installer.version.major': installerMajor.toString(), 'installer.version.minor': installerMinor.toString(), 'installer.version.patch': installerPatch.toString(), - 'installer.version.preRelease': installerPreRelease.join('.') + 'installer.version.preRelease': installerPreRelease?.join('.') }, { hash: [ @@ -109,12 +109,12 @@ export class DependencyMetric extends ScopeMetric { const { major, minor, patch, prerelease } = new SemVer(rawPackageVersion) return { - owner, - name, + owner: owner === '' ? undefined : owner, + name: name === '' ? undefined : name, major, minor, patch, - preRelease: prerelease + preRelease: prerelease.length === 0 ? undefined : prerelease } } } diff --git a/src/test/scopes/npm/__snapshots__/npm-scope.e2e.test.ts.snap b/src/test/scopes/npm/__snapshots__/npm-scope.e2e.test.ts.snap index 542ba5ba..a7d37aa2 100644 --- a/src/test/scopes/npm/__snapshots__/npm-scope.e2e.test.ts.snap +++ b/src/test/scopes/npm/__snapshots__/npm-scope.e2e.test.ts.snap @@ -74,7 +74,7 @@ exports[`class: NpmScope > run > correctly captures dependency data 1`] = ` "installer.version.major": "1", "installer.version.minor": "0", "installer.version.patch": "0", - "installer.version.preRelease": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "installer.version.preRelease": undefined, "installer.version.raw": "92521fc3cbd964bdc9f584a991b89fddaa5754ed1cc96d6d42445338669c1305", "name": "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae", "owner": undefined, @@ -82,7 +82,7 @@ exports[`class: NpmScope > run > correctly captures dependency data 1`] = ` "version.major": "1", "version.minor": "0", "version.patch": "0", - "version.preRelease": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "version.preRelease": undefined, "version.raw": "92521fc3cbd964bdc9f584a991b89fddaa5754ed1cc96d6d42445338669c1305", }, "endTime": [ @@ -103,7 +103,7 @@ exports[`class: NpmScope > run > correctly captures dependency data 1`] = ` "installer.version.major": "1", "installer.version.minor": "0", "installer.version.patch": "0", - "installer.version.preRelease": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "installer.version.preRelease": undefined, "installer.version.raw": "92521fc3cbd964bdc9f584a991b89fddaa5754ed1cc96d6d42445338669c1305", "name": "ec46e364d52dab2e207d33617267a84df5838926793c1b0a2974899fe28229f1", "owner": undefined, @@ -111,7 +111,7 @@ exports[`class: NpmScope > run > correctly captures dependency data 1`] = ` "version.major": "0", "version.minor": "1", "version.patch": "0", - "version.preRelease": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "version.preRelease": undefined, "version.raw": "6ad9613a455798d6d92e5f5f390ab4baa70596bc869ed6b17f5cdd2b28635f06", }, "endTime": [ diff --git a/src/test/scopes/npm/metrics/dependency-metric.test.ts b/src/test/scopes/npm/metrics/dependency-metric.test.ts index 4ef32d21..ba79d06a 100644 --- a/src/test/scopes/npm/metrics/dependency-metric.test.ts +++ b/src/test/scopes/npm/metrics/dependency-metric.test.ts @@ -37,14 +37,14 @@ describe('dependencyMetric', () => { 'version.major': '0', 'version.minor': '0', 'version.patch': '1', - 'version.preRelease': '', + 'version.preRelease': undefined, 'installer.name': 'test-1-installer', 'installer.owner': undefined, 'installer.raw': 'test-1-installer', 'installer.version.major': '1', 'installer.version.minor': '0', 'installer.version.patch': '0', - 'installer.version.preRelease': '', + 'installer.version.preRelease': undefined, 'installer.version.raw': '1.0.0' }, { @@ -135,13 +135,13 @@ describe('dependencyMetric', () => { 'installer.version.major': '1', 'installer.version.minor': '0', 'installer.version.patch': '0', - 'installer.version.preRelease': '', + 'installer.version.preRelease': undefined, 'installer.version.raw': '1.0.0+9999', 'version.raw': '0.0.1+12345', 'version.major': '0', 'version.minor': '0', 'version.patch': '1', - 'version.preRelease': '' + 'version.preRelease': undefined }, { hash: [ @@ -232,7 +232,7 @@ describe('dependencyMetric', () => { 'installer.version.major': '1', 'installer.version.minor': '0', 'installer.version.patch': '0', - 'installer.version.preRelease': '', + 'installer.version.preRelease': undefined, 'installer.version.raw': '1.0.0', 'version.raw': '0.0.1-rc.0+12345', 'version.major': '0',