From 7ee777f6645d572f0fc2d51e55fbe197ab4f12cd Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Sun, 27 Feb 2022 12:51:25 +0300 Subject: [PATCH] Require Node.js 12 and move to ESM (#31) --- .github/workflows/main.yml | 4 ++-- cli.js | 24 +++++++++++++----------- package.json | 17 +++++++++-------- test.js | 16 ++++++++-------- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18531b3..9f06ce6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/cli.js b/cli.js index e11be56..02ea2cb 100755 --- a/cli.js +++ b/cli.js @@ -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 @@ -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 () => { @@ -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') { diff --git a/package.json b/package.json index 8c7c53c..3804cf7 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,9 @@ "cpy": "cli.js" }, "engines": { - "node": ">=8" + "node": ">=12.20" }, + "type": "module", "scripts": { "test": "xo && ava" }, @@ -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" } } diff --git a/test.js b/test.js index e99ca4b..7cdfcd0 100644 --- a/test.js +++ b/test.js @@ -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'); @@ -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 => { @@ -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'))); });