Comparing version 7.0.0-next.1698927729.5177d5ac4a3edb7d0e0e3264566edd9556a00df9 to 8.0.0-next.1699858303.399448cc2578fca105003a24fd7d22883f7552e9
{ | ||
"title": "Safe FS", | ||
"name": "safefs", | ||
"version": "7.0.0-next.1698927729.5177d5ac4a3edb7d0e0e3264566edd9556a00df9", | ||
"version": "8.0.0-next.1699858303.399448cc2578fca105003a24fd7d22883f7552e9", | ||
"description": "Stop getting EMFILE errors! Open only as many files as the operating system supports.", | ||
@@ -15,3 +15,5 @@ "homepage": "https://github.com/bevry/safefs", | ||
"openFile", | ||
"path" | ||
"path", | ||
"typed", | ||
"types" | ||
], | ||
@@ -72,7 +74,7 @@ "badges": { | ||
"engines": { | ||
"node": ">=14" | ||
"node": ">=4" | ||
}, | ||
"editions": [ | ||
{ | ||
"description": "ESNext source code for Node.js 14 || 16 || 18 || 20 || 21 with Require for modules", | ||
"description": "ESNext source code for Node.js 4 || 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with Require for modules", | ||
"directory": "source", | ||
@@ -87,3 +89,3 @@ "entry": "index.js", | ||
"engines": { | ||
"node": "14 || 16 || 18 || 20 || 21" | ||
"node": "4 || 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21" | ||
} | ||
@@ -95,16 +97,19 @@ } | ||
"dependencies": { | ||
"graceful-fs": "^4.2.11" | ||
"graceful-fs": "^4.2.11", | ||
"version-compare": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@bevry/update-contributors": "^1.22.0", | ||
"assert-helpers": "^8.4.0", | ||
"eslint": "^8.52.0", | ||
"eslint-config-bevry": "^3.28.0", | ||
"@bevry/update-contributors": "^1.23.0", | ||
"assert-helpers": "^11.1.0", | ||
"eslint": "^8.53.0", | ||
"eslint-config-bevry": "^3.29.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-babel": "^5.3.1", | ||
"eslint-plugin-prettier": "^5.0.1", | ||
"kava": "^5.17.0", | ||
"prettier": "^3.0.3", | ||
"jsdoc": "^4.0.2", | ||
"kava": "3.2.0", | ||
"prettier": "^3.1.0", | ||
"projectz": "^2.23.0", | ||
"valid-directory": "^4.0.0" | ||
"surge": "^0.23.1", | ||
"valid-directory": "^4.1.0" | ||
}, | ||
@@ -115,4 +120,6 @@ "scripts": { | ||
"our:deploy": "printf '%s\n' 'no need for this project'", | ||
"our:meta": "npm run our:meta:contributors && npm run our:meta:projectz", | ||
"our:meta": "npm run our:meta:contributors && npm run our:meta:docs && npm run our:meta:projectz", | ||
"our:meta:contributors": "update-contributors", | ||
"our:meta:docs": "npm run our:meta:docs:jsdoc", | ||
"our:meta:docs:jsdoc": "rm -Rf ./docs && jsdoc --recurse --pedantic --access all --destination ./docs --package ./package.json --readme ./README.md ./source && mv ./docs/$npm_package_name/$npm_package_version/* ./docs/ && rm -Rf ./docs/$npm_package_name/$npm_package_version", | ||
"our:meta:projectz": "projectz compile", | ||
@@ -141,4 +148,5 @@ "our:release": "npm run our:release:prepare && npm run our:release:check-changelog && npm run our:release:check-dirty && npm run our:release:tag && npm run our:release:push", | ||
"semi": false, | ||
"singleQuote": true | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
} | ||
} |
@@ -37,2 +37,4 @@ <!-- TITLE/ --> | ||
[Complete API Documentation.](http://master.safefs.bevry.surge.sh/docs/) | ||
```javascript | ||
@@ -72,4 +74,16 @@ var safefs = require('safefs') | ||
<ul><li><code>safefs</code> aliases <code>safefs/source/index.js</code></li> | ||
<li><code>safefs/source/index.js</code> is <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> source code for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> 14 || 16 || 18 || 20 || 21 with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li></ul> | ||
<li><code>safefs/source/index.js</code> is <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> source code for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> 4 || 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li></ul> | ||
<h3><a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a></h3> | ||
This project provides its type information via inline <a href="http://usejsdoc.org" title="JSDoc is an API documentation generator for JavaScript, similar to Javadoc or phpDocumentor">JSDoc Comments</a>. To make use of this in <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a>, set your <code>maxNodeModuleJsDepth</code> compiler option to `5` or thereabouts. You can accomlish this via your `tsconfig.json` file like so: | ||
``` json | ||
{ | ||
"compilerOptions": { | ||
"maxNodeModuleJsDepth": 5 | ||
} | ||
} | ||
``` | ||
<!-- /INSTALL --> | ||
@@ -76,0 +90,0 @@ |
/* eslint no-sync:0 */ | ||
'use strict' | ||
// Import | ||
const fsUtil = require('graceful-fs') | ||
// builtins | ||
const pathUtil = require('path') | ||
const processUtil = require('process') | ||
const nodeVersion = processUtil.versions.node | ||
const umask = processUtil.umask | ||
const cwd = processUtil.cwd | ||
const exec = require('child_process').exec | ||
// packages | ||
const fsUtil = require('graceful-fs') | ||
const versionCompare = require('version-compare').default | ||
// ===================================== | ||
// Define Module | ||
/** | ||
* Utilities to safely interact with the filesystem. | ||
*/ | ||
const safefs = { | ||
@@ -15,3 +26,7 @@ // ===================================== | ||
// Get the parent path | ||
/** | ||
* Get the parent path | ||
* @param {String} path | ||
* @return {String} | ||
*/ | ||
getParentPathSync(path) { | ||
@@ -27,4 +42,16 @@ return ( | ||
// Ensure path exists | ||
// next(err, existed) | ||
/** | ||
* @callback EnsurePathCallback | ||
* @param {Error|null} err | ||
* @param {Boolean} existed | ||
* @returns {void} | ||
*/ | ||
/** | ||
* Ensure the path exists | ||
* @param {String} path | ||
* @param {Object} opts | ||
* @param {Number} opts.mode | ||
* @param {EnsurePathCallback} next | ||
* @returns {this} | ||
*/ | ||
ensurePath(path, opts, next) { | ||
@@ -39,3 +66,3 @@ // Prepare | ||
// Check | ||
safefs.exists(path, function (exists) { | ||
fsUtil.exists(path, function (exists) { | ||
// Error | ||
@@ -54,3 +81,3 @@ if (exists) return next(null, true) | ||
safefs.exists(path, function (exists) { | ||
fsUtil.exists(path, function (exists) { | ||
// Error | ||
@@ -76,4 +103,15 @@ if (!exists) { | ||
// Write File | ||
// next(err) | ||
/** | ||
* @callback Errback | ||
* @param {Error|null} err | ||
* @returns {void} | ||
*/ | ||
/** | ||
* Write the file, ensuring the path exists | ||
* @param {String} path | ||
* @param {String|Buffer} data | ||
* @param {WriteFileOptions} opts | ||
* @param {Errback} next | ||
* @returns {this} | ||
*/ | ||
writeFile(path, data, opts, next) { | ||
@@ -99,4 +137,10 @@ // Prepare | ||
// Append File | ||
// next(err) | ||
/** | ||
* Append to the file, ensuring the path exists | ||
* @param {String} path | ||
* @param {String|Buffer} data | ||
* @param {WriteFileOptions} opts | ||
* @param {Errback} next | ||
* @returns {this} | ||
*/ | ||
appendFile(path, data, opts, next) { | ||
@@ -122,4 +166,9 @@ // Prepare | ||
// Mkdir | ||
// next(err) | ||
/** | ||
* Make the directory | ||
* @param {String} path | ||
* @param {Number} mode | ||
* @param {Errback} next | ||
* @returns {this} | ||
*/ | ||
mkdir(path, mode, next) { | ||
@@ -133,3 +182,3 @@ // Prepare | ||
/* eslint no-bitwise:0, no-magic-numbers:0 */ | ||
mode = 0o777 & ~process.umask() | ||
mode = 0o777 & ~umask() | ||
} | ||
@@ -144,8 +193,11 @@ | ||
// Unlink | ||
// don't error if the path doesn't already exist | ||
// next(err) | ||
/** | ||
* Remove the file, don't error if the path is already removed. | ||
* @param {String} path | ||
* @param {Errback} next | ||
* @returns {this} | ||
*/ | ||
unlink(path, next) { | ||
// Stat | ||
safefs.exists(path, function (exists) { | ||
fsUtil.exists(path, function (exists) { | ||
if (exists === false) return next() | ||
@@ -158,2 +210,31 @@ fsUtil.unlink(path, next) | ||
}, | ||
/** | ||
* Remove the directory, don't error if the path is already removed. | ||
* @param {String} path | ||
* @param {Errback} next | ||
* @returns {this} | ||
*/ | ||
rmdir(path, next) { | ||
function wrappedNext(err) { | ||
if (err && err.code === 'ENOENT') return next() | ||
next(err) | ||
} | ||
// https://nodejs.org/api/fs.html#fsrmdirpath-options-callback | ||
if (versionCompare(nodeVersion, '14') >= 0) { | ||
fsUtil.rm( | ||
path, | ||
{ recursive: true, force: true, maxRetries: 2 }, | ||
wrappedNext | ||
) | ||
} else if ( | ||
versionCompare(nodeVersion, '12') >= 0 && | ||
versionCompare(nodeVersion, '16') < 0 | ||
) { | ||
fsUtil.rmdir(path, { recursive: true, maxRetries: 2 }, wrappedNext) | ||
} else { | ||
exec(`rm -rf ${JSON.stringify(path)}`, { cwd: cwd() }, wrappedNext) | ||
} | ||
}, | ||
} | ||
@@ -160,0 +241,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31300
214
161
2
13
1
+ Addedversion-compare@^3.0.0
+ Addededitions@6.21.0(transitive)
+ Addedversion-compare@3.11.0(transitive)
+ Addedversion-range@4.14.0(transitive)