Skip to content

Commit

Permalink
fix: dont generate build files in symlinked node_modules (#1111)
Browse files Browse the repository at this point in the history
* fix: ignore symlinked packages

fixes #871

* fix: skipping hide build fies for links in node_modules
  • Loading branch information
soldair authored and alexeagle committed Oct 9, 2019
1 parent f432f35 commit 2e7de34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
13 changes: 10 additions & 3 deletions internal/npm_install/generate_build_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,13 @@ def _maybe(repo_rule, name, **kwargs):
.filter(f => !f.startsWith('.'))
.map(f => path.posix.join(p, f))
.filter(f => isDirectory(f));
packages.forEach(f => pkgs.push(parsePackage(f), ...findPackages(path.posix.join(f, 'node_modules'))));
packages.forEach(f => {
let hide = true;
if (fs.lstatSync(f).isSymbolicLink()) {
hide = false;
}
pkgs.push(parsePackage(f, hide), ...findPackages(path.posix.join(f, 'node_modules')));
});
const scopes = listing.filter(f => f.startsWith('@'))
.map(f => path.posix.join(p, f))
.filter(f => isDirectory(f));
Expand Down Expand Up @@ -486,7 +492,7 @@ def _maybe(repo_rule, name, **kwargs):
* package json and return it as an object along with
* some additional internal attributes prefixed with '_'.
*/
function parsePackage(p) {
function parsePackage(p, hide = true) {
// Parse the package.json file of this package
const packageJson = path.posix.join(p, 'package.json');
const pkg = isFile(packageJson) ? JSON.parse(fs.readFileSync(packageJson, { encoding: 'utf8' })) :
Expand All @@ -509,7 +515,8 @@ def _maybe(repo_rule, name, **kwargs):
// Hide bazel files in this package. We do this before parsing
// the next package to prevent issues caused by symlinks between
// package and nested packages setup by the package manager.
hideBazelFiles(pkg);
if (hide)
hideBazelFiles(pkg);
return pkg;
}
/**
Expand Down
13 changes: 9 additions & 4 deletions internal/npm_install/generate_build_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,13 @@ function findPackages(p = 'node_modules') {
.map(f => path.posix.join(p, f))
.filter(f => isDirectory(f));

packages.forEach(
f => pkgs.push(parsePackage(f), ...findPackages(path.posix.join(f, 'node_modules'))));
packages.forEach(f => {
let hide = true;
if (fs.lstatSync(f).isSymbolicLink()) {
hide = false;
}
pkgs.push(parsePackage(f, hide), ...findPackages(path.posix.join(f, 'node_modules')))
});

const scopes = listing.filter(f => f.startsWith('@'))
.map(f => path.posix.join(p, f))
Expand Down Expand Up @@ -541,7 +546,7 @@ function findScopes() {
* package json and return it as an object along with
* some additional internal attributes prefixed with '_'.
*/
function parsePackage(p: string): Dep {
function parsePackage(p: string, hide: boolean = true): Dep {
// Parse the package.json file of this package
const packageJson = path.posix.join(p, 'package.json');
const pkg = isFile(packageJson) ? JSON.parse(fs.readFileSync(packageJson, {encoding: 'utf8'})) :
Expand Down Expand Up @@ -571,7 +576,7 @@ function parsePackage(p: string): Dep {
// Hide bazel files in this package. We do this before parsing
// the next package to prevent issues caused by symlinks between
// package and nested packages setup by the package manager.
hideBazelFiles(pkg);
if (hide) hideBazelFiles(pkg);

return pkg;
}
Expand Down

0 comments on commit 2e7de34

Please sign in to comment.