{"id":10561,"library":"bare-path","title":"Bare Path Manipulation","description":"bare-path is a JavaScript library designed for cross-platform path manipulation, focusing on string-based operations rather than interacting with the underlying file system. It provides utilities for joining, normalizing, resolving, and dissecting file paths, similar to Node.js's built-in `path` module. The current stable version is 3.0.0. Its primary differentiator is its minimalist approach and explicit separation of POSIX and Windows path logic via subpath exports, making it highly portable and suitable for environments where `node:path` might not be available or desired due to its implicit OS-specific behavior. It maintains a steady release cadence for core utility packages, prioritizing stability and broad compatibility.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/holepunchto/bare-path","tags":["javascript"],"install":[{"cmd":"npm install bare-path","lang":"bash","label":"npm"},{"cmd":"yarn add bare-path","lang":"bash","label":"yarn"},{"cmd":"pnpm add bare-path","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for internal operating system detection and path logic.","package":"bare-os","optional":false}],"imports":[{"note":"The main path utilities object is exported as a default. For full CommonJS interoperability in ESM, use `import * as path from 'bare-path';`.","wrong":"import { path } from 'bare-path';","symbol":"path","correct":"import path from 'bare-path';"},{"note":"CommonJS `require` imports the entire module object, which is the path utility methods.","wrong":"const { path } = require('bare-path');","symbol":"path (CommonJS)","correct":"const path = require('bare-path');"},{"note":"Access platform-specific path utilities directly via subpath imports. Similar import for `bare-path/posix` exists.","wrong":"import { win32Path } from 'bare-path';","symbol":"win32Path","correct":"import win32Path from 'bare-path/win32';"}],"quickstart":{"code":"import path from 'bare-path';\n\n// Join path segments, handling separators automatically\nconst fullPath = path.join('users', 'admin', 'documents', 'report.txt');\nconsole.log(`Joined path: ${fullPath}`); // Expected: users/admin/documents/report.txt (on POSIX)\n\n// Normalize a path, resolving '..' and '.' segments\nconst normalizedPath = path.normalize('/foo/bar//../baz/.');\nconsole.log(`Normalized path: ${normalizedPath}`); // Expected: /foo/baz\n\n// Get the directory name of a path\nconst dirname = path.dirname('/home/user/file.js');\nconsole.log(`Directory name: ${dirname}`); // Expected: /home/user\n\n// Get the base name of a path (filename)\nconst basename = path.basename('/home/user/file.js');\nconsole.log(`Base name: ${basename}`); // Expected: file.js\n\n// Get the base name without extension\nconst basenameNoExt = path.basename('/home/user/file.js', '.js');\nconsole.log(`Base name without extension: ${basenameNoExt}`); // Expected: file\n\n// Get the extension of a path\nconst extname = path.extname('/home/user/archive.tar.gz');\nconsole.log(`Extension name: ${extname}`); // Expected: .gz","lang":"javascript","description":"Demonstrates basic path manipulation functions like joining, normalizing, and extracting parts of a path using `bare-path`."},"warnings":[{"fix":"Migrate to standard ES module imports (e.g., `import path from 'bare-path'`) and use the official subpath exports (`bare-path/win32`, `bare-path/posix`) for platform-specific utilities. Ensure your `package.json` specifies `\"type\": \"module\"` for ESM usage or correctly configures a CJS environment.","message":"Version 3.x introduces explicit ES Modules (`'exports'` field in `package.json`) which might alter module resolution behavior, especially for subpath imports and CJS interoperability. Direct access to internal files via deep `require()` or `import` paths might be broken.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Understand that `bare-path` operates solely on the provided string inputs. For file system interactions (e.g., `fs.readFile`), use `node:path` methods if you need guarantees about actual file system paths, or manually combine `bare-path` outputs with `process.cwd()` for root-relative paths.","message":"`bare-path` is purely a string manipulation utility and does not interact with the file system. It will not resolve symbolic links, check for file existence, or convert paths to absolute paths relative to the current working directory on disk. This differs from aspects of `node:path` module when used with `fs` operations.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer `path.join()`, `path.resolve()`, and `path.normalize()` methods for cross-platform compatibility. If you need strict platform behavior, explicitly import and use `bare-path/posix` or `bare-path/win32`.","message":"When using `bare-path` on Windows, ensure you are aware of path separator differences. While `path.join` and `path.normalize` abstract this, manually constructed paths or external inputs may use backslashes (`\\`) which might require explicit handling or using the `bare-path/win32` export for Windows-specific behaviors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"If using ES modules, ensure you are using `import path from 'bare-path';`. If in a CommonJS context, use `const path = require('bare-path');`. Verify that your `package.json` has `\"type\": \"module\"` if you intend to use ESM globally, or manage file extensions (`.mjs`/`.cjs`).","cause":"Attempting to import `bare-path` in an ES module context using a CommonJS `require()` syntax, or incorrect `package.json` `type` field setting.","error":"Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'bare-path' imported from ..."},{"fix":"Before dynamically importing a local absolute path on Windows, convert it to a `file://` URL: `import { pathToFileURL } from 'node:url'; const modulePath = pathToFileURL(absolutePath).href; await import(modulePath);`","cause":"Dynamic `import()` on Windows with a bare, absolute path (e.g., `C:\\path\\to\\module.js`) instead of a `file://` URL scheme. This is a Node.js ESM loader requirement.","error":"Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolutePath is something like C:\\Users\\...\\node_modules\\...\\index.js."}],"ecosystem":"npm"}