From 2e7de341d50ef42c60ea0bfc295ba5f24fa517cc Mon Sep 17 00:00:00 2001 From: Ryan Day Date: Wed, 9 Oct 2019 12:08:18 -0700 Subject: [PATCH] fix: dont generate build files in symlinked node_modules (#1111) * fix: ignore symlinked packages fixes #871 * fix: skipping hide build fies for links in node_modules --- internal/npm_install/generate_build_file.js | 13 ++++++++++--- internal/npm_install/generate_build_file.ts | 13 +++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/internal/npm_install/generate_build_file.js b/internal/npm_install/generate_build_file.js index 1a419e8b22..8653976944 100644 --- a/internal/npm_install/generate_build_file.js +++ b/internal/npm_install/generate_build_file.js @@ -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)); @@ -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' })) : @@ -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; } /** diff --git a/internal/npm_install/generate_build_file.ts b/internal/npm_install/generate_build_file.ts index f326bbae14..d16beeb31d 100644 --- a/internal/npm_install/generate_build_file.ts +++ b/internal/npm_install/generate_build_file.ts @@ -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)) @@ -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'})) : @@ -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; }