aboutsummaryrefslogtreecommitdiff
path: root/node_modules/make-dir
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/make-dir')
-rw-r--r--node_modules/make-dir/index.d.ts66
-rw-r--r--node_modules/make-dir/index.js156
-rw-r--r--node_modules/make-dir/license9
-rw-r--r--node_modules/make-dir/package.json59
-rw-r--r--node_modules/make-dir/readme.md125
5 files changed, 415 insertions, 0 deletions
diff --git a/node_modules/make-dir/index.d.ts b/node_modules/make-dir/index.d.ts
new file mode 100644
index 0000000..3a78251
--- /dev/null
+++ b/node_modules/make-dir/index.d.ts
@@ -0,0 +1,66 @@
+/// <reference types="node"/>
+import * as fs from 'fs';
+
+declare namespace makeDir {
+ interface Options {
+ /**
+ Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
+
+ @default 0o777
+ */
+ readonly mode?: number;
+
+ /**
+ Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
+
+ Using a custom `fs` implementation will block the use of the native `recursive` option if `fs.mkdir` or `fs.mkdirSync` is not the native function.
+
+ @default require('fs')
+ */
+ readonly fs?: typeof fs;
+ }
+}
+
+declare const makeDir: {
+ /**
+ Make a directory and its parents if needed - Think `mkdir -p`.
+
+ @param path - Directory to create.
+ @returns The path to the created directory.
+
+ @example
+ ```
+ import makeDir = require('make-dir');
+
+ (async () => {
+ const path = await makeDir('unicorn/rainbow/cake');
+
+ console.log(path);
+ //=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
+
+ // Multiple directories:
+ const paths = await Promise.all([
+ makeDir('unicorn/rainbow'),
+ makeDir('foo/bar')
+ ]);
+
+ console.log(paths);
+ // [
+ // '/Users/sindresorhus/fun/unicorn/rainbow',
+ // '/Users/sindresorhus/fun/foo/bar'
+ // ]
+ })();
+ ```
+ */
+ (path: string, options?: makeDir.Options): Promise<string>;
+
+ /**
+ Synchronously make a directory and its parents if needed - Think `mkdir -p`.
+
+ @param path - Directory to create.
+ @returns The path to the created directory.
+ */
+ sync(path: string, options?: makeDir.Options): string;
+};
+
+export = makeDir;
diff --git a/node_modules/make-dir/index.js b/node_modules/make-dir/index.js
new file mode 100644
index 0000000..75889d8
--- /dev/null
+++ b/node_modules/make-dir/index.js
@@ -0,0 +1,156 @@
+'use strict';
+const fs = require('fs');
+const path = require('path');
+const {promisify} = require('util');
+const semver = require('semver');
+
+const useNativeRecursiveOption = semver.satisfies(process.version, '>=10.12.0');
+
+// https://github.com/nodejs/node/issues/8987
+// https://github.com/libuv/libuv/pull/1088
+const checkPath = pth => {
+ if (process.platform === 'win32') {
+ const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, ''));
+
+ if (pathHasInvalidWinCharacters) {
+ const error = new Error(`Path contains invalid characters: ${pth}`);
+ error.code = 'EINVAL';
+ throw error;
+ }
+ }
+};
+
+const processOptions = options => {
+ // https://github.com/sindresorhus/make-dir/issues/18
+ const defaults = {
+ mode: 0o777,
+ fs
+ };
+
+ return {
+ ...defaults,
+ ...options
+ };
+};
+
+const permissionError = pth => {
+ // This replicates the exception of `fs.mkdir` with native the
+ // `recusive` option when run on an invalid drive under Windows.
+ const error = new Error(`operation not permitted, mkdir '${pth}'`);
+ error.code = 'EPERM';
+ error.errno = -4048;
+ error.path = pth;
+ error.syscall = 'mkdir';
+ return error;
+};
+
+const makeDir = async (input, options) => {
+ checkPath(input);
+ options = processOptions(options);
+
+ const mkdir = promisify(options.fs.mkdir);
+ const stat = promisify(options.fs.stat);
+
+ if (useNativeRecursiveOption && options.fs.mkdir === fs.mkdir) {
+ const pth = path.resolve(input);
+
+ await mkdir(pth, {
+ mode: options.mode,
+ recursive: true
+ });
+
+ return pth;
+ }
+
+ const make = async pth => {
+ try {
+ await mkdir(pth, options.mode);
+
+ return pth;
+ } catch (error) {
+ if (error.code === 'EPERM') {
+ throw error;
+ }
+
+ if (error.code === 'ENOENT') {
+ if (path.dirname(pth) === pth) {
+ throw permissionError(pth);
+ }
+
+ if (error.message.includes('null bytes')) {
+ throw error;
+ }
+
+ await make(path.dirname(pth));
+
+ return make(pth);
+ }
+
+ try {
+ const stats = await stat(pth);
+ if (!stats.isDirectory()) {
+ throw new Error('The path is not a directory');
+ }
+ } catch (_) {
+ throw error;
+ }
+
+ return pth;
+ }
+ };
+
+ return make(path.resolve(input));
+};
+
+module.exports = makeDir;
+
+module.exports.sync = (input, options) => {
+ checkPath(input);
+ options = processOptions(options);
+
+ if (useNativeRecursiveOption && options.fs.mkdirSync === fs.mkdirSync) {
+ const pth = path.resolve(input);
+
+ fs.mkdirSync(pth, {
+ mode: options.mode,
+ recursive: true
+ });
+
+ return pth;
+ }
+
+ const make = pth => {
+ try {
+ options.fs.mkdirSync(pth, options.mode);
+ } catch (error) {
+ if (error.code === 'EPERM') {
+ throw error;
+ }
+
+ if (error.code === 'ENOENT') {
+ if (path.dirname(pth) === pth) {
+ throw permissionError(pth);
+ }
+
+ if (error.message.includes('null bytes')) {
+ throw error;
+ }
+
+ make(path.dirname(pth));
+ return make(pth);
+ }
+
+ try {
+ if (!options.fs.statSync(pth).isDirectory()) {
+ throw new Error('The path is not a directory');
+ }
+ } catch (_) {
+ throw error;
+ }
+ }
+
+ return pth;
+ };
+
+ return make(path.resolve(input));
+};
diff --git a/node_modules/make-dir/license b/node_modules/make-dir/license
new file mode 100644
index 0000000..e7af2f7
--- /dev/null
+++ b/node_modules/make-dir/license
@@ -0,0 +1,9 @@
+MIT License
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/make-dir/package.json b/node_modules/make-dir/package.json
new file mode 100644
index 0000000..98403ea
--- /dev/null
+++ b/node_modules/make-dir/package.json
@@ -0,0 +1,59 @@
+{
+ "name": "make-dir",
+ "version": "3.1.0",
+ "description": "Make a directory and its parents if needed - Think `mkdir -p`",
+ "license": "MIT",
+ "repository": "sindresorhus/make-dir",
+ "funding": "https://github.com/sponsors/sindresorhus",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "scripts": {
+ "test": "xo && nyc ava && tsd"
+ },
+ "files": [
+ "index.js",
+ "index.d.ts"
+ ],
+ "keywords": [
+ "mkdir",
+ "mkdirp",
+ "make",
+ "directories",
+ "dir",
+ "dirs",
+ "folders",
+ "directory",
+ "folder",
+ "path",
+ "parent",
+ "parents",
+ "intermediate",
+ "recursively",
+ "recursive",
+ "create",
+ "fs",
+ "filesystem",
+ "file-system"
+ ],
+ "dependencies": {
+ "semver": "^6.0.0"
+ },
+ "devDependencies": {
+ "@types/graceful-fs": "^4.1.3",
+ "@types/node": "^13.7.1",
+ "ava": "^1.4.0",
+ "codecov": "^3.2.0",
+ "graceful-fs": "^4.1.15",
+ "nyc": "^15.0.0",
+ "path-type": "^4.0.0",
+ "tempy": "^0.2.1",
+ "tsd": "^0.11.0",
+ "xo": "^0.25.4"
+ }
+}
diff --git a/node_modules/make-dir/readme.md b/node_modules/make-dir/readme.md
new file mode 100644
index 0000000..a10a1a4
--- /dev/null
+++ b/node_modules/make-dir/readme.md
@@ -0,0 +1,125 @@
+# make-dir [![Build Status](https://travis-ci.org/sindresorhus/make-dir.svg?branch=master)](https://travis-ci.org/sindresorhus/make-dir) [![codecov](https://codecov.io/gh/sindresorhus/make-dir/branch/master/graph/badge.svg)](https://codecov.io/gh/sindresorhus/make-dir)
+
+> Make a directory and its parents if needed - Think `mkdir -p`
+
+## Advantages over [`mkdirp`](https://github.com/substack/node-mkdirp)
+
+- Promise API *(Async/await ready!)*
+- Fixes many `mkdirp` issues: [#96](https://github.com/substack/node-mkdirp/pull/96) [#70](https://github.com/substack/node-mkdirp/issues/70) [#66](https://github.com/substack/node-mkdirp/issues/66)
+- 100% test coverage
+- CI-tested on macOS, Linux, and Windows
+- Actively maintained
+- Doesn't bundle a CLI
+- Uses the native `fs.mkdir/mkdirSync` [`recursive` option](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_mkdir_path_options_callback) in Node.js >=10.12.0 unless [overridden](#fs)
+
+## Install
+
+```
+$ npm install make-dir
+```
+
+## Usage
+
+```
+$ pwd
+/Users/sindresorhus/fun
+$ tree
+.
+```
+
+```js
+const makeDir = require('make-dir');
+
+(async () => {
+ const path = await makeDir('unicorn/rainbow/cake');
+
+ console.log(path);
+ //=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
+})();
+```
+
+```
+$ tree
+.
+└── unicorn
+ └── rainbow
+ └── cake
+```
+
+Multiple directories:
+
+```js
+const makeDir = require('make-dir');
+
+(async () => {
+ const paths = await Promise.all([
+ makeDir('unicorn/rainbow'),
+ makeDir('foo/bar')
+ ]);
+
+ console.log(paths);
+ /*
+ [
+ '/Users/sindresorhus/fun/unicorn/rainbow',
+ '/Users/sindresorhus/fun/foo/bar'
+ ]
+ */
+})();
+```
+
+## API
+
+### makeDir(path, options?)
+
+Returns a `Promise` for the path to the created directory.
+
+### makeDir.sync(path, options?)
+
+Returns the path to the created directory.
+
+#### path
+
+Type: `string`
+
+Directory to create.
+
+#### options
+
+Type: `object`
+
+##### mode
+
+Type: `integer`\
+Default: `0o777`
+
+Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
+
+##### fs
+
+Type: `object`\
+Default: `require('fs')`
+
+Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
+
+Using a custom `fs` implementation will block the use of the native `recursive` option if `fs.mkdir` or `fs.mkdirSync` is not the native function.
+
+## Related
+
+- [make-dir-cli](https://github.com/sindresorhus/make-dir-cli) - CLI for this module
+- [del](https://github.com/sindresorhus/del) - Delete files and directories
+- [globby](https://github.com/sindresorhus/globby) - User-friendly glob matching
+- [cpy](https://github.com/sindresorhus/cpy) - Copy files
+- [cpy-cli](https://github.com/sindresorhus/cpy-cli) - Copy files on the command-line
+- [move-file](https://github.com/sindresorhus/move-file) - Move a file
+
+---
+
+<div align="center">
+ <b>
+ <a href="https://tidelift.com/subscription/pkg/npm-make-dir?utm_source=npm-make-dir&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
+ </b>
+ <br>
+ <sub>
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
+ </sub>
+</div>