Skip to content

Commit 892fcc6

Browse files
clydinangular-robot[bot]
authored andcommitted
fix(@angular-devkit/build-angular): convert dev-server glob proxy entries for esbuild builder
When using the esbuild-based browser application builder with the development server, an underlying Vite server is used. The Vite server currently does not support glob-based entries for the proxy configuration. They must either be prefix strings or regular expressions. The Webpack-based development server, however, does support globs. To remove the need to have different proxy configuration files for the two servers, the entries will now be normalized to regular expressions when using the Vite server. This allows existing proxy configurations to work without modification.
1 parent 740610a commit 892fcc6

File tree

6 files changed

+32
-6
lines changed

6 files changed

+32
-6
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"@types/node-fetch": "^2.1.6",
113113
"@types/npm-package-arg": "^6.1.0",
114114
"@types/pacote": "^11.1.3",
115+
"@types/picomatch": "^2.3.0",
115116
"@types/pidusage": "^2.0.1",
116117
"@types/progress": "^2.0.3",
117118
"@types/resolve": "^1.17.1",
@@ -124,8 +125,8 @@
124125
"@types/yarnpkg__lockfile": "^1.1.5",
125126
"@typescript-eslint/eslint-plugin": "5.59.2",
126127
"@typescript-eslint/parser": "5.59.2",
127-
"@yarnpkg/lockfile": "1.1.0",
128128
"@vitejs/plugin-basic-ssl": "1.0.1",
129+
"@yarnpkg/lockfile": "1.1.0",
129130
"ajv": "8.12.0",
130131
"ajv-formats": "2.1.1",
131132
"ansi-colors": "4.1.3",
@@ -181,6 +182,7 @@
181182
"ora": "5.4.1",
182183
"pacote": "15.1.3",
183184
"parse5-html-rewriting-stream": "7.0.0",
185+
"picomatch": "2.3.1",
184186
"pidtree": "^0.6.0",
185187
"pidusage": "^3.0.0",
186188
"piscina": "3.2.0",

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ ts_library(
136136
"@npm//@types/less",
137137
"@npm//@types/loader-utils",
138138
"@npm//@types/node",
139+
"@npm//@types/picomatch",
139140
"@npm//@types/semver",
140141
"@npm//@types/text-table",
141142
"@npm//@vitejs/plugin-basic-ssl",

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"open": "8.4.2",
5050
"ora": "5.4.1",
5151
"parse5-html-rewriting-stream": "7.0.0",
52+
"picomatch": "2.3.1",
5253
"piscina": "3.2.0",
5354
"postcss": "8.4.23",
5455
"postcss-loader": "7.3.0",

packages/angular_devkit/build_angular/src/builders/dev-server/load-proxy-config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import { hasMagic as isDynamicPattern } from 'glob';
910
import { existsSync } from 'node:fs';
1011
import { readFile } from 'node:fs/promises';
1112
import { extname, resolve } from 'node:path';
1213
import { pathToFileURL } from 'node:url';
14+
import { parse as parseGlob } from 'picomatch';
1315
import { assertIsError } from '../../utils/error';
1416
import { loadEsmModule } from '../../utils/load-esm';
1517

@@ -69,6 +71,21 @@ export async function loadProxyConfiguration(root: string, proxyConfig: string |
6971
}
7072
}
7173

