From f4c71e5eb937ce92cc8803d4a6e19400d22ae611 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 24 Jan 2023 21:11:09 -0500 Subject: [PATCH] Protect against shimmed process usage in Vercel Edge (#5969) * Protect against shimmed process usage in Vercel Edge * Adding a changeset --- .changeset/nasty-dolphins-cry.md | 7 +++++++ packages/astro/src/core/logger/core.ts | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .changeset/nasty-dolphins-cry.md diff --git a/.changeset/nasty-dolphins-cry.md b/.changeset/nasty-dolphins-cry.md new file mode 100644 index 000000000..26437be43 --- /dev/null +++ b/.changeset/nasty-dolphins-cry.md @@ -0,0 +1,7 @@ +--- +'astro': patch +--- + +Fix usage of logger in Vercel Edge + +This protects against usage of `process` global in shimmed environments. diff --git a/packages/astro/src/core/logger/core.ts b/packages/astro/src/core/logger/core.ts index dc50d49e0..dbd2ae895 100644 --- a/packages/astro/src/core/logger/core.ts +++ b/packages/astro/src/core/logger/core.ts @@ -101,10 +101,18 @@ function padStr(str: string, len: number) { export let defaultLogLevel: LoggerLevel; if (typeof process !== 'undefined') { - if (process.argv.includes('--verbose')) { - defaultLogLevel = 'debug'; - } else if (process.argv.includes('--silent')) { - defaultLogLevel = 'silent'; + // This could be a shimmed environment so we don't know that `process` is the full + // NodeJS.process. This code treats it as a plain object so TS doesn't let us + // get away with incorrect assumptions. + let proc: object = process; + if('argv' in proc && Array.isArray(proc.argv)) { + if (proc.argv.includes('--verbose')) { + defaultLogLevel = 'debug'; + } else if (proc.argv.includes('--silent')) { + defaultLogLevel = 'silent'; + } else { + defaultLogLevel = 'info'; + } } else { defaultLogLevel = 'info'; }