Cross platform compatibility

From aj-geddes/useful-ai-prompts · View interactive version

Cross platform compatibility is an AI agent skill from the GitHub repository aj-geddes/useful-ai-prompts. Handle cross-platform compatibility including file paths, environment detection, platform-specific dependencies, and testing across Windows, macOS, and Linux. Use when dealing with platform-specific code or OS compatibility.

How to use this skill

Skill file

Cross-Platform Compatibility

Table of Contents

Overview

Comprehensive guide to writing code that works seamlessly across Windows, macOS, and Linux. Covers file path handling, environment detection, platform-specific features, and testing strategies.

When to Use

Quick Start

Minimal working example:

// ❌ BAD: Hardcoded paths with platform-specific separators
const configPath = "C:\\Users\\user\\config.json"; // Windows only
const dataPath = "/home/user/data.txt"; // Unix only

// ✅ GOOD: Use path module
import path from "path";
import os from "os";

// Platform-independent path construction
const configPath = path.join(os.homedir(), "config", "app.json");
const dataPath = path.join(process.cwd(), "data", "users.txt");

// Resolve relative paths
const absolutePath = path.resolve("./config/settings.json");

// Get path components
const dirname = path.dirname("/path/to/file.txt"); // '/path/to'
const basename = path.basename("/path/to/file.txt"); // 'file.txt'
const extname = path.extname("/path/to/file.txt"); // '.txt'

// Normalize paths (handle .. and .)
const normalized = path.normalize("/path/to/../file.txt"); // '/path/file.txt'

Reference Guides

Detailed implementations in the references/ directory:

| Guide | Contents |

|---|---|

| File Path Handling | File Path Handling |

| Platform Detection | Platform Detection |

| Line Endings | Line Endings |

| Environment Variables | Environment Variables |

| Shell Commands | Shell Commands |

| File Permissions | File Permissions |

| Process Management | Process Management |

| Platform-Specific Dependencies | Platform-Specific Dependencies |

| Testing Across Platforms | Testing Across Platforms |

| Character Encoding | Character Encoding |

| Build Configuration | Build Configuration |

Best Practices

✅ DO

❌ DON'T

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.