UNPKG

1.03 kBJavaScriptView Raw
1/*!
2 * delete <https://github.com/jonschlinkert/delete>
3 *
4 * Copyright (c) 2014 Jon Schlinkert, contributors.
5 * Licensed under the MIT license.
6 */
7
8'use strict';
9
10var isPathCwd = require('is-path-cwd');
11var isPathInCwd = require('is-path-in-cwd');
12var rimraf = require('rimraf');
13
14function safeCheck(filepath) {
15 if (isPathCwd(filepath)) {
16 throw new Error('Cannot delete the current working directory. Can be overriden with the `force` option.');
17 }
18
19 if (!isPathInCwd(filepath)) {
20 throw new Error('Cannot delete files/folders outside the current working directory. Can be overriden with the `force` option.');
21 }
22}
23
24module.exports = function (filepath, options, next) {
25 if (typeof options === 'function') {
26 next = options;
27 options = {};
28 }
29
30 if (!(options && options.force)) {
31 safeCheck(filepath);
32 }
33 return rimraf(filepath, next);
34};
35
36
37module.exports.sync = function (filepath, options) {
38 if (!(options && options.force)) {
39 safeCheck(filepath);
40 }
41 return rimraf.sync(filepath);
42};