fast-folder-size
Advanced tools
Comparing version
@@ -8,43 +8,81 @@ const fs = require('fs') | ||
// Only run for Windows | ||
if (process.platform !== 'win32') { | ||
process.exit(0) | ||
exports.onDuZipDownloaded = function (tempFilePath, workspace) { | ||
decompress(tempFilePath, path.join(workspace, 'bin')) | ||
} | ||
// check if du is already installed | ||
if ( | ||
fs.existsSync( | ||
path.join(__dirname, 'bin', `du${process.arch === 'x64' ? '64' : ''}.exe`) | ||
) | ||
) { | ||
process.exit(0) | ||
} | ||
exports.downloadDuZip = function (mirror, workspace) { | ||
const duZipLocation = | ||
mirror || 'https://download.sysinternals.com/files/DU.zip' | ||
const duZipLocation = | ||
process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION || | ||
'https://download.sysinternals.com/files/DU.zip' | ||
// checks for proxy variables in user environment | ||
const proxyAddress = | ||
process.env.HTTPS_PROXY || | ||
process.env.https_proxy || | ||
process.env.HTTP_PROXY || | ||
process.env.http_proxy | ||
// checks for proxy variables in user environment | ||
const proxyAddress = | ||
process.env.HTTPS_PROXY || | ||
process.env.https_proxy || | ||
process.env.HTTP_PROXY || | ||
process.env.http_proxy | ||
if (proxyAddress) { | ||
https.globalAgent = new HttpsProxyAgent(proxyAddress) | ||
} | ||
if (proxyAddress) { | ||
const agent = new HttpsProxyAgent(proxyAddress) | ||
console.log(`downloading du.zip from ${duZipLocation}`) | ||
if (!mirror) { | ||
console.log( | ||
`if you have trouble while downloading, try set process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION to a proper mirror or local file path` | ||
) | ||
} | ||
https.globalAgent = agent | ||
https.get(duZipLocation, function (res) { | ||
const tempFilePath = path.join(os.tmpdir(), 'du.zip') | ||
const fileStream = fs.createWriteStream(tempFilePath) | ||
res.pipe(fileStream) | ||
fileStream.on('finish', function () { | ||
fileStream.close() | ||
exports.onDuZipDownloaded(tempFilePath, workspace) | ||
}) | ||
}) | ||
} | ||
https.get(duZipLocation, function (res) { | ||
const tempFilePath = path.join(os.tmpdir(), 'du.zip') | ||
exports.default = function (workspace) { | ||
// Only run for Windows | ||
if (process.platform !== 'win32') { | ||
return | ||
} | ||
const fileStream = fs.createWriteStream(tempFilePath) | ||
res.pipe(fileStream) | ||
// check if du is already installed | ||
const duBinFilename = `du${process.arch === 'x64' ? '64' : ''}.exe` | ||
const defaultDuBinPath = path.join(workspace, 'bin', duBinFilename) | ||
fileStream.on('finish', function () { | ||
fileStream.close() | ||
decompress(tempFilePath, path.join(__dirname, 'bin')) | ||
}) | ||
}) | ||
if (fs.existsSync(defaultDuBinPath)) { | ||
console.log(`${duBinFilename} found at ${defaultDuBinPath}`) | ||
return | ||
} | ||
console.log(`${duBinFilename} not found at ${defaultDuBinPath}`) | ||
const mirrorOrCache = process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION | ||
if ( | ||
!mirrorOrCache || | ||
mirrorOrCache.startsWith('http://') || | ||
mirrorOrCache.startsWith('https://') | ||
) { | ||
exports.downloadDuZip(mirrorOrCache, workspace) | ||
return | ||
} | ||
if (fs.existsSync(mirrorOrCache)) { | ||
exports.onDuZipDownloaded(mirrorOrCache, workspace) | ||
return | ||
} | ||
const message = `du.zip not found at ${mirrorOrCache}` | ||
// this will result the process to exit with code 1 | ||
throw Error(message) | ||
} | ||
// only auto execute default() function when its invoked directly | ||
if (require.main === module) { | ||
exports.default(__dirname) | ||
} |
{ | ||
"name": "fast-folder-size", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Node CLI or module to calculate folder size", | ||
@@ -31,2 +31,3 @@ "main": "index.js", | ||
"@types/node": "^20.2.5", | ||
"@types/tap": "^15.0.8", | ||
"eslint": "^8.41.0", | ||
@@ -33,0 +34,0 @@ "eslint-config-prettier": "^8.8.0", |
@@ -11,3 +11,4 @@ > The license of this software has changed to AWISC - Anti War ISC License | ||
- [Sysinternals DU](https://docs.microsoft.com/en-us/sysinternals/downloads/du) on Windows, automatically downloaded at installation time because the license does not allow redistribution. See below about specifying the download location. | ||
- [Sysinternals DU](https://docs.microsoft.com/en-us/sysinternals/downloads/du) on Windows, automatically downloaded at | ||
installation time because the license does not allow redistribution. See below about specifying the download location. | ||
- native `du` on other platforms | ||
@@ -61,7 +62,15 @@ | ||
If you need to change this, e.g. to download from an internal package repository, | ||
set the **FAST_FOLDER_SIZE_DU_ZIP_LOCATION** environment variable. For example: | ||
If you need to change this, e.g. to download from an internal package repository | ||
or re-use an existing du.zip, you can set the **FAST_FOLDER_SIZE_DU_ZIP_LOCATION** environment variable. | ||
For example: | ||
```shell | ||
export FAST_FOLDER_SIZE_DU_ZIP_LOCATION=https://your.internal.repository/DU.zip | ||
export FAST_FOLDER_SIZE_DU_ZIP_LOCATION="https://your.internal.repository/DU.zip" | ||
``` | ||
or | ||
```shell | ||
export FAST_FOLDER_SIZE_DU_ZIP_LOCATION="D://download/du.zip" | ||
``` |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
14016
37.22%20
5.26%270
59.76%75
13.64%8
14.29%14
75%