Skip to content

Commit 7ee777f

Browse files
authoredFeb 27, 2022
Require Node.js 12 and move to ESM (#31)
1 parent d6bdd28 commit 7ee777f

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed
 

‎.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 16
1314
- 14
1415
- 12
15-
- 10
16-
- 8
16+
1717
steps:
1818
- uses: actions/checkout@v2
1919
- uses: actions/setup-node@v1

‎cli.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env node
2-
'use strict';
3-
const meow = require('meow');
4-
const cpy = require('cpy');
2+
3+
import process from 'node:process';
4+
import meow from 'meow';
5+
import cpy from 'cpy';
56

67
const cli = meow(`
78
Usage
@@ -23,27 +24,28 @@ const cli = meow(`
2324
Copy all .html files inside src folder into dist and preserve path structure
2425
$ cpy '**/*.html' '../dist/' --cwd=src --parents
2526
`, {
27+
importMeta: import.meta,
2628
flags: {
2729
overwrite: {
2830
type: 'boolean',
29-
default: true
31+
default: true,
3032
},
3133
parents: {
3234
type: 'boolean',
33-
default: false
35+
default: false,
3436
},
3537
cwd: {
3638
type: 'string',
37-
default: process.cwd()
39+
default: process.cwd(),
3840
},
3941
rename: {
40-
type: 'string'
42+
type: 'string',
4143
},
4244
dot: {
4345
type: 'boolean',
44-
default: false
45-
}
46-
}
46+
default: false,
47+
},
48+
},
4749
});
4850

4951
(async () => {
@@ -53,7 +55,7 @@ const cli = meow(`
5355
rename: cli.flags.rename,
5456
parents: cli.flags.parents,
5557
overwrite: cli.flags.overwrite,
56-
dot: cli.flags.dot
58+
dot: cli.flags.dot,
5759
});
5860
} catch (error) {
5961
if (error.name === 'CpyError') {

‎package.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
"cpy": "cli.js"
2222
},
2323
"engines": {
24-
"node": ">=8"
24+
"node": ">=12.20"
2525
},
26+
"type": "module",
2627
"scripts": {
2728
"test": "xo && ava"
2829
},
@@ -50,14 +51,14 @@
5051
"contents"
5152
],
5253
"dependencies": {
53-
"cpy": "^8.0.0",
54-
"meow": "^6.1.1"
54+
"cpy": "^8.1.2",
55+
"meow": "^10.1.2"
5556
},
5657
"devDependencies": {
57-
"ava": "^2.4.0",
58-
"execa": "^1.0.0",
59-
"path-exists": "^4.0.0",
60-
"tempfile": "^3.0.0",
61-
"xo": "^0.25.3"
58+
"ava": "^4.0.1",
59+
"execa": "^6.1.0",
60+
"path-exists": "^5.0.0",
61+
"tempfile": "^4.0.0",
62+
"xo": "^0.48.0"
6263
}
6364
}

‎test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import path from 'path';
2-
import fs from 'fs';
1+
import path from 'node:path';
2+
import fs from 'node:fs';
33
import test from 'ava';
44
import tempfile from 'tempfile';
5-
import execa from 'execa';
6-
import pathExists from 'path-exists';
5+
import {execa} from 'execa';
6+
import {pathExistsSync} from 'path-exists';
77

88
const read = (...args) => fs.readFileSync(path.join(...args), 'utf8');
99

@@ -12,11 +12,11 @@ test.beforeEach(t => {
1212
});
1313

1414
test('missing file operands', async t => {
15-
await t.throwsAsync(execa('./cli.js'), /`source` and `destination` required/);
15+
await t.throwsAsync(execa('./cli.js'), {message: /`source` and `destination` required/});
1616
});
1717

1818
test('source file does not exist', async t => {
19-
await t.throwsAsync(execa('./cli.js', [path.join(t.context.tmp, 'nonexistentfile'), t.context.tmp]), /nonexistentfile/);
19+
await t.throwsAsync(execa('./cli.js', [path.join(t.context.tmp, 'nonexistentfile'), t.context.tmp]), {message: /nonexistentfile/});
2020
});
2121

2222
test('cwd', async t => {
@@ -71,6 +71,6 @@ test('do not copy files in the negated glob patterns', async t => {
7171
await execa('./cli.js', ['src/*.*', '!src/*.jsx', '!src/*.es2015', 'dest', '--cwd', t.context.tmp]);
7272

7373
t.is(read(t.context.tmp, 'dest/hello.js'), 'console.log("hello");');
74-
t.false(pathExists.sync(path.join(t.context.tmp, 'dest/hello.jsx')));
75-
t.false(pathExists.sync(path.join(t.context.tmp, 'dest/hello.es2015')));
74+
t.false(pathExistsSync(path.join(t.context.tmp, 'dest/hello.jsx')));
75+
t.false(pathExistsSync(path.join(t.context.tmp, 'dest/hello.es2015')));
7676
});

0 commit comments

Comments
 (0)
Please sign in to comment.