Skip to content

Commit 2967705

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. (cherry picked from commit 892fcc6)
1 parent ffbcc6b commit 2967705

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-2
lines changed

package.json

Lines changed: 2 additions & 0 deletions
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",
@@ -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.2.4",

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: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@
183183
dependencies:
184184
tslib "^2.3.0"
185185

186+
"@angular/[email protected]":
187+
version "16.0.0"
188+
resolved "https://registry.yarnpkg.com/@angular/compiler-cli/-/compiler-cli-16.0.0.tgz#eadcbc65c82c90c663c57bd012f132480bcae218"
189+
integrity sha512-oyJzxiTHxziv7mD0QuA7K6tpDoL6YNGPkquKjeJjNVZvUrodGsvJ8xHO4ydmjK3nMu2ET1YarsdI8bRp4vp/7w==
190+
dependencies:
191+
"@babel/core" "7.19.3"
192+
"@jridgewell/sourcemap-codec" "^1.4.14"
193+
chokidar "^3.0.0"
194+
convert-source-map "^1.5.1"
195+
reflect-metadata "^0.1.2"
196+
semver "^7.0.0"
197+
tslib "^2.3.0"
198+
yargs "^17.2.1"
199+
186200
"@angular/[email protected]":
187201
version "16.0.0-next.7"
188202
resolved "https://registry.yarnpkg.com/@angular/compiler-cli/-/compiler-cli-16.0.0-next.7.tgz#b99504ede7e4e3620dc5087b83a357ec8ad79aac"
@@ -197,6 +211,13 @@
197211
tslib "^2.3.0"
198212
yargs "^17.2.1"
199213

214+
"@angular/[email protected]":
215+
version "16.0.0"
216+
resolved "https://registry.yarnpkg.com/@angular/compiler/-/compiler-16.0.0.tgz#9039e29e420ef119f02fb7ec9621bfc897679fac"
217+
integrity sha512-xtg+KRvSeB9DUzMDtvlaRGKv+Y0MERsz+JOoqV9H4606ThNz5h8ih6fEhVKYqG100o7GhdJaVFO+vlr2/edUHA==
218+
dependencies:
219+
tslib "^2.3.0"
220+
200221
"@angular/[email protected]":
201222
version "16.0.0-next.7"
202223
resolved "https://registry.yarnpkg.com/@angular/compiler/-/compiler-16.0.0-next.7.tgz#15058e4390defb5db094d64e1a2f9c9587691533"
@@ -3464,6 +3485,11 @@
34643485
dependencies:
34653486
parse5 "*"
34663487

3488+
"@types/picomatch@^2.3.0":
3489+
version "2.3.0"
3490+
resolved "https://registry.yarnpkg.com/@types/picomatch/-/picomatch-2.3.0.tgz#75db5e75a713c5a83d5b76780c3da84a82806003"
3491+
integrity sha512-O397rnSS9iQI4OirieAtsDqvCj4+3eY1J+EPdNTKuHuRWIfUoGyzX294o8C4KJYaLqgSrd2o60c5EqCU8Zv02g==
3492+
34673493
"@types/pidusage@^2.0.1":
34683494
version "2.0.2"
34693495
resolved "https://registry.yarnpkg.com/@types/pidusage/-/pidusage-2.0.2.tgz#3f8c4b19ba7ea438a733d093661e92b60e5f88ee"
@@ -9676,7 +9702,7 @@ picocolors@^1.0.0:
96769702
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
96779703
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==
96789704

9679-
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
9705+
picomatch@2.3.1, picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
96809706
version "2.3.1"
96819707
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
96829708
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==

0 commit comments

Comments
 (0)