fix: cjs warning respect the logLevel flag (#17993) · vitejs/vite@dc3c14f (original) (raw)

Original file line number Diff line number Diff line change
@@ -25,6 +25,18 @@ asyncFunctions.forEach((name) => {
25 25
26 26 function warnCjsUsage() {
27 27 if (process.env.VITE_CJS_IGNORE_WARNING) return
28 +const logLevelIndex = process.argv.findIndex((arg) =>
29 +/^(?:-l|--logLevel)/.test(arg),
30 +)
31 +if (logLevelIndex > 0) {
32 +const logLevelValue = process.argv[logLevelIndex + 1]
33 +if (logLevelValue === 'silent' |
34 +return
35 +}
36 +if (/silent|error/.test(process.argv[logLevelIndex])) {
37 +return
38 +}
39 +}
28 40 const yellow = (str) => `\u001b[33m${str}\u001b[39m`
29 41 const log = process.env.VITE_CJS_TRACE ? console.trace : console.warn
30 42 log(