From ea598f8e2e192510fa44e59ec189737911b0f439 Mon Sep 17 00:00:00 2001 From: Romuald Brillout Date: Fri, 29 Mar 2024 11:28:44 +0100 Subject: [PATCH] fix: clean esbuild errros --- .../getVikeConfig/transpileAndExecuteFile.ts | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.ts b/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.ts index db1e576761..9f9a2ee556 100644 --- a/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.ts +++ b/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.ts @@ -3,7 +3,7 @@ export { getConfigBuildErrorFormatted } export { getConfigExecutionErrorIntroMsg } export { isTemporaryBuildFile } -import { build, type BuildResult, type BuildOptions, formatMessages } from 'esbuild' +import { build, type BuildResult, type BuildOptions, formatMessages, type Message } from 'esbuild' import fs from 'fs' import path from 'path' import pc from '@brillout/picocolors' @@ -129,7 +129,7 @@ async function transpileWithEsbuild( // - A pointer import // - Externalized { - name: 'vike-esbuild-plugin', + name: 'vike-esbuild', setup(build) { // https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366 const useEsbuildResolver = 'useEsbuildResolver' @@ -149,6 +149,7 @@ async function transpileWithEsbuild( */ // Let esbuild throw the error. (It throws a nice & pretty error.) + cleanEsbuildErrors(resolved.errors) return resolved } @@ -360,3 +361,29 @@ function getErrIntroMsg(operation: 'transpile' | 'execute', filePath: FilePathRe ].join(' ') return msg } + +function cleanEsbuildErrors(errors: Message[]) { + errors.forEach( + (e) => + (e.notes = e.notes.filter( + (note) => + // Remove note: + // ```shell + // You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle. + // ``` + // + // From error: + // ```shell + // ✘ [ERROR] Could not resolve "#root/renderer/onRenderHtml_typo" [plugin vike-esbuild] + // + // renderer/+config.h.js:1:29: + // 1 │ import { onRenderHtml } from "#root/renderer/onRenderHtml_typo" + // ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // + // You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle. + // + // ``` + !note.text.includes('as external to exclude it from the bundle') + )) + ) +}