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(qwik): Improve logging of vite plugin #5389

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
"program": "${workspaceFolder}/packages/docs/node_modules/vite/bin/vite.js",
"args": ["build"]
},
{
"type": "node",
"name": "docs build.server",
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"cwd": "${workspaceFolder}/packages/docs",
"program": "${workspaceFolder}/packages/docs/node_modules/vite/bin/vite.js",
"args": ["build", "-c", "adapters/cloudflare-pages/vite.config.ts"]
},
{
"type": "node",
"name": "vscode-jest-tests",
Expand Down
46 changes: 46 additions & 0 deletions packages/qwik/src/optimizer/src/plugins/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,57 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
}
}
},

onLog(level, log) {
if (log.plugin == ('vite-plugin-qwik' satisfies QwikVitePlugin['name'])) {
const color = LOG_COLOR[level] || ANSI_COLOR.White;
const frames = (log.frame || '')
.split('\n')
.map(
(line) =>
(line.match(/^\s*\^\s*$/) ? ANSI_COLOR.BrightWhite : ANSI_COLOR.BrightBlack) + line
);
// eslint-disable-next-line no-console
console[level](
`${color}%s\n${ANSI_COLOR.BrightWhite}%s\n%s${ANSI_COLOR.RESET}`,
`[${log.plugin}](${level}): ${log.message}\n`,
` ${log?.loc?.file}:${log?.loc?.line}:${log?.loc?.column}\n`,
` ${frames.join('\n ')}\n`
);
return false;
}
},
};

return vitePlugin;
}

const ANSI_COLOR = {
Black: '\x1b[30m',
Red: '\x1b[31m',
Green: '\x1b[32m',
Yellow: '\x1b[33m',
Blue: '\x1b[34m',
Magenta: '\x1b[35m',
Cyan: '\x1b[36m',
White: '\x1b[37m',
BrightBlack: '\x1b[90m',
BrightRed: '\x1b[91m',
BrightGreen: '\x1b[92m',
BrightYellow: '\x1b[93m',
BrightBlue: '\x1b[94m',
BrightMagenta: '\x1b[95m',
BrightCyan: '\x1b[96m',
BrightWhite: '\x1b[97m',
RESET: '\x1b[0m',
};

const LOG_COLOR = {
warn: ANSI_COLOR.Yellow,
info: ANSI_COLOR.Cyan,
debug: ANSI_COLOR.BrightBlack,
};

function updateEntryDev(code: string) {
code = code.replace(/["']@builder.io\/qwik["']/g, `'${VITE_CLIENT_MODULE}'`);
return code;
Expand Down
Loading