{"library":"server-cli-only","title":"server-cli-only","description":"The `server-cli-only` package, currently at version 0.3.2, acts as a build-time failsafe to prevent specific modules from being bundled into client-side (browser) code. Its primary function is to restrict imports of designated modules exclusively to server-side environments such as React Server Components, Node.js, Bun, Deno, and various edge runtimes (Vercel, Netlify, Cloudflare). Unlike the `server-only` package, which strictly targets the 'react-server' runtime, `server-cli-only` expands its allowed runtimes to encompass a broader range of server and CLI execution environments, including those defined by WinterCG specifications. This ensures sensitive code or data remains server-side, throwing build-time errors if inadvertently imported into a browser context or an unknown runtime, thereby preventing potential security vulnerabilities and unexpected client behavior. The package maintains a stable, low-frequency release cadence as it primarily focuses on a core, foundational restriction mechanism.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install server-cli-only"],"cli":null},"imports":["import \"server-cli-only\";","if (typeof require !== 'undefined') { require(\"server-cli-only\"); }","// No types are exported or intended to be used directly from this package."],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import \"server-cli-only\"; // This line prevents the module from being bundled into browser code\n\ninterface SensitiveConfig {\n  apiKey: string;\n  databaseUrl: string;\n}\n\nexport function getSensitiveConfig(): SensitiveConfig {\n  // In a real application, fetch from environment variables or a secure store\n  return {\n    apiKey: process.env.MY_API_KEY ?? 'sk_test_123',\n    databaseUrl: process.env.DATABASE_URL ?? 'mongodb://localhost:27017/mydb',\n  };\n}\n\n// Example usage for a server or CLI script:\n// If this file is executed directly via Node.js, Bun, or Deno:\n// e.g., `ts-node src/server-logic.ts`\nif (typeof process !== 'undefined' && process.argv[1] === require.main?.filename) {\n  console.log(\"Executing server-side logic directly via CLI.\");\n  const config = getSensitiveConfig();\n  console.log(\"Retrieved API Key (first 5 chars):\", config.apiKey.substring(0, 5) + '...');\n  console.log(\"Database URL:\", config.databaseUrl);\n}\n// If imported into a React Server Component, it would execute there.\n// If imported into a React Client Component, it would throw a build error.","lang":"typescript","description":"Demonstrates how to use `server-cli-only` to restrict a module containing sensitive configuration to server/CLI environments, preventing client-side leakage.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}