Home / File/ check.js — astro Source File

check.js — astro Source File

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

File javascript CoreAstro CoreMiddleware 5 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  6e63560f_8c71_c453_90bf_78fa760e9716["check.js"]
  dc804f3e_b1ea_df4a_3cc9_40b536be6a5d["node:child_process"]
  6e63560f_8c71_c453_90bf_78fa760e9716 --> dc804f3e_b1ea_df4a_3cc9_40b536be6a5d
  e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"]
  6e63560f_8c71_c453_90bf_78fa760e9716 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  6e63560f_8c71_c453_90bf_78fa760e9716 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  2a508d35_5271_6ab9_1ae5_ced1613f7e29["p-limit"]
  6e63560f_8c71_c453_90bf_78fa760e9716 --> 2a508d35_5271_6ab9_1ae5_ced1613f7e29
  e5bc1d28_6010_ae61_773d_cc0746339061["tsconfck"]
  6e63560f_8c71_c453_90bf_78fa760e9716 --> e5bc1d28_6010_ae61_773d_cc0746339061
  style 6e63560f_8c71_c453_90bf_78fa760e9716 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// @ts-check

import { spawn } from 'node:child_process';
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import * as path from 'node:path';
import pLimit from 'p-limit';
import { toJson } from 'tsconfck';

const skippedExamples = ['toolbar-app', 'component', 'server-islands'];

function checkExamples() {
	let examples = readdirSync('./examples', { withFileTypes: true });
	examples = examples.filter((dirent) => dirent.isDirectory()).filter((dirent) => !skippedExamples.includes(dirent.name));

	console.log(`Running astro check on ${examples.length} examples...`);

	// Run astro check in parallel with 5 at most
	const checkPromises = [];
	const limit = pLimit(5);

	for (const example of examples) {
		checkPromises.push(
			limit(
				() =>
					new Promise((resolve) => {
						// Sometimes some examples may get deleted, but after a `git pull` the directory still exists.
						// This can stall the process time as it'll typecheck the entire monorepo, so do a quick exist
						// check here before typechecking this directory.
						if (!existsSync(path.join('./examples/', example.name, 'package.json'))) {
							resolve(0);
							return;
						}

						const originalConfig = prepareExample(example.name);
						let data = '';
						const child = spawn('node', ['../../packages/astro/bin/astro.mjs', 'check'], {
							cwd: path.join('./examples', example.name),
							env: { ...process.env, FORCE_COLOR: 'true' },
						});

						child.stdout.on('data', function (buffer) {
							data += buffer.toString();
						});

						child.on('exit', (code) => {
							if (code !== 0) {
								console.error(data);
							}
							if (originalConfig) {
								resetExample(example.name, originalConfig);
							}
							resolve(code);
						});
					})
			)
		);
	}

	Promise.all(checkPromises).then((codes) => {
		if (codes.some((code) => code !== 0)) {
			process.exit(1);
		}

		console.log('No errors found!');
	});
}

/**
 * @param {string} examplePath
 */
function prepareExample(examplePath) {
	const tsconfigPath = path.join('./examples/', examplePath, 'tsconfig.json');
	if (!existsSync(tsconfigPath)) return
	
	const originalConfig = readFileSync(tsconfigPath, 'utf-8');
	const tsconfig = JSON.parse(toJson(originalConfig));

	// Swap to strictest config to make sure it also passes
	tsconfig.extends = 'astro/tsconfigs/strictest';
	tsconfig.compilerOptions ??= {}
	tsconfig.compilerOptions.types = tsconfig.compilerOptions.types ?? []; // Speeds up tests

	writeFileSync(tsconfigPath, JSON.stringify(tsconfig));

	return originalConfig;
}

/**
 * @param {string} examplePath
 * @param {string} originalConfig
 */
function resetExample(examplePath, originalConfig) {
	const tsconfigPath = path.join('./examples/', examplePath, 'tsconfig.json');
	writeFileSync(tsconfigPath, originalConfig);
}

checkExamples();

Domain

Subdomains

Dependencies

  • node:child_process
  • node:fs
  • node:path
  • p-limit
  • tsconfck

Frequently Asked Questions

What does check.js do?
check.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in check.js?
check.js defines 3 function(s): checkExamples, prepareExample, resetExample.
What does check.js depend on?
check.js imports 5 module(s): node:child_process, node:fs, node:path, p-limit, tsconfck.
Where is check.js in the architecture?
check.js is located at scripts/smoke/check.js (domain: CoreAstro, subdomain: CoreMiddleware, directory: scripts/smoke).

Analyze Your Own Codebase

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

Try Supermodel Free