Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular-devkit/build-angular): remove unactionable error overlay suggestion from Vite-based dev server #26171

Merged
merged 1 commit into from Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -443,6 +443,10 @@ export async function setupServer(
const relativeFile = normalizePath(path.relative(virtualProjectRoot, file));
const codeContents = outputFiles.get(relativeFile)?.contents;
if (codeContents === undefined) {
if (relativeFile.endsWith('/node_modules/vite/dist/client/client.mjs')) {
return loadViteClientCode(file);
}

return;
}

Expand Down Expand Up @@ -683,6 +687,28 @@ export async function setupServer(
return configuration;
}

/**
* Reads the resolved Vite client code from disk and updates the content to remove
* an unactionable suggestion to update the Vite configuration file to disable the
* error overlay. The Vite configuration file is not present when used in the Angular
* CLI.
* @param file The absolute path to the Vite client code.
* @returns
*/
async function loadViteClientCode(file: string) {
const originalContents = await readFile(file, 'utf-8');
let contents = originalContents.replace('You can also disable this overlay by setting', '');
contents = contents.replace(
// eslint-disable-next-line max-len
'<code part="config-option-name">server.hmr.overlay</code> to <code part="config-option-value">false</code> in <code part="config-file-name">vite.config.js.</code>',
'',
);

assert(originalContents !== contents, 'Failed to update Vite client error overlay text.');

return contents;
}

function pathnameWithoutServePath(url: string, serverOptions: NormalizedDevServerOptions): string {
const parsedUrl = new URL(url, 'http://localhost');
let pathname = decodeURIComponent(parsedUrl.pathname);
Expand Down