New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@wrote/ensure-path

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wrote/ensure-path - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

67

build/index.js

@@ -1,36 +0,23 @@

"use strict";
const { mkdir } = require('fs');
let makePromise = require('makepromise'); if (makePromise && makePromise.__esModule) makePromise = makePromise.default;
const { dirname } = require('path');
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = ensurePath;
var _fs = require("fs");
var _makepromise = _interopRequireDefault(require("makepromise"));
var _path = require("path");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Make sure that a file can be created by creating all directories to which it belongs, e.g., `ensurePath('/usr/local/test/wrote.data')` will attempt to create `/usr/local/test/` directory recursively starting from `usr`.
* Makes sure that a file can be created by creating all directories to which it belongs, e.g., `ensurePath('~/path/to/wrote.data')` will attempt to create `~/path/to` directory recursively.
* @param {string} path Path to the file
* @returns {Promise.<string>} Same path as passed
* @throws {Error} When the first folder in the path is non-executable
*/
async function ensurePath(path) {
const dir = (0, _path.dirname)(path);
async function ensurePath(path) {
const dir = dirname(path)
try {
await make(dir);
return path;
await make(dir)
return path
} catch (err) {
if (/EEXIST/.test(err.message) && err.message.indexOf(dir) != -1) {
return path;
return path
}
throw err;
throw err
}
}
/**

@@ -40,34 +27,18 @@ * Recursive promise-based mkdir.

*/
async function make(dir) {
try {
const res = await makeDir(dir);
return res;
await makePromise(mkdir, dir)
} catch (err) {
if (/ENOENT/.test(err.message)) {
const parentDir = (0, _path.dirname)(dir);
await make(parentDir);
const res2 = await make(dir);
return res2;
if (err.code == 'ENOENT') {
const parentDir = dirname(dir)
await make(parentDir)
await make(dir)
} else if (err.code != 'EEXIST') { // created in parallel
throw err
}
throw err;
}
}
/**
* Promisified fs.mkdir
* @param {string} dir directory name
* @returns {string} created directory name
*/
async function makeDir(dir) {
const res = await (0, _makepromise.default)(_fs.mkdir, dir, dir);
return res;
}
/**
* @typedef {Object} Config
* @property {string} type The type.
*/
module.exports = ensurePath
//# sourceMappingURL=index.js.map

@@ -0,1 +1,7 @@

## 15 September 2018
### 1.0.3
- [fix] Make sure there is no error when multiple calls are made in parallel.
## 4 July 2018

@@ -2,0 +8,0 @@

{
"name": "@wrote/ensure-path",
"version": "1.0.2",
"version": "1.0.3",
"description": "Create all directories on the way to the path.",
"main": "build",
"scripts": {
"t": "zoroaster -b",
"test": "zoroaster -b test/spec",
"test-build": "BABEL_ENV=test-build yarn test",
"test-all": "yarn-s test test-build",
"test-watch": "yarn test -w",
"t": "zoroaster -a",
"test": "yarn t test/spec",
"spec": "yarn t test/spec",
"mask": "yarn t test/mask",
"test-build": "ALAMODE_ENV=test-build yarn test",
"lint": "eslint .",

@@ -17,4 +17,4 @@ "doc": "NODE_DEBUG=doc doc documentary -o README.md",

"example/": "yarn e example/example.js",
"build": "yarn-s b doc",
"b": "b --source-maps"
"b": "alamode src -o build",
"build": "yarn-s b doc"
},

@@ -49,12 +49,13 @@ "files": [

"devDependencies": {
"catchment": "2.0.1",
"documentary": "1.8.2",
"eslint-config-artdeco": "1.0.0",
"catchment": "3.1.1",
"documentary": "1.15.2",
"eslint-config-artdeco": "1.0.1",
"spawncommand": "2.0.1",
"temp-context": "1.0.0",
"yarn-s": "1.1.0",
"zoroaster": "2.1.0"
"zoroaster": "3.2.0"
},
"dependencies": {
"makepromise": "2.0.0"
"makepromise": "3.0.1"
}
}

@@ -16,2 +16,3 @@ # @wrote/ensure-path

* [`async ensurePath(path: string): string`](#async-ensurepathpath-string-string)
- [Copyright](#copyright)

@@ -46,6 +47,6 @@ ## API

---
## Copyright
(c) [Art Deco][1] 2018
[1]: https://artdeco.bz
[1]: https://artdeco.bz

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc