-
-
Notifications
You must be signed in to change notification settings - Fork 332
Fix Workspace Circular Symlink #1319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Workspace Circular Symlink #1319
Conversation
|
|
||
| const syncGlob = ({ cwd, patterns }: { cwd?: string; patterns: string | string[] }) => fg.sync(patterns, { cwd }); | ||
| const syncGlob = ({ cwd, patterns }: { cwd?: string; patterns: string | string[] }) => | ||
| fg.sync(patterns, { cwd, followSymbolicLinks: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps GLOBAL_IGNORE_PATTERNS is the better fix?
commit: |
|
Thanks for the PR! I do wonder if this actually fixes the issue you described. The fixture currently doesn't seem to fail without this change. So could you please set up something that fails/hangs first so that we have something to work with? |
Hi Lars, Thanks for taking a look at this! Hmm, I seem to be getting the failure. I thought there might be issues with symlinks and GitHub, so I tried deleting the branch locally and checking it out again but that seems to have worked. Let me know if you have any other ideas! I'm running the test with bun test ./packages/knip/test/workspaces-circular-symlinks.test.tsWithout Changes const syncGlob = ({ cwd, patterns }: { cwd?: string; patterns: string | string[] }) =>
fg.sync(patterns, { cwd });bun test ./packages/knip/test/workspaces-circular-symlinks.test.ts
bun test v1.2.15 (df017990)
packages/knip/test/workspaces-circular-symlinks.test.ts:
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}`);
^
AssertionError: Expected 1 file but found 32
32 !== 1
generatedMessage: false,
actual: 32,
expected: 1,
operator: "strictEqual",
code: "ERR_ASSERTION"
at /Users/mattietea/Desktop/knip/packages/knip/test/workspaces-circular-symlinks.test.ts:16:10
✗ syncGlob should not traverse circular symlinks [8.60ms]
0 pass
1 fail
Ran 1 tests across 1 files. [57.00ms]
Truncated return value of _globSyncWith Changes const syncGlob = ({ cwd, patterns }: { cwd?: string; patterns: string | string[] }) =>
fg.sync(patterns, { cwd, followSymbolicLinks: false }); |
f4844ad to
0faa3b8
Compare
|
Thanks Matt! Confirmed & merged. |
|
🚀 This pull request is included in v5.78.0. See Release 5.78.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
Issue
Knip hangs indefinitely when analyzing workspaces containing circular symlinks in
node_modules. This occurs in monorepos where workspace-to-workspace symlinks create circular referencesRoot Cause
The
syncGlobfunction insrc/util/glob.tsusesfast-globwith default options, which includesfollowSymbolicLinks: true. When encountering circular symlinks, fast-glob enters an infinite traversal loop.Fix
Added
followSymbolicLinks: falseto thesyncGlobfunction.Impact
Before:
After: