Skip to content

Commit

Permalink
Require Node.js 16
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 2, 2023
1 parent cdb7ed4 commit f18399d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 37 deletions.
25 changes: 13 additions & 12 deletions index.d.ts
@@ -1,7 +1,7 @@
import {Options as GlobOptions} from 'globby';
import {Options as CpFileOptions} from 'cp-file';
import {type Options as GlobOptions} from 'globby';
import {type Options as CpFileOptions} from 'cp-file';

export interface Entry {
export type Entry = {
/**
Resolved path to the file.
Expand Down Expand Up @@ -36,9 +36,9 @@ export interface Entry {
@example 'js'
*/
readonly extension: string;
}
};

export interface Options extends Readonly<GlobOptions>, CpFileOptions {
export type Options = {
/**
Working directory to find source files.
Expand All @@ -61,6 +61,7 @@ export interface Options extends Readonly<GlobOptions>, CpFileOptions {
import cpy from 'cpy';
await cpy('foo.js', 'destination', {
// The `basename` is the filename with extension.
rename: basename => `prefix-${basename}`
});
Expand Down Expand Up @@ -102,9 +103,9 @@ export interface Options extends Readonly<GlobOptions>, CpFileOptions {
```
*/
readonly filter?: (file: Entry) => boolean | Promise<boolean>;
}
} & Readonly<GlobOptions> & CpFileOptions; // eslint-disable-line @typescript-eslint/no-redundant-type-constituents

export interface ProgressData {
export type ProgressData = {
/**
Copied file count.
*/
Expand All @@ -124,19 +125,19 @@ export interface ProgressData {
Completed percentage. A value between `0` and `1`.
*/
percent: number;
}
};

export interface ProgressEmitter {
export type ProgressEmitter = {
on(
event: 'progress',
handler: (progress: ProgressData) => void
): Promise<string[]>;
}
};

export interface CopyStatus {
export type CopyStatus = {
written: number;
percent: number;
}
};

/**
Copy files.
Expand Down
7 changes: 2 additions & 5 deletions index.js
Expand Up @@ -4,7 +4,7 @@ import path from 'node:path';
import os from 'node:os';
import pMap from 'p-map';
import arrify from 'arrify';
import cpFile from 'cp-file';
import {copyFile} from 'cp-file';
import pFilter from 'p-filter';
import {isDynamicPattern} from 'globby';
import micromatch from 'micromatch';
Expand Down Expand Up @@ -265,10 +265,7 @@ export default function cpy(
);

try {
await cpFile(entry.path, to, options).on(
'progress',
fileProgressHandler,
);
await copyFile(entry.path, to, {...options, onProgress: fileProgressHandler});
} catch (error) {
throw new CpyError(
`Cannot copy from \`${entry.relativePath}\` to \`${to}\`: ${error.message}`,
Expand Down
3 changes: 2 additions & 1 deletion index.test-d.ts
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import cpy, {ProgressEmitter, ProgressData, Entry} from './index.js';
import cpy, {type ProgressEmitter, type ProgressData, type Entry} from './index.js';

expectType<Promise<string[]> & ProgressEmitter>(
cpy(['source/*.png', '!source/goat.png'], 'destination'),
Expand All @@ -8,6 +8,7 @@ expectType<Promise<string[]> & ProgressEmitter>(
cpy('foo.js', 'destination', {rename: 'foobar'}),
);
expectType<Promise<string[]> & ProgressEmitter>(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
cpy('foo.js', 'destination', {rename: basename => `prefix-${basename}`}),
);
expectType<Promise<string[]> & ProgressEmitter>(
Expand Down
25 changes: 12 additions & 13 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"type": "module",
"exports": "./index.js",
"engines": {
"node": "^12.20.0 || ^14.17.0 || >=16.0.0"
"node": ">=16"
},
"scripts": {
"test": "xo && ava && tsd"
Expand Down Expand Up @@ -47,21 +47,20 @@
],
"dependencies": {
"arrify": "^3.0.0",
"cp-file": "^9.1.0",
"globby": "^13.1.1",
"junk": "^4.0.0",
"micromatch": "^4.0.4",
"nested-error-stacks": "^2.1.0",
"cp-file": "^10.0.0",
"globby": "^13.1.4",
"junk": "^4.0.1",
"micromatch": "^4.0.5",
"nested-error-stacks": "^2.1.1",
"p-filter": "^3.0.0",
"p-map": "^5.3.0"
"p-map": "^6.0.0"
},
"devDependencies": {
"ava": "^4.0.1",
"ava": "^5.2.0",
"proxyquire": "^2.1.3",
"rimraf": "^3.0.2",
"tempy": "^2.0.0",
"tsd": "^0.19.1",
"typescript": "^4.5.5",
"xo": "^0.48.0"
"rimraf": "^5.0.0",
"tempy": "^3.0.0",
"tsd": "^0.28.1",
"xo": "^0.54.2"
}
}
1 change: 1 addition & 0 deletions readme.md
Expand Up @@ -108,6 +108,7 @@ Filename or function returning a filename used to rename every file in `source`.
import cpy from 'cpy';

await cpy('foo.js', 'destination', {
// The `basename` is the filename with extension.
rename: basename => `prefix-${basename}`
});

Expand Down
12 changes: 6 additions & 6 deletions test.js
Expand Up @@ -2,9 +2,9 @@ import process from 'node:process';
import path from 'node:path';
import fs from 'node:fs';
import crypto from 'node:crypto';
import rimraf from 'rimraf';
import {rimrafSync} from 'rimraf';
import test from 'ava';
import tempy from 'tempy';
import {temporaryFile, temporaryDirectory} from 'tempy';
import proxyquire from 'proxyquire';
import CpyError from './cpy-error.js';
import cpy from './index.js';
Expand All @@ -18,13 +18,13 @@ const cpyMockedError = module => proxyquire('.', {
});

test.beforeEach(t => {
t.context.tmp = tempy.file();
t.context.dir = tempy.directory();
t.context.tmp = temporaryFile();
t.context.dir = temporaryDirectory();
});

test.afterEach(t => {
rimraf.sync(t.context.tmp);
rimraf.sync(t.context.dir);
rimrafSync(t.context.tmp);
rimrafSync(t.context.dir);
});

test('reject Errors on missing `source`', async t => {
Expand Down

0 comments on commit f18399d

Please sign in to comment.