From bb457e048083ab7811d1136907367cb3c9776ba7 Mon Sep 17 00:00:00 2001 From: David Chambers Date: Mon, 15 Jun 2020 11:30:00 +0200 Subject: [PATCH] drop support for unmaintained versions of Node.js --- .config | 2 +- bin/doctest | 9 ++----- lib/command.js | 19 --------------- lib/command.mjs | 25 +++++++++++++++++-- lib/common.js | 26 -------------------- package.json | 3 +++ test/index.js | 65 ++++++++++++++++++++----------------------------- 7 files changed, 55 insertions(+), 94 deletions(-) delete mode 100644 lib/command.js diff --git a/.config b/.config index 77639fdf..be08f381 100644 --- a/.config +++ b/.config @@ -1,5 +1,5 @@ repo-owner = davidchambers repo-name = doctest author-name = David Chambers -source-files = lib/*.js +source-files = lib/*.js lib/*.mjs version-tag-prefix = diff --git a/bin/doctest b/bin/doctest index f4b89b40..6a69e691 100755 --- a/bin/doctest +++ b/bin/doctest @@ -4,7 +4,6 @@ var path = require ('path'); -var esmSupported = Number ((process.versions.node.split ('.'))[0]) >= 9; var args = process.argv.slice (2); var idx = args.indexOf ('--nodejs'); var flags = idx >= 0 && idx < args.length - 1; @@ -12,13 +11,9 @@ var flags = idx >= 0 && idx < args.length - 1; require ('child_process') .spawn ( process.execPath, - [].concat (esmSupported ? ['--experimental-modules'] : []) + [].concat (['--experimental-modules']) .concat (flags ? args[idx + 1].split (/\s+/) : []) - .concat (['--', - path.resolve (__dirname, - '..', - 'lib', - 'command' + (esmSupported ? '.mjs' : '.js'))]) + .concat (['--', path.resolve (__dirname, '..', 'lib', 'command.mjs')]) .concat (flags ? (args.slice (0, idx)).concat (args.slice (idx + 2)) : args), {cwd: process.cwd (), env: process.env, stdio: [0, 1, 2]} diff --git a/lib/command.js b/lib/command.js deleted file mode 100644 index 4cb340d1..00000000 --- a/lib/command.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -var common = require ('./common'); -var program = require ('./program'); -var doctest = require ('..'); - - -if (program.module === 'esm') { - process.stderr.write ( - common.formatErrors ([ - 'Node.js v' + - process.versions.node + - ' does not support ECMAScript modules (supported since v9.0.0)' - ]) - ); - process.exit (1); -} - -common.runDoctests (doctest, program); diff --git a/lib/command.mjs b/lib/command.mjs index d3b8c314..897d47f1 100644 --- a/lib/command.mjs +++ b/lib/command.mjs @@ -1,5 +1,26 @@ -import common from './common.js'; import doctest from './doctest.mjs'; import program from './program.js'; -common.runDoctests (doctest, program); + +// formatErrors :: Array String -> String +function formatErrors(errors) { + return (errors.map (function(s) { return 'error: ' + s + '\n'; })).join (''); +} + +if (program.args.length === 0) { + process.stderr.write (formatErrors (['No files for doctesting provided'])); + process.exit (1); +} + +Promise.all (program.args.map (function(path) { + return (doctest (path, program)).then (function(results) { + return results.reduce (function(status, tuple) { + return tuple[0] ? status : 1; + }, 0); + }); +})).then (function(statuses) { + process.exit (statuses.every (function(s) { return s === 0; }) ? 0 : 1); +}, function(err) { + process.stderr.write (formatErrors ([err.message])); + process.exit (1); +}); diff --git a/lib/common.js b/lib/common.js index 8a9c5940..dae6b7a5 100644 --- a/lib/common.js +++ b/lib/common.js @@ -1,11 +1,6 @@ 'use strict'; -// formatErrors :: Array String -> String -exports.formatErrors = function(errors) { - return (errors.map (function(s) { return 'error: ' + s + '\n'; })).join (''); -}; - // sanitizeFileContents :: String -> String exports.sanitizeFileContents = function(contents) { return contents.replace (/\r\n?/g, '\n').replace (/^#!.*/, ''); @@ -15,24 +10,3 @@ exports.sanitizeFileContents = function(contents) { exports.unlines = function(lines) { return lines.reduce (function(s, line) { return s + line + '\n'; }, ''); }; - -exports.runDoctests = function(doctest, program) { - if (program.args.length === 0) { - process.stderr.write (exports.formatErrors ([ - 'No files for doctesting provided' - ])); - process.exit (1); - } - Promise.all (program.args.map (function(path) { - return (doctest (path, program)).then (function(results) { - return results.reduce (function(status, tuple) { - return tuple[0] ? status : 1; - }, 0); - }); - })).then (function(statuses) { - process.exit (statuses.every (function(s) { return s === 0; }) ? 0 : 1); - }, function(err) { - process.stderr.write (exports.formatErrors ([err.message])); - process.exit (1); - }); -}; diff --git a/package.json b/package.json index e55ce43b..c5499a56 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,9 @@ "type": "git", "url": "git://github.com/davidchambers/doctest.git" }, + "engines": { + "node": ">=10.0.0" + }, "dependencies": { "coffeescript": "1.12.x", "commander": "2.20.x", diff --git a/test/index.js b/test/index.js index ba271120..f18e1745 100644 --- a/test/index.js +++ b/test/index.js @@ -8,9 +8,6 @@ var Z = require ('sanctuary-type-classes'); var doctest = require ('..'); -var esmSupported = Number ((process.versions.node.split ('.'))[0]) >= 9; - - // unlines :: Array String -> String function unlines(lines) { return lines.reduce (function(s, line) { return s + line + '\n'; }, ''); @@ -62,7 +59,7 @@ function testCommand(command, expected) { var stderr = ''; try { stdout = execSync ( - command + (esmSupported ? ' --nodejs --no-warnings' : ''), + command + ' --nodejs --no-warnings', {encoding: 'utf8', stdio: 'pipe'} ); } catch (err) { @@ -211,43 +208,33 @@ testCommand ('bin/doctest --module commonjs lib/doctest.js', { stderr: '' }); -if (esmSupported) { - testCommand ('bin/doctest --module esm test/esm/index.mjs', { - status: 0, - stdout: unlines ([ - 'running doctests in test/esm/index.mjs...', - '.' - ]), - stderr: '' - }); +testCommand ('bin/doctest --module esm test/esm/index.mjs', { + status: 0, + stdout: unlines ([ + 'running doctests in test/esm/index.mjs...', + '.' + ]), + stderr: '' +}); - testCommand ('bin/doctest --module esm test/esm/dependencies.mjs', { - status: 0, - stdout: unlines ([ - 'running doctests in test/esm/dependencies.mjs...', - '.' - ]), - stderr: '' - }); +testCommand ('bin/doctest --module esm test/esm/dependencies.mjs', { + status: 0, + stdout: unlines ([ + 'running doctests in test/esm/dependencies.mjs...', + '.' + ]), + stderr: '' +}); - testCommand ('bin/doctest --module esm test/esm/incorrect.mjs', { - status: 1, - stdout: unlines ([ - 'running doctests in test/esm/incorrect.mjs...', - 'x', - 'FAIL: expected 32 on line 4 (got "0°F")' - ]), - stderr: '' - }); -} else { - testCommand ('bin/doctest --module esm test/esm/index.mjs', { - status: 1, - stdout: '', - stderr: unlines ([ - 'error: Node.js v' + process.versions.node + ' does not support ECMAScript modules (supported since v9.0.0)' - ]) - }); -} +testCommand ('bin/doctest --module esm test/esm/incorrect.mjs', { + status: 1, + stdout: unlines ([ + 'running doctests in test/esm/incorrect.mjs...', + 'x', + 'FAIL: expected 32 on line 4 (got "0°F")' + ]), + stderr: '' +}); testCommand ('bin/doctest --print test/commonjs/exports/index.js', { status: 0,