cross-platform-compatibility by aj-geddes/useful-ai-prompts
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill cross-platform-compatibility编写能在 Windows、macOS 和 Linux 上无缝运行代码的全面指南。涵盖文件路径处理、环境检测、平台特定功能以及测试策略。
最小工作示例:
// ❌ 错误:使用平台特定分隔符硬编码路径
const configPath = "C:\\Users\\user\\config.json"; // 仅限 Windows
const dataPath = "/home/user/data.txt"; // 仅限 Unix
// ✅ 正确:使用 path 模块
import path from "path";
import os from "os";
// 平台无关的路径构造
const configPath = path.join(os.homedir(), "config", "app.json");
const dataPath = path.join(process.cwd(), "data", "users.txt");
// 解析相对路径
const absolutePath = path.resolve("./config/settings.json");
// 获取路径组件
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'
// 规范化路径(处理 .. 和 .)
const normalized = path.normalize("/path/to/../file.txt"); // '/path/file.txt'
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
references/ 目录下的详细实现:
每周安装量
109
代码仓库
GitHub 星标数
116
首次出现
Jan 21, 2026
安全审计
安装于
gemini-cli90
opencode90
claude-code89
codex88
cursor80
github-copilot72
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.
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'
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 |
Weekly Installs
109
Repository
GitHub Stars
116
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketFailSnykPass
Installed on
gemini-cli90
opencode90
claude-code89
codex88
cursor80
github-copilot72
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
157,400 周安装
| Process Management |
| Platform-Specific Dependencies | Platform-Specific Dependencies |
| Testing Across Platforms | Testing Across Platforms |
| Character Encoding | Character Encoding |
| Build Configuration | Build Configuration |