Skip to content

Commit

Permalink
fix(@ngtools/webpack): resources path normalizations
Browse files Browse the repository at this point in the history
Compiler host `readResource` is always called with POSIX seperators. However the `denormalizePath` method doesn't convert forward slashes to back slashes which causes `getModifiedResourceFiles` to return an empty `Set`.

We were also assuming that `_changedFiles` is an FS path which was not the case as it's original type is `Path`

Fix #15012
  • Loading branch information
alan-agius4 authored and Keen Yee Liau committed Jul 9, 2019
1 parent f0e7e5d commit 317ef00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,6 @@ describe('Browser Builder rebuilds', () => {
});

it('rebuilds AOT factories', async () => {
// DISABLED_FOR_IVY - These should pass but require fixes for resource rebuilds
// https://github.com/angular/angular/pull/30954
if (ivyEnabled) {
pending('Broken in Ivy.');

return;
}

host.writeMultipleFiles({
'src/app/app.component.css': `
@import './imported-styles.css';
Expand Down
16 changes: 8 additions & 8 deletions packages/ngtools/webpack/src/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class WebpackCompilerHost implements ts.CompilerHost {
try {
exists = this._syncHost.isFile(fullPath);
if (exists) {
this._changedFiles.add(fullPath);
this._changedFiles.add(workaroundResolve(fullPath));
}
} catch {}

Expand Down Expand Up @@ -339,16 +339,15 @@ export class WebpackCompilerHost implements ts.CompilerHost {
}

readResource(fileName: string) {
this._readResourceFiles.add(fileName);
// These paths are meant to be used by the loader so we must denormalize them
const denormalizedFileName = workaroundResolve(fileName);
this._readResourceFiles.add(denormalizedFileName);

if (this.directTemplateLoading && (fileName.endsWith('.html') || fileName.endsWith('.svg'))) {
return this.readFile(fileName);
}

if (this._resourceLoader) {
// These paths are meant to be used by the loader so we must denormalize them.
const denormalizedFileName = this.denormalizePath(normalize(fileName));

return this._resourceLoader.get(denormalizedFileName);
} else {
return this.readFile(fileName);
Expand All @@ -359,14 +358,15 @@ export class WebpackCompilerHost implements ts.CompilerHost {
const modifiedFiles = new Set<string>();

for (const changedFile of this._changedFiles) {
if (this._readResourceFiles.has(changedFile)) {
modifiedFiles.add(changedFile);
const denormalizedFileName = workaroundResolve(changedFile);
if (this._readResourceFiles.has(denormalizedFileName)) {
modifiedFiles.add(denormalizedFileName);
}

if (!this._resourceLoader) {
continue;
}
for (const resourcePath of this._resourceLoader.getAffectedResources(changedFile)) {
for (const resourcePath of this._resourceLoader.getAffectedResources(denormalizedFileName)) {
modifiedFiles.add(resourcePath);
}
}
Expand Down

0 comments on commit 317ef00

Please sign in to comment.