diff --git a/lib/index.ts b/lib/index.ts index 5a60a96c..6b19eeb5 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -23,7 +23,7 @@ export { async function buildDepTree( manifestFileContents: string, lockFileContents: string, includeDev = false, lockfileType?: LockfileType, - strict: boolean = true): Promise { + strict: boolean = true, manifestFilePath: string = 'package.json'): Promise { if (!lockfileType) { lockfileType = LockfileType.npm; @@ -51,6 +51,9 @@ async function buildDepTree( } const manifestFile: ManifestFile = parseManifestFile(manifestFileContents); + if (!manifestFile.name) { + manifestFile.name = manifestFilePath; + } const lockFile: Lockfile = lockfileParser.parseLockFile(lockFileContents); return lockfileParser.getDependencyTree(manifestFile, lockFile, includeDev, strict); @@ -88,6 +91,7 @@ async function buildDepTreeFromFiles( const manifestFileContents = fs.readFileSync(manifestFileFullPath, 'utf-8'); const lockFileContents = fs.readFileSync(lockFileFullPath, 'utf-8'); + // note: currenty we path manifestFilePath just a file name, so we can use the param as is return await buildDepTree(manifestFileContents, lockFileContents, includeDev, - lockFileType, strict); + lockFileType, strict, manifestFilePath); } diff --git a/test/lib/package-lock.ts b/test/lib/package-lock.ts index 34ec27cc..e6168472 100644 --- a/test/lib/package-lock.ts +++ b/test/lib/package-lock.ts @@ -80,7 +80,7 @@ test('Parse npm package-lock.json with missing package name', async (t) => { ); t.false(_.isEmpty(depTree.dependencies)); - t.equals(depTree.name, undefined); + t.equals(depTree.name, 'package.json'); }); test('Parse npm package-lock.json with empty dependencies and includeDev = false', async (t) => { diff --git a/test/lib/yarn.ts b/test/lib/yarn.ts index 09b1144a..6b408eb3 100644 --- a/test/lib/yarn.ts +++ b/test/lib/yarn.ts @@ -120,7 +120,7 @@ if (getRuntimeVersion() < 6) { ); t.false(_.isEmpty(depTree.dependencies)); - t.equals(depTree.name, undefined); + t.equals(depTree.name, 'package.json'); }); test('Parse yarn.lock with empty dependencies and includeDev = false', async (t) => {