Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored Feb 27, 2022
1 parent d6bdd28 commit 7ee777f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
- 8

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
24 changes: 13 additions & 11 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const cpy = require('cpy');

import process from 'node:process';
import meow from 'meow';
import cpy from 'cpy';

const cli = meow(`
Usage
Expand All @@ -23,27 +24,28 @@ const cli = meow(`
Copy all .html files inside src folder into dist and preserve path structure
$ cpy '**/*.html' '../dist/' --cwd=src --parents
`, {
importMeta: import.meta,
flags: {
overwrite: {
type: 'boolean',
default: true
default: true,
},
parents: {
type: 'boolean',
default: false
default: false,
},
cwd: {
type: 'string',
default: process.cwd()
default: process.cwd(),
},
rename: {
type: 'string'
type: 'string',
},
dot: {
type: 'boolean',
default: false
}
}
default: false,
},
},
});

(async () => {
Expand All @@ -53,7 +55,7 @@ const cli = meow(`
rename: cli.flags.rename,
parents: cli.flags.parents,
overwrite: cli.flags.overwrite,
dot: cli.flags.dot
dot: cli.flags.dot,
});
} catch (error) {
if (error.name === 'CpyError') {
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"cpy": "cli.js"
},
"engines": {
"node": ">=8"
"node": ">=12.20"
},
"type": "module",
"scripts": {
"test": "xo && ava"
},
Expand Down Expand Up @@ -50,14 +51,14 @@
"contents"
],
"dependencies": {
"cpy": "^8.0.0",
"meow": "^6.1.1"
"cpy": "^8.1.2",
"meow": "^10.1.2"
},
"devDependencies": {
"ava": "^2.4.0",
"execa": "^1.0.0",
"path-exists": "^4.0.0",
"tempfile": "^3.0.0",
"xo": "^0.25.3"
"ava": "^4.0.1",
"execa": "^6.1.0",
"path-exists": "^5.0.0",
"tempfile": "^4.0.0",
"xo": "^0.48.0"
}
}
16 changes: 8 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path';
import fs from 'fs';
import path from 'node:path';
import fs from 'node:fs';
import test from 'ava';
import tempfile from 'tempfile';
import execa from 'execa';
import pathExists from 'path-exists';
import {execa} from 'execa';
import {pathExistsSync} from 'path-exists';

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

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

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

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

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

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

0 comments on commit 7ee777f

Please sign in to comment.