CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-std-env

Runtime agnostic JavaScript utility library for environment detection, platform information, CI/CD provider detection, and runtime identification.

Pending
Overview
Eval results
Files

provider-detection.mddocs/

Provider Detection

CI/CD and hosting provider identification with support for 50+ popular services including GitHub Actions, GitLab CI, Vercel, Netlify, and many others.

Capabilities

Provider Name

Current provider name as detected from environment variables.

/**
 * Current CI/CD or hosting provider name
 * Empty string if no provider is detected
 */
const provider: ProviderName;

type ProviderName = 
  | ""                          // Unknown/no provider
  | "appveyor"                  // AppVeyor
  | "aws_amplify"               // AWS Amplify
  | "azure_pipelines"           // Azure Pipelines  
  | "azure_static"              // Azure Static Web Apps
  | "appcircle"                 // Appcircle
  | "bamboo"                    // Atlassian Bamboo
  | "bitbucket"                 // Bitbucket Pipelines
  | "bitrise"                   // Bitrise
  | "buddy"                     // Buddy
  | "buildkite"                 // Buildkite
  | "circle"                    // CircleCI
  | "cirrus"                    // Cirrus CI
  | "cloudflare_pages"          // Cloudflare Pages
  | "cloudflare_workers"        // Cloudflare Workers
  | "codebuild"                 // AWS CodeBuild
  | "codefresh"                 // Codefresh
  | "drone"                     // Drone CI
  | "dsari"                     // DSARI
  | "github_actions"            // GitHub Actions
  | "gitlab"                    // GitLab CI
  | "gocd"                      // GoCD
  | "layerci"                   // LayerCI
  | "hudson"                    // Hudson CI
  | "jenkins"                   // Jenkins
  | "magnum"                    // Magnum CI
  | "netlify"                   // Netlify
  | "nevercode"                 // Nevercode
  | "render"                    // Render
  | "sail"                      // Sail CI
  | "semaphore"                 // Semaphore CI
  | "screwdriver"               // Screwdriver
  | "shippable"                 // Shippable
  | "solano"                    // Solano CI
  | "strider"                   // Strider CD
  | "teamcity"                  // TeamCity
  | "travis"                    // Travis CI
  | "vercel"                    // Vercel
  | "appcenter"                 // App Center
  | "codesandbox"               // CodeSandbox
  | "stackblitz"                // StackBlitz
  | "stormkit"                  // Stormkit
  | "cleavr"                    // Cleavr
  | "zeabur"                    // Zeabur
  | "codesphere"                // Codesphere
  | "railway"                   // Railway
  | "deno-deploy"               // Deno Deploy
  | "firebase_app_hosting";     // Firebase App Hosting

Usage Examples:

import { provider } from "std-env";

console.log(`Current provider: ${provider}`);

// Provider-specific logic
switch (provider) {
  case "github_actions":
    console.log("Running in GitHub Actions");
    // Use GitHub-specific environment variables
    const runId = process.env.GITHUB_RUN_ID;
    break;
    
  case "gitlab":
    console.log("Running in GitLab CI");
    // Use GitLab-specific features
    const jobId = process.env.CI_JOB_ID;
    break;
    
  case "vercel":
    console.log("Running on Vercel");
    // Use Vercel-specific environment
    const deploymentUrl = process.env.VERCEL_URL;
    break;
    
  case "netlify":
    console.log("Running on Netlify");
    // Use Netlify-specific features
    const deployId = process.env.DEPLOY_ID;
    break;
    
  default:
    if (provider) {
      console.log(`Running on ${provider}`);
    } else {
      console.log("No provider detected");
    }
}

Provider Information

Detailed provider information including CI status and metadata.

/**
 * Current provider information with metadata
 * Contains provider name, CI status, and additional properties
 */
const providerInfo: ProviderInfo;

interface ProviderInfo {
  /** Provider name */
  name: ProviderName;
  /** Whether this is a CI environment (optional, defaults to true for most CI providers) */
  ci?: boolean;
  /** Additional provider-specific metadata */
  [meta: string]: any;
}

Usage Examples:

