Skip to content

Commit 81a70d5

Browse files
committed
test(size): print the verdaccio echo to log
1 parent e9e2fd8 commit 81a70d5

File tree

4 files changed

+54
-52
lines changed

4 files changed

+54
-52
lines changed

scripts/benchmark-size/runner/calculate-size/index.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,48 @@ export interface PackageSizeReportOutput {
2323
rollupSize: number | undefined;
2424
}
2525

26-
export const getPackageSizeReportRunner =
27-
(options: PackageSizeReportOptions) => async (context: ListrContext, task: ListrTaskWrapper<ListrContext, any>) => {
28-
try {
29-
task.output = "preparing...";
30-
const projectDir = join(options.tmpDir, options.packageName.replace("/", "_"));
31-
await fsPromise.mkdir(projectDir);
32-
const entryPoint = join(projectDir, "index.js");
33-
const bundlersContext = { ...options, entryPoint, projectDir };
26+
export const generatePackageSizeReport = async (options: PackageSizeReportOptions) => {
27+
const { packageName } = options;
28+
try {
29+
console.info(`[${packageName}] preparing...`);
30+
const projectDir = join(options.tmpDir, options.packageName.replace("/", "_"));
31+
await fsPromise.mkdir(projectDir);
32+
const entryPoint = join(projectDir, "index.js");
33+
const bundlersContext = { ...options, entryPoint, projectDir };
3434

35-
task.output = "generating project and installing dependencies";
36-
await generateProject(projectDir, options);
35+
console.info(`[${packageName}] generating project and installing dependencies`);
36+
await generateProject(projectDir, options);
3737

38-
task.output = "calculating npm size";
39-
const npmSizeResult = calculateNpmSize(projectDir, options.packageName);
38+
console.info(`[${packageName}] calculating npm size`);
39+
const npmSizeResult = calculateNpmSize(projectDir, options.packageName);
4040

41-
const skipBundlerTests = bundlersContext.packageContext.skipBundlerTests;
41+
const skipBundlerTests = bundlersContext.packageContext.skipBundlerTests;
4242

43-
task.output = "calculating webpack 5 full bundle size";
44-
const webpackSize = skipBundlerTests ? undefined : await getWebpackSize(bundlersContext);
43+
console.info(`[${packageName}] calculating webpack 5 full bundle size`);
44+
const webpackSize = skipBundlerTests ? undefined : await getWebpackSize(bundlersContext);
4545

46-
task.output = "calculating rollup full bundle size";
47-
const rollupSize = skipBundlerTests ? undefined : await getRollupSize(bundlersContext);
46+
console.info(`[${packageName}] calculating rollup full bundle size`);
47+
const rollupSize = skipBundlerTests ? undefined : await getRollupSize(bundlersContext);
4848

49-
task.output = "calculating esbuild full bundle size";
50-
const esbuildSize = skipBundlerTests ? undefined : await getEsbuildSize(bundlersContext);
49+
console.info(`[${packageName}] calculating esbuild full bundle size`);
50+
const esbuildSize = skipBundlerTests ? undefined : await getEsbuildSize(bundlersContext);
5151

52-
task.output = "output results";
53-
const packageVersion = JSON.parse(
54-
await fsPromise.readFile(
55-
join(options.workspacePackages.filter((pkg) => pkg.name === options.packageName)[0].location, "package.json"),
56-
"utf8"
57-
)
58-
).version;
59-
options.output.push({
60-
name: options.packageName,
61-
version: packageVersion,
62-
...npmSizeResult,
63-
webpackSize,
64-
esbuildSize,
65-
rollupSize,
66-
});
67-
} catch (e) {
68-
e.message = `[${options.packageName}]` + e.message;
69-
}
70-
};
52+
console.info(`[${packageName}] output results`);
53+
const packageVersion = JSON.parse(
54+
await fsPromise.readFile(
55+
join(options.workspacePackages.filter((pkg) => pkg.name === options.packageName)[0].location, "package.json"),
56+
"utf8"
57+
)
58+
).version;
59+
options.output.push({
60+
name: options.packageName,
61+
version: packageVersion,
62+
...npmSizeResult,
63+
webpackSize,
64+
esbuildSize,
65+
rollupSize,
66+
});
67+
} catch (e) {
68+
e.message = `[${options.packageName}]` + e.message;
69+
}
70+
};

scripts/benchmark-size/runner/index.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { appendFileSync, mkdirSync, promises as fsPromise, readFileSync, rmdirSync } from "fs";
22
import { ensureDirSync, ensureFile } from "fs-extra";
33
import hbs from "handlebars";
4-
import { Listr } from "listr2";
54
import { tmpdir } from "os";
5+
import map from "p-map";
66
import { join } from "path";
77

8-
import { getPackageSizeReportRunner, PackageSizeReportOutput } from "./calculate-size";
8+
import { generatePackageSizeReport, PackageSizeReportOutput } from "./calculate-size";
99
import {
1010
DEFAULT_LIMIT_CONFIG_PATH,
1111
DEFAULT_RAW_OUTPUT_PATH,
@@ -91,19 +91,18 @@ export const sizeReport = async (options: SizeReportOptions) => {
9191
// Wait for the register to spin up.
9292
await sleep(1000);
9393
const sizeReportContext = await getSizeReportContext({ port: PORT });
94-
const tasks = new Listr(
95-
packageContextToTest.map((packageContext) => ({
96-
title: packageContext.package,
97-
task: getPackageSizeReportRunner({
98-
...sizeReportContext,
99-
packageName: packageContext.package,
100-
packageContext,
101-
}),
102-
})),
103-
{ concurrent: 4 }
104-
);
10594
try {
106-
await tasks.run();
95+
await map(
96+
packageContextToTest,
97+
async (packageContext) => {
98+
await generatePackageSizeReport({
99+
...sizeReportContext,
100+
packageName: packageContext.package,
101+
packageContext,
102+
});
103+
},
104+
{ concurrency: 10 }
105+
);
107106
} finally {
108107
localRegistryProcess.kill();
109108
rmdirSync(sizeReportContext.tmpDir, { recursive: true });

scripts/benchmark-size/runner/local-registry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export const localPublishChangedPackages = async (): Promise<string> => {
2525
export const spawnLocalRegistry = (port: number) =>
2626
exec("npx", ["verdaccio", "-c", "verdaccio/config.yaml", "-l", "" + port], {
2727
cwd: PROJECT_ROOT,
28+
stdio: "inherit",
2829
});

scripts/benchmark-size/runner/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
"@rollup/plugin-json": "^4.1.0",
1313
"@rollup/plugin-node-resolve": "^13.3.0",
1414
"@types/execa": "^2.0.0",
15+
"@types/p-map": "^2.0.0",
1516
"esbuild": "latest",
1617
"execa": "^5.1.1",
1718
"fs-extra": "^10.1.0",
1819
"handlebars": "^4.7.7",
1920
"listr2": "^4.0.5",
21+
"p-map": "^5.5.0",
2022
"rollup": "latest",
2123
"rollup-plugin-terser": "^7.0.2",
2224
"semver": "^7.3.7",

0 commit comments

Comments
 (0)