Skip to content

Commit

Permalink
feat: allow disabling compressed size calculation (#1756)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Oct 5, 2023
1 parent a584068 commit d656ea0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ async function _build(nitro: Nitro, rollupConfig: RollupConfig) {
nitro.logger.success("Nitro server built");
if (nitro.options.logLevel > 1) {
process.stdout.write(
await generateFSTree(nitro.options.output.serverDir)
await generateFSTree(nitro.options.output.serverDir, {
compressedSizes: nitro.options.logging.compressedSizes,
})
);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ const NitroDefaults: NitroConfig = {
watchOptions: { ignoreInitial: true },
devProxy: {},

// Logging
logging: {
compressedSizes: true,
},

// Routing
baseURL: process.env.NITRO_APP_BASE_URL || "/",
handlers: [],
Expand Down
5 changes: 5 additions & 0 deletions src/types/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ export interface NitroOptions extends PresetOptions {
watchOptions: WatchOptions;
devProxy: Record<string, string | ProxyServerOptions>;

// Logging
logging: {
compressedSizes: boolean;
};

// Routing
baseURL: string;
handlers: NitroEventHandler[];
Expand Down
21 changes: 15 additions & 6 deletions src/utils/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { gzipSize } from "gzip-size";
import chalk from "chalk";
import { isTest } from "std-env";

export async function generateFSTree(dir: string) {
export async function generateFSTree(
dir: string,
options: { compressedSizes?: boolean } = {}
) {
if (isTest) {
return;
}
Expand All @@ -19,7 +22,7 @@ export async function generateFSTree(dir: string) {
const path = resolve(dir, file);
const src = await fsp.readFile(path);
const size = src.byteLength;
const gzip = await gzipSize(src);
const gzip = options.compressedSizes ? await gzipSize(src) : 0;
return { file, path, size, gzip };
})
)
Expand Down Expand Up @@ -50,17 +53,23 @@ export async function generateFSTree(dir: string) {
}

treeText += chalk.gray(
` ${treeChar} ${rpath} (${prettyBytes(item.size)}) (${prettyBytes(
item.gzip
)} gzip)\n`
` ${treeChar} ${rpath} (${prettyBytes(item.size)})`
);
if (options.compressedSizes) {
treeText += chalk.gray(` (${prettyBytes(item.gzip)} gzip)`);
}
treeText += "\n";
totalSize += item.size;
totalGzip += item.gzip;
}

treeText += `${chalk.cyan("Σ Total size:")} ${prettyBytes(
totalSize + totalNodeModulesSize
)} (${prettyBytes(totalGzip + totalNodeModulesGzip)} gzip)\n`;
)}`;
if (options.compressedSizes) {
treeText += ` (${prettyBytes(totalGzip + totalNodeModulesGzip)} gzip)`;
}
treeText += "\n";

return treeText;
}

0 comments on commit d656ea0

Please sign in to comment.