diff --git a/internal-packages/benchmark-utils/package.json b/internal-packages/benchmark-utils/package.json index d2b8e62..7922767 100644 --- a/internal-packages/benchmark-utils/package.json +++ b/internal-packages/benchmark-utils/package.json @@ -4,6 +4,7 @@ "private": true, "type": "module", "exports": { + "./run-build": "./src/run-build.ts", "./seeded-random": "./src/seeded-random.ts" }, "devDependencies": { diff --git a/internal-packages/benchmark-utils/src/run-build.ts b/internal-packages/benchmark-utils/src/run-build.ts new file mode 100644 index 0000000..feb8381 --- /dev/null +++ b/internal-packages/benchmark-utils/src/run-build.ts @@ -0,0 +1,33 @@ +import { execSync } from 'node:child_process' +import { Buffer } from 'node:buffer' +import { delimiter, resolve } from 'node:path' + +function asString(value: unknown): string { + if (typeof value === 'string') return value + if (Buffer.isBuffer(value)) return value.toString('utf8') + return '' +} + +export function runBuild(configName: string, baseDir: string): void { + const localBin = resolve(baseDir, 'node_modules/.bin') + const env = { + ...process.env, + PATH: `${localBin}${delimiter}${process.env.PATH ?? ''}`, + } + try { + execSync(`rolldown -c configs/${configName}.ts`, { + cwd: baseDir, + stdio: 'pipe', + env, + }) + } catch (err) { + const isObject = typeof err === 'object' && err !== null + const status = isObject && 'status' in err && typeof err.status === 'number' ? err.status : null + const stdout = asString(isObject && 'stdout' in err ? err.stdout : undefined) + const stderr = asString(isObject && 'stderr' in err ? err.stderr : undefined) + throw new Error( + `build:${configName} failed (exit ${status ?? 'unknown'}):\n${stdout}${stderr}`, + { cause: err }, + ) + } +} diff --git a/packages/emotion/benchmark/bench/emotion.bench.ts b/packages/emotion/benchmark/bench/emotion.bench.ts index 373d192..46a279f 100644 --- a/packages/emotion/benchmark/bench/emotion.bench.ts +++ b/packages/emotion/benchmark/bench/emotion.bench.ts @@ -1,13 +1,18 @@ import { bench, describe } from 'vitest' import { execSync } from 'node:child_process' -import { existsSync, rmSync } from 'node:fs' +import { existsSync, readdirSync, rmSync } from 'node:fs' import { resolve } from 'node:path' +import { runBuild } from '@rolldown/benchmark-utils/run-build' const baseDir = resolve(import.meta.dirname, '..') const distBase = resolve(baseDir, 'dist') const componentsDir = resolve(baseDir, 'shared-app/src/components') +const expectedComponents = 100 -if (!existsSync(componentsDir)) { +const currentComponents = existsSync(componentsDir) + ? readdirSync(componentsDir).filter((f) => f.endsWith('.tsx')).length + : 0 +if (currentComponents !== expectedComponents) { execSync('pnpm generate', { cwd: baseDir, stdio: 'inherit' }) } @@ -18,18 +23,11 @@ function cleanDist(name: string) { } } -function runBuild(name: string) { - execSync(`rolldown -c configs/${name}.ts`, { - cwd: baseDir, - stdio: 'pipe', - }) -} - describe('Emotion Benchmark', () => { bench( '@rolldown/plugin-emotion', () => { - runBuild('custom') + runBuild('custom', baseDir) }, { teardown: () => cleanDist('custom') }, ) @@ -37,7 +35,7 @@ describe('Emotion Benchmark', () => { bench( '@rolldown/plugin-babel', () => { - runBuild('babel') + runBuild('babel', baseDir) }, { teardown: () => cleanDist('babel') }, ) @@ -45,7 +43,7 @@ describe('Emotion Benchmark', () => { bench( '@rollup/plugin-swc', () => { - runBuild('swc') + runBuild('swc', baseDir) }, { teardown: () => cleanDist('swc') }, ) diff --git a/packages/emotion/benchmark/bench/emotion.test.ts b/packages/emotion/benchmark/bench/emotion.test.ts new file mode 100644 index 0000000..cbb6865 --- /dev/null +++ b/packages/emotion/benchmark/bench/emotion.test.ts @@ -0,0 +1,21 @@ +import { describe, test } from 'vitest' +import { execSync } from 'node:child_process' +import { resolve } from 'node:path' +import { runBuild } from '@rolldown/benchmark-utils/run-build' + +const baseDir = resolve(import.meta.dirname, '..') + +execSync('pnpm generate -- --total=10 --silent', { + cwd: baseDir, + stdio: 'inherit', +}) + +describe('Emotion build', () => { + test.for(['custom', 'babel', 'swc'] as const)( + 'build:%s exits with code 0', + { timeout: 30_000 }, + (name) => { + runBuild(name, baseDir) + }, + ) +}) diff --git a/packages/emotion/benchmark/scripts/generate-app.ts b/packages/emotion/benchmark/scripts/generate-app.ts index b4884c8..db1333a 100644 --- a/packages/emotion/benchmark/scripts/generate-app.ts +++ b/packages/emotion/benchmark/scripts/generate-app.ts @@ -274,7 +274,9 @@ function main() { mkdirSync(componentsDir, { recursive: true }) const components: Array<{ type: ComponentType; index: number }> = [] - const TOTAL = 100 + const totalArg = process.argv.find((a) => a.startsWith('--total=')) + const TOTAL = totalArg ? Number.parseInt(totalArg.slice('--total='.length), 10) : 100 + const silent = process.argv.includes('--silent') const perType = Math.floor(TOTAL / COMPONENT_TYPES.length) const remainder = TOTAL % COMPONENT_TYPES.length @@ -293,9 +295,11 @@ function main() { .join('\n') writeFileSync(join(componentsDir, 'index.ts'), exports + '\n') - console.log(`Generated ${components.length} components in ${componentsDir}`) - for (const type of COMPONENT_TYPES) { - console.log(` ${type}: ${components.filter((c) => c.type === type).length}`) + if (!silent) { + console.log(`Generated ${components.length} components in ${componentsDir}`) + for (const type of COMPONENT_TYPES) { + console.log(` ${type}: ${components.filter((c) => c.type === type).length}`) + } } } diff --git a/packages/jsx-remove-attributes/benchmark/bench/jsx-remove-attributes.bench.ts b/packages/jsx-remove-attributes/benchmark/bench/jsx-remove-attributes.bench.ts index f193c5e..10d0819 100644 --- a/packages/jsx-remove-attributes/benchmark/bench/jsx-remove-attributes.bench.ts +++ b/packages/jsx-remove-attributes/benchmark/bench/jsx-remove-attributes.bench.ts @@ -1,13 +1,18 @@ import { bench, describe } from 'vitest' import { execSync } from 'node:child_process' -import { existsSync, rmSync } from 'node:fs' +import { existsSync, readdirSync, rmSync } from 'node:fs' import { resolve } from 'node:path' +import { runBuild } from '@rolldown/benchmark-utils/run-build' const baseDir = resolve(import.meta.dirname, '..') const distBase = resolve(baseDir, 'dist') const componentsDir = resolve(baseDir, 'shared-app/src/components') +const expectedComponents = 100 -if (!existsSync(componentsDir)) { +const currentComponents = existsSync(componentsDir) + ? readdirSync(componentsDir).filter((f) => f.endsWith('.tsx')).length + : 0 +if (currentComponents !== expectedComponents) { execSync('pnpm generate', { cwd: baseDir, stdio: 'inherit' }) } @@ -18,18 +23,11 @@ function cleanDist(name: string) { } } -function runBuild(name: string) { - execSync(`rolldown -c configs/${name}.ts`, { - cwd: baseDir, - stdio: 'pipe', - }) -} - describe('JSX Remove Attributes Benchmark', () => { bench( '@rolldown/plugin-jsx-remove-attributes', () => { - runBuild('custom') + runBuild('custom', baseDir) }, { teardown: () => cleanDist('custom') }, ) @@ -37,7 +35,7 @@ describe('JSX Remove Attributes Benchmark', () => { bench( '@rolldown/plugin-babel', () => { - runBuild('babel') + runBuild('babel', baseDir) }, { teardown: () => cleanDist('babel') }, ) @@ -45,7 +43,7 @@ describe('JSX Remove Attributes Benchmark', () => { bench( '@rollup/plugin-swc', () => { - runBuild('swc') + runBuild('swc', baseDir) }, { teardown: () => cleanDist('swc') }, ) diff --git a/packages/jsx-remove-attributes/benchmark/bench/jsx-remove-attributes.test.ts b/packages/jsx-remove-attributes/benchmark/bench/jsx-remove-attributes.test.ts new file mode 100644 index 0000000..f022749 --- /dev/null +++ b/packages/jsx-remove-attributes/benchmark/bench/jsx-remove-attributes.test.ts @@ -0,0 +1,21 @@ +import { describe, test } from 'vitest' +import { execSync } from 'node:child_process' +import { resolve } from 'node:path' +import { runBuild } from '@rolldown/benchmark-utils/run-build' + +const baseDir = resolve(import.meta.dirname, '..') + +execSync('pnpm generate -- --total=10 --silent', { + cwd: baseDir, + stdio: 'inherit', +}) + +describe('JSX Remove Attributes build', () => { + test.for(['custom', 'babel', 'swc'] as const)( + 'build:%s exits with code 0', + { timeout: 30_000 }, + (name) => { + runBuild(name, baseDir) + }, + ) +}) diff --git a/packages/jsx-remove-attributes/benchmark/scripts/generate-app.ts b/packages/jsx-remove-attributes/benchmark/scripts/generate-app.ts index d77da0a..51f97fb 100644 --- a/packages/jsx-remove-attributes/benchmark/scripts/generate-app.ts +++ b/packages/jsx-remove-attributes/benchmark/scripts/generate-app.ts @@ -184,7 +184,9 @@ function main() { mkdirSync(componentsDir, { recursive: true }) const components: Array<{ type: ComponentType; index: number }> = [] - const TOTAL = 100 + const totalArg = process.argv.find((a) => a.startsWith('--total=')) + const TOTAL = totalArg ? Number.parseInt(totalArg.slice('--total='.length), 10) : 100 + const silent = process.argv.includes('--silent') const perType = Math.floor(TOTAL / COMPONENT_TYPES.length) const remainder = TOTAL % COMPONENT_TYPES.length @@ -203,9 +205,11 @@ function main() { .join('\n') writeFileSync(join(componentsDir, 'index.ts'), exports + '\n') - console.log(`Generated ${components.length} components in ${componentsDir}`) - for (const type of COMPONENT_TYPES) { - console.log(` ${type}: ${components.filter((c) => c.type === type).length}`) + if (!silent) { + console.log(`Generated ${components.length} components in ${componentsDir}`) + for (const type of COMPONENT_TYPES) { + console.log(` ${type}: ${components.filter((c) => c.type === type).length}`) + } } } diff --git a/packages/styled-jsx/benchmark/bench/styled-jsx.bench.ts b/packages/styled-jsx/benchmark/bench/styled-jsx.bench.ts index 44f8458..1b2a118 100644 --- a/packages/styled-jsx/benchmark/bench/styled-jsx.bench.ts +++ b/packages/styled-jsx/benchmark/bench/styled-jsx.bench.ts @@ -1,13 +1,18 @@ import { bench, describe } from 'vitest' import { execSync } from 'node:child_process' -import { existsSync, rmSync } from 'node:fs' +import { existsSync, readdirSync, rmSync } from 'node:fs' import { resolve } from 'node:path' +import { runBuild } from '@rolldown/benchmark-utils/run-build' const baseDir = resolve(import.meta.dirname, '..') const distBase = resolve(baseDir, 'dist') const componentsDir = resolve(baseDir, 'shared-app/src/components') +const expectedComponents = 100 -if (!existsSync(componentsDir)) { +const currentComponents = existsSync(componentsDir) + ? readdirSync(componentsDir).filter((f) => f.endsWith('.tsx')).length + : 0 +if (currentComponents !== expectedComponents) { execSync('pnpm generate', { cwd: baseDir, stdio: 'inherit' }) } @@ -18,18 +23,11 @@ function cleanDist(name: string) { } } -function runBuild(name: string) { - execSync(`rolldown -c configs/${name}.ts`, { - cwd: baseDir, - stdio: 'pipe', - }) -} - describe('Styled JSX Benchmark', () => { bench( '@rolldown/plugin-styled-jsx', () => { - runBuild('custom') + runBuild('custom', baseDir) }, { teardown: () => cleanDist('custom') }, ) @@ -37,7 +35,7 @@ describe('Styled JSX Benchmark', () => { bench( '@rolldown/plugin-babel', () => { - runBuild('babel') + runBuild('babel', baseDir) }, { teardown: () => cleanDist('babel') }, ) @@ -45,7 +43,7 @@ describe('Styled JSX Benchmark', () => { bench( '@rollup/plugin-swc', () => { - runBuild('swc') + runBuild('swc', baseDir) }, { teardown: () => cleanDist('swc') }, ) diff --git a/packages/styled-jsx/benchmark/bench/styled-jsx.test.ts b/packages/styled-jsx/benchmark/bench/styled-jsx.test.ts new file mode 100644 index 0000000..e8f7754 --- /dev/null +++ b/packages/styled-jsx/benchmark/bench/styled-jsx.test.ts @@ -0,0 +1,21 @@ +import { describe, test } from 'vitest' +import { execSync } from 'node:child_process' +import { resolve } from 'node:path' +import { runBuild } from '@rolldown/benchmark-utils/run-build' + +const baseDir = resolve(import.meta.dirname, '..') + +execSync('pnpm generate -- --total=10 --silent', { + cwd: baseDir, + stdio: 'inherit', +}) + +describe('Styled JSX build', () => { + test.for(['custom', 'babel', 'swc'] as const)( + 'build:%s exits with code 0', + { timeout: 30_000 }, + (name) => { + runBuild(name, baseDir) + }, + ) +}) diff --git a/packages/styled-jsx/benchmark/scripts/generate-app.ts b/packages/styled-jsx/benchmark/scripts/generate-app.ts index 49e5d3a..d35b598 100644 --- a/packages/styled-jsx/benchmark/scripts/generate-app.ts +++ b/packages/styled-jsx/benchmark/scripts/generate-app.ts @@ -275,7 +275,9 @@ function main() { mkdirSync(componentsDir, { recursive: true }) const components: Array<{ type: ComponentType; index: number }> = [] - const TOTAL = 100 + const totalArg = process.argv.find((a) => a.startsWith('--total=')) + const TOTAL = totalArg ? Number.parseInt(totalArg.slice('--total='.length), 10) : 100 + const silent = process.argv.includes('--silent') const perType = Math.floor(TOTAL / COMPONENT_TYPES.length) const remainder = TOTAL % COMPONENT_TYPES.length @@ -294,9 +296,11 @@ function main() { .join('\n') writeFileSync(join(componentsDir, 'index.ts'), exports + '\n') - console.log(`Generated ${components.length} components in ${componentsDir}`) - for (const type of COMPONENT_TYPES) { - console.log(` ${type}: ${components.filter((c) => c.type === type).length}`) + if (!silent) { + console.log(`Generated ${components.length} components in ${componentsDir}`) + for (const type of COMPONENT_TYPES) { + console.log(` ${type}: ${components.filter((c) => c.type === type).length}`) + } } } diff --git a/packages/transform-imports/benchmark/bench/transform-imports.bench.ts b/packages/transform-imports/benchmark/bench/transform-imports.bench.ts index 352d5e1..c231c99 100644 --- a/packages/transform-imports/benchmark/bench/transform-imports.bench.ts +++ b/packages/transform-imports/benchmark/bench/transform-imports.bench.ts @@ -1,13 +1,18 @@ import { bench, describe } from 'vitest' import { execSync } from 'node:child_process' -import { existsSync, rmSync } from 'node:fs' +import { existsSync, readdirSync, rmSync } from 'node:fs' import { resolve } from 'node:path' +import { runBuild } from '@rolldown/benchmark-utils/run-build' const baseDir = resolve(import.meta.dirname, '..') const distBase = resolve(baseDir, 'dist') const modulesDir = resolve(baseDir, 'shared-app/src/modules') +const expectedModules = 100 -if (!existsSync(modulesDir)) { +const currentModules = existsSync(modulesDir) + ? readdirSync(modulesDir).filter((f) => f.endsWith('.js')).length + : 0 +if (currentModules !== expectedModules) { execSync('pnpm generate', { cwd: baseDir, stdio: 'inherit' }) } @@ -18,18 +23,11 @@ function cleanDist(name: string) { } } -function runBuild(name: string) { - execSync(`rolldown -c configs/${name}.ts`, { - cwd: baseDir, - stdio: 'pipe', - }) -} - describe('Transform Imports Benchmark', () => { bench( '@rolldown/plugin-transform-imports', () => { - runBuild('custom') + runBuild('custom', baseDir) }, { teardown: () => cleanDist('custom') }, ) @@ -37,7 +35,7 @@ describe('Transform Imports Benchmark', () => { bench( 'babel-plugin-transform-imports', () => { - runBuild('babel') + runBuild('babel', baseDir) }, { teardown: () => cleanDist('babel') }, ) @@ -45,7 +43,7 @@ describe('Transform Imports Benchmark', () => { bench( '@swc/plugin-transform-imports', () => { - runBuild('swc') + runBuild('swc', baseDir) }, { teardown: () => cleanDist('swc') }, ) diff --git a/packages/transform-imports/benchmark/bench/transform-imports.test.ts b/packages/transform-imports/benchmark/bench/transform-imports.test.ts new file mode 100644 index 0000000..c1d136e --- /dev/null +++ b/packages/transform-imports/benchmark/bench/transform-imports.test.ts @@ -0,0 +1,21 @@ +import { describe, test } from 'vitest' +import { execSync } from 'node:child_process' +import { resolve } from 'node:path' +import { runBuild } from '@rolldown/benchmark-utils/run-build' + +const baseDir = resolve(import.meta.dirname, '..') + +execSync('pnpm generate -- --total=10 --silent', { + cwd: baseDir, + stdio: 'inherit', +}) + +describe('Transform Imports build', () => { + test.for(['custom', 'babel', 'swc'] as const)( + 'build:%s exits with code 0', + { timeout: 30_000 }, + (name) => { + runBuild(name, baseDir) + }, + ) +}) diff --git a/packages/transform-imports/benchmark/scripts/generate-app.ts b/packages/transform-imports/benchmark/scripts/generate-app.ts index 59c8d51..c48bad5 100644 --- a/packages/transform-imports/benchmark/scripts/generate-app.ts +++ b/packages/transform-imports/benchmark/scripts/generate-app.ts @@ -166,7 +166,9 @@ function main() { if (existsSync(appDir)) rmSync(appDir, { recursive: true }) mkdirSync(join(appDir, 'modules'), { recursive: true }) - const TOTAL = 100 + const totalArg = process.argv.find((a) => a.startsWith('--total=')) + const TOTAL = totalArg ? Number.parseInt(totalArg.slice('--total='.length), 10) : 100 + const silent = process.argv.includes('--silent') const files: string[] = [] for (let i = 0; i < TOTAL; i++) { @@ -185,9 +187,11 @@ function main() { .join('\n') writeFileSync(join(appDir, 'index.js'), entry + '\n') - console.log(`Generated ${TOTAL} modules in ${appDir}/modules/`) - for (const type of PATTERN_TYPES) { - console.log(` Pattern distribution includes: ${type}`) + if (!silent) { + console.log(`Generated ${TOTAL} modules in ${appDir}/modules/`) + for (const type of PATTERN_TYPES) { + console.log(` Pattern distribution includes: ${type}`) + } } }