diff options
Diffstat (limited to 'deps/npm/node_modules/@npmcli/move-file')
-rw-r--r-- | deps/npm/node_modules/@npmcli/move-file/LICENSE.md | 22 | ||||
-rw-r--r-- | deps/npm/node_modules/@npmcli/move-file/README.md | 68 | ||||
-rw-r--r-- | deps/npm/node_modules/@npmcli/move-file/index.js | 93 | ||||
-rw-r--r-- | deps/npm/node_modules/@npmcli/move-file/package.json | 33 |
4 files changed, 216 insertions, 0 deletions
diff --git a/deps/npm/node_modules/@npmcli/move-file/LICENSE.md b/deps/npm/node_modules/@npmcli/move-file/LICENSE.md new file mode 100644 index 0000000000..072bf20840 --- /dev/null +++ b/deps/npm/node_modules/@npmcli/move-file/LICENSE.md @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com) +Copyright (c) npm, Inc. + +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/deps/npm/node_modules/@npmcli/move-file/README.md b/deps/npm/node_modules/@npmcli/move-file/README.md new file mode 100644 index 0000000000..da682ebd51 --- /dev/null +++ b/deps/npm/node_modules/@npmcli/move-file/README.md @@ -0,0 +1,68 @@ +# @npmcli/move-file + +A fork of [move-file](https://github.com/sindresorhus/move-file) with +compatibility with all node 10.x versions. + +> Move a file + +The built-in +[`fs.rename()`](https://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback) +is just a JavaScript wrapper for the C `rename(2)` function, which doesn't +support moving files across partitions or devices. This module is what you +would have expected `fs.rename()` to be. + +## Highlights + +- Promise API. +- Supports moving a file across partitions and devices. +- Optionally prevent overwriting an existing file. +- Creates non-existent destination directories for you. +- Support for Node versions that lack built-in recursive `fs.mkdir()` + +## Install + +``` +$ npm install @npmcli/move-file +``` + +## Usage + +```js +const moveFile = require('@npmcli/move-file'); + +(async () => { + await moveFile('source/unicorn.png', 'destination/unicorn.png'); + console.log('The file has been moved'); +})(); +``` + +## API + +### moveFile(source, destination, options?) + +Returns a `Promise` that resolves when the file has been moved. + +### moveFile.sync(source, destination, options?) + +#### source + +Type: `string` + +File you want to move. + +#### destination + +Type: `string` + +Where you want the file moved. + +#### options + +Type: `object` + +##### overwrite + +Type: `boolean`\ +Default: `true` + +Overwrite existing destination file. diff --git a/deps/npm/node_modules/@npmcli/move-file/index.js b/deps/npm/node_modules/@npmcli/move-file/index.js new file mode 100644 index 0000000000..d1567d1f64 --- /dev/null +++ b/deps/npm/node_modules/@npmcli/move-file/index.js @@ -0,0 +1,93 @@ +const { dirname } = require('path') +const { promisify } = require('util') +const { + access: access_, + accessSync, + copyFile: copyFile_, + copyFileSync, + unlink: unlink_, + unlinkSync, + rename: rename_, + renameSync, +} = require('fs') + +const access = promisify(access_) +const copyFile = promisify(copyFile_) +const unlink = promisify(unlink_) +const rename = promisify(rename_) + +const mkdirp = require('mkdirp') + +const pathExists = async path => { + try { + await access(path) + return true + } catch (er) { + return er.code !== 'ENOENT' + } +} + +const pathExistsSync = path => { + try { + accessSync(path) + return true + } catch (er) { + return er.code !== 'ENOENT' + } +} + +module.exports = async (source, destination, options = {}) => { + if (!source || !destination) { + throw new TypeError('`source` and `destination` file required') + } + + options = { + overwrite: true, + ...options + } + + if (!options.overwrite && await pathExists(destination)) { + throw new Error(`The destination file exists: ${destination}`) + } + + await mkdirp(dirname(destination)) + + try { + await rename(source, destination) + } catch (error) { + if (error.code === 'EXDEV') { + await copyFile(source, destination) + await unlink(source) + } else { + throw error + } + } +} + +module.exports.sync = (source, destination, options = {}) => { + if (!source || !destination) { + throw new TypeError('`source` and `destination` file required') + } + + options = { + overwrite: true, + ...options + } + + if (!options.overwrite && pathExistsSync(destination)) { + throw new Error(`The destination file exists: ${destination}`) + } + + mkdirp.sync(dirname(destination)) + + try { + renameSync(source, destination) + } catch (error) { + if (error.code === 'EXDEV') { + copyFileSync(source, destination) + unlinkSync(source) + } else { + throw error + } + } +} diff --git a/deps/npm/node_modules/@npmcli/move-file/package.json b/deps/npm/node_modules/@npmcli/move-file/package.json new file mode 100644 index 0000000000..476bc76ba7 --- /dev/null +++ b/deps/npm/node_modules/@npmcli/move-file/package.json @@ -0,0 +1,33 @@ +{ + "name": "@npmcli/move-file", + "version": "1.0.1", + "files": [ + "index.js" + ], + "description": "move a file (fork of move-file)", + "dependencies": { + "mkdirp": "^1.0.4" + }, + "devDependencies": { + "require-inject": "^1.4.4", + "tap": "^14.10.7" + }, + "scripts": { + "test": "tap", + "snap": "tap", + "preversion": "npm test", + "postversion": "npm publish", + "prepublishOnly": "git push origin --follow-tags" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/npm/move-file" + }, + "tap": { + "check-coverage": true + }, + "license": "MIT", + "engines": { + "node": ">=10" + } +} |