@cjser/move-file 4.1.0-cjser.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjser/index.cjs +145 -0
- package/index.d.ts +92 -0
- package/index.js +119 -0
- package/license +9 -0
- package/package.json +82 -0
- package/readme.md +116 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// packages/@cjser/move-file.tmp-26-1778153581865/index.js
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
moveFile: () => moveFile,
|
|
33
|
+
moveFileSync: () => moveFileSync,
|
|
34
|
+
renameFile: () => renameFile,
|
|
35
|
+
renameFileSync: () => renameFileSync
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
var import_node_process = __toESM(require("node:process"), 1);
|
|
39
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
40
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
41
|
+
var resolvePath = (cwd, sourcePath, destinationPath) => {
|
|
42
|
+
sourcePath = import_node_path.default.resolve(cwd, sourcePath);
|
|
43
|
+
destinationPath = import_node_path.default.resolve(cwd, destinationPath);
|
|
44
|
+
return {
|
|
45
|
+
sourcePath,
|
|
46
|
+
destinationPath
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
var validatePathsExist = (sourcePath, destinationPath, suffix = "Path") => {
|
|
50
|
+
if (!sourcePath || !destinationPath) {
|
|
51
|
+
throw new TypeError(`\`source${suffix}\` and \`destination${suffix}\` required`);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var validateSameDirectory = (source, destination) => {
|
|
55
|
+
if (import_node_path.default.dirname(source) !== import_node_path.default.dirname(destination)) {
|
|
56
|
+
throw new Error("`source` and `destination` must be in the same directory");
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var _moveFile = async (sourcePath, destinationPath, { overwrite = true, cwd = import_node_process.default.cwd(), directoryMode, validateDirectory = false } = {}) => {
|
|
60
|
+
if (cwd) {
|
|
61
|
+
({ sourcePath, destinationPath } = resolvePath(cwd, sourcePath, destinationPath));
|
|
62
|
+
}
|
|
63
|
+
if (validateDirectory) {
|
|
64
|
+
validateSameDirectory(sourcePath, destinationPath);
|
|
65
|
+
}
|
|
66
|
+
if (!overwrite && import_node_fs.default.existsSync(destinationPath)) {
|
|
67
|
+
throw new Error(`The destination file exists: ${destinationPath}`);
|
|
68
|
+
}
|
|
69
|
+
await import_node_fs.promises.mkdir(import_node_path.default.dirname(destinationPath), {
|
|
70
|
+
recursive: true,
|
|
71
|
+
mode: directoryMode
|
|
72
|
+
});
|
|
73
|
+
try {
|
|
74
|
+
await import_node_fs.promises.rename(sourcePath, destinationPath);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (error.code === "EXDEV") {
|
|
77
|
+
const stats = await import_node_fs.promises.lstat(sourcePath);
|
|
78
|
+
if (stats.isSymbolicLink()) {
|
|
79
|
+
const target = await import_node_fs.promises.readlink(sourcePath);
|
|
80
|
+
await import_node_fs.promises.symlink(target, destinationPath);
|
|
81
|
+
await import_node_fs.promises.unlink(sourcePath);
|
|
82
|
+
} else {
|
|
83
|
+
await import_node_fs.promises.cp(sourcePath, destinationPath, { recursive: true, preserveTimestamps: true });
|
|
84
|
+
await import_node_fs.promises.rm(sourcePath, { recursive: true });
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var _moveFileSync = (sourcePath, destinationPath, { overwrite = true, cwd = import_node_process.default.cwd(), directoryMode, validateDirectory = false } = {}) => {
|
|
92
|
+
if (cwd) {
|
|
93
|
+
({ sourcePath, destinationPath } = resolvePath(cwd, sourcePath, destinationPath));
|
|
94
|
+
}
|
|
95
|
+
if (validateDirectory) {
|
|
96
|
+
validateSameDirectory(sourcePath, destinationPath);
|
|
97
|
+
}
|
|
98
|
+
if (!overwrite && import_node_fs.default.existsSync(destinationPath)) {
|
|
99
|
+
throw new Error(`The destination file exists: ${destinationPath}`);
|
|
100
|
+
}
|
|
101
|
+
import_node_fs.default.mkdirSync(import_node_path.default.dirname(destinationPath), {
|
|
102
|
+
recursive: true,
|
|
103
|
+
mode: directoryMode
|
|
104
|
+
});
|
|
105
|
+
try {
|
|
106
|
+
import_node_fs.default.renameSync(sourcePath, destinationPath);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (error.code === "EXDEV") {
|
|
109
|
+
const stats = import_node_fs.default.lstatSync(sourcePath);
|
|
110
|
+
if (stats.isSymbolicLink()) {
|
|
111
|
+
const target = import_node_fs.default.readlinkSync(sourcePath);
|
|
112
|
+
import_node_fs.default.symlinkSync(target, destinationPath);
|
|
113
|
+
import_node_fs.default.unlinkSync(sourcePath);
|
|
114
|
+
} else {
|
|
115
|
+
import_node_fs.default.cpSync(sourcePath, destinationPath, { recursive: true, preserveTimestamps: true });
|
|
116
|
+
import_node_fs.default.rmSync(sourcePath, { recursive: true });
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
async function moveFile(sourcePath, destinationPath, options) {
|
|
124
|
+
validatePathsExist(sourcePath, destinationPath);
|
|
125
|
+
return _moveFile(sourcePath, destinationPath, options);
|
|
126
|
+
}
|
|
127
|
+
function moveFileSync(sourcePath, destinationPath, options) {
|
|
128
|
+
validatePathsExist(sourcePath, destinationPath);
|
|
129
|
+
return _moveFileSync(sourcePath, destinationPath, options);
|
|
130
|
+
}
|
|
131
|
+
async function renameFile(source, destination, options = {}) {
|
|
132
|
+
validatePathsExist(source, destination, "");
|
|
133
|
+
return _moveFile(source, destination, { ...options, validateDirectory: true });
|
|
134
|
+
}
|
|
135
|
+
function renameFileSync(source, destination, options = {}) {
|
|
136
|
+
validatePathsExist(source, destination, "");
|
|
137
|
+
return _moveFileSync(source, destination, { ...options, validateDirectory: true });
|
|
138
|
+
}
|
|
139
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
140
|
+
0 && (module.exports = {
|
|
141
|
+
moveFile,
|
|
142
|
+
moveFileSync,
|
|
143
|
+
renameFile,
|
|
144
|
+
renameFileSync
|
|
145
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export type Options = {
|
|
2
|
+
/**
|
|
3
|
+
Overwrite existing destination file.
|
|
4
|
+
|
|
5
|
+
@default true
|
|
6
|
+
*/
|
|
7
|
+
readonly overwrite?: boolean;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
The working directory to find source files.
|
|
11
|
+
|
|
12
|
+
The source and destination path are relative to this.
|
|
13
|
+
|
|
14
|
+
@default process.cwd()
|
|
15
|
+
*/
|
|
16
|
+
readonly cwd?: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
[Permissions](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) for created directories.
|
|
20
|
+
|
|
21
|
+
It has no effect on Windows.
|
|
22
|
+
|
|
23
|
+
@default 0o777
|
|
24
|
+
*/
|
|
25
|
+
readonly directoryMode?: number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
Move a file, directory, or symlink asynchronously.
|
|
30
|
+
|
|
31
|
+
@param sourcePath - The file, directory, or symlink you want to move.
|
|
32
|
+
@param destinationPath - Where you want it moved.
|
|
33
|
+
@returns A `Promise` that resolves when the file, directory, or symlink has been moved.
|
|
34
|
+
|
|
35
|
+
@example
|
|
36
|
+
```
|
|
37
|
+
import {moveFile} from '@cjser/move-file';
|
|
38
|
+
|
|
39
|
+
await moveFile('source/unicorn.png', 'destination/unicorn.png');
|
|
40
|
+
console.log('The file has been moved');
|
|
41
|
+
```
|
|
42
|
+
*/
|
|
43
|
+
export function moveFile(sourcePath: string, destinationPath: string, options?: Options): Promise<void>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
Move a file, directory, or symlink synchronously.
|
|
47
|
+
|
|
48
|
+
@param sourcePath - The file, directory, or symlink you want to move.
|
|
49
|
+
@param destinationPath - Where you want it moved.
|
|
50
|
+
|
|
51
|
+
@example
|
|
52
|
+
```
|
|
53
|
+
import {moveFileSync} from '@cjser/move-file';
|
|
54
|
+
|
|
55
|
+
moveFileSync('source/unicorn.png', 'destination/unicorn.png');
|
|
56
|
+
console.log('The file has been moved');
|
|
57
|
+
```
|
|
58
|
+
*/
|
|
59
|
+
export function moveFileSync(sourcePath: string, destinationPath: string, options?: Options): void;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
Rename a file asynchronously.
|
|
63
|
+
|
|
64
|
+
@param source - The file you want to rename.
|
|
65
|
+
@param destination - The name of the renamed file.
|
|
66
|
+
@returns A `Promise` that resolves when the file has been renamed.
|
|
67
|
+
|
|
68
|
+
@example
|
|
69
|
+
```
|
|
70
|
+
import {renameFile} from '@cjser/move-file';
|
|
71
|
+
|
|
72
|
+
await renameFile('unicorn.png', 'unicorns.png', {cwd: 'source'});
|
|
73
|
+
console.log('The file has been renamed');
|
|
74
|
+
```
|
|
75
|
+
*/
|
|
76
|
+
export function renameFile(source: string, destination: string, options?: Options): Promise<void>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
Rename a file synchronously.
|
|
80
|
+
|
|
81
|
+
@param source - The file you want to rename.
|
|
82
|
+
@param destination - The name of the renamed file.
|
|
83
|
+
|
|
84
|
+
@example
|
|
85
|
+
```
|
|
86
|
+
import {renameFileSync} from '@cjser/move-file';
|
|
87
|
+
|
|
88
|
+
renameFileSync('unicorn.png', 'unicorns.png', {cwd: 'source'});
|
|
89
|
+
console.log('The file has been renamed');
|
|
90
|
+
```
|
|
91
|
+
*/
|
|
92
|
+
export function renameFileSync(source: string, destination: string, options?: Options): void;
|
package/index.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fs, {promises as fsPromises} from 'node:fs';
|
|
4
|
+
|
|
5
|
+
const resolvePath = (cwd, sourcePath, destinationPath) => {
|
|
6
|
+
sourcePath = path.resolve(cwd, sourcePath);
|
|
7
|
+
destinationPath = path.resolve(cwd, destinationPath);
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
sourcePath,
|
|
11
|
+
destinationPath,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const validatePathsExist = (sourcePath, destinationPath, suffix = 'Path') => {
|
|
16
|
+
if (!sourcePath || !destinationPath) {
|
|
17
|
+
throw new TypeError(`\`source${suffix}\` and \`destination${suffix}\` required`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const validateSameDirectory = (source, destination) => {
|
|
22
|
+
if (path.dirname(source) !== path.dirname(destination)) {
|
|
23
|
+
throw new Error('`source` and `destination` must be in the same directory');
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const _moveFile = async (sourcePath, destinationPath, {overwrite = true, cwd = process.cwd(), directoryMode, validateDirectory = false} = {}) => {
|
|
28
|
+
if (cwd) {
|
|
29
|
+
({sourcePath, destinationPath} = resolvePath(cwd, sourcePath, destinationPath));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (validateDirectory) {
|
|
33
|
+
validateSameDirectory(sourcePath, destinationPath);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!overwrite && fs.existsSync(destinationPath)) {
|
|
37
|
+
throw new Error(`The destination file exists: ${destinationPath}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await fsPromises.mkdir(path.dirname(destinationPath), {
|
|
41
|
+
recursive: true,
|
|
42
|
+
mode: directoryMode,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
await fsPromises.rename(sourcePath, destinationPath);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (error.code === 'EXDEV') {
|
|
49
|
+
const stats = await fsPromises.lstat(sourcePath);
|
|
50
|
+
if (stats.isSymbolicLink()) {
|
|
51
|
+
const target = await fsPromises.readlink(sourcePath);
|
|
52
|
+
await fsPromises.symlink(target, destinationPath);
|
|
53
|
+
await fsPromises.unlink(sourcePath);
|
|
54
|
+
} else {
|
|
55
|
+
await fsPromises.cp(sourcePath, destinationPath, {recursive: true, preserveTimestamps: true});
|
|
56
|
+
await fsPromises.rm(sourcePath, {recursive: true});
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const _moveFileSync = (sourcePath, destinationPath, {overwrite = true, cwd = process.cwd(), directoryMode, validateDirectory = false} = {}) => {
|
|
65
|
+
if (cwd) {
|
|
66
|
+
({sourcePath, destinationPath} = resolvePath(cwd, sourcePath, destinationPath));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (validateDirectory) {
|
|
70
|
+
validateSameDirectory(sourcePath, destinationPath);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!overwrite && fs.existsSync(destinationPath)) {
|
|
74
|
+
throw new Error(`The destination file exists: ${destinationPath}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fs.mkdirSync(path.dirname(destinationPath), {
|
|
78
|
+
recursive: true,
|
|
79
|
+
mode: directoryMode,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
fs.renameSync(sourcePath, destinationPath);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error.code === 'EXDEV') {
|
|
86
|
+
const stats = fs.lstatSync(sourcePath);
|
|
87
|
+
if (stats.isSymbolicLink()) {
|
|
88
|
+
const target = fs.readlinkSync(sourcePath);
|
|
89
|
+
fs.symlinkSync(target, destinationPath);
|
|
90
|
+
fs.unlinkSync(sourcePath);
|
|
91
|
+
} else {
|
|
92
|
+
fs.cpSync(sourcePath, destinationPath, {recursive: true, preserveTimestamps: true});
|
|
93
|
+
fs.rmSync(sourcePath, {recursive: true});
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export async function moveFile(sourcePath, destinationPath, options) {
|
|
102
|
+
validatePathsExist(sourcePath, destinationPath);
|
|
103
|
+
return _moveFile(sourcePath, destinationPath, options);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function moveFileSync(sourcePath, destinationPath, options) {
|
|
107
|
+
validatePathsExist(sourcePath, destinationPath);
|
|
108
|
+
return _moveFileSync(sourcePath, destinationPath, options);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function renameFile(source, destination, options = {}) {
|
|
112
|
+
validatePathsExist(source, destination, '');
|
|
113
|
+
return _moveFile(source, destination, {...options, validateDirectory: true});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function renameFileSync(source, destination, options = {}) {
|
|
117
|
+
validatePathsExist(source, destination, '');
|
|
118
|
+
return _moveFileSync(source, destination, {...options, validateDirectory: true});
|
|
119
|
+
}
|
package/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
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:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
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.
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cjser/move-file",
|
|
3
|
+
"version": "4.1.0-cjser.2",
|
|
4
|
+
"description": "Move a file, directory, or symlink - Even works across devices",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://code.moenext.com/3rdeye/cjser.git"
|
|
9
|
+
},
|
|
10
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Sindre Sorhus",
|
|
13
|
+
"email": "sindresorhus@gmail.com",
|
|
14
|
+
"url": "https://sindresorhus.com"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
"types": "./index.d.ts",
|
|
19
|
+
"require": "./dist-cjser/index.cjs",
|
|
20
|
+
"default": "./index.js"
|
|
21
|
+
},
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "xo && ava && tsd"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"index.js",
|
|
31
|
+
"index.d.ts",
|
|
32
|
+
"dist-cjser"
|
|
33
|
+
],
|
|
34
|
+
"keywords": [
|
|
35
|
+
"move",
|
|
36
|
+
"file",
|
|
37
|
+
"directory",
|
|
38
|
+
"folder",
|
|
39
|
+
"symlink",
|
|
40
|
+
"mv",
|
|
41
|
+
"fs",
|
|
42
|
+
"file-system",
|
|
43
|
+
"devices",
|
|
44
|
+
"partitions"
|
|
45
|
+
],
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^25.0.10",
|
|
48
|
+
"ava": "^6.4.1",
|
|
49
|
+
"sinon": "^21.0.1",
|
|
50
|
+
"temp-write": "^6.0.0",
|
|
51
|
+
"tempy": "^3.1.2",
|
|
52
|
+
"tsd": "^0.33.0",
|
|
53
|
+
"xo": "^1.2.3"
|
|
54
|
+
},
|
|
55
|
+
"xo": {
|
|
56
|
+
"rules": {
|
|
57
|
+
"no-bitwise": "off"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"types": "./index.d.ts",
|
|
61
|
+
"main": "./dist-cjser/index.cjs",
|
|
62
|
+
"cjser": {
|
|
63
|
+
"sourceVersion": "4.1.0",
|
|
64
|
+
"cjserVersion": 2,
|
|
65
|
+
"original": {
|
|
66
|
+
"name": "move-file",
|
|
67
|
+
"version": "4.1.0",
|
|
68
|
+
"exports": {
|
|
69
|
+
"types": "./index.d.ts",
|
|
70
|
+
"default": "./index.js"
|
|
71
|
+
},
|
|
72
|
+
"repository": "sindresorhus/move-file",
|
|
73
|
+
"files": [
|
|
74
|
+
"index.js",
|
|
75
|
+
"index.d.ts"
|
|
76
|
+
],
|
|
77
|
+
"scripts": {
|
|
78
|
+
"test": "xo && ava && tsd"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# move-file
|
|
2
|
+
|
|
3
|
+
> Move a file, directory, or symlink
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
## Highlights
|
|
8
|
+
|
|
9
|
+
- Promise API.
|
|
10
|
+
- Supports moving a file, directory, or symlink across partitions and devices.
|
|
11
|
+
- Optionally prevent overwriting an existing file.
|
|
12
|
+
- Creates non-existent destination directories for you.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install move-file
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import {moveFile} from 'move-file';
|
|
24
|
+
|
|
25
|
+
await moveFile('source/unicorn.png', 'destination/unicorn.png');
|
|
26
|
+
console.log('The file has been moved');
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API
|
|
30
|
+
|
|
31
|
+
### moveFile(sourcePath, destinationPath, options?)
|
|
32
|
+
|
|
33
|
+
Returns a `Promise` that resolves when the file, directory, or symlink has been moved.
|
|
34
|
+
|
|
35
|
+
### moveFileSync(sourcePath, destinationPath, options?)
|
|
36
|
+
|
|
37
|
+
#### sourcePath
|
|
38
|
+
|
|
39
|
+
Type: `string`
|
|
40
|
+
|
|
41
|
+
The file, directory, or symlink you want to move.
|
|
42
|
+
|
|
43
|
+
#### destinationPath
|
|
44
|
+
|
|
45
|
+
Type: `string`
|
|
46
|
+
|
|
47
|
+
Where you want it moved.
|
|
48
|
+
|
|
49
|
+
#### options
|
|
50
|
+
|
|
51
|
+
Type: `object`
|
|
52
|
+
|
|
53
|
+
See [Options](#options-2).
|
|
54
|
+
|
|
55
|
+
### renameFile(source, destination, options?)
|
|
56
|
+
|
|
57
|
+
Returns a `Promise` that resolves when the file has been renamed. `source` and `destination` must be in the same directory.
|
|
58
|
+
|
|
59
|
+
### renameFileSync(source, destination, options?)
|
|
60
|
+
|
|
61
|
+
#### source
|
|
62
|
+
|
|
63
|
+
Type: `string`
|
|
64
|
+
|
|
65
|
+
The file you want to rename.
|
|
66
|
+
|
|
67
|
+
#### destination
|
|
68
|
+
|
|
69
|
+
Type: `string`
|
|
70
|
+
|
|
71
|
+
What you want to rename the file to.
|
|
72
|
+
|
|
73
|
+
#### options
|
|
74
|
+
|
|
75
|
+
Type: `object`
|
|
76
|
+
|
|
77
|
+
See [Options](#options-2).
|
|
78
|
+
|
|
79
|
+
### Options
|
|
80
|
+
|
|
81
|
+
##### overwrite
|
|
82
|
+
|
|
83
|
+
Type: `boolean`\
|
|
84
|
+
Default: `true`
|
|
85
|
+
|
|
86
|
+
Overwrite existing destination file.
|
|
87
|
+
|
|
88
|
+
##### cwd
|
|
89
|
+
|
|
90
|
+
Type: `string`\
|
|
91
|
+
Default: `process.cwd()`
|
|
92
|
+
|
|
93
|
+
The working directory to find source files.
|
|
94
|
+
|
|
95
|
+
The source and destination path are relative to this.
|
|
96
|
+
|
|
97
|
+
##### directoryMode
|
|
98
|
+
|
|
99
|
+
Type: `number`\
|
|
100
|
+
Default: `0o777`
|
|
101
|
+
|
|
102
|
+
[Permissions](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) for created directories.
|
|
103
|
+
|
|
104
|
+
It has no effect on Windows.
|
|
105
|
+
|
|
106
|
+
## Related
|
|
107
|
+
|
|
108
|
+
- [move-file-cli](https://github.com/sindresorhus/move-file-cli) - CLI for this module
|
|
109
|
+
- [copy-file](https://github.com/sindresorhus/copy-file) - Copy a file
|
|
110
|
+
- [cpy](https://github.com/sindresorhus/cpy) - Copy files
|
|
111
|
+
- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed
|
|
112
|
+
|
|
113
|
+
## cjser
|
|
114
|
+
|
|
115
|
+
This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
|
|
116
|
+
Original repository: https://github.com/sindresorhus/move-file
|