0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Removed unused console.warn trap function (#537)

This commit is contained in:
Mats 2021-06-24 23:07:49 +02:00 committed by GitHub
parent feb9a3141e
commit 4cd84c6607
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 13 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
#528 Removes unused trapWarn function

View file

@ -18,7 +18,7 @@ import { buildCollectionPage, buildStaticPage, getPageType } from './build/page.
import { generateSitemap } from './build/sitemap.js'; import { generateSitemap } from './build/sitemap.js';
import { logURLStats, collectBundleStats, mapBundleStatsToURLStats } from './build/stats.js'; import { logURLStats, collectBundleStats, mapBundleStatsToURLStats } from './build/stats.js';
import { getDistPath, stopTimer } from './build/util.js'; import { getDistPath, stopTimer } from './build/util.js';
import { debug, defaultLogDestination, defaultLogLevel, error, info, warn, trapWarn } from './logger.js'; import { debug, defaultLogDestination, defaultLogLevel, error, info, warn } from './logger.js';
import { createRuntime } from './runtime.js'; import { createRuntime } from './runtime.js';
const defaultLogging: LogOptions = { const defaultLogging: LogOptions = {
@ -71,7 +71,6 @@ export async function build(astroConfig: AstroConfig, logging: LogOptions = defa
timer.build = performance.now(); timer.build = performance.now();
const pages = await allPages(pagesRoot); const pages = await allPages(pagesRoot);
info(logging, 'build', yellow('! building pages...')); info(logging, 'build', yellow('! building pages...'));
const release = trapWarn(); // Vue also console.warns, this silences it.
await Promise.all( await Promise.all(
pages.map(async (filepath) => { pages.map(async (filepath) => {
const buildPage = getPageType(filepath) === 'collection' ? buildCollectionPage : buildStaticPage; const buildPage = getPageType(filepath) === 'collection' ? buildCollectionPage : buildStaticPage;
@ -88,7 +87,6 @@ export async function build(astroConfig: AstroConfig, logging: LogOptions = defa
}) })
); );
info(logging, 'build', green('✔'), 'pages built.'); info(logging, 'build', green('✔'), 'pages built.');
release();
debug(logging, 'build', `built pages [${stopTimer(timer.build)}]`); debug(logging, 'build', `built pages [${stopTimer(timer.build)}]`);
// after pages are built, build depTree // after pages are built, build depTree

View file

@ -150,16 +150,6 @@ export const logger = {
error: error.bind(null, defaultLogOptions), error: error.bind(null, defaultLogOptions),
}; };
/** For silencing libraries that go directly to console.warn */
export function trapWarn(cb: (...args: any[]) => void = () => {}) {
/* eslint-disable no-console */
const consoleWarn = console.warn;
console.warn = function (...args: any[]) {
cb(...args);
};
return () => (console.warn = consoleWarn);
}
function padStr(str: string, len: number) { function padStr(str: string, len: number) {
const strLen = stringWidth(str); const strLen = stringWidth(str);
if (strLen > len) { if (strLen > len) {