mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-07 21:07:46 +00:00
[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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 },
|
||||
},
|
||||
|
||||
@@ -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(),
|
||||
|
||||
39
packages/cli/test/integration.js
vendored
39
packages/cli/test/integration.js
vendored
@@ -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.`;
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 = {};
|
||||
|
||||
@@ -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) });
|
||||
}
|
||||
|
||||
@@ -10,10 +10,5 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
"build": {
|
||||
"env": {
|
||||
"VERCEL_BUILDER_DEBUG": "1"
|
||||
}
|
||||
},
|
||||
"probes": [{ "path": "/", "mustContain": "hello world" }]
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user