Skip to content

Commit 2021e66

Browse files
alan-agius4dgp1130
authored andcommitted
fix(@angular-devkit/build-angular): watch symbolic links
This commit addresses an issue which caused symbolic links not to be watched properly. Closes #15100
1 parent 25ef9e7 commit 2021e66

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

packages/angular_devkit/build_angular/src/webpack/configs/common.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,17 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise<Config
334334
watch: buildOptions.watch,
335335
watchOptions: {
336336
poll,
337+
// The below is needed as when preserveSymlinks is enabled we disable `resolve.symlinks`.
338+
followSymlinks: buildOptions.preserveSymlinks,
337339
ignored: poll === undefined ? undefined : '**/node_modules/**',
338340
},
341+
snapshot: {
342+
module: {
343+
// Use hash of content instead of timestamp because the timestamp of the symlink will be used
344+
// instead of the referenced files which causes changes in symlinks not to be picked up.
345+
hash: buildOptions.preserveSymlinks,
346+
},
347+
},
339348
performance: {
340349
hints: false,
341350
},
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { symlink } from 'fs/promises';
2+
import { resolve } from 'path';
3+
import { appendToFile, expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
4+
import { execAndWaitForOutputToMatch, waitForAnyProcessOutputToMatch } from '../../utils/process';
5+
import { updateJsonFile } from '../../utils/project';
6+
7+
const buildReadyRegEx = /Build at: /;
8+
9+
export default async function () {
10+
await updateJsonFile('angular.json', (configJson) => {
11+
configJson.projects['test-project'].architect.build.options.preserveSymlinks = true;
12+
});
13+
14+
await writeMultipleFiles({
15+
'src/link-source.ts': '// empty file',
16+
'src/main.ts': `import './link-dest';`,
17+
});
18+
19+
await symlink(resolve('src/link-source.ts'), resolve('src/link-dest.ts'));
20+
21+
await execAndWaitForOutputToMatch(
22+
'ng',
23+
['build', '--watch', '--configuration=development'],
24+
buildReadyRegEx,
25+
);
26+
27+
// Trigger a rebuild
28+
await appendToFile('src/link-source.ts', `console.log('foo-bar');`);
29+
await waitForAnyProcessOutputToMatch(buildReadyRegEx);
30+
await expectFileToMatch('dist/test-project/main.js', `console.log('foo-bar')`);
31+
}

0 commit comments

Comments
 (0)