Skip to content

fix(@ngtools/webpack): delete all virtual files for styles on change #15144

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

Merged
merged 1 commit into from
Jul 25, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
// tslint:disable:no-big-function
import { Architect } from '@angular-devkit/architect';
import { TestLogger } from '@angular-devkit/architect/testing';
import { logging, normalize, virtualFs } from '@angular-devkit/core';
import { join, logging, normalize, virtualFs } from '@angular-devkit/core';
import { debounceTime, take, takeWhile, tap } from 'rxjs/operators';
import {
createArchitect,
host,
ivyEnabled,
lazyModuleFiles,
lazyModuleFnImport,
outputPath,
} from '../utils';

describe('Browser Builder rebuilds', () => {
Expand Down Expand Up @@ -477,4 +478,64 @@ describe('Browser Builder rebuilds', () => {
.toPromise();
await run.stop();
});

it('rebuilds AOT on CSS changes', async () => {
const overrides = { watch: true, aot: true };

let buildCount = 1;
const run = await architect.scheduleTarget(target, overrides);
await run.output.pipe(
debounceTime(1000),
tap(() => {
const content = virtualFs.fileBufferToString(
host.scopedSync().read(join(outputPath, 'main.js')),
);

switch (buildCount) {
case 1:
expect(content).not.toContain('color: green');
host.appendToFile('src/app/app.component.css', 'h1 { color: green; }');
break;
case 2:
expect(content).toContain('color: green');
break;
}

buildCount++;
}),
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
take(2),
).toPromise();
await run.stop();
});

it('rebuilds AOT on HTML changes', async () => {
const overrides = { watch: true, aot: true };

let buildCount = 1;
const run = await architect.scheduleTarget(target, overrides);
await run.output.pipe(
debounceTime(1000),
tap(() => {
const content = virtualFs.fileBufferToString(
host.scopedSync().read(join(outputPath, 'main.js')),
);

switch (buildCount) {
case 1:
expect(content).not.toContain('New Updated Content');
host.appendToFile('src/app/app.component.html', 'New Updated Content');
break;
case 2:
expect(content).toContain('New Updated Content');
break;
}

buildCount++;
}),
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
take(2),
).toPromise();
await run.stop();
});
});
20 changes: 18 additions & 2 deletions packages/ngtools/webpack/src/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ export class WebpackCompilerHost implements ts.CompilerHost {
'.js.map',
'.ngfactory.js',
'.ngfactory.js.map',
'.ngstyle.js',
'.ngstyle.js.map',
'.ngsummary.json',
];

private _virtualStyleFileExtensions = [
'.shim.ngstyle.js',
'.shim.ngstyle.js.map',
];

constructor(
private _options: ts.CompilerOptions,
basePath: string,
Expand Down Expand Up @@ -110,6 +113,10 @@ export class WebpackCompilerHost implements ts.CompilerHost {
});
}

if (fullPath.endsWith('.ts')) {
return;
}

// In case resolveJsonModule and allowJs we also need to remove virtual emitted files
// both if they exists or not.
if (
Expand All @@ -119,6 +126,15 @@ export class WebpackCompilerHost implements ts.CompilerHost {
if (this._memoryHost.exists(fullPath)) {
this._memoryHost.delete(fullPath);
}

return;
}

for (const ext of this._virtualStyleFileExtensions) {
const virtualFile = (fullPath + ext) as Path;
if (this._memoryHost.exists(virtualFile)) {
this._memoryHost.delete(virtualFile);
}
}
}

Expand Down