Skip to content

Commit

Permalink
Fix temporary directory fallback in __getTempDir internal function (#5)
Browse files Browse the repository at this point in the history
This pull request enhances the robustness of the `__getTempDir` function by including the `os.tmpdir()` method from Node.js core as a fallback option. This change ensures the function correctly identifies the temporary directory path across various environments, improving overall reliability and functionality.

Signed-off-by: Ryuu Mitsuki <[email protected]>
  • Loading branch information
mitsuki31 committed Jul 9, 2024
2 parents 37b1b2f + ae851b0 commit 50b1e36
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ function isNullOrUndefined(o) {
}

/**
* Gets the temporary directory path based on the environment.
* Retrieves the temporary directory path based on the current environment.
*
* This function checks common environment variables for temporary directories,
* such as TMPDIR on Unix-like and MacOS systems, and TMP/TEMP on Windows.
* If no environment variable is set, it defaults to a 'tmp' directory
* within the current working directory.
* This function first checks common environment variables for temporary directories:
* - `TMPDIR` on UNIX-like and macOS systems
* - `TMP` or `TEMP` on Windows systems
*
* If none of these environment variables are set or return null, it falls back to the
* `os.tmpdir()` function. If this also returns null, it uses the current working directory
* and creates a new directory called `tmp`.
*
* @private
* @function
Expand All @@ -60,7 +63,8 @@ function isNullOrUndefined(o) {
function __getTempDir() {
return process.env.TMPDIR // Unix-like & MacOS systems
|| (process.env.TMP || process.env.TEMP) // Windows system
|| path.resolve(process.cwd(), 'tmp'); // Default path
|| require('node:os').tmpdir() // Fallback
|| path.resolve(process.cwd(), 'tmp'); // Otherwise, use current directory
}


Expand Down

0 comments on commit 50b1e36

Please sign in to comment.