Skip to content

Commit 3a287be

Browse files
committed
refactor: remove left over webpack version 4 code
1 parent 8a8384b commit 3a287be

File tree

3 files changed

+102
-94
lines changed

3 files changed

+102
-94
lines changed

packages/angular_devkit/build_angular/src/webpack/plugins/builder-watch-plugin.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ export interface BuilderWatcherFactory {
2323
export interface WebpackWatcher {
2424
close(): void;
2525
pause(): void;
26-
// Webpack 4
27-
getFileTimestamps(): Map<string, number>;
28-
getContextTimestamps(): Map<string, number>;
29-
// Webpack 5
3026
getFileTimeInfoEntries(): Map<string, { safeTime: number; timestamp: number }>;
3127
getContextTimeInfoEntries(): Map<string, { safeTime: number; timestamp: number }>;
3228
}
@@ -126,10 +122,12 @@ class BuilderWatchFileSystem implements WebpackWatchFileSystem {
126122
}
127123
}
128124

125+
const timeInfoMap = new Map(timeInfo);
126+
129127
callback(
130128
undefined,
131-
new Map(timeInfo),
132-
new Map(timeInfo),
129+
timeInfoMap,
130+
timeInfoMap,
133131
new Set([...fileChanges, ...directoryChanges, ...missingChanges]),
134132
removals,
135133
);
@@ -141,12 +139,6 @@ class BuilderWatchFileSystem implements WebpackWatchFileSystem {
141139
watcher.close();
142140
},
143141
pause() {},
144-
getFileTimestamps() {
145-
return timeInfo.toTimestamps();
146-
},
147-
getContextTimestamps() {
148-
return timeInfo.toTimestamps();
149-
},
150142
getFileTimeInfoEntries() {
151143
return new Map(timeInfo);
152144
},

packages/ngtools/webpack/src/ivy/plugin.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ export class AngularWebpackPlugin {
161161
}
162162
const emitRegistration = compilation[AngularPluginSymbol].register();
163163

164-
// Store watch mode; assume true if not present (webpack < 4.23.0)
165-
this.watchMode = compiler.watchMode ?? true;
164+
this.watchMode = compiler.watchMode;
166165

