Skip to content

1.3.0

Choose a tag to compare

@Pinta365 Pinta365 released this 25 Sep 18:28
· 5 commits to main since this release

@cross/dir 1.3.0

Error classes

dir() now throws typed errors, both extending Error with type and platform properties:

  • UnsupportedDirectoryError: the directory type is unknown or not available on the current platform.
  • DirectoryNotFoundError: the type is supported, but its path could not be resolved on this system.
import { dir, DirectoryNotFoundError } from "@cross/dir";

try {
    await dir("projects");
} catch (error) {
    if (error instanceof DirectoryNotFoundError) { /* ... */ }
}

Error messages are unchanged. The only exception is the Windows hint, which now refers to the new option.

Options object

dir() now accepts an options object as its second argument:

await dir("download", { windowsSpecialFolders: true });

Passing a boolean (dir("download", true)) still works but is deprecated and will be removed in 2.0.

New directory type: preference

Resolves to the same path as config on Linux and Windows, and to ~/Library/Preferences on macOS.

On macOS, config currently points to ~/Library/Preferences, which Apple reserves for system-managed .plist
files. It is planned to move to ~/Library/Application Support in 2.0. If you rely on the current location, switch to
preference now.

Fixes

- Windows: download now resolves the actual Downloads location through the shell's known folder
  (shell:Downloads), so relocated Downloads folders are found. It falls back to %USERPROFILE%\Downloads if that
  lookup fails. This requires the windowsSpecialFolders option, as before.

Deprecations (removal planned for 2.0)

- Boolean second argument to dir(). Use { windowsSpecialFolders: true } instead.