Skip to content

Commit

Permalink
feat: lockfile parser must always return depTree.name
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliabaron committed Dec 2, 2018
1 parent ab43cb5 commit 3a9d98a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export {
async function buildDepTree(
manifestFileContents: string, lockFileContents: string,
includeDev = false, lockfileType?: LockfileType,
strict: boolean = true): Promise<PkgTree> {
strict: boolean = true, manifestFilePath: string = 'package.json'): Promise<PkgTree> {

if (!lockfileType) {
lockfileType = LockfileType.npm;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion test/lib/package-lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion test/lib/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 3a9d98a

Please sign in to comment.