Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 27, 2022
1 parent 0934ab1 commit 1e39ee8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 29 deletions.
26 changes: 11 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import process from 'node:process';
import EventEmitter from 'node:events';
import path from 'node:path';
import os from 'node:os';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ expectType<Promise<string[]> & ProgressEmitter>(

expectType<Promise<string[]> & ProgressEmitter>(
cpy('foo.js', 'destination', {
filter: file => {
filter(file) {
expectType<Entry>(file);

expectType<string>(file.path);
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

## Install

```
$ npm install cpy
```sh
npm install cpy
```

## Usage
Expand Down
9 changes: 5 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import process from 'node:process';
import path from 'node:path';
import fs from 'node:fs';
import crypto from 'node:crypto';
Expand All @@ -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]() {
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 1e39ee8

Please sign in to comment.