import { providerInfo } from "std-env";

console.log(`Provider: ${providerInfo.name}`);
console.log(`Is CI: ${providerInfo.ci}`);

// Check if it's a CI provider
if (providerInfo.ci) {
  console.log("Running in CI environment");
  // Disable interactive features
  // Enable CI-specific logging
} else if (providerInfo.name) {
  console.log("Running on hosting platform");
  // Platform-specific optimizations
}

// Access additional metadata
console.log("Provider info:", JSON.stringify(providerInfo, null, 2));

Provider Detection Logic

Provider detection works by checking specific environment variables that each provider sets:

Major CI/CD Providers

// Examples of environment variables checked for each provider:

// GitHub Actions
if (process.env.GITHUB_ACTIONS) {
  // Detected as "github_actions"
}

// GitLab CI
if (process.env.GITLAB_CI || process.env.CI_MERGE_REQUEST_ID) {
  // Detected as "gitlab"
}

// CircleCI
if (process.env.CIRCLECI) {
  // Detected as "circle"
}

// Travis CI
if (process.env.TRAVIS) {
  // Detected as "travis"
}

// Jenkins
if (process.env.JENKINS_URL) {
  // Detected as "jenkins"
}

Hosting and Deployment Platforms

// Vercel
if (process.env.NOW_BUILDER || process.env.VERCEL || process.env.VERCEL_ENV) {
  // Detected as "vercel"
  // Note: ci: false for Vercel (hosting platform, not CI)
}

// Netlify
if (process.env.NETLIFY) {
  // Detected as "netlify"
  // Note: ci: false for Netlify (hosting platform, not CI)
}

// Railway
if (process.env.RAILWAY_PROJECT_ID || process.env.RAILWAY_SERVICE_ID) {
  // Detected as "railway"
}

// Cloudflare Pages
if (process.env.CF_PAGES) {
  // Detected as "cloudflare_pages"
}

Special Detection Cases

// StackBlitz - Special detection for webcontainer
if (process.env.SHELL === "/bin/jsh" && process.versions?.webcontainer) {
  // Detected as "stackblitz" with ci: false
}

// CodeSandbox
if (process.env.CODESANDBOX_SSE || process.env.CODESANDBOX_HOST) {
  // Detected as "codesandbox" with ci: false
}

Provider-Specific Usage Patterns

CI/CD Integration

import { provider, providerInfo, isCI } from "std-env";

// CI-specific behavior
if (isCI) {
  switch (provider) {
    case "github_actions":
      // Set GitHub Actions outputs
      console.log(`::set-output name=result::success`);
      break;
      
    case "gitlab":
      // Use GitLab CI artifacts
      console.log("Saving artifacts to GitLab");
      break;
      
    case "jenkins":
      // Use Jenkins environment
      const buildNumber = process.env.BUILD_NUMBER;
      break;
  }
}

Deployment Platform Integration

import { provider } from "std-env";

// Platform-specific deployment logic
switch (provider) {
  case "vercel":
    // Vercel-specific optimizations
    console.log(`Deploy URL: ${process.env.VERCEL_URL}`);
    break;
    
  case "netlify":
    // Netlify-specific features
    console.log(`Deploy ID: ${process.env.DEPLOY_ID}`);
    break;
    
  case "railway":
    // Railway-specific configuration
    console.log(`Service: ${process.env.RAILWAY_SERVICE_NAME}`);
    break;
}

Development Environment Detection

import { provider, providerInfo } from "std-env";

// Development platform detection
const isDevelopmentPlatform = provider && !providerInfo.ci;

if (isDevelopmentPlatform) {
  switch (provider) {
    case "codesandbox":
      console.log("Running in CodeSandbox");
      // Enable CodeSandbox-specific features
      break;
      
    case "stackblitz":
      console.log("Running in StackBlitz");
      // Enable StackBlitz-specific features
      break;
  }
}

Install with Tessl CLI

npx tessl i tessl/npm-std-env

docs

environment-detection.md

environment-variables.md

index.md

platform-detection.md

provider-detection.md

runtime-detection.md

tile.json