pax_global_header00006660000000000000000000000064137335023110014510gustar00rootroot0000000000000052 comment=cd0543eb74807173a2015002907e98094ce3a78e del-6.0.0/000077500000000000000000000000001373350231100122575ustar00rootroot00000000000000del-6.0.0/.editorconfig000066400000000000000000000002571373350231100147400ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 del-6.0.0/.gitattributes000066400000000000000000000000231373350231100151450ustar00rootroot00000000000000* text=auto eol=lf del-6.0.0/.github/000077500000000000000000000000001373350231100136175ustar00rootroot00000000000000del-6.0.0/.github/funding.yml000066400000000000000000000001551373350231100157750ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/del custom: https://sindresorhus.com/donate del-6.0.0/.github/security.md000066400000000000000000000002631373350231100160110ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. del-6.0.0/.gitignore000066400000000000000000000000271373350231100142460ustar00rootroot00000000000000node_modules yarn.lock del-6.0.0/.npmrc000066400000000000000000000000231373350231100133720ustar00rootroot00000000000000package-lock=false del-6.0.0/.travis.yml000066400000000000000000000001301373350231100143620ustar00rootroot00000000000000os: - linux - osx - windows language: node_js node_js: - '14' - '12' - '10' del-6.0.0/benchmark.js000066400000000000000000000032601373350231100145500ustar00rootroot00000000000000'use strict'; const path = require('path'); const Benchmark = require('benchmark'); const makeDir = require('make-dir'); const tempy = require('tempy'); const del = require('.'); const suite = new Benchmark.Suite('concurrency'); const temporaryDir = tempy.directory(); const fixtures = Array.from({length: 2000}, (_, index) => { return path.resolve(temporaryDir, (index + 1).toString()); }); function createFixtures() { for (const fixture of fixtures) { makeDir.sync(path.resolve(temporaryDir, fixture)); } } const concurrencies = [ 1, 3, 5, 10, 15, 20, 50, 100, 200, 300, 400, 500, 1000, Infinity ]; for (const concurrency of concurrencies) { const name = `concurrency: ${concurrency.toString()}`; suite.add({ name, defer: true, async fn(deferred) { // Can't use `setup()` because it isn't called after every // defer and it breaks using `async` keyword here. // https://github.com/bestiejs/benchmark.js/issues/136 createFixtures(); const removedFiles = await del(['**/*'], { cwd: temporaryDir, concurrency }); if (removedFiles.length !== fixtures.length) { const error = new Error( `"${name}": files removed: ${removedFiles.length}, expected: ${fixtures.length}` ); console.error(error); del.sync(temporaryDir, {cwd: temporaryDir, force: true}); // eslint-disable-next-line unicorn/no-process-exit process.exit(1); } deferred.resolve(); } }); } suite .on('cycle', event => { console.log(String(event.target)); }) .on('complete', function () { console.log(`Fastest is ${this.filter('fastest').map('name')}`); del.sync(temporaryDir, {cwd: temporaryDir, force: true}); }) .run({async: true}); del-6.0.0/index.d.ts000066400000000000000000000056351373350231100141710ustar00rootroot00000000000000import {GlobbyOptions} from 'globby'; declare namespace del { interface Options extends GlobbyOptions { /** Allow deleting the current working directory and outside. @default false */ readonly force?: boolean; /** See what would be deleted. @default false @example ``` import del = require('del'); (async () => { const deletedPaths = await del(['temp/*.js'], {dryRun: true}); console.log('Files and directories that would be deleted:\n', deletedPaths.join('\n')); })(); ``` */ readonly dryRun?: boolean; /** Concurrency limit. Minimum: `1`. @default Infinity */ readonly concurrency?: number; } } declare const del: { /** Synchronously delete files and directories using glob patterns. Note that glob patterns can only contain forward-slashes, not backward-slashes. Windows file paths can use backward-slashes as long as the path does not contain any glob-like characters, otherwise use `path.posix.join()` instead of `path.join()`. @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js) - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns) @param options - You can specify any of the [`globby` options](https://github.com/sindresorhus/globby#options) in addition to the `del` options. In contrast to the `globby` defaults, `expandDirectories`, `onlyFiles`, and `followSymbolicLinks` are `false` by default. @returns The deleted paths. */ sync: ( patterns: string | readonly string[], options?: del.Options ) => string[]; /** Delete files and directories using glob patterns. Note that glob patterns can only contain forward-slashes, not backward-slashes. Windows file paths can use backward-slashes as long as the path does not contain any glob-like characters, otherwise use `path.posix.join()` instead of `path.join()`. @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js) - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns) @param options - You can specify any of the [`globby` options](https://github.com/sindresorhus/globby#options) in addition to the `del` options. In contrast to the `globby` defaults, `expandDirectories`, `onlyFiles`, and `followSymbolicLinks` are `false` by default. @returns The deleted paths. @example ``` import del = require('del'); (async () => { const deletedPaths = await del(['temp/*.js', '!temp/unicorn.js']); console.log('Deleted files and directories:\n', deletedPaths.join('\n')); })(); ``` */ ( patterns: string | readonly string[], options?: del.Options ): Promise; }; export = del; del-6.0.0/index.js000066400000000000000000000052641373350231100137330ustar00rootroot00000000000000'use strict'; const {promisify} = require('util'); const path = require('path'); const globby = require('globby'); const isGlob = require('is-glob'); const slash = require('slash'); const gracefulFs = require('graceful-fs'); const isPathCwd = require('is-path-cwd'); const isPathInside = require('is-path-inside'); const rimraf = require('rimraf'); const pMap = require('p-map'); const rimrafP = promisify(rimraf); const rimrafOptions = { glob: false, unlink: gracefulFs.unlink, unlinkSync: gracefulFs.unlinkSync, chmod: gracefulFs.chmod, chmodSync: gracefulFs.chmodSync, stat: gracefulFs.stat, statSync: gracefulFs.statSync, lstat: gracefulFs.lstat, lstatSync: gracefulFs.lstatSync, rmdir: gracefulFs.rmdir, rmdirSync: gracefulFs.rmdirSync, readdir: gracefulFs.readdir, readdirSync: gracefulFs.readdirSync }; function safeCheck(file, cwd) { if (isPathCwd(file)) { throw new Error('Cannot delete the current working directory. Can be overridden with the `force` option.'); } if (!isPathInside(file, cwd)) { throw new Error('Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.'); } } function normalizePatterns(patterns) { patterns = Array.isArray(patterns) ? patterns : [patterns]; patterns = patterns.map(pattern => { if (process.platform === 'win32' && isGlob(pattern) === false) { return slash(pattern); } return pattern; }); return patterns; } module.exports = async (patterns, {force, dryRun, cwd = process.cwd(), ...options} = {}) => { options = { expandDirectories: false, onlyFiles: false, followSymbolicLinks: false, cwd, ...options }; patterns = normalizePatterns(patterns); const files = (await globby(patterns, options)) .sort((a, b) => b.localeCompare(a)); const mapper = async file => { file = path.resolve(cwd, file); if (!force) { safeCheck(file, cwd); } if (!dryRun) { await rimrafP(file, rimrafOptions); } return file; }; const removedFiles = await pMap(files, mapper, options); removedFiles.sort((a, b) => a.localeCompare(b)); return removedFiles; }; module.exports.sync = (patterns, {force, dryRun, cwd = process.cwd(), ...options} = {}) => { options = { expandDirectories: false, onlyFiles: false, followSymbolicLinks: false, cwd, ...options }; patterns = normalizePatterns(patterns); const files = globby.sync(patterns, options) .sort((a, b) => b.localeCompare(a)); const removedFiles = files.map(file => { file = path.resolve(cwd, file); if (!force) { safeCheck(file, cwd); } if (!dryRun) { rimraf.sync(file, rimrafOptions); } return file; }); removedFiles.sort((a, b) => a.localeCompare(b)); return removedFiles; }; del-6.0.0/index.test-d.ts000066400000000000000000000013731373350231100151410ustar00rootroot00000000000000import {expectType} from 'tsd'; import del = require('.'); const paths = [ 'temp/*.js', '!temp/unicorn.js' ]; // Del expectType>(del('temp/*.js')); expectType>(del(paths)); expectType>(del(paths, {force: true})); expectType>(del(paths, {dryRun: true})); expectType>(del(paths, {concurrency: 20})); expectType>(del(paths, {cwd: ''})); // Del (sync) expectType(del.sync('tmp/*.js')); expectType(del.sync(paths)); expectType(del.sync(paths, {force: true})); expectType(del.sync(paths, {dryRun: true})); expectType(del.sync(paths, {concurrency: 20})); expectType(del.sync(paths, {cwd: ''})); del-6.0.0/license000066400000000000000000000021351373350231100136250ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://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. del-6.0.0/package.json000066400000000000000000000021521373350231100145450ustar00rootroot00000000000000{ "name": "del", "version": "6.0.0", "description": "Delete files and directories", "license": "MIT", "repository": "sindresorhus/del", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "engines": { "node": ">=10" }, "scripts": { "test": "xo && ava && tsd", "bench": "node benchmark.js" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "delete", "files", "folders", "directories", "remove", "destroy", "trash", "unlink", "clean", "cleaning", "cleanup", "rm", "rmrf", "rimraf", "rmdir", "glob", "gulpfriendly", "file", "folder", "directory", "fs", "filesystem" ], "dependencies": { "globby": "^11.0.1", "graceful-fs": "^4.2.4", "is-glob": "^4.0.1", "is-path-cwd": "^2.2.0", "is-path-inside": "^3.0.2", "p-map": "^4.0.0", "rimraf": "^3.0.2", "slash": "^3.0.0" }, "devDependencies": { "ava": "^2.4.0", "benchmark": "^2.1.4", "make-dir": "^3.1.0", "tempy": "^0.7.0", "tsd": "^0.13.1", "xo": "^0.33.1" } } del-6.0.0/readme.md000066400000000000000000000074061373350231100140450ustar00rootroot00000000000000# del [![Build Status](https://travis-ci.com/sindresorhus/del.svg?branch=master)](https://travis-ci.com/github/sindresorhus/del) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo) > Delete files and directories using [globs](https://github.com/sindresorhus/globby#globbing-patterns) Similar to [rimraf](https://github.com/isaacs/rimraf), but with a Promise API and support for multiple files and globbing. It also protects you against deleting the current working directory and above. ## Install ``` $ npm install del ``` ## Usage ```js const del = require('del'); (async () => { const deletedFilePaths = await del(['temp/*.js', '!temp/unicorn.js']); const deletedDirectoryPaths = await del(['temp', 'public']); console.log('Deleted files:\n', deletedFilePaths.join('\n')); console.log('\n\n'); console.log('Deleted directories:\n', deletedDirectoryPaths.join('\n)); })(); ``` ## Beware The glob pattern `**` matches all children and *the parent*. So this won't work: ```js del.sync(['public/assets/**', '!public/assets/goat.png']); ``` You have to explicitly ignore the parent directories too: ```js del.sync(['public/assets/**', '!public/assets', '!public/assets/goat.png']); ``` To delete all subdirectories inside `public/`, you can do: ```js del.sync(['public/*/']); ``` Suggestions on how to improve this welcome! ## API Note that glob patterns can only contain forward-slashes, not backward-slashes. Windows file paths can use backward-slashes as long as the path does not contain any glob-like characters, otherwise use `path.posix.join()` instead of `path.join()`. ### del(patterns, options?) Returns `Promise` with the deleted paths. ### del.sync(patterns, options?) Returns `string[]` with the deleted paths. #### patterns Type: `string | string[]` See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js) - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns) #### options Type: `object` You can specify any of the [`globby` options](https://github.com/sindresorhus/globby#options) in addition to the below options. In contrast to the `globby` defaults, `expandDirectories`, `onlyFiles`, and `followSymbolicLinks` are `false` by default. ##### force Type: `boolean`\ Default: `false` Allow deleting the current working directory and outside. ##### dryRun Type: `boolean`\ Default: `false` See what would be deleted. ```js const del = require('del'); (async () => { const deletedPaths = await del(['temp/*.js'], {dryRun: true}); console.log('Files and directories that would be deleted:\n', deletedPaths.join('\n')); })(); ``` ##### concurrency Type: `number`\ Default: `Infinity`\ Minimum: `1` Concurrency limit. ## CLI See [del-cli](https://github.com/sindresorhus/del-cli) for a CLI for this module and [trash-cli](https://github.com/sindresorhus/trash-cli) for a safe version that is suitable for running by hand. ## del for enterprise Available as part of the Tidelift Subscription. The maintainers of del and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-del?utm_source=npm-del&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) ## Related - [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed - [globby](https://github.com/sindresorhus/globby) - User-friendly glob matching del-6.0.0/test.js000066400000000000000000000225521373350231100136020ustar00rootroot00000000000000import path from 'path'; import fs from 'fs'; import {serial as test} from 'ava'; import tempy from 'tempy'; import makeDir from 'make-dir'; import del from '.'; const processCwd = process.cwd(); function exists(t, files) { for (const file of files) { t.true(fs.existsSync(path.join(t.context.tmp, file))); } } function notExists(t, files) { for (const file of files) { t.false(fs.existsSync(path.join(t.context.tmp, file))); } } const fixtures = [ '1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp' ]; test.beforeEach(t => { t.context.tmp = tempy.directory(); for (const fixture of fixtures) { makeDir.sync(path.join(t.context.tmp, fixture)); } }); test('delete files - async', async t => { await del(['*.tmp', '!1*'], {cwd: t.context.tmp}); exists(t, ['1.tmp', '.dot.tmp']); notExists(t, ['2.tmp', '3.tmp', '4.tmp']); }); test('delete files - sync', t => { del.sync(['*.tmp', '!1*'], {cwd: t.context.tmp}); exists(t, ['1.tmp', '.dot.tmp']); notExists(t, ['2.tmp', '3.tmp', '4.tmp']); }); test('take options into account - async', async t => { await del(['*.tmp', '!1*'], { cwd: t.context.tmp, dot: true }); exists(t, ['1.tmp']); notExists(t, ['2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); }); test('take options into account - sync', t => { del.sync(['*.tmp', '!1*'], { cwd: t.context.tmp, dot: true }); exists(t, ['1.tmp']); notExists(t, ['2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); }); test('return deleted files - async', async t => { t.deepEqual( await del('1.tmp', {cwd: t.context.tmp}), [path.join(t.context.tmp, '1.tmp')] ); }); test('return deleted files - sync', t => { t.deepEqual( del.sync('1.tmp', {cwd: t.context.tmp}), [path.join(t.context.tmp, '1.tmp')] ); }); test('don\'t delete files, but return them - async', async t => { const deletedFiles = await del(['*.tmp', '!1*'], { cwd: t.context.tmp, dryRun: true }); exists(t, ['1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); t.deepEqual(deletedFiles, [ path.join(t.context.tmp, '2.tmp'), path.join(t.context.tmp, '3.tmp'), path.join(t.context.tmp, '4.tmp') ]); }); test('don\'t delete files, but return them - sync', t => { const deletedFiles = del.sync(['*.tmp', '!1*'], { cwd: t.context.tmp, dryRun: true }); exists(t, ['1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); t.deepEqual(deletedFiles, [ path.join(t.context.tmp, '2.tmp'), path.join(t.context.tmp, '3.tmp'), path.join(t.context.tmp, '4.tmp') ]); }); // Currently this is only testable locally on macOS. // https://github.com/sindresorhus/del/issues/68 test('does not throw EINVAL - async', async t => { await del('**/*', { cwd: t.context.tmp, dot: true }); const nestedFile = path.resolve(t.context.tmp, 'a/b/c/nested.js'); const totalAttempts = 200; let count = 0; while (count !== totalAttempts) { makeDir.sync(nestedFile); // eslint-disable-next-line no-await-in-loop const removed = await del('**/*', { cwd: t.context.tmp, dot: true }); const expected = [ path.resolve(t.context.tmp, 'a'), path.resolve(t.context.tmp, 'a/b'), path.resolve(t.context.tmp, 'a/b/c'), path.resolve(t.context.tmp, 'a/b/c/nested.js') ]; t.deepEqual(removed, expected); count += 1; } notExists(t, [...fixtures, 'a']); t.is(count, totalAttempts); }); test('does not throw EINVAL - sync', t => { del.sync('**/*', { cwd: t.context.tmp, dot: true }); const nestedFile = path.resolve(t.context.tmp, 'a/b/c/nested.js'); const totalAttempts = 200; let count = 0; while (count !== totalAttempts) { makeDir.sync(nestedFile); const removed = del.sync('**/*', { cwd: t.context.tmp, dot: true }); const expected = [ path.resolve(t.context.tmp, 'a'), path.resolve(t.context.tmp, 'a/b'), path.resolve(t.context.tmp, 'a/b/c'), path.resolve(t.context.tmp, 'a/b/c/nested.js') ]; t.deepEqual(removed, expected); count += 1; } notExists(t, [...fixtures, 'a']); t.is(count, totalAttempts); }); test('delete relative files outside of process.cwd using cwd - async', async t => { await del(['1.tmp'], {cwd: t.context.tmp}); exists(t, ['2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); notExists(t, ['1.tmp']); }); test('delete relative files outside of process.cwd using cwd - sync', t => { del.sync(['1.tmp'], {cwd: t.context.tmp}); exists(t, ['2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); notExists(t, ['1.tmp']); }); test('delete absolute files outside of process.cwd using cwd - async', async t => { const absolutePath = path.resolve(t.context.tmp, '1.tmp'); await del([absolutePath], {cwd: t.context.tmp}); exists(t, ['2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); notExists(t, ['1.tmp']); }); test('delete absolute files outside of process.cwd using cwd - sync', t => { const absolutePath = path.resolve(t.context.tmp, '1.tmp'); del.sync([absolutePath], {cwd: t.context.tmp}); exists(t, ['2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); notExists(t, ['1.tmp']); }); test('cannot delete actual working directory without force: true - async', async t => { process.chdir(t.context.tmp); await t.throwsAsync(del([t.context.tmp]), { instanceOf: Error, message: 'Cannot delete the current working directory. Can be overridden with the `force` option.' }); exists(t, ['', '1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); process.chdir(processCwd); }); test('cannot delete actual working directory without force: true - sync', t => { process.chdir(t.context.tmp); t.throws(() => { del.sync([t.context.tmp]); }, { instanceOf: Error, message: 'Cannot delete the current working directory. Can be overridden with the `force` option.' }); exists(t, ['', '1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); process.chdir(processCwd); }); test('cannot delete actual working directory with cwd option without force: true - async', async t => { process.chdir(t.context.tmp); await t.throwsAsync(del([t.context.tmp], {cwd: __dirname}), { instanceOf: Error, message: 'Cannot delete the current working directory. Can be overridden with the `force` option.' }); exists(t, ['', '1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); process.chdir(processCwd); }); test('cannot delete actual working directory with cwd option without force: true - sync', t => { process.chdir(t.context.tmp); t.throws(() => { del.sync([t.context.tmp], {cwd: __dirname}); }, { instanceOf: Error, message: 'Cannot delete the current working directory. Can be overridden with the `force` option.' }); exists(t, ['', '1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); process.chdir(processCwd); }); test('cannot delete files outside cwd without force: true - async', async t => { const absolutePath = path.resolve(t.context.tmp, '1.tmp'); await t.throwsAsync(del([absolutePath]), { instanceOf: Error, message: 'Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.' }); exists(t, ['1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); }); test('cannot delete files outside cwd without force: true - sync', t => { const absolutePath = path.resolve(t.context.tmp, '1.tmp'); t.throws(() => { del.sync([absolutePath]); }, { instanceOf: Error, message: 'Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.' }); exists(t, ['', '1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); }); test('cannot delete files inside process.cwd when outside cwd without force: true - async', async t => { process.chdir(t.context.tmp); const removeFile = path.resolve(t.context.tmp, '2.tmp'); const cwd = path.resolve(t.context.tmp, '1.tmp'); await t.throwsAsync(del([removeFile], {cwd}), { instanceOf: Error, message: 'Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.' }); exists(t, ['1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); process.chdir(processCwd); }); test('cannot delete files inside process.cwd when outside cwd without force: true - sync', t => { process.chdir(t.context.tmp); const removeFile = path.resolve(t.context.tmp, '2.tmp'); const cwd = path.resolve(t.context.tmp, '1.tmp'); t.throws(() => { del.sync([removeFile], {cwd}); }, { instanceOf: Error, message: 'Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.' }); exists(t, ['1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); process.chdir(processCwd); }); test('windows can pass absolute paths with "\\" - async', async t => { const filePath = path.resolve(t.context.tmp, '1.tmp'); const removeFiles = await del([filePath], {cwd: t.context.tmp, dryRun: true}); t.deepEqual(removeFiles, [filePath]); }); test('windows can pass absolute paths with "\\" - sync', t => { const filePath = path.resolve(t.context.tmp, '1.tmp'); const removeFiles = del.sync([filePath], {cwd: t.context.tmp, dryRun: true}); t.deepEqual(removeFiles, [filePath]); }); test('windows can pass relative paths with "\\" - async', async t => { const nestedFile = path.resolve(t.context.tmp, 'a/b/c/nested.js'); makeDir.sync(nestedFile); const removeFiles = await del([nestedFile], {cwd: t.context.tmp, dryRun: true}); t.deepEqual(removeFiles, [nestedFile]); }); test('windows can pass relative paths with "\\" - sync', t => { const nestedFile = path.resolve(t.context.tmp, 'a/b/c/nested.js'); makeDir.sync(nestedFile); const removeFiles = del.sync([nestedFile], {cwd: t.context.tmp, dryRun: true}); t.deepEqual(removeFiles, [nestedFile]); });