[build-utils] Prefix debug message (#8378)

This PR adds `VERCEL_DEBUG_PREFIX` environment variable which lets you set a prefix for the debug logs.
This commit is contained in:
Steven
2022-08-24 14:50:20 -04:00
committed by GitHub
parent 1c14e945f9
commit 3856623785
9 changed files with 9 additions and 91 deletions

View File

@@ -3,5 +3,7 @@ import { getPlatformEnv } from './get-platform-env';
export default function debug(message: string, ...additional: any[]) {
if (getPlatformEnv('BUILDER_DEBUG')) {
console.log(message, ...additional);
} else if (process.env.VERCEL_DEBUG_PREFIX) {
console.log(`${process.env.VERCEL_DEBUG_PREFIX}${message}`, ...additional);
}
}

View File

@@ -1856,7 +1856,9 @@ export default class DevServer {
devCacheDir,
env: {
...envConfigs.runEnv,
VERCEL_BUILDER_DEBUG: this.output.debugEnabled ? '1' : undefined,
VERCEL_DEBUG_PREFIX: this.output.debugEnabled
? '[builder]'
: undefined,
},
buildEnv: { ...envConfigs.buildEnv },
},

View File

@@ -76,25 +76,6 @@ module.exports = async function prepare(session, binaryPath, tmpFixturesDir) {
},
}),
},
'build-env-debug': {
'now.json': JSON.stringify({
builds: [{ src: 'index.js', use: '@vercel/node' }],
}),
'package.json': JSON.stringify({
scripts: {
'now-build': 'node now-build.js',
},
}),
'now-build.js': `
const fs = require('fs');
fs.writeFileSync(
'index.js',
fs.readFileSync('index.js', 'utf8')
.replace('BUILD_ENV_DEBUG', process.env.NOW_BUILDER_DEBUG ? 'on' : 'off'),
);
`,
'index.js': `module.exports = (req, res) => { res.status(200).send('BUILD_ENV_DEBUG'); }`,
},
'now-revert-alias-1': {
'index.json': JSON.stringify({ name: 'now-revert-alias-1' }),
'now.json': getRevertAliasConfigFile(),

View File

@@ -2170,45 +2170,6 @@ test('use build-env', async t => {
t.is(content.trim(), 'bar');
});
test('use `--debug` CLI flag', async t => {
const directory = fixture('build-env-debug');
const { stderr, stdout, exitCode } = await execa(
binaryPath,
[
directory,
'--public',
'--name',
session,
'--debug',
...defaultArgs,
'--yes',
],
{
reject: false,
}
);
console.log(stderr);
console.log(stdout);
console.log(exitCode);
// Ensure the exit code is right
t.is(exitCode, 0, `Received:\n"${stderr}"\n"${stdout}"`);
// Test if the output is really a URL
const deploymentUrl = pickUrl(stdout);
const { href, host } = new URL(deploymentUrl);
t.is(host.split('-')[0], session);
await waitForDeployment(href);
// get the content
const response = await fetch(href);
const content = await response.text();
t.is(content.trim(), 'off');
});
test('try to deploy non-existing path', async t => {
const goal = `Error! The specified file or directory "${session}" does not exist.`;

View File

@@ -151,11 +151,6 @@ async function compile(
}
}
debug(
'Tracing input files: ' +
[...inputFiles].map(p => relative(workPath, p)).join(', ')
);
let tsCompile: Register;
function compileTypeScript(path: string, source: string): string {
const relPath = relative(baseDir, path);
@@ -257,11 +252,8 @@ async function compile(
);
for (const warning of warnings) {
if (warning?.stack) {
debug(warning.stack.replace('Error: ', 'Warning: '));
debug(`Warning from trace: ${warning.message}`);
}
}
for (const path of fileList) {
let entry = fsCache.get(path);
if (!entry) {

View File

@@ -242,9 +242,7 @@ export const build: BuildV2 = async ({
);
for (const warning of warnings) {
if (warning?.stack) {
debug(warning.stack.replace('Error: ', 'Warning: '));
}
debug(`Warning from trace: ${warning.message}`);
}
const lambdaFiles: Files = {};

View File

@@ -265,10 +265,9 @@ async function createRenderFunction(
});
for (const warning of trace.warnings) {
if (warning.stack) {
debug(warning.stack.replace('Error: ', 'Warning: '));
}
debug(`Warning from trace: ${warning.message}`);
}
for (const file of trace.fileList) {
files[file] = await FileFsRef.fromFsPath({ fsPath: join(rootDir, file) });
}

View File

@@ -10,10 +10,5 @@
}
}
],
"build": {
"env": {
"VERCEL_BUILDER_DEBUG": "1"
}
},
"probes": [{ "path": "/", "mustContain": "hello world" }]
}

View File

@@ -308,18 +308,6 @@ async function testDeployment(fixturePath) {
const uploadNowJson = nowJson.uploadNowJson;
delete nowJson.uploadNowJson;
['VERCEL_BUILDER_DEBUG', 'VERCEL_BUILD_CLI_PACKAGE'].forEach(name => {
if (process.env[name]) {
if (!nowJson.build) {
nowJson.build = {};
}
if (!nowJson.build.env) {
nowJson.build.env = {};
}
nowJson.build.env[name] = process.env[name];
}
});
const probePath = path.resolve(fixturePath, 'probe.js');
let probes = [];
if ('probes' in nowJson) {