Skip to content

Commit

Permalink
fix(@angular/build): add asset tracking to application builder watch …
Browse files Browse the repository at this point in the history
…files

This commit updates the application builder to include assets in the watch process, triggering file re-copying when changes are detected.

Closes angular#28415
  • Loading branch information
alan-agius4 committed Jan 7, 2025
1 parent 1c011a2 commit 395e388
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ export async function executeBuild(

// Copy assets
if (assets) {
executionResult.addAssets(await resolveAssets(assets, workspaceRoot));
const resolvedAssets = await resolveAssets(assets, workspaceRoot);
executionResult.addAssets(resolvedAssets);
executionResult.extraWatchFiles.push(...resolvedAssets.map(({ source }) => source));
}

// Extract and write licenses for used packages
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import { concatMap, count, take, timeout } from 'rxjs';
import { buildApplication } from '../../index';
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';

/**
* Maximum time in milliseconds for single build/rebuild
* This accounts for CI variability.
*/
const BUILD_TIMEOUT = 10_000;

describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
describe('Behavior: "Rebuilds when input asset changes"', () => {
beforeEach(async () => {
// Application code is not needed for styles tests
await harness.writeFile('src/main.ts', 'console.log("TEST");');
await harness.writeFile('public/asset.txt', 'foo');
});

it('emits updated asset', async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
assets: [
{
glob: '**/*',
input: 'public',
},
],
watch: true,
});

const buildCount = await harness
.execute({ outputLogsOnFailure: false })
.pipe(
timeout(BUILD_TIMEOUT),
concatMap(async ({ result }, index) => {
switch (index) {
case 0:
expect(result?.success).toBeTrue();
harness.expectFile('dist/browser/asset.txt').content.toContain('foo');

await harness.writeFile('public/asset.txt', 'bar');
break;
case 1:
expect(result?.success).toBeTrue();
harness.expectFile('dist/browser/asset.txt').content.toContain('bar');
break;
}
}),
take(2),
count(),
)
.toPromise();

expect(buildCount).toBe(2);
});
});
});

0 comments on commit 395e388

Please sign in to comment.