From 106d7d8ff813059c437d7c428539b7719292d1d6 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Tue, 19 Jul 2022 16:15:50 +0200 Subject: [PATCH] Move to ESM (#143) --- .github/workflows/main.yml | 3 +- benchmark.js | 30 +++--- index.d.ts | 184 ++++++++++++++++++------------------- index.js | 44 ++++----- index.test-d.ts | 28 +++--- package.json | 12 ++- readme.md | 36 ++++---- test.js | 129 +++++++++++++------------- 8 files changed, 227 insertions(+), 239 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3488385..9e63517 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,9 +10,8 @@ jobs: fail-fast: false matrix: node-version: + - 16 - 14 - - 12 - - 10 os: - ubuntu-latest - macos-latest diff --git a/benchmark.js b/benchmark.js index 3d194fb..b8f388a 100644 --- a/benchmark.js +++ b/benchmark.js @@ -1,17 +1,15 @@ -'use strict'; -const path = require('path'); -const Benchmark = require('benchmark'); -const makeDir = require('make-dir'); -const tempy = require('tempy'); -const del = require('.'); +import path from 'node:path'; +import process from 'node:process'; +import Benchmark from 'benchmark'; +import makeDir from 'make-dir'; +import tempy from 'tempy'; +import {deleteAsync, deleteSync} from './index.js'; const suite = new Benchmark.Suite('concurrency'); const temporaryDir = tempy.directory(); -const fixtures = Array.from({length: 2000}, (_, index) => { - return path.resolve(temporaryDir, (index + 1).toString()); -}); +const fixtures = Array.from({length: 2000}, (_, index) => path.resolve(temporaryDir, (index + 1).toString())); function createFixtures() { for (const fixture of fixtures) { @@ -33,7 +31,7 @@ const concurrencies = [ 400, 500, 1000, - Infinity + Number.POSITIVE_INFINITY, ]; for (const concurrency of concurrencies) { @@ -48,26 +46,26 @@ for (const concurrency of concurrencies) { // https://github.com/bestiejs/benchmark.js/issues/136 createFixtures(); - const removedFiles = await del(['**/*'], { + const removedFiles = await deleteAsync(['**/*'], { cwd: temporaryDir, - concurrency + concurrency, }); if (removedFiles.length !== fixtures.length) { const error = new Error( - `"${name}": files removed: ${removedFiles.length}, expected: ${fixtures.length}` + `"${name}": files removed: ${removedFiles.length}, expected: ${fixtures.length}`, ); console.error(error); - del.sync(temporaryDir, {cwd: temporaryDir, force: true}); + deleteSync(temporaryDir, {cwd: temporaryDir, force: true}); // eslint-disable-next-line unicorn/no-process-exit process.exit(1); } deferred.resolve(); - } + }, }); } @@ -78,6 +76,6 @@ suite .on('complete', function () { console.log(`Fastest is ${this.filter('fastest').map('name')}`); - del.sync(temporaryDir, {cwd: temporaryDir, force: true}); + deleteSync(temporaryDir, {cwd: temporaryDir, force: true}); }) .run({async: true}); diff --git a/index.d.ts b/index.d.ts index 25608eb..828ec1a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,116 +1,106 @@ import {GlobbyOptions} from 'globby'; -declare namespace del { - interface ProgressData { - /** - Deleted files and directories count. - */ - deletedCount: number; - - /** - Total files and directories count. - */ - totalCount: number; - - /** - Completed percentage. A value between `0` and `1`. - */ - percent: number; - } - - 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; - - /** - Called after each file or directory is deleted. - - @example - ``` - import del from 'del'; - - await del(patterns, { - onProgress: progress => { - // … - }}); - ``` - */ - readonly onProgress?: (progress: ProgressData) => void; - } +export interface ProgressData { + /** + Deleted files and directories count. + */ + deletedCount: number; + + /** + Total files and directories count. + */ + totalCount: number; + + /** + Completed percentage. A value between `0` and `1`. + */ + percent: number; } -declare const del: { +export interface Options extends GlobbyOptions { /** - Synchronously delete files and directories using glob patterns. + Allow deleting the current working directory and outside. - 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()`. + @default false + */ + readonly force?: boolean; + + /** + See what would be deleted. - @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/main/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. + @default false + + @example + ``` + import {deleteAsync} from 'del'; + + const deletedPaths = await deleteAsync(['temp/*.js'], {dryRun: true}); + + console.log('Files and directories that would be deleted:\n', deletedPaths.join('\n')); + ``` */ - sync: ( - patterns: string | readonly string[], - options?: del.Options - ) => string[]; + readonly dryRun?: boolean; /** - Delete files and directories using glob patterns. + Concurrency limit. Minimum: `1`. - 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()`. + @default Infinity + */ + readonly concurrency?: number; - @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/main/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. + /** + Called after each file or directory is deleted. @example ``` - import del = require('del'); + import {deleteAsync} from 'del'; - (async () => { - const deletedPaths = await del(['temp/*.js', '!temp/unicorn.js']); - - console.log('Deleted files and directories:\n', deletedPaths.join('\n')); - })(); + await deleteAsync(patterns, { + onProgress: progress => { + // … + }}); ``` */ - ( - patterns: string | readonly string[], - options?: del.Options - ): Promise; -}; + readonly onProgress?: (progress: ProgressData) => void; +} -export = del; +/** +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/main/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 {deleteAsync} from 'del'; + +const deletedPaths = await deleteAsync(['temp/*.js', '!temp/unicorn.js']); + +console.log('Deleted files and directories:\n', deletedPaths.join('\n')); +``` +*/ +export function deleteAsync( + patterns: string | readonly string[], + options?: Options +): Promise; + +/** +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/main/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. +*/ +export function deleteSync( + patterns: string | readonly string[], + options?: Options +): string[]; diff --git a/index.js b/index.js index 472b93c..dfb7e33 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,14 @@ -'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'); +import {promisify} from 'node:util'; +import path from 'node:path'; +import process from 'node:process'; +import globby from 'globby'; +import isGlob from 'is-glob'; +import slash from 'slash'; +import gracefulFs from 'graceful-fs'; +import isPathCwd from 'is-path-cwd'; +import isPathInside from 'is-path-inside'; +import rimraf from 'rimraf'; +import pMap from 'p-map'; const rimrafP = promisify(rimraf); @@ -25,7 +25,7 @@ const rimrafOptions = { rmdir: gracefulFs.rmdir, rmdirSync: gracefulFs.rmdirSync, readdir: gracefulFs.readdir, - readdirSync: gracefulFs.readdirSync + readdirSync: gracefulFs.readdirSync, }; function safeCheck(file, cwd) { @@ -52,25 +52,25 @@ function normalizePatterns(patterns) { return patterns; } -module.exports = async (patterns, {force, dryRun, cwd = process.cwd(), onProgress = () => {}, ...options} = {}) => { +export async function deleteAsync(patterns, {force, dryRun, cwd = process.cwd(), onProgress = () => {}, ...options} = {}) { options = { expandDirectories: false, onlyFiles: false, followSymbolicLinks: false, cwd, - ...options + ...options, }; patterns = normalizePatterns(patterns); - const files = (await globby(patterns, options)) - .sort((a, b) => b.localeCompare(a)); + const paths = await globby(patterns, options); + const files = paths.sort((a, b) => b.localeCompare(a)); if (files.length === 0) { onProgress({ totalCount: 0, deletedCount: 0, - percent: 1 + percent: 1, }); } @@ -92,7 +92,7 @@ module.exports = async (patterns, {force, dryRun, cwd = process.cwd(), onProgres onProgress({ totalCount: files.length, deletedCount, - percent: deletedCount / files.length + percent: deletedCount / files.length, }); return file; @@ -103,15 +103,15 @@ module.exports = async (patterns, {force, dryRun, cwd = process.cwd(), onProgres removedFiles.sort((a, b) => a.localeCompare(b)); return removedFiles; -}; +} -module.exports.sync = (patterns, {force, dryRun, cwd = process.cwd(), ...options} = {}) => { +export function deleteSync(patterns, {force, dryRun, cwd = process.cwd(), ...options} = {}) { options = { expandDirectories: false, onlyFiles: false, followSymbolicLinks: false, cwd, - ...options + ...options, }; patterns = normalizePatterns(patterns); @@ -136,4 +136,4 @@ module.exports.sync = (patterns, {force, dryRun, cwd = process.cwd(), ...options removedFiles.sort((a, b) => a.localeCompare(b)); return removedFiles; -}; +} diff --git a/index.test-d.ts b/index.test-d.ts index bff5f02..9ede2d2 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,25 +1,25 @@ import {expectType} from 'tsd'; -import del = require('.'); +import {deleteAsync, deleteSync} from './index.js'; const paths = [ 'temp/*.js', - '!temp/unicorn.js' + '!temp/unicorn.js', ]; // Del -expectType>(del('temp/*.js')); -expectType>(del(paths)); +expectType>(deleteAsync('temp/*.js')); +expectType>(deleteAsync(paths)); -expectType>(del(paths, {force: true})); -expectType>(del(paths, {dryRun: true})); -expectType>(del(paths, {concurrency: 20})); -expectType>(del(paths, {cwd: ''})); +expectType>(deleteAsync(paths, {force: true})); +expectType>(deleteAsync(paths, {dryRun: true})); +expectType>(deleteAsync(paths, {concurrency: 20})); +expectType>(deleteAsync(paths, {cwd: ''})); // Del (sync) -expectType(del.sync('tmp/*.js')); -expectType(del.sync(paths)); +expectType(deleteSync('tmp/*.js')); +expectType(deleteSync(paths)); -expectType(del.sync(paths, {force: true})); -expectType(del.sync(paths, {dryRun: true})); -expectType(del.sync(paths, {concurrency: 20})); -expectType(del.sync(paths, {cwd: ''})); +expectType(deleteSync(paths, {force: true})); +expectType(deleteSync(paths, {dryRun: true})); +expectType(deleteSync(paths, {concurrency: 20})); +expectType(deleteSync(paths, {cwd: ''})); diff --git a/package.json b/package.json index 5f533a6..d373fe1 100644 --- a/package.json +++ b/package.json @@ -10,11 +10,13 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=10" + "node": "^14.13.1 || >=16.0.0" }, "scripts": { - "test": "xo && ava && tsd", + "test": "xo && ava --serial --no-worker-threads && tsd", "bench": "node benchmark.js" }, "files": [ @@ -56,11 +58,11 @@ "slash": "^3.0.0" }, "devDependencies": { - "ava": "^2.4.0", + "ava": "^4.3.1", "benchmark": "^2.1.4", "make-dir": "^3.1.0", "tempy": "^0.7.0", - "tsd": "^0.13.1", - "xo": "^0.33.1" + "tsd": "^0.22.0", + "xo": "^0.50.0" } } diff --git a/readme.md b/readme.md index eefdde8..eb0882f 100644 --- a/readme.md +++ b/readme.md @@ -13,16 +13,14 @@ $ npm install del ## Usage ```js -const del = require('del'); +import {deleteAsync} from 'del'; -(async () => { - const deletedFilePaths = await del(['temp/*.js', '!temp/unicorn.js']); - const deletedDirectoryPaths = await del(['temp', 'public']); +const deletedFilePaths = await deleteAsync(['temp/*.js', '!temp/unicorn.js']); +const deletedDirectoryPaths = await deleteAsync(['temp', 'public']); - console.log('Deleted files:\n', deletedFilePaths.join('\n')); - console.log('\n\n'); - console.log('Deleted directories:\n', deletedDirectoryPaths.join('\n')); -})(); +console.log('Deleted files:\n', deletedFilePaths.join('\n')); +console.log('\n\n'); +console.log('Deleted directories:\n', deletedDirectoryPaths.join('\n')); ``` ## Beware @@ -32,19 +30,19 @@ The glob pattern `**` matches all children and *the parent*. So this won't work: ```js -del.sync(['public/assets/**', '!public/assets/goat.png']); +deleteSync(['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']); +deleteSync(['public/assets/**', '!public/assets', '!public/assets/goat.png']); ``` To delete all subdirectories inside `public/`, you can do: ```js -del.sync(['public/*/']); +deleteSync(['public/*/']); ``` Suggestions on how to improve this welcome! @@ -53,11 +51,11 @@ Suggestions on how to improve this welcome! 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?) +### deleteAsync(patterns, options?) Returns `Promise` with the deleted paths. -### del.sync(patterns, options?) +### deleteSync(patterns, options?) Returns `string[]` with the deleted paths. @@ -91,13 +89,11 @@ Default: `false` See what would be deleted. ```js -const del = require('del'); +import {deleteAsync} from 'del'; -(async () => { - const deletedPaths = await del(['temp/*.js'], {dryRun: true}); +const deletedPaths = await deleteAsync(['temp/*.js'], {dryRun: true}); - console.log('Files and directories that would be deleted:\n', deletedPaths.join('\n')); -})(); +console.log('Files and directories that would be deleted:\n', deletedPaths.join('\n')); ``` ##### concurrency @@ -115,9 +111,9 @@ Type: `(progress: ProgressData) => void` Called after each file or directory is deleted. ```js -import del from 'del'; +import {deleteAsync} from 'del'; -await del(patterns, { +await deleteAsync(patterns, { onProgress: progress => { // … }}); diff --git a/test.js b/test.js index b7aa11c..84c1431 100644 --- a/test.js +++ b/test.js @@ -1,10 +1,13 @@ -import path from 'path'; -import fs from 'fs'; -import {serial as test} from 'ava'; +import {fileURLToPath} from 'node:url'; +import fs from 'node:fs'; +import path from 'node:path'; +import process from 'node:process'; +import test from 'ava'; import tempy from 'tempy'; import makeDir from 'make-dir'; -import del from '.'; +import {deleteAsync, deleteSync} from './index.js'; +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const processCwd = process.cwd(); function exists(t, files) { @@ -24,7 +27,7 @@ const fixtures = [ '2.tmp', '3.tmp', '4.tmp', - '.dot.tmp' + '.dot.tmp', ]; test.beforeEach(t => { @@ -36,23 +39,23 @@ test.beforeEach(t => { }); test('delete files - async', async t => { - await del(['*.tmp', '!1*'], {cwd: t.context.tmp}); + await deleteAsync(['*.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}); + deleteSync(['*.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*'], { + await deleteAsync(['*.tmp', '!1*'], { cwd: t.context.tmp, - dot: true + dot: true, }); exists(t, ['1.tmp']); @@ -60,9 +63,9 @@ test('take options into account - async', async t => { }); test('take options into account - sync', t => { - del.sync(['*.tmp', '!1*'], { + deleteSync(['*.tmp', '!1*'], { cwd: t.context.tmp, - dot: true + dot: true, }); exists(t, ['1.tmp']); @@ -71,50 +74,50 @@ test('take options into account - sync', t => { test('return deleted files - async', async t => { t.deepEqual( - await del('1.tmp', {cwd: t.context.tmp}), - [path.join(t.context.tmp, '1.tmp')] + await deleteAsync('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')] + deleteSync('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*'], { + const deletedFiles = await deleteAsync(['*.tmp', '!1*'], { cwd: t.context.tmp, - dryRun: true + 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') + path.join(t.context.tmp, '4.tmp'), ]); }); test('don\'t delete files, but return them - sync', t => { - const deletedFiles = del.sync(['*.tmp', '!1*'], { + const deletedFiles = deleteSync(['*.tmp', '!1*'], { cwd: t.context.tmp, - dryRun: true + 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') + 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('**/*', { + await deleteAsync('**/*', { cwd: t.context.tmp, - dot: true + dot: true, }); const nestedFile = path.resolve(t.context.tmp, 'a/b/c/nested.js'); @@ -125,16 +128,16 @@ test('does not throw EINVAL - async', async t => { makeDir.sync(nestedFile); // eslint-disable-next-line no-await-in-loop - const removed = await del('**/*', { + const removed = await deleteAsync('**/*', { cwd: t.context.tmp, - dot: true + 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') + path.resolve(t.context.tmp, 'a/b/c/nested.js'), ]; t.deepEqual(removed, expected); @@ -147,9 +150,9 @@ test('does not throw EINVAL - async', async t => { }); test('does not throw EINVAL - sync', t => { - del.sync('**/*', { + deleteSync('**/*', { cwd: t.context.tmp, - dot: true + dot: true, }); const nestedFile = path.resolve(t.context.tmp, 'a/b/c/nested.js'); @@ -159,16 +162,16 @@ test('does not throw EINVAL - sync', t => { while (count !== totalAttempts) { makeDir.sync(nestedFile); - const removed = del.sync('**/*', { + const removed = deleteSync('**/*', { cwd: t.context.tmp, - dot: true + 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') + path.resolve(t.context.tmp, 'a/b/c/nested.js'), ]; t.deepEqual(removed, expected); @@ -181,14 +184,14 @@ test('does not throw EINVAL - sync', t => { }); test('delete relative files outside of process.cwd using cwd - async', async t => { - await del(['1.tmp'], {cwd: t.context.tmp}); + await deleteAsync(['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}); + deleteSync(['1.tmp'], {cwd: t.context.tmp}); exists(t, ['2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); notExists(t, ['1.tmp']); @@ -196,7 +199,7 @@ test('delete relative files outside of process.cwd using cwd - sync', t => { 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}); + await deleteAsync([absolutePath], {cwd: t.context.tmp}); exists(t, ['2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); notExists(t, ['1.tmp']); @@ -204,7 +207,7 @@ test('delete absolute files outside of process.cwd using cwd - async', async t = 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}); + deleteSync([absolutePath], {cwd: t.context.tmp}); exists(t, ['2.tmp', '3.tmp', '4.tmp', '.dot.tmp']); notExists(t, ['1.tmp']); @@ -213,9 +216,9 @@ test('delete absolute files outside of process.cwd using cwd - sync', t => { test('cannot delete actual working directory without force: true - async', async t => { process.chdir(t.context.tmp); - await t.throwsAsync(del([t.context.tmp]), { + await t.throwsAsync(deleteAsync([t.context.tmp]), { instanceOf: Error, - message: 'Cannot delete the current working directory. Can be overridden with the `force` option.' + 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']); @@ -226,10 +229,10 @@ test('cannot delete actual working directory without force: true - sync', t => { process.chdir(t.context.tmp); t.throws(() => { - del.sync([t.context.tmp]); + deleteSync([t.context.tmp]); }, { instanceOf: Error, - message: 'Cannot delete the current working directory. Can be overridden with the `force` option.' + 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']); @@ -239,9 +242,9 @@ test('cannot delete actual working directory without force: true - sync', t => { 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}), { + await t.throwsAsync(deleteAsync([t.context.tmp], {cwd: __dirname}), { instanceOf: Error, - message: 'Cannot delete the current working directory. Can be overridden with the `force` option.' + 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']); @@ -252,10 +255,10 @@ test('cannot delete actual working directory with cwd option without force: true process.chdir(t.context.tmp); t.throws(() => { - del.sync([t.context.tmp], {cwd: __dirname}); + deleteSync([t.context.tmp], {cwd: __dirname}); }, { instanceOf: Error, - message: 'Cannot delete the current working directory. Can be overridden with the `force` option.' + 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']); @@ -265,9 +268,9 @@ test('cannot delete actual working directory with cwd option without force: true 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]), { + await t.throwsAsync(deleteAsync([absolutePath]), { instanceOf: Error, - message: 'Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.' + 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']); @@ -277,10 +280,10 @@ 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]); + deleteSync([absolutePath]); }, { instanceOf: Error, - message: 'Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.' + 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']); @@ -291,9 +294,9 @@ test('cannot delete files inside process.cwd when outside cwd without force: tru const removeFile = path.resolve(t.context.tmp, '2.tmp'); const cwd = path.resolve(t.context.tmp, '1.tmp'); - await t.throwsAsync(del([removeFile], {cwd}), { + await t.throwsAsync(deleteAsync([removeFile], {cwd}), { instanceOf: Error, - message: 'Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.' + 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']); @@ -306,10 +309,10 @@ test('cannot delete files inside process.cwd when outside cwd without force: tru const cwd = path.resolve(t.context.tmp, '1.tmp'); t.throws(() => { - del.sync([removeFile], {cwd}); + deleteSync([removeFile], {cwd}); }, { instanceOf: Error, - message: 'Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.' + 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']); @@ -319,7 +322,7 @@ test('cannot delete files inside process.cwd when outside cwd without force: tru 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}); + const removeFiles = await deleteAsync([filePath], {cwd: t.context.tmp, dryRun: true}); t.deepEqual(removeFiles, [filePath]); }); @@ -327,7 +330,7 @@ test('windows can pass absolute paths with "\\" - async', async t => { 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}); + const removeFiles = deleteSync([filePath], {cwd: t.context.tmp, dryRun: true}); t.deepEqual(removeFiles, [filePath]); }); @@ -336,7 +339,7 @@ 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}); + const removeFiles = await deleteAsync([nestedFile], {cwd: t.context.tmp, dryRun: true}); t.deepEqual(removeFiles, [nestedFile]); }); @@ -345,7 +348,7 @@ 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}); + const removeFiles = deleteSync([nestedFile], {cwd: t.context.tmp, dryRun: true}); t.deepEqual(removeFiles, [nestedFile]); }); @@ -353,28 +356,28 @@ test('windows can pass relative paths with "\\" - sync', t => { test('onProgress option - progress of non-existent file', async t => { let report; - await del('non-existent-directory', {onProgress: event => { + await deleteAsync('non-existent-directory', {onProgress(event) { report = event; }}); t.deepEqual(report, { totalCount: 0, deletedCount: 0, - percent: 1 + percent: 1, }); }); test('onProgress option - progress of single file', async t => { let report; - await del(t.context.tmp, {cwd: __dirname, force: true, onProgress: event => { + await deleteAsync(t.context.tmp, {cwd: __dirname, force: true, onProgress(event) { report = event; }}); t.deepEqual(report, { totalCount: 1, deletedCount: 1, - percent: 1 + percent: 1, }); }); @@ -383,17 +386,17 @@ test('onProgress option - progress of multiple files', async t => { const sourcePath = process.platform === 'win32' ? path.resolve(`${t.context.tmp}/*`).replace(/\\/g, '/') : `${t.context.tmp}/*`; - await del(sourcePath, { + await deleteAsync(sourcePath, { cwd: __dirname, force: true, - onProgress: event => { + onProgress(event) { report = event; - } + }, }); t.deepEqual(report, { totalCount: 4, deletedCount: 4, - percent: 1 + percent: 1, }); });