Skip to content

Commit 5cb324a

Browse files
committed
fix(@angular-devkit/build-angular): correctly watch files when app is in a directory that starts with a dot
This commit fixes an issue were previously, application files in a directory that starts with a dot were being ignored from watching. Closes angular#26441
1 parent 3810bd4 commit 5cb324a

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

packages/angular_devkit/build_angular/src/builders/application/build-action.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export async function* runEsBuildBuildAction(
8686
// Ignore all node modules directories to avoid excessive file watchers.
8787
// Package changes are handled below by watching manifest and lock files.
8888
'**/node_modules/**',
89-
'**/.*/**',
89+
workspaceRoot.replace(/\\/g, '/') + '/**/.*/**',
9090
],
9191
});
9292

tests/legacy-cli/e2e/tests/build/poll.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { setTimeout } from 'node:timers/promises';
12
import { getGlobalVariable } from '../../utils/env';
23
import { appendToFile } from '../../utils/fs';
34
import { waitForAnyProcessOutputToMatch } from '../../utils/process';
45
import { ngServe } from '../../utils/project';
5-
import { expectToFail, wait } from '../../utils/utils';
6+
import { expectToFail } from '../../utils/utils';
67

78
const webpackGoodRegEx = getGlobalVariable('argv')['esbuild']
89
? /Application bundle generation complete\./
@@ -13,7 +14,7 @@ export default async function () {
1314

1415
// Wait before editing a file.
1516
// Editing too soon seems to trigger a rebuild and throw polling out of whack.
16-
await wait(3000);
17+
await setTimeout(3000);
1718
await appendToFile('src/main.ts', 'console.log(1);');
1819

1920
// We have to wait poll time + rebuild build time for the regex match.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { setTimeout } from 'node:timers/promises';
2+
import { getGlobalVariable } from '../../utils/env';
3+
import { appendToFile, createDir, rimraf } from '../../utils/fs';
4+
import { installWorkspacePackages } from '../../utils/packages';
5+
import { ng, waitForAnyProcessOutputToMatch } from '../../utils/process';
6+
import { ngServe, updateJsonFile, useSha } from '../../utils/project';
7+
8+
const goodRegEx = getGlobalVariable('argv')['esbuild']
9+
? /Application bundle generation complete\./
10+
: / Compiled successfully\./;
11+
12+
export default async function () {
13+
const originalCwd = process.cwd();
14+
// Delete angular.json so that we can create a new app.
15+
await rimraf('angular.json');
16+
await createDir('./.subdirectory');
17+
18+
try {
19+
process.chdir('./.subdirectory');
20+
21+
await ng('new', 'subdirectory-test-project', '--skip-install');
22+
process.chdir('./subdirectory-test-project');
23+
24+
await useSha();
25+
await installWorkspacePackages();
26+
27+
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
28+
if (useWebpackBuilder) {
29+
await updateJsonFile('angular.json', (json) => {
30+
const build = json['projects']['subdirectory-test-project']['architect']['build'];
31+
build.builder = '@angular-devkit/build-angular:browser';
32+
build.options = {
33+
...build.options,
34+
main: build.options.browser,
35+
browser: undefined,
36+
};
37+
38+
build.configurations.development = {
39+
...build.configurations.development,
40+
vendorChunk: true,
41+
namedChunks: true,
42+
buildOptimizer: false,
43+
};
44+
});
45+
}
46+
47+
await ngServe();
48+
49+
// Wait before editing a file.
50+
await setTimeout(1000);
51+
await appendToFile('src/main.ts', 'console.log(1);');
52+
await waitForAnyProcessOutputToMatch(goodRegEx);
53+
} finally {
54+
process.chdir(originalCwd);
55+
}
56+
}

tests/legacy-cli/e2e/utils/utils.ts

-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ export function expectToFail(fn: () => Promise<any>, errorMessage?: string): Pro
1818
);
1919
}
2020

21-
export function wait(msecs: number): Promise<void> {
22-
return new Promise((resolve) => {
23-
setTimeout(resolve, msecs);
24-
});
25-
}
26-
2721
export async function mktempd(prefix: string, tempRoot?: string): Promise<string> {
2822
return realpath(await mkdtemp(path.join(tempRoot ?? tmpdir(), prefix)));
2923
}

0 commit comments

Comments
 (0)