or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration-management.mdcontent-hashing.mdfile-operations.mdindex.mdpath-utilities.mdprocess-coordination.mdsystem-information.md
tile.json

system-information.mddocs/

System Information

System detection utilities for gathering CPU information and CI environment details to optimize Gatsby's build processes and provide appropriate defaults based on the runtime environment.

Capabilities

CPU Core Detection

Determines the number of available CPU cores with environment variable overrides for build optimization.

/**
 * Calculate CPU core count with environment variable support
 * @param ignoreEnvVar - If true, ignores GATSBY_CPU_COUNT environment variable
 * @returns Number of CPU cores (physical cores by default, or as configured)
 * @throws Error if there's a problem counting CPU cores
 */
function cpuCoreCount(ignoreEnvVar?: boolean): number;

Usage Examples:

import { cpuCoreCount } from "gatsby-core-utils";

// Get available CPU cores for parallel processing
const cores = cpuCoreCount();
console.log(`Available cores: ${cores}`);

// Use for determining worker process count
const workerCount = Math.max(1, cores - 1); // Leave one core free
const workers = new Array(workerCount).fill(null).map(() => createWorker());

// Force physical core count (ignore environment override)  
const physicalCores = cpuCoreCount(true);
console.log(`Physical cores: ${physicalCores}`);

Environment Variable Configuration:

The GATSBY_CPU_COUNT environment variable can override default behavior:

# Use logical cores (includes hyperthreading)
export GATSBY_CPU_COUNT=logical_cores

# Use physical cores only (default behavior)
export GATSBY_CPU_COUNT=physical_cores  

# Set specific core count
export GATSBY_CPU_COUNT=4

Internal Implementation Details:

The cpuCoreCount() function uses platform-specific detection methods internally:

  • Linux: Uses lscpu command to count unique physical cores
  • macOS: Uses sysctl hw.physicalcpu_max command
  • Windows: Uses WMIC to query CPU core information
  • Fallback: Returns logical core count from os.cpus().length if platform-specific detection fails

CI Environment Detection

Detects if the code is running in a Continuous Integration environment.

/**
 * Determines if the current environment is a CI environment
 * Checks for various CI platform indicators and environment variables
 * @returns True if running in any recognized CI environment
 */
function isCI(): boolean;

Usage Examples:

import { isCI } from "gatsby-core-utils";

// Adjust behavior for CI environments
if (isCI()) {
  console.log("Running in CI - enabling optimizations");
  // Disable interactive prompts
  // Use different caching strategies
  // Enable verbose logging
} else {
  console.log("Running in development - enabling dev features");
  // Enable file watching
  // Show interactive prompts
  // Use local caching
}

// Conditional feature flags
const enableAnalytics = !isCI(); // Disable analytics in CI
const useProgressBar = !isCI(); // Disable progress bars in CI

CI Environment Name Detection

Identifies the specific CI platform being used.

/**
 * Gets the name of the CI environment
 * @returns CI platform name or null if not in CI
 */
function getCIName(): string | null;

Usage Examples:

import { getCIName, isCI } from "gatsby-core-utils";

// Platform-specific optimizations
const ciName = getCIName();
if (ciName) {
  console.log(`Running on ${ciName}`);
  
  switch (ciName) {
    case "GitHub Actions":
      // GitHub Actions specific settings
      process.env.FORCE_COLOR = "1"; // Enable colors
      break;
    case "Vercel Now":
      // Vercel specific optimizations
      console.log("Optimizing for Vercel deployment");
      break;
    case "CircleCI":
      // CircleCI specific settings
      console.log("Using CircleCI optimizations");
      break;
  }
}

// Error reporting with CI context
function reportError(error) {
  const context = {
    ci: isCI(),
    platform: getCIName(),
    // ... other context
  };
  errorReporter.report(error, context);
}

Supported CI Platforms:

  • GitHub Actions (GITHUB_ACTIONS)
  • CircleCI (CIRCLECI, CIRCLE_BRANCH)
  • Vercel/ZEIT Now (VERCEL_URL, NOW_REGION, NOW_BUILDER, VERCEL_BUILDER)
  • CodeSandbox (CODESANDBOX_SSE)
  • Heroku (Node.js path detection)
  • Generic CI (CI environment variable)
  • Custom CI (CI_NAME environment variable)

Terminal Program Detection

Detects the terminal program being used for optimal output formatting.

/**
 * Detects the terminal program being used
 * @returns Terminal program name or undefined if not detected
 */
function getTermProgram(): string | undefined;

Usage Examples:

import { getTermProgram } from "gatsby-core-utils";

// Optimize output for specific terminals
const terminal = getTermProgram();
switch (terminal) {
  case "vscode":
    // VS Code integrated terminal optimizations
    console.log("Detected VS Code terminal");
    break;
  case "Windows Terminal":
    // Windows Terminal specific features
    console.log("Using Windows Terminal features");
    break;
  case "iTerm.app":
    // iTerm2 specific optimizations
    console.log("iTerm2 detected - enabling enhanced features");
    break;
}

// Conditional feature enabling
const supportsRichOutput = ["vscode", "Windows Terminal", "iTerm.app"].includes(terminal);

Detection Sources:

  • TERM_PROGRAM environment variable (macOS, Linux)
  • WT_SESSION environment variable (Windows Terminal)
  • Process analysis for integrated terminals

Performance Optimization Strategies

Build Process Optimization

import { cpuCoreCount, isCI } from "gatsby-core-utils";

// Optimize parallel processing based on environment
function getBuildConcurrency() {
  const cores = cpuCoreCount();
  
  if (isCI()) {
    // In CI, use more aggressive parallelization
    return cores;
  } else {
    // In development, leave resources for other processes
    return Math.max(1, cores - 1);
  }
}

const concurrency = getBuildConcurrency();
console.log(`Using ${concurrency} parallel build processes`);

Memory and Resource Management

import { cpuCoreCount, getCIName } from "gatsby-core-utils";

// Adjust memory limits based on system capabilities
function getMemoryLimits() {
  const cores = cpuCoreCount();
  const ciName = getCIName();
  
  // Different CI platforms have different resource constraints
  switch (ciName) {
    case "GitHub Actions":
      return { maxMemoryPerWorker: "1GB", maxWorkers: 2 };
    case "Vercel Now":
      return { maxMemoryPerWorker: "512MB", maxWorkers: 1 };
    default:
      return { 
        maxMemoryPerWorker: "2GB", 
        maxWorkers: Math.min(cores, 4) 
      };
  }
}

Error Handling

System information functions handle failures gracefully:

  • cpuCoreCount() falls back to 1 if detection fails and throws descriptive errors
  • Physical CPU detection within cpuCoreCount() falls back to logical core count if platform-specific detection fails
  • isCI() and getCIName() return safe defaults (false/null) if detection fails
  • getTermProgram() returns undefined if terminal cannot be detected

These functions are designed to provide sensible defaults rather than failing, ensuring Gatsby builds can proceed even when system detection encounters issues.