Home / File/ index.js — astro Source File

index.js — astro Source File

Architecture documentation for index.js, a javascript file in the astro codebase. 6 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  55347ca2_52cb_1c86_118a_1b626edf2916["index.js"]
  4265c711_d908_961d_b7f8_d10af2c1c59b["_util.js"]
  55347ca2_52cb_1c86_118a_1b626edf2916 --> 4265c711_d908_961d_b7f8_d10af2c1c59b
  f1feebfd_7bf6_a301_7fce_29c4c8bbc773["makeProject"]
  55347ca2_52cb_1c86_118a_1b626edf2916 --> f1feebfd_7bf6_a301_7fce_29c4c8bbc773
  5d6d1861_a18d_b246_cd94_08889ab7e74c["promises"]
  55347ca2_52cb_1c86_118a_1b626edf2916 --> 5d6d1861_a18d_b246_cd94_08889ab7e74c
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  55347ca2_52cb_1c86_118a_1b626edf2916 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"]
  55347ca2_52cb_1c86_118a_1b626edf2916 --> d9a92db9_c95e_9165_13ac_24b3d859d946
  9bb26a58_9168_1c6f_129c_0135fa673fe1["mri"]
  55347ca2_52cb_1c86_118a_1b626edf2916 --> 9bb26a58_9168_1c6f_129c_0135fa673fe1
  style 55347ca2_52cb_1c86_118a_1b626edf2916 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import fs from 'node:fs/promises';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import mri from 'mri';
import { makeProject } from './bench/_util.js';

const args = mri(process.argv.slice(2));

if (args.help || args.h) {
	console.log(`\
astro-benchmark <command> [options]

Command
  [empty]         Run all benchmarks
  memory          Run build memory and speed test
  render          Run rendering speed test
  server-stress   Run server stress test
  cli-startup     Run CLI startup speed test

Options
  --project <project-name>       Project to use for benchmark, see benchmark/make-project/ for available names
  --output  <output-file>        Output file to write results to
`);
	process.exit(0);
}

const commandName = args._[0];
const benchmarks = {
	memory: () => import('./bench/memory.js'),
	render: () => import('./bench/render.js'),
	'server-stress': () => import('./bench/server-stress.js'),
	'cli-startup': () => import('./bench/cli-startup.js'),
};

if (commandName && !(commandName in benchmarks)) {
	console.error(`Invalid benchmark name: ${commandName}`);
	process.exit(1);
}

if (commandName) {
	// Run single benchmark
	const bench = benchmarks[commandName];
	const benchMod = await bench();
	const projectDir = await makeProject(args.project || benchMod.defaultProject);
	const outputFile = await getOutputFile(commandName);
	await benchMod.run(projectDir, outputFile);
} else {
	// Run all benchmarks
	for (const name in benchmarks) {
		const bench = benchmarks[name];
		const benchMod = await bench();
		const projectDir = await makeProject(args.project || benchMod.defaultProject);
		const outputFile = await getOutputFile(name);
		await benchMod.run(projectDir, outputFile);
	}
}

/**
 * @param {string} benchmarkName
 */
export async function getOutputFile(benchmarkName) {
	let file;
	if (args.output) {
		file = pathToFileURL(path.resolve(args.output));
	} else {
		file = new URL(`./results/${benchmarkName}-bench-${Date.now()}.json`, import.meta.url);
	}

	// Prepare output file directory
	await fs.mkdir(new URL('./', file), { recursive: true });
	return file;
}

Subdomains

Dependencies

Frequently Asked Questions

What does index.js do?
index.js is a source file in the astro codebase, written in javascript. It belongs to the PerformanceBenchmarking domain, MetricsCalculator subdomain.
What functions are defined in index.js?
index.js defines 5 function(s): benchmarks.cli-startup, benchmarks.memory, benchmarks.render, benchmarks.server-stress, getOutputFile.
What does index.js depend on?
index.js imports 6 module(s): _util.js, makeProject, mri, node:path, node:url, promises.
Where is index.js in the architecture?
index.js is located at benchmark/index.js (domain: PerformanceBenchmarking, subdomain: MetricsCalculator, directory: benchmark).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free