Skip to content

Commit d844c33

Browse files
committed
refactor(@angular/build): handle relative @ng/components
This update serves as a preparatory step to address #29248. The change involves modifying the line 'urlPartial' in [r3_hmr_compiler.ts](https://github.com/angular/angular/blob/4e6017a9f5cda389c5fbf4f2c1519ce1bba23e11/packages/compiler/src/render3/r3_hmr_compiler.ts#L57) to start with `./` instead of `/`.
1 parent 612da79 commit d844c33

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/angular/build/src/tools/vite/middlewares/component-middleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function createAngularComponentMiddleware(
1818
return;
1919
}
2020

21-
if (!req.url.startsWith(ANGULAR_COMPONENT_PREFIX)) {
21+
if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {
2222
next();
2323

2424
return;

packages/angular/build/src/tools/vite/plugins/angular-memory-plugin.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ export async function createAngularMemoryPlugin(
4646
// Vite will resolve these these files example:
4747
// `file:///@ng/component?c=src%2Fapp%2Fapp.component.ts%40AppComponent&t=1737017253850`
4848
const sourcePath = fileURLToPath(source);
49-
const { root } = parse(sourcePath);
50-
const sourceWithoutRoot = normalizePath('/' + sourcePath.slice(root.length));
49+
const sourceWithoutRoot = sourcePath.startsWith(virtualProjectRoot)
50+
? normalizePath('/' + relative(virtualProjectRoot, sourcePath))
51+
: // TODO: remove once https://github.com/angular/angular/blob/4e6017a9f5cda389c5fbf4f2c1519ce1bba23e11/packages/compiler/src/render3/r3_hmr_compiler.ts#L57
52+
// is changed from `/@ng` to `./@ng/`
53+
normalizePath('/' + sourcePath.slice(parse(sourcePath).root.length));
5154

5255
if (sourceWithoutRoot.startsWith(ANGULAR_PREFIX)) {
5356
const [, query] = source.split('?', 2);

0 commit comments

Comments
 (0)