Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: don't log more than 100 pages per route #11444

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/red-crabs-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'astro': patch
---

Limits the number of pages logged by default to 100 per route.

If there are more than 100 pages it will log the first 100 pages and then log a summary of the total number of pages.

For example:

```sh
10:08:26 ├─ /blog/article-98/index.html (+0ms)
10:08:26 ├─ /blog/article-99/index.html (+1ms)
10:08:26 └─ ...rendering 100 more paths. Done. (+63ms)
```

To see the full list of pages rendered, enable debug logging using the `--verbose` flag.
36 changes: 30 additions & 6 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async function generatePage(
pipeline: BuildPipeline
) {
// prepare information we need
const { config, internals, logger } = pipeline;
const { config, logger } = pipeline;
const pageModulePromise = ssrEntry.page;

// Calculate information of the page, like scripts, links and styles
Expand All @@ -223,6 +223,9 @@ async function generatePage(
styles,
mod: pageModule,
};

const maxPathsToLog = 100;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to disable this when verbose mode is enabled. I'm not 100% sure how you get it from here, but a search for verbose should hopefully find an example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


// Now we explode the routes. A route render itself, and it can render its fallbacks (i18n routing)
for (const route of eachRouteInRouteData(pageData)) {
const icon =
Expand All @@ -234,18 +237,39 @@ async function generatePage(
const paths = await getPathsForRoute(route, pageModule, pipeline, builtPaths);
let timeStart = performance.now();
let prevTimeEnd = timeStart;

const shouldTruncate =
pipeline.logger.options.level !== 'debug' && paths.length > maxPathsToLog;
Comment on lines +241 to +242
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log all pages if when verbose mode is enabled


for (let i = 0; i < paths.length; i++) {
const path = paths[i];
pipeline.logger.debug('build', `Generating: ${path}`);
const filePath = getOutputFilename(config, path, pageData.route.type);
const lineIcon = i === paths.length - 1 ? '└─' : '├─';
logger.info(null, ` ${blue(lineIcon)} ${dim(filePath)}`, false);
if (i < maxPathsToLog) {
const filePath = getOutputFilename(config, path, pageData.route.type);
const lineIcon = i === paths.length - 1 ? '└─' : '├─';
logger.info(null, ` ${blue(lineIcon)} ${dim(filePath)}`, false);
}
await generatePath(path, pipeline, generationOptions, route);
if (!shouldTruncate || i < maxPathsToLog) {
const timeEnd = performance.now();
const timeChange = getTimeStat(prevTimeEnd, timeEnd);
const timeIncrease = `(+${timeChange})`;
logger.info('SKIP_FORMAT', ` ${dim(timeIncrease)}`);
prevTimeEnd = timeEnd;
}
if (shouldTruncate && i === maxPathsToLog && paths.length > maxPathsToLog) {
logger.info(
null,
` ${blue('└─')} ${dim(`...rendering ${paths.length - maxPathsToLog} more paths.`)}`,
false
);
}
}
if (shouldTruncate) {
const timeEnd = performance.now();
const timeChange = getTimeStat(prevTimeEnd, timeEnd);
const timeIncrease = `(+${timeChange})`;
logger.info('SKIP_FORMAT', ` ${dim(timeIncrease)}`);
prevTimeEnd = timeEnd;
logger.info('SKIP_FORMAT', ` ${green('Done.')} ${dim(timeIncrease)}`);
}
}
}
Expand Down
Loading