Skip to content

Commit 2e7de34

Browse files
soldairalexeagle
authored andcommitted
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
1 parent f432f35 commit 2e7de34

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

internal/npm_install/generate_build_file.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,13 @@ def _maybe(repo_rule, name, **kwargs):
458458
.filter(f => !f.startsWith('.'))
459459
.map(f => path.posix.join(p, f))
460460
.filter(f => isDirectory(f));
461-
packages.forEach(f => pkgs.push(parsePackage(f), ...findPackages(path.posix.join(f, 'node_modules'))));
461+
packages.forEach(f => {
462+
let hide = true;
463+
if (fs.lstatSync(f).isSymbolicLink()) {
464+
hide = false;
465+
}
466+
pkgs.push(parsePackage(f, hide), ...findPackages(path.posix.join(f, 'node_modules')));
467+
});
462468
const scopes = listing.filter(f => f.startsWith('@'))
463469
.map(f => path.posix.join(p, f))
464470
.filter(f => isDirectory(f));
@@ -486,7 +492,7 @@ def _maybe(repo_rule, name, **kwargs):
486492
* package json and return it as an object along with
487493
* some additional internal attributes prefixed with '_'.
488494
*/
489-
function parsePackage(p) {
495+
function parsePackage(p, hide = true) {
490496
// Parse the package.json file of this package
491497
const packageJson = path.posix.join(p, 'package.json');
492498
const pkg = isFile(packageJson) ? JSON.parse(fs.readFileSync(packageJson, { encoding: 'utf8' })) :
@@ -509,7 +515,8 @@ def _maybe(repo_rule, name, **kwargs):
509515
// Hide bazel files in this package. We do this before parsing
510516
// the next package to prevent issues caused by symlinks between
511517
// package and nested packages setup by the package manager.
512-
hideBazelFiles(pkg);
518+
if (hide)
519+
hideBazelFiles(pkg);
513520
return pkg;
514521
}
515522
/**

internal/npm_install/generate_build_file.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,13 @@ function findPackages(p = 'node_modules') {
504504
.map(f => path.posix.join(p, f))
505505
.filter(f => isDirectory(f));
506506

507-
packages.forEach(
508-
f => pkgs.push(parsePackage(f), ...findPackages(path.posix.join(f, 'node_modules'))));
507+
packages.forEach(f => {
508+
let hide = true;
509+
if (fs.lstatSync(f).isSymbolicLink()) {
510+
hide = false;
511+
}
512+
pkgs.push(parsePackage(f, hide), ...findPackages(path.posix.join(f, 'node_modules')))
513+
});
509514

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

576581
return pkg;
577582
}

0 commit comments

Comments
 (0)