Skip to content

Commit bffae52

Browse files
authored
Fix Workspace Circular Symlink (#1319)
1 parent 5cb4c30 commit bffae52

9 files changed

Lines changed: 46 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@fixtures/workspaces-symlinks",
3+
"workspaces": [
4+
"packages/*"
5+
]
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const libA = 'lib-a';

packages/knip/fixtures/workspaces-circular-symlinks/packages/lib-a/node_modules/@fixtures/lib-b

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@fixtures/lib-a",
3+
"version": "1.0.0",
4+
"main": "./index.ts",
5+
"exports": {
6+
".": "./index.ts"
7+
}
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const libB = 'lib-b';

packages/knip/fixtures/workspaces-circular-symlinks/packages/lib-b/node_modules/@fixtures/lib-a

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@fixtures/lib-b",
3+
"version": "1.0.0",
4+
"main": "./index.ts",
5+
"exports": {
6+
".": "./index.ts"
7+
}
8+
}

packages/knip/src/util/glob.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ const defaultGlob = async ({ cwd, dir = cwd, patterns, gitignore = true, label }
5454
});
5555
};
5656

57-
const syncGlob = ({ cwd, patterns }: { cwd?: string; patterns: string | string[] }) => fg.sync(patterns, { cwd });
57+
const syncGlob = ({ cwd, patterns }: { cwd?: string; patterns: string | string[] }) =>
58+
fg.sync(patterns, { cwd, followSymbolicLinks: false });
5859

5960
const firstGlob = async ({ cwd, patterns }: GlobOptions) => {
6061
const stream = fg.globStream(patterns.map(removeProductionSuffix), { cwd, ignore: GLOBAL_IGNORE_PATTERNS });
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import assert from 'node:assert/strict';
2+
import test from 'node:test';
3+
import { _syncGlob } from '../src/util/glob.js';
4+
import { main } from '../src/index.js';
5+
import { createOptions } from '../src/util/create-options.js';
6+
import baseCounters from './helpers/baseCounters.js';
7+
import { resolve } from './helpers/resolve.js';
8+
9+
const cwd = resolve('fixtures/workspaces-circular-symlinks');
10+
11+
test('syncGlob should not traverse circular symlinks', () => {
12+
const libACwd = resolve('fixtures/workspaces-circular-symlinks/packages/lib-a');
13+
const files = _syncGlob({ patterns: ['./**/*.ts'], cwd: libACwd });
14+
15+
const expected = 1;
16+
assert.equal(files.length, expected, `Expected ${expected} file but found ${files.length}`);
17+
assert.equal(files[0], 'index.ts');
18+
});

0 commit comments

Comments
 (0)