Skip to content

Commit e729f6e

Browse files
committed
build: update dependency webpack-dev-server to v5
1 parent 9f9be11 commit e729f6e

File tree

6 files changed

+195
-62
lines changed

6 files changed

+195
-62
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
"watchpack": "2.4.0",
215215
"webpack": "5.90.3",
216216
"webpack-dev-middleware": "6.1.1",
217-
"webpack-dev-server": "4.15.1",
217+
"webpack-dev-server": "5.0.2",
218218
"webpack-merge": "5.10.0",
219219
"webpack-subresource-integrity": "5.1.0",
220220
"yargs": "17.7.2",

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"watchpack": "2.4.0",
6767
"webpack": "5.90.3",
6868
"webpack-dev-middleware": "6.1.1",
69-
"webpack-dev-server": "4.15.1",
69+
"webpack-dev-server": "5.0.2",
7070
"webpack-merge": "5.10.0",
7171
"webpack-subresource-integrity": "5.1.0"
7272
},

packages/angular_devkit/build_angular/src/builders/dev-server/tests/behavior/build-assets_spec.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,7 @@ describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupT
5555

5656
it('should return 404 for non existing assets', async () => {
5757
setupTarget(harness, {
58-
assets: ['src/extra.js'],
59-
optimization: {
60-
scripts: true,
61-
},
62-
});
63-
64-
harness.useTarget('serve', {
65-
...BASE_OPTIONS,
66-
});
67-
68-
const { result, response } = await executeOnceAndFetch(harness, 'extra.js');
69-
70-
expect(result?.success).toBeTrue();
71-
expect(await response?.status).toBe(404);
72-
});
73-
74-
it('should return 404 for non existing assets', async () => {
75-
setupTarget(harness, {
76-
assets: ['src/extra.js'],
58+
assets: [],
7759
optimization: {
7860
scripts: true,
7961
},
@@ -83,7 +65,7 @@ describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupT
8365
...BASE_OPTIONS,
8466
});
8567

86-
const { result, response } = await executeOnceAndFetch(harness, 'extra.js');
68+
const { result, response } = await executeOnceAndFetch(harness, 'does-not-exist.js');
8769

8870
expect(result?.success).toBeTrue();
8971
expect(await response?.status).toBe(404);

packages/angular_devkit/build_angular/src/tools/webpack/configs/dev-server.ts

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ function getServerConfig(
155155
* Private method to enhance a webpack config with Proxy configuration.
156156
* @private
157157
*/
158-
async function addProxyConfig(root: string, proxyConfig: string | undefined) {
158+
async function addProxyConfig(
159+
root: string,
160+
proxyConfig: string | undefined,
161+
): Promise<object[] | undefined> {
159162
if (!proxyConfig) {
160163
return undefined;
161164
}
@@ -166,13 +169,15 @@ async function addProxyConfig(root: string, proxyConfig: string | undefined) {
166169
throw new Error(`Proxy configuration file ${proxyPath} does not exist.`);
167170
}
168171

172+
let proxyConfiguration: Record<string, object> | object[];
173+
169174
switch (extname(proxyPath)) {
170175
case '.json': {
171176
const content = await fsPromises.readFile(proxyPath, 'utf-8');
172177

173178
const { parse, printParseErrorCode } = await import('jsonc-parser');
174179
const parseErrors: import('jsonc-parser').ParseError[] = [];
175-
const proxyConfiguration = parse(content, parseErrors, { allowTrailingComma: true });
180+
proxyConfiguration = parse(content, parseErrors, { allowTrailingComma: true });
176181

177182
if (parseErrors.length > 0) {
178183
let errorMessage = `Proxy configuration file ${proxyPath} contains parse errors:`;
@@ -183,32 +188,44 @@ async function addProxyConfig(root: string, proxyConfig: string | undefined) {
183188
throw new Error(errorMessage);
184189
}
185190

186-
return proxyConfiguration;
191+
break;
187192
}
188193
case '.mjs':
189194
// Load the ESM configuration file using the TypeScript dynamic import workaround.
190195
// Once TypeScript provides support for keeping the dynamic import this workaround can be
191196
// changed to a direct dynamic import.
192-
return (await loadEsmModule<{ default: unknown }>(pathToFileURL(proxyPath))).default;
197+
proxyConfiguration = (
198+
await loadEsmModule<{ default: Record<string, object> | object[] }>(
199+
pathToFileURL(proxyPath),
200+
)
201+
).default;
202+
break;
193203
case '.cjs':
194-
return require(proxyPath);
204+
proxyConfiguration = require(proxyPath);
205+
break;
195206
default:
196207
// The file could be either CommonJS or ESM.
197208
// CommonJS is tried first then ESM if loading fails.
198209
try {
199-
return require(proxyPath);
210+
proxyConfiguration = require(proxyPath);
200211
} catch (e) {
201212
assertIsError(e);
202-
if (e.code === 'ERR_REQUIRE_ESM') {
203-
// Load the ESM configuration file using the TypeScript dynamic import workaround.
204-
// Once TypeScript provides support for keeping the dynamic import this workaround can be
205-
// changed to a direct dynamic import.
206-
return (await loadEsmModule<{ default: unknown }>(pathToFileURL(proxyPath))).default;
213+
if (e.code !== 'ERR_REQUIRE_ESM') {
214+
throw e;
207215
}
208216

209-
throw e;
217+
// Load the ESM configuration file using the TypeScript dynamic import workaround.
218+
// Once TypeScript provides support for keeping the dynamic import this workaround can be
219+
// changed to a direct dynamic import.
220+
proxyConfiguration = (
221+
await loadEsmModule<{ default: Record<string, object> | object[] }>(
222+
pathToFileURL(proxyPath),
223+
)
224+
).default;
210225
}
211226
}
227+
228+
return normalizeProxyConfiguration(proxyConfiguration);
212229
}
213230

214231
/**
@@ -333,3 +350,9 @@ function getPublicHostOptions(options: WebpackDevServerOptions, webSocketPath: s
333350

334351
return `auto://${publicHost || '0.0.0.0:0'}${webSocketPath}`;
335352
}
353+
354+
function normalizeProxyConfiguration(proxy: Record<string, object> | object[]): object[] {
355+
return Array.isArray(proxy)
356+
? proxy
357+
: Object.entries(proxy).map(([context, value]) => ({ context: [context], ...value }));
358+
}

packages/angular_devkit/build_webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
},
2626
"peerDependencies": {
2727
"webpack": "^5.30.0",
28-
"webpack-dev-server": "^4.0.0"
28+
"webpack-dev-server": "^5.0.2"
2929
}
3030
}

0 commit comments

Comments
 (0)