next
Version:
The React Framework
86 lines (85 loc) • 4.17 kB
JavaScript
import { loadEnvConfig } from '@next/env';
import * as inspector from 'inspector';
import * as Log from '../../build/output/log';
import { bold, purple, strikethrough } from '../../lib/picocolors';
import { experimentalSchema } from '../config-schema';
import { getAgentName } from '../../telemetry/agent-name';
import { bundlerName, getBundlerFromEnv } from '../../lib/bundler';
import { hasCurrentAgentFeedback, hasCurrentAgentRules, removeAgentFeedbackFiles, removeAgentRulesFiles, writeAgentFeedbackFiles, writeAgentFiles } from './generate-agent-files';
/**
* Logs basic startup info that doesn't require config.
* Called before "Ready in X" to show immediate feedback.
*/ export function logStartInfo({ networkUrl, appUrl, envInfo, logBundler }) {
const versionSuffix = logBundler ? ` (${bundlerName(getBundlerFromEnv())})` : '';
Log.bootstrap(`${bold(purple(`${Log.prefixes.ready} Next.js ${"16.4.3"}`))}${versionSuffix}`);
if (appUrl) {
Log.bootstrap(`- Local: ${appUrl}`);
}
if (networkUrl) {
Log.bootstrap(`- Network: ${networkUrl}`);
}
const inspectorUrl = inspector.url();
if (inspectorUrl) {
// Could also parse this port from the inspector URL.
// process.debugPort will always be defined even if the process is not being inspected.
// The full URL seems noisy as far as I can tell.
// Node.js will print the full URL anyway.
const debugPort = process.debugPort;
Log.bootstrap(`- Debugger port: ${debugPort}`);
}
if (envInfo == null ? void 0 : envInfo.length) Log.bootstrap(`- Environments: ${envInfo.join(', ')}`);
}
/**
* Logs experimental features and config-dependent info.
* Called after getRequestHandlers completes.
*/ export function logExperimentalInfo({ experimentalFeatures, cacheComponents, partialPrefetching }) {
if (cacheComponents) {
Log.bootstrap(`- Cache Components enabled`);
}
if (partialPrefetching) {
Log.bootstrap(`- Partial Prefetching enabled`);
}
if (experimentalFeatures == null ? void 0 : experimentalFeatures.length) {
Log.bootstrap(`- Experiments (use with caution):`);
for (const exp of experimentalFeatures){
const isValid = Object.prototype.hasOwnProperty.call(experimentalSchema, exp.key);
if (isValid) {
const symbol = typeof exp.value === 'boolean' ? exp.value === true ? bold('✓') : bold('⨯') : '·';
const suffix = typeof exp.value === 'number' || typeof exp.value === 'string' ? `: ${JSON.stringify(exp.value)}` : '';
const reason = exp.reason ? ` (${exp.reason})` : '';
Log.bootstrap(` ${symbol} ${exp.key}${suffix}${reason}`);
} else {
Log.bootstrap(` ? ${strikethrough(exp.key)} (invalid experimental key)`);
}
}
}
// New line after the bootstrap info
Log.info('');
}
/**
* Keep the agent-rules block in sync with next.config. Enabling it still
* requires a detected agent; disabling it removes only that managed block,
* even when no agent is currently detected.
*/ export async function syncAgentRulesForDev(dir, enabled) {
if (!enabled) return removeAgentRulesFiles(dir);
if (await getAgentName() === null) return null;
if (hasCurrentAgentRules(dir)) return null;
return writeAgentFiles(dir);
}
/**
* Keep the opt-in agent-feedback block in sync with next.config. Enabling it
* still requires a detected agent; disabling it removes only that managed
* block, even when no agent is currently detected.
*/ export async function syncAgentFeedbackForDev(dir, enabled) {
if (!enabled) return removeAgentFeedbackFiles(dir);
if (await getAgentName() === null) return null;
if (hasCurrentAgentFeedback(dir)) return null;
return writeAgentFeedbackFiles(dir);
}
/**
* Gets environment info for logging. Fast operation that doesn't require config.
*/ export function getEnvInfo(dir) {
const { loadedEnvFiles } = loadEnvConfig(dir, true, console, false);
return loadedEnvFiles.map((f)=>f.path);
}
//# sourceMappingURL=app-info-log.js.map