74+
/**
75+
* Converts glob patterns to regular expressions to support Vite's proxy option.
76+
* @param proxy A proxy configuration object.
77+
*/
78+
export function normalizeProxyConfiguration(proxy: Record<string, unknown>) {
79+
// TODO: Consider upstreaming glob support
80+
for (const key of Object.keys(proxy)) {
81+
if (isDynamicPattern(key)) {
82+
const { output } = parseGlob(key);
83+
proxy[`^${output}$`] = proxy[key];
84+
delete proxy[key];
85+
}
86+
}
87+
}
88+
7289
/**
7390
* Calculates the line and column for an error offset in the content of a JSON file.
7491
* @param location The offset error location from the beginning of the content.

packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import path from 'node:path';
1818
import { InlineConfig, ViteDevServer, createServer, normalizePath } from 'vite';
1919
import { buildEsbuildBrowser } from '../browser-esbuild';
2020
import type { Schema as BrowserBuilderOptions } from '../browser-esbuild/schema';
21-
import { loadProxyConfiguration } from './load-proxy-config';
21+
import { loadProxyConfiguration, normalizeProxyConfiguration } from './load-proxy-config';
2222
import type { NormalizedDevServerOptions } from './options';
2323
import type { DevServerBuilderOutput } from './webpack-server';
2424

@@ -182,6 +182,9 @@ export async function setupServer(
182182
serverOptions.workspaceRoot,
183183
serverOptions.proxyConfig,
184184
);
185+
if (proxy) {
186+
normalizeProxyConfiguration(proxy);
187+
}
185188

186189
const configuration: InlineConfig = {
187190
configFile: false,

yarn.lock

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125

126126
"@angular/build-tooling@https://github.com/angular/dev-infra-private-build-tooling-builds.git#988781b092b543a21af7996f26cda23b43b70226":
127127
version "0.0.0-e82631b66d14e57672e21ca7d021b8425214771e"
128-
uid "988781b092b543a21af7996f26cda23b43b70226"
129128
resolved "https://github.com/angular/dev-infra-private-build-tooling-builds.git#988781b092b543a21af7996f26cda23b43b70226"
130129
dependencies:
131130
"@angular-devkit/build-angular" "16.0.0-rc.4"
@@ -286,7 +285,6 @@
286285

287286
"@angular/ng-dev@https://github.com/angular/dev-infra-private-ng-dev-builds.git#01d77bf81a01d438b86026aacb9abeee03f53f65":
288287
version "0.0.0-e82631b66d14e57672e21ca7d021b8425214771e"
289-
uid "01d77bf81a01d438b86026aacb9abeee03f53f65"
290288
resolved "https://github.com/angular/dev-infra-private-ng-dev-builds.git#01d77bf81a01d438b86026aacb9abeee03f53f65"
291289
dependencies:
292290
"@yarnpkg/lockfile" "^1.1.0"
@@ -3367,6 +3365,11 @@
33673365
dependencies:
33683366
parse5 "*"
33693367

3368+
"@types/picomatch@^2.3.0":
3369+
version "2.3.0"
3370+
resolved "https://registry.yarnpkg.com/@types/picomatch/-/picomatch-2.3.0.tgz#75db5e75a713c5a83d5b76780c3da84a82806003"
3371+
integrity sha512-O397rnSS9iQI4OirieAtsDqvCj4+3eY1J+EPdNTKuHuRWIfUoGyzX294o8C4KJYaLqgSrd2o60c5EqCU8Zv02g==
3372+
33703373
"@types/pidusage@^2.0.1":
33713374
version "2.0.2"
33723375
resolved "https://registry.yarnpkg.com/@types/pidusage/-/pidusage-2.0.2.tgz#3f8c4b19ba7ea438a733d093661e92b60e5f88ee"
@@ -9378,7 +9381,7 @@ picocolors@^1.0.0:
93789381
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
93799382
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==
93809383

9381-
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
9384+
picomatch@2.3.1, picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
93829385
version "2.3.1"
93839386
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
93849387
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
@@ -10308,7 +10311,6 @@ sass@^1.55.0:
1030810311

1030910312
"sauce-connect-proxy@https://saucelabs.com/downloads/sc-4.8.1-linux.tar.gz":
1031010313
version "0.0.0"
10311-
uid "9c16682e4c9716734432789884f868212f95f563"
1031210314
resolved "https://saucelabs.com/downloads/sc-4.8.1-linux.tar.gz#9c16682e4c9716734432789884f868212f95f563"
1031310315

1031410316
saucelabs@^1.5.0:

0 commit comments

Comments
 (0)