Skip to content

Commit a032c0c

Browse files
romulocintramanucorporat
authored andcommitted
feat(compiler): watch *.html files (#1531)
* feat(compiler): watch *.html files * Update fs-watch-rebuild.spec.ts * Update fs-watch-rebuild.spec.ts
1 parent 9f7041a commit a032c0c

7 files changed

Lines changed: 19 additions & 10 deletions

File tree

src/compiler/build/build-ctx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class BuildContext implements d.BuildCtx {
3131
hasConfigChanges = false;
3232
hasCopyChanges = false;
3333
hasFinished = false;
34-
hasIndexHtmlChanges = false;
34+
hasHtmlChanges = false;
3535
hasPrintedResults = false;
3636
hasServiceWorkerChanges = false;
3737
hasScriptChanges = true;

src/compiler/build/build-hmr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function generateHmr(config: d.Config, compilerCtx: d.CompilerCtx, buildC
2626
hmr.excludeHmr = excludeHmr.slice();
2727
}
2828

29-
if (buildCtx.hasIndexHtmlChanges) {
29+
if (buildCtx.hasHtmlChanges) {
3030
hmr.indexHtmlUpdated = true;
3131
}
3232

src/compiler/fs-watch/fs-watch-rebuild.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function generateBuildFromFsWatch(config: d.Config, compilerCtx: d.Compil
4747
buildCtx.hasStyleChanges = hasStyleChanges(buildCtx);
4848

4949
// figure out if any changed files were index.html files
50-
buildCtx.hasIndexHtmlChanges = hasIndexHtmlChanges(config, buildCtx);
50+
buildCtx.hasHtmlChanges = hasHtmlChanges(config, buildCtx);
5151

5252
buildCtx.hasServiceWorkerChanges = hasServiceWorkerChanges(config, buildCtx);
5353

@@ -164,10 +164,11 @@ export function isStyleExt(ext: string) {
164164
const STYLE_EXT = ['css', 'scss', 'sass', 'pcss', 'styl', 'stylus', 'less'];
165165

166166

167-
function hasIndexHtmlChanges(config: d.Config, buildCtx: d.BuildCtx) {
168-
const anyIndexHtmlChanged = buildCtx.filesChanged.some(fileChanged => config.sys.path.basename(fileChanged).toLowerCase() === 'index.html');
169-
if (anyIndexHtmlChanged) {
170-
// any index.html in any directory that changes counts too
167+
function hasHtmlChanges(config: d.Config, buildCtx: d.BuildCtx) {
168+
const anyHtmlChanged = buildCtx.filesChanged.some(f => f.toLowerCase().endsWith('.html'));
169+
170+
if (anyHtmlChanged) {
171+
// any *.html in any directory that changes counts and rebuilds
171172
return true;
172173
}
173174

src/compiler/fs-watch/test/fs-watch-rebuild.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ describe('fs-watch, rebuild', () => {
5151
expect(buildCtx.hasStyleChanges).toBe(true);
5252
});
5353

54+
it('hasHtmlChanges', () => {
55+
compilerCtx.activeFilesUpdated = ['file.HTML', 'file2.html'];
56+
const buildCtx = generateBuildFromFsWatch(config, compilerCtx);
57+
expect(buildCtx).toBeDefined();
58+
expect(buildCtx.hasHtmlChanges).toBe(true);
59+
});
60+
5461
it('should rebuild for dirsAdded, and recursive add files/dirs', async () => {
5562
const root = path.resolve('/');
5663
await compilerCtx.fs.disk.mkdir(path.join(root, 'added-1'));

src/compiler/output-targets/output-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function canSkipAppCoreBuild(buildCtx: d.BuildCtx) {
118118
if (buildCtx.requiresFullBuild) {
119119
return false;
120120
}
121-
if (buildCtx.isRebuild && (buildCtx.hasScriptChanges || buildCtx.hasStyleChanges || buildCtx.hasIndexHtmlChanges)) {
121+
if (buildCtx.isRebuild && (buildCtx.hasScriptChanges || buildCtx.hasStyleChanges || buildCtx.hasHtmlChanges)) {
122122
return false;
123123
}
124124
return true;

src/compiler/output-targets/output-www.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ function generateHostConfig(config: d.Config, compilerCtx: d.CompilerCtx, output
8383
return compilerCtx.fs.writeFile(hostConfigPath, hostConfigContent);
8484
}
8585

86+
8687
async function generateIndexHtml(config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, criticalPath: string[], outputTarget: d.OutputTargetWww) {
87-
if (compilerCtx.hasSuccessfulBuild && !buildCtx.hasIndexHtmlChanges) {
88+
if (compilerCtx.hasSuccessfulBuild && !buildCtx.hasHtmlChanges) {
8889
// no need to rebuild index.html if there were no app file changes
8990
return;
9091
}

src/declarations/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface BuildCtx {
4949
hasCopyChanges: boolean;
5050
hasError: boolean;
5151
hasFinished: boolean;
52-
hasIndexHtmlChanges: boolean;
52+
hasHtmlChanges: boolean;
5353
hasPrintedResults: boolean;
5454
hasServiceWorkerChanges: boolean;
5555
hasScriptChanges: boolean;

0 commit comments

Comments
 (0)