Skip to content

Commit

Permalink
fix(builtin): include optionalDependencies in strictly visible packag…
Browse files Browse the repository at this point in the history
…es (#2657)

These are identical to regular dependencies except that a failure to install them is non-fatal.
They should be visible as Bazel dependencies.

Note I didn't include peerDependencies here still. These are an indication that some consumer should install the package, and that results in a bazel-visible dependency, so I think that's working correctly
  • Loading branch information
alexeagle authored May 7, 2021
1 parent 8abc8e0 commit 2a1ed31
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
9 changes: 5 additions & 4 deletions internal/npm_install/generate_build_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,11 @@ export function getDirectDependencySet(pkgJsonPath: string): Set<string> {
stripBom(fs.readFileSync(pkgJsonPath, {encoding: 'utf8'}))
);

const dependencies: string[] = Object.keys(pkgJson.dependencies || {});
const devDependencies: string[] = Object.keys(pkgJson.devDependencies || {});

return new Set([...dependencies, ...devDependencies]);
return new Set([
...Object.keys(pkgJson.dependencies || {}),
...Object.keys(pkgJson.devDependencies || {}),
...Object.keys(pkgJson.optionalDependencies || {}),
]);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions internal/npm_install/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,11 @@ function hasRootBuildFile(pkg, rootPath) {
}
function getDirectDependencySet(pkgJsonPath) {
const pkgJson = JSON.parse(stripBom(fs.readFileSync(pkgJsonPath, { encoding: 'utf8' })));
const dependencies = Object.keys(pkgJson.dependencies || {});
const devDependencies = Object.keys(pkgJson.devDependencies || {});
return new Set([...dependencies, ...devDependencies]);
return new Set([
...Object.keys(pkgJson.dependencies || {}),
...Object.keys(pkgJson.devDependencies || {}),
...Object.keys(pkgJson.optionalDependencies || {}),
]);
}
exports.getDirectDependencySet = getDirectDependencySet;
function findPackages(p, dependencies) {
Expand Down
4 changes: 3 additions & 1 deletion internal/npm_install/test/package.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"@angular/core": "9.1.0"
},
"devDependencies": {
"@angular/common": "9.1.0",
"@angular/common": "9.1.0"
},
"optionalDependencies": {
"zone.js": "0.8.29"
}
}

0 comments on commit 2a1ed31

Please sign in to comment.