167166
// Initialize the resource loader if not already setup
168167
if (!resourceLoader) {

tests/legacy-cli/e2e/tests/basic/rebuild.ts

+97-80
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ import {
44
execAndWaitForOutputToMatch,
55
ng,
66
} from '../../utils/process';
7-
import {writeFile, writeMultipleFiles} from '../../utils/fs';
8-
import {wait} from '../../utils/utils';
9-
import {request} from '../../utils/http';
7+
import { writeFile, writeMultipleFiles } from '../../utils/fs';
8+
import { wait } from '../../utils/utils';
9+
import { request } from '../../utils/http';
1010

1111
const validBundleRegEx = / Compiled successfully./;
1212

13-
export default function() {
14-
return execAndWaitForOutputToMatch('ng', ['serve'], validBundleRegEx)
15-
// Add a lazy module.
16-
.then(() => ng('generate', 'module', 'lazy', '--routing'))
17-
// Should trigger a rebuild with a new bundle.
18-
// We need to use Promise.all to ensure we are waiting for the rebuild just before we write
19-
// the file, otherwise rebuilds can be too fast and fail CI.
20-
.then(() => Promise.all([
21-
waitForAnyProcessOutputToMatch(validBundleRegEx, 20000),
22-
writeFile('src/app/app.module.ts', `
13+
export default function () {
14+
return (
15+
execAndWaitForOutputToMatch('ng', ['serve'], validBundleRegEx)
16+
// Add a lazy module.
17+
.then(() => ng('generate', 'module', 'lazy', '--routing'))
18+
// Should trigger a rebuild with a new bundle.
19+
// We need to use Promise.all to ensure we are waiting for the rebuild just before we write
20+
// the file, otherwise rebuilds can be too fast and fail CI.
21+
.then(() =>
22+
Promise.all([
23+
waitForAnyProcessOutputToMatch(validBundleRegEx, 20000),
24+
writeFile(
25+
'src/app/app.module.ts',
26+
`
2327
import { BrowserModule } from '@angular/platform-browser';
2428
import { NgModule } from '@angular/core';
2529
import { FormsModule } from '@angular/forms';
@@ -44,21 +48,23 @@ export default function() {
4448
bootstrap: [AppComponent]
4549
})
4650
export class AppModule { }
47-
`),
48-
]))
49-
// Count the bundles.
50-
.then((results) => {
51-
const stdout = results[0].stdout;
52-
// First regexp is for Webpack 4; Second is for Webpack 5
53-
if (!/(lazy-module|0)\.js/g.test(stdout) && !/lazy_module_ts\.js/g.test(stdout)) {
54-
throw new Error('Expected webpack to create a new chunk, but did not.');
55-
}
56-
})
57-
// Change multiple files and check that all of them are invalidated and recompiled.
58-
.then(() => Promise.all([
59-
waitForAnyProcessOutputToMatch(validBundleRegEx, 20000),
60-
writeMultipleFiles({
61-
'src/app/app.module.ts': `
51+
`,
52+
),
53+
]),
54+
)
55+
// Count the bundles.
56+
.then((results) => {
57+
const stdout = results[0].stdout;
58+
if (!/lazy_module_ts\.js/g.test(stdout)) {
59+
throw new Error('Expected webpack to create a new chunk, but did not.');
60+
}
61+
})
62+
// Change multiple files and check that all of them are invalidated and recompiled.
63+
.then(() =>
64+
Promise.all([
65+
waitForAnyProcessOutputToMatch(validBundleRegEx, 20000),
66+
writeMultipleFiles({
67+
'src/app/app.module.ts': `
6268
import { BrowserModule } from '@angular/platform-browser';
6369
import { NgModule } from '@angular/core';
6470
@@ -79,7 +85,7 @@ export default function() {
7985
console.log('$$_E2E_GOLDEN_VALUE_1');
8086
export let X = '$$_E2E_GOLDEN_VALUE_2';
8187
`,
82-
'src/main.ts': `
88+
'src/main.ts': `
8389
import { enableProdMode } from '@angular/core';
8490
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
8591
@@ -96,12 +102,14 @@ export default function() {
96102
console.log(m.X);
97103
console.log('$$_E2E_GOLDEN_VALUE_3');
98104
`,
99-
}),
100-
]))
101-
.then(() => Promise.all([
102-
waitForAnyProcessOutputToMatch(validBundleRegEx, 20000),
103-
writeMultipleFiles({
104-
'src/app/app.module.ts': `
105+
}),
106+
]),
107+
)
108+
.then(() =>
109+
Promise.all([
110+
waitForAnyProcessOutputToMatch(validBundleRegEx, 20000),
111+
writeMultipleFiles({
112+
'src/app/app.module.ts': `
105113
106114
import { BrowserModule } from '@angular/platform-browser';
107115
import { NgModule } from '@angular/core';
@@ -124,49 +132,58 @@ export default function() {
124132
export let X = '$$_E2E_GOLDEN_VALUE_2';
125133
console.log('File changed with no import/export changes');
126134
`,
127-
}),
128-
]))
129-
.then(() => wait(2000))
130-
.then(() => request('http://localhost:4200/main.js'))
131-
.then((body) => {
132-
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
133-
throw new Error('Expected golden value 1.');
134-
}
135-
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_2/)) {
136-
throw new Error('Expected golden value 2.');
137-
}
138-
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_3/)) {
139-
throw new Error('Expected golden value 3.');
140-
}
141-
})
142-
.then(() => Promise.all([
143-
waitForAnyProcessOutputToMatch(validBundleRegEx, 20000),
144-
writeMultipleFiles({
145-
'src/app/app.component.html': '<h1>testingTESTING123</h1>',
146-
}),
147-
]))
148-
.then(() => wait(2000))
149-
.then(() => request('http://localhost:4200/main.js'))
150-
.then((body) => {
151-
if (!body.match(/testingTESTING123/)) {
152-
throw new Error('Expected component HTML to update.');
153-
}
154-
})
155-
.then(() => Promise.all([
156-
waitForAnyProcessOutputToMatch(validBundleRegEx, 20000),
157-
writeMultipleFiles({
158-
'src/app/app.component.css': ':host { color: blue; }',
159-
}),
160-
]))
161-
.then(() => wait(2000))
162-
.then(() => request('http://localhost:4200/main.js'))
163-
.then((body) => {
164-
if (!body.match(/color:\s?blue/)) {
165-
throw new Error('Expected component CSS to update.');
166-
}
167-
})
168-
.then(() => killAllProcesses(), (err: unknown) => {
169-
killAllProcesses();
170-
throw err;
171-
});
135+
}),
136+
]),
137+
)
138+
.then(() => wait(2000))
139+
.then(() => request('http://localhost:4200/main.js'))
140+
.then((body) => {
141+
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
142+
throw new Error('Expected golden value 1.');
143+
}
144+
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_2/)) {
145+
throw new Error('Expected golden value 2.');
146+
}
147+
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_3/)) {
148+
throw new Error('Expected golden value 3.');
149+
}
150+
})
151+
.then(() =>
152+
Promise.all([
153+
waitForAnyProcessOutputToMatch(validBundleRegEx, 20000),
154+
writeMultipleFiles({
155+
'src/app/app.component.html': '<h1>testingTESTING123</h1>',
156+
}),
157+
]),
158+
)
159+
.then(() => wait(2000))
160+
.then(() => request('http://localhost:4200/main.js'))
161+
.then((body) => {
162+
if (!body.match(/testingTESTING123/)) {
163+
throw new Error('Expected component HTML to update.');
164+
}
165+
})
166+
.then(() =>
167+
Promise.all([
168+
waitForAnyProcessOutputToMatch(validBundleRegEx, 20000),
169+
writeMultipleFiles({
170+
'src/app/app.component.css': ':host { color: blue; }',
171+
}),
172+
]),
173+
)
174+
.then(() => wait(2000))
175+
.then(() => request('http://localhost:4200/main.js'))
176+
.then((body) => {
177+
if (!body.match(/color:\s?blue/)) {
178+
throw new Error('Expected component CSS to update.');
179+
}
180+
})
181+
.then(
182+
() => killAllProcesses(),
183+
(err: unknown) => {
184+
killAllProcesses();
185+
throw err;
186+
},
187+
)
188+
);
172189
}

0 commit comments

Comments
 (0)