Skip to content

Commit

Permalink
fix: Allow package.json to have missing dependency property
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Oct 5, 2018
1 parent 4254065 commit 55de7e0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ async function buildDepTree(
}

const manifestFile: ManifestFile = parseManifestFile(manifestFileContents);
if (!manifestFile.dependencies && !includeDev) {
throw new Error("No 'dependencies' property in package.json");
}

const lockFile: Lockfile = lockfileParser.parseLockFile(lockFileContents);
return lockfileParser.getDependencyTree(manifestFile, lockFile, includeDev);
}
Expand Down
6 changes: 6 additions & 0 deletions test/lib/fixtures/dev-deps-only/expected-tree-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "pkg-dev-deps-only",
"version": "0.0.1",
"hasDevDependencies": true,
"dependencies": {}
}
11 changes: 11 additions & 0 deletions test/lib/package-lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ test('Parse npm package-lock.json with dev deps only', async (t) => {
t.deepEqual(depTree, expectedDepTree, 'Tree is created with dev deps only');
});

test('Parse npm package-lock.json with dev deps only', async (t) => {
const expectedDepTreeEmpty = load('dev-deps-only/expected-tree-empty.json');
const depTree = await buildDepTreeFromFiles(
`${__dirname}/fixtures/dev-deps-only/`,
'package.json',
'package-lock.json',
false,
);
t.deepEqual(depTree, expectedDepTreeEmpty, 'Tree is created empty');
});

test('Parse npm package-lock.json with cyclic deps', async (t) => {
const depTree = await buildDepTreeFromFiles(
`${__dirname}/fixtures/cyclic-dep-simple/`,
Expand Down

0 comments on commit 55de7e0

Please sign in to comment.