From 2e58d7383a08150a59ee7b3a02d8bffd92259f6d Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 6 Jan 2025 13:32:22 +0000 Subject: [PATCH] refactor(@angular/build): normalize source path for windows compatibility This update resolves an issue that prevents SSR from functioning correctly on Windows when using the latest Vite. --- .../src/tools/vite/plugins/angular-memory-plugin.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/angular/build/src/tools/vite/plugins/angular-memory-plugin.ts b/packages/angular/build/src/tools/vite/plugins/angular-memory-plugin.ts index 201ce171b3ea..47bfebb8ca15 100644 --- a/packages/angular/build/src/tools/vite/plugins/angular-memory-plugin.ts +++ b/packages/angular/build/src/tools/vite/plugins/angular-memory-plugin.ts @@ -47,27 +47,28 @@ export async function createAngularMemoryPlugin( } if (importer) { - if (source[0] === '.' && normalizePath(importer).startsWith(virtualProjectRoot)) { + const normalizedImporter = normalizePath(importer); + if (source[0] === '.' && normalizedImporter.startsWith(virtualProjectRoot)) { // Remove query if present - const [importerFile] = importer.split('?', 1); + const [importerFile] = normalizedImporter.split('?', 1); source = '/' + join(dirname(relative(virtualProjectRoot, importerFile)), source); } else if ( !ssr && source[0] === '/' && importer.endsWith('index.html') && - normalizePath(importer).startsWith(virtualProjectRoot) + normalizedImporter.startsWith(virtualProjectRoot) ) { // This is only needed when using SSR and `angularSsrMiddleware` (old style) to correctly resolve // .js files when using lazy-loading. // Remove query if present - const [importerFile] = importer.split('?', 1); + const [importerFile] = normalizedImporter.split('?', 1); source = '/' + join(dirname(relative(virtualProjectRoot, importerFile)), basename(source)); } } const [file] = source.split('?', 1); - if (outputFiles.has(file)) { + if (outputFiles.has(normalizePath(file))) { return join(virtualProjectRoot, source); } },