Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/angular/build/src/tools/esbuild/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class WatcherQueue {
}

export async function createWatcher(options?: WatcherOptions): Promise<BuildWatcher> {
if (options?.polling) {
if (options?.polling || options?.followSymlinks) {
return createChokidarWatcher(options);
}

Expand Down
38 changes: 38 additions & 0 deletions packages/angular/build/src/tools/esbuild/watcher_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as os from 'node:os';
import * as path from 'node:path';
import { setTimeout } from 'node:timers/promises';
import {
type BuildWatcher,
ChangedFiles,
createWatcher,
getDirectoryPath,
Expand Down Expand Up @@ -482,5 +483,42 @@ describe('Watcher', () => {

await watcher.close();
}, 10000);

it('should detect changes behind a directory symlink when followSymlinks is true', async () => {
const externalDir = fs.realpathSync(
fs.mkdtempSync(path.join(os.tmpdir(), 'watcher-external-')),
);
let watcher: BuildWatcher | undefined;

try {
const externalTargetFile = path.join(externalDir, 'index.ts');
fs.writeFileSync(externalTargetFile, 'export const a = 1;');

const symlinkDir = path.join(tempDir, 'symlinked-lib');
fs.symlinkSync(externalDir, symlinkDir, 'junction');

const symlinkedFile = path.join(symlinkDir, 'index.ts');

watcher = await createWatcher({
followSymlinks: true,
cwd: tempDir,
});

watcher.add(symlinkedFile);
await setTimeout(150);

const iterator = watcher[Symbol.asyncIterator]();
const nextPromise = iterator.next();

fs.writeFileSync(externalTargetFile, 'export const a = 2;');

const result = await nextPromise;
expect(result.done).toBeFalsy();
expect(result.value?.all.some((f: string) => f.includes('index.ts'))).toBeTrue();
} finally {
await watcher?.close();
fs.rmSync(externalDir, { recursive: true, force: true });
}
}, 10000);
Comment thread
clydin marked this conversation as resolved.
});
});