From 1e39ee84372ccc9e4155afa14f4a4861187b378f Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 27 Feb 2022 16:40:24 +0700 Subject: [PATCH] Meta tweaks --- index.js | 26 +++++++++++--------------- index.test-d.ts | 2 +- package.json | 14 +++++++------- readme.md | 4 ++-- test.js | 9 +++++---- 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/index.js b/index.js index 57c0314..d2eb105 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +import process from 'node:process'; import EventEmitter from 'node:events'; import path from 'node:path'; import os from 'node:os'; @@ -62,17 +63,12 @@ Expand patterns like `'node_modules/{globby,micromatch}'` into `['node_modules/g @param {string[]} patterns @returns {string[]} */ -const expandPatternsWithBraceExpansion = patterns => { - let collection = []; - for (const pattern of patterns) { - collection = [...collection, ...micromatch.braces(pattern, { - expand: true, - nodupes: true, - })]; - } - - return collection; -}; +const expandPatternsWithBraceExpansion = patterns => patterns.flatMap(pattern => ( + micromatch.braces(pattern, { + expand: true, + nodupes: true, + }) +)); /** @param {object} props @@ -119,14 +115,14 @@ const preprocessDestinationPath = ({entry, destination, options}) => { */ const renameFile = (source, rename) => { const filename = path.basename(source, path.extname(source)); - const ext = path.extname(source); - const dir = path.dirname(source); + const fileExtension = path.extname(source); + const directory = path.dirname(source); if (typeof rename === 'string') { - return path.join(dir, rename); + return path.join(directory, rename); } if (typeof rename === 'function') { - return path.join(dir, `${rename(filename)}${ext}`); + return path.join(directory, `${rename(filename)}${fileExtension}`); } return source; diff --git a/index.test-d.ts b/index.test-d.ts index 2871cdc..77d7fec 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -25,7 +25,7 @@ expectType & ProgressEmitter>( expectType & ProgressEmitter>( cpy('foo.js', 'destination', { - filter: file => { + filter(file) { expectType(file); expectType(file.path); diff --git a/package.json b/package.json index 39c72e8..3143ee6 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "type": "module", "exports": "./index.js", "engines": { - "node": ">=12.20" + "node": "^12.20.0 || ^14.17.0 || >=16.0.0" }, "scripts": { "test": "xo && ava && tsd" @@ -48,20 +48,20 @@ "dependencies": { "arrify": "^3.0.0", "cp-file": "^9.1.0", - "globby": "^12.0.2", + "globby": "^13.1.1", "junk": "^4.0.0", - "micromatch": "^4.0.4", + "micromatch": "^4.0.4", "nested-error-stacks": "^2.1.0", "p-filter": "^3.0.0", "p-map": "^5.3.0" }, "devDependencies": { - "ava": "^3.15.0", + "ava": "^4.0.1", "proxyquire": "^2.1.3", "rimraf": "^3.0.2", "tempy": "^2.0.0", - "tsd": "^0.18.0", - "typescript": "^4.4.4", - "xo": "^0.42.0" + "tsd": "^0.19.1", + "typescript": "^4.5.5", + "xo": "^0.48.0" } } diff --git a/readme.md b/readme.md index 4ea84d2..1c9813e 100644 --- a/readme.md +++ b/readme.md @@ -12,8 +12,8 @@ ## Install -``` -$ npm install cpy +```sh +npm install cpy ``` ## Usage diff --git a/test.js b/test.js index 2745b7d..f470c95 100644 --- a/test.js +++ b/test.js @@ -1,3 +1,4 @@ +import process from 'node:process'; import path from 'node:path'; import fs from 'node:fs'; import crypto from 'node:crypto'; @@ -8,7 +9,7 @@ import proxyquire from 'proxyquire'; import CpyError from './cpy-error.js'; import cpy from './index.js'; -const read = (...args) => fs.readFileSync(path.join(...args), 'utf8'); +const read = (...arguments_) => fs.readFileSync(path.join(...arguments_), 'utf8'); const cpyMockedError = module => proxyquire('.', { [module]() { @@ -62,7 +63,7 @@ test('throws on invalid concurrency value', async t => { test('copy array of files with filter', async t => { await cpy(['license', 'package.json'], t.context.tmp, { - filter: file => { + filter(file) { if (file.path.endsWith('license')) { t.is(file.path, path.join(process.cwd(), 'license')); t.is(file.name, 'license'); @@ -85,7 +86,7 @@ test('copy array of files with filter', async t => { test('copy array of files with async filter', async t => { await cpy(['license', 'package.json'], t.context.tmp, { - filter: async file => { + async filter(file) { if (file.path.endsWith(`${path.sep}license`)) { t.is(file.path, path.join(process.cwd(), 'license')); t.is(file.name, 'license'); @@ -411,7 +412,7 @@ test('reports correct completedSize', async t => { test('returns the event emitter on early rejection', t => { const rejectedPromise = cpy(null, null); t.is(typeof rejectedPromise.on, 'function'); - rejectedPromise.catch(() => {}); // eslint-disable-line promise/prefer-await-to-then + rejectedPromise.catch(() => {}); }); test('returns destination path', async t => {