Skip to content

Commit

Permalink
fix: suppress punycode warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Dec 17, 2024
1 parent 4634288 commit 9e760fb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,31 @@ const { cli } = require("@webiny/cli");
// let's intercept those and make sure messages are just forwarded
// to the main thread.
const types = ["log", "error", "warn"];

// Suppress punycode warnings. This is a known issue which we can't fix.
const filterOutPunycodeWarnings = message => {
if (typeof message === "string" && message.includes("punycode")) {
return false;
}

return true;
};

for (let i = 0; i < types.length; i++) {
const type = types[i];
console[type] = (...message) => {
parentPort.postMessage(
JSON.stringify({
type,
message: message.filter(Boolean).map(m => {
if (m instanceof Error) {
return m.message;
}
return m;
})
message: message
.filter(Boolean)
.filter(filterOutPunycodeWarnings)
.map(m => {
if (m instanceof Error) {
return m.message;
}
return m;
})
})
);
};
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const yargs = require("yargs");
// Disable help processing until after plugins are imported.
yargs.help(false);

// Suppress punycode warnings. This is a known issue which we can't fix.
require("./utils/suppressPunycodeWarnings");

// Loads environment variables from multiple sources.
require("./utils/loadEnvVariables");

Expand Down
7 changes: 7 additions & 0 deletions packages/cli/utils/suppressPunycodeWarnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const originalConsoleError = console.error;
console.error = (message, ...args) => {
if (typeof message === "string" && message.includes("punycode")) {
return;
}
originalConsoleError.call(console, message, ...args);
};

0 comments on commit 9e760fb

Please sign in to comment.