From 6e682545fc54e52bf5d870e9090ebcee6ddcd9d7 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Sun, 4 Jul 2021 14:58:29 +0200 Subject: [PATCH] Update supported Node.js version and dependencies --- .github/workflows/ci.yml | 2 +- .gitignore | 1 - index.js | 30 +++++++----------- package.json | 44 +++++++++++++------------- stage-4-plugins/best-match.js | 3 +- stage-4.js | 3 +- test/fixtures/esm-export.js | 3 +- test/fixtures/esm-import.cjs | 2 +- test/fixtures/esm-import.js | 2 +- test/fixtures/install-and-load.js | 2 +- test/protocol-ava-3.js | 2 +- test/snapshots/protocol-ava-3.js.md | 20 ++++++------ test/snapshots/protocol-ava-3.js.snap | Bin 522 -> 526 bytes test/snapshots/throws-helper.js.md | 2 +- test/snapshots/throws-helper.js.snap | Bin 376 -> 376 bytes test/stage-4.js | 4 +-- test/throws-helper.js | 2 +- test/transform-test-files.js | 13 +++----- throws-helper.js | 2 -- transform-test-files.js | 3 +- 20 files changed, 63 insertions(+), 77 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88f3391..37f37a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [^10.18.0, ^12.14.0, ^13.5.0] + node-version: [^12.22, ^14.16, ^16] os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v1 diff --git a/.gitignore b/.gitignore index 4f52d76..ccc2930 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -/.nyc_output /coverage /node_modules diff --git a/index.js b/index.js index ec54978..26cee96 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,3 @@ -'use strict'; const fs = require('fs'); const path = require('path'); const installPrecompiler = require('@ava/require-precompiled'); @@ -9,7 +8,7 @@ const convertSourceMap = require('convert-source-map'); const dotProp = require('dot-prop'); const escapeStringRegexp = require('escape-string-regexp'); const findUp = require('find-up'); -const isPlainObject = require('is-plain-object'); +const {isPlainObject} = require('is-plain-object'); const md5Hex = require('md5-hex'); const packageHash = require('package-hash'); const pkgConf = require('pkg-conf'); @@ -37,8 +36,8 @@ function enableParserPlugins(api) { return { name: 'ava-babel-pipeline-enable-parser-plugins', - manipulateOptions(_, parserOpts) { - parserOpts.plugins.push( + manipulateOptions(_, parserOptions) { + parserOptions.plugins.push( 'bigInt', 'classPrivateProperties', 'classProperties', @@ -77,13 +76,13 @@ function wantsStage4(babelOptions, projectDir) { return true; } - const stage4 = require('./stage-4'); - return babelOptions.presets.every(arr => { - if (!Array.isArray(arr)) { + const stage4 = require('./stage-4.js'); + return babelOptions.presets.every(array => { + if (!Array.isArray(array)) { return true; // There aren't any preset options. } - const [ref, options] = arr; + const [ref, options] = array; // Require the preset to handle any aliasing that may be taking place. const resolved = require(babel.resolvePreset(ref, projectDir)); return resolved !== stage4 || options !== false; @@ -119,12 +118,7 @@ function hashPartialConfig({babelrc, config, options: {plugins, presets}}, proje } const [firstComponent] = path.relative(projectDir, filename).split(path.sep); - let hash; - if (firstComponent === 'node_modules') { - hash = packageHash.sync(findUp.sync('package.json', {cwd: path.dirname(filename)})); - } else { - hash = md5Hex(stripBomBuf(fs.readFileSync(filename))); - } + const hash = firstComponent === 'node_modules' ? packageHash.sync(findUp.sync('package.json', {cwd: path.dirname(filename)})) : md5Hex(stripBomBuf(fs.readFileSync(filename))); pluginAndPresetHashes.set(filename, hash); inputs.push(hash); @@ -182,12 +176,12 @@ function createCompileFn({babelOptions, cacheDir, compileEnhancements, projectDi const {options: partialOptions} = partialConfig; partialOptions.plugins.push(enableParserPlugins); - if (ensureStage4 && !partialOptions.presets.some(containsStage4)) { + if (ensureStage4 && !partialOptions.presets.some(preset => containsStage4(preset))) { // Apply last. partialOptions.presets.unshift(createConfigItem('./stage-4', 'preset')); } - if (compileEnhancements && !partialOptions.presets.some(containsTransformTestFiles)) { + if (compileEnhancements && !partialOptions.presets.some(preset => containsTransformTestFiles(preset))) { // Apply first. partialOptions.presets.push(createConfigItem('./transform-test-files', 'preset', {powerAssert: true})); } @@ -344,13 +338,13 @@ module.exports = ({negotiateProtocol}) => { } return { - extensions: extensions.slice(), + extensions: [...extensions], lookup }; }, get extensions() { - return extensions.slice(); + return [...extensions]; } }; }, diff --git a/package.json b/package.json index 63ae3b7..90fa1a9 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.1", "description": "Babel provider for AVA", "engines": { - "node": ">=10.18.0 <11 || >=12.14.0 <13 || >=13.5.0" + "node": ">=12.22 <13 || >=14.16 <15 || >=16" }, "files": [ "espower-patterns.json", @@ -21,38 +21,38 @@ "babel" ], "scripts": { - "test": "xo && nyc ava" + "test": "xo && c8 ava" }, "dependencies": { "@ava/require-precompiled": "^1.0.0", - "@babel/core": "^7.8.4", - "@babel/generator": "^7.8.4", - "@babel/plugin-proposal-dynamic-import": "^7.8.3", - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3", - "@babel/plugin-proposal-optional-chaining": "^7.8.3", - "@babel/plugin-transform-modules-commonjs": "^7.8.3", + "@babel/core": "^7.14.6", + "@babel/generator": "^7.14.5", + "@babel/plugin-proposal-dynamic-import": "^7.14.5", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5", + "@babel/plugin-proposal-optional-chaining": "^7.14.5", + "@babel/plugin-transform-modules-commonjs": "^7.14.5", "babel-plugin-espower": "^3.0.1", - "concordance": "^4.0.0", - "convert-source-map": "^1.7.0", - "dot-prop": "^5.2.0", + "concordance": "^5.0.4", + "convert-source-map": "^1.8.0", + "dot-prop": "^6.0.1", "empower-core": "^1.2.0", - "escape-string-regexp": "^2.0.0", - "find-up": "^4.1.0", - "is-plain-object": "^3.0.0", + "escape-string-regexp": "^4.0.0", + "find-up": "^5.0.0", + "is-plain-object": "^5.0.0", "md5-hex": "^3.0.1", "package-hash": "^4.0.0", "pkg-conf": "^3.1.0", - "source-map-support": "^0.5.16", + "source-map-support": "^0.5.19", "strip-bom-buf": "^2.0.0", - "write-file-atomic": "^3.0.1" + "write-file-atomic": "^3.0.3" }, "devDependencies": { - "ava": "^3.2.0", - "execa": "^4.0.0", - "nyc": "^15.0.0", + "ava": "^3.15.0", + "c8": "^7.7.3", + "execa": "^5.1.1", "proxyquire": "^2.1.3", - "tempy": "^0.3.0", - "xo": "^0.25.3" + "tempy": "^1.0.1", + "xo": "^0.39.1" }, "ava": { "files": [ @@ -60,7 +60,7 @@ "!test/fixtures/**/*.js" ] }, - "nyc": { + "c8": { "reporter": [ "html", "lcov", diff --git a/stage-4-plugins/best-match.js b/stage-4-plugins/best-match.js index 19f6f34..beb7e77 100644 --- a/stage-4-plugins/best-match.js +++ b/stage-4-plugins/best-match.js @@ -1,4 +1,3 @@ -'use strict'; const process = require('process'); // eslint-disable-line node/prefer-global/process function getClosestVersion() { @@ -7,7 +6,7 @@ function getClosestVersion() { return 'v8-6.8'; } - const v8 = parseFloat(process.versions.v8); + const v8 = Number.parseFloat(process.versions.v8); if (v8 >= 6.8) { return 'v8-6.8'; } diff --git a/stage-4.js b/stage-4.js index 95781c5..554caf0 100644 --- a/stage-4.js +++ b/stage-4.js @@ -1,7 +1,6 @@ -'use strict'; module.exports = (api, options) => { const transformModules = !options || options.modules !== false; - const plugins = require('./stage-4-plugins/best-match') + const plugins = require('./stage-4-plugins/best-match.js') .filter(module => { if (transformModules) { return true; diff --git a/test/fixtures/esm-export.js b/test/fixtures/esm-export.js index 646633a..47c8f5a 100644 --- a/test/fixtures/esm-export.js +++ b/test/fixtures/esm-export.js @@ -1 +1,2 @@ -export default 'value from esm-export.js'; +const value = 'value from esm-export.js'; +export default value; diff --git a/test/fixtures/esm-import.cjs b/test/fixtures/esm-import.cjs index 21c17f7..d4f561b 100644 --- a/test/fixtures/esm-import.cjs +++ b/test/fixtures/esm-import.cjs @@ -1,3 +1,3 @@ -import value from './esm-export'; +import value from './esm-export.js'; console.log('logging in esm-import.cjs:', value); diff --git a/test/fixtures/esm-import.js b/test/fixtures/esm-import.js index 1f8620a..63e249e 100644 --- a/test/fixtures/esm-import.js +++ b/test/fixtures/esm-import.js @@ -1,3 +1,3 @@ -import value from './esm-export'; +import value from './esm-export.js'; console.log('logging in esm-import.js:', value); diff --git a/test/fixtures/install-and-load.js b/test/fixtures/install-and-load.js index 99e7c36..cbced61 100644 --- a/test/fixtures/install-and-load.js +++ b/test/fixtures/install-and-load.js @@ -1,5 +1,5 @@ const path = require('path'); -const makeProvider = require('../..'); +const makeProvider = require('../../index.js'); const provider = makeProvider({ negotiateProtocol() { diff --git a/test/protocol-ava-3.js b/test/protocol-ava-3.js index 05bf482..5d58161 100644 --- a/test/protocol-ava-3.js +++ b/test/protocol-ava-3.js @@ -124,7 +124,7 @@ test('worker(): load compiled files', withProvider, async (t, provider) => { t.log(stderr); } - t.snapshot(stdout, file); + t.snapshot(stdout, `${file}`); } }); diff --git a/test/snapshots/protocol-ava-3.js.md b/test/snapshots/protocol-ava-3.js.md index a3d3cbb..f6db398 100644 --- a/test/snapshots/protocol-ava-3.js.md +++ b/test/snapshots/protocol-ava-3.js.md @@ -2,9 +2,9 @@ The actual snapshot is saved in `protocol-ava-3.js.snap`. -Generated by [AVA](https://ava.li). +Generated by [AVA](https://avajs.dev). -## main() config validation: throw when babelConfig contains keys other than 'compileEnhancements', 'extensions' or 'testOptions' +## main() config validation: throw when babelConfig is not true or a plain object > Snapshot 1 @@ -12,21 +12,21 @@ Generated by [AVA](https://ava.li). message: 'Unexpected Babel configuration for AVA. See https://github.com/avajs/babel/blob/v${pkg.version}/README.md for allowed values.', } -## main() config validation: throw when babelConfig is not true or a plain object - -> Snapshot 1 +> Snapshot 2 Error { message: 'Unexpected Babel configuration for AVA. See https://github.com/avajs/babel/blob/v${pkg.version}/README.md for allowed values.', } -> Snapshot 2 +> Snapshot 3 Error { message: 'Unexpected Babel configuration for AVA. See https://github.com/avajs/babel/blob/v${pkg.version}/README.md for allowed values.', } -> Snapshot 3 +## main() config validation: throw when babelConfig contains keys other than 'compileEnhancements', 'extensions' or 'testOptions' + +> Snapshot 1 Error { message: 'Unexpected Babel configuration for AVA. See https://github.com/avajs/babel/blob/v${pkg.version}/README.md for allowed values.', @@ -40,7 +40,7 @@ Generated by [AVA](https://ava.li). message: 'Unexpected Babel configuration for AVA. See https://github.com/avajs/babel/blob/v${pkg.version}/README.md for allowed values.', } -## main() config validation: throw when babelConfig.extensions contains duplicates +## main() config validation: throw when babelConfig.extensions contains empty strings > Snapshot 1 @@ -48,7 +48,7 @@ Generated by [AVA](https://ava.li). message: 'Unexpected Babel configuration for AVA. See https://github.com/avajs/babel/blob/v${pkg.version}/README.md for allowed values.', } -## main() config validation: throw when babelConfig.extensions contains empty strings +## main() config validation: throw when babelConfig.extensions contains non-strings > Snapshot 1 @@ -56,7 +56,7 @@ Generated by [AVA](https://ava.li). message: 'Unexpected Babel configuration for AVA. See https://github.com/avajs/babel/blob/v${pkg.version}/README.md for allowed values.', } -## main() config validation: throw when babelConfig.extensions contains non-strings +## main() config validation: throw when babelConfig.extensions contains duplicates > Snapshot 1 diff --git a/test/snapshots/protocol-ava-3.js.snap b/test/snapshots/protocol-ava-3.js.snap index 88f3314f3b08f2bdf85107f0b008bf5304821411..b27b6d1fa88915503b2522ea3ba1378e08ce75e6 100644 GIT binary patch delta 491 zcmVlaUd|5)cqz zVB}?BWMp9E2Pqa|WM*Jw6=Y=3O)V}?OizXJYeVx=D+*GROHxx5oD!2#bAJ?)^YhX& z(@TpIOEUBG6w>mG6dc1G^%R0rQx!5wN(zdt^!3v-OEOB6^pf*)^%Khyvx@bTKsxo4 za`Kb(%T%fhveWg-Qj3a#`fK%rTpe9}UG;KPz(ytJa$Uw;qe(OgCL`EPJViNWXIobiz&FMsqn z2Nf^q+2jA;A@kO)K<`hCV9^YqhMZN)wKBIoQH<#>R=R(}W)UM;)QN?G;lzm*C1TSU z(_cvz$gJS_lE4TSm0@LIn3>yC-=+6Hyw#$0f6Vha42)pWZ$Lcbd!!F*vToSa>Z$3C zI3U_UMa4kjxN5gdbufJqY`s+^2>o%l_lnsrWWgs`fSu^qdpt;*{IJ( zeKzW|QJ)Q{&sZ4*8I5!D)6+BaG}09^^Au8xb9FOw3-XIf^pdlRtsv?Z(u(qP!BRjc YgQT*GQ4BD`ZU8?00HxsjEZqtK05ALD%>V!Z diff --git a/test/snapshots/throws-helper.js.md b/test/snapshots/throws-helper.js.md index 1b874c0..07a1e5e 100644 --- a/test/snapshots/throws-helper.js.md +++ b/test/snapshots/throws-helper.js.md @@ -2,7 +2,7 @@ The actual snapshot is saved in `throws-helper.js.snap`. -Generated by [AVA](https://ava.li). +Generated by [AVA](https://avajs.dev). ## creates a helper diff --git a/test/snapshots/throws-helper.js.snap b/test/snapshots/throws-helper.js.snap index 99dc6ecf1cb4f8ee7ad8b8f4ac1c02c4986eacfd..fd4146a0ccf7e01d1807ea6ea274c26a803377ab 100644 GIT binary patch literal 376 zcmV-;0f+uURzVtY6)GMaJIOn*3;vb6$00000000Ba zV_;xlVbERraqWav(>SiC?zNHqkS)N-00L4#91=Z!lk)j$kJ$SmPFI<@nHa&M%|HcJ zyt^BA{}(^ox@5=WN@KAcMzE+qGXuk(#?FH*OROX39SAFYajQ*}5iGiog@J*YfgNlz zBP)X-BTtE5X0b+Ee!hmLrZut*Qxs!bXa7kiO ziAITzLSk`oY7t0@jzU^yPO6SVPG(-Jrb0EBfJtkbt444lY+hf*C!a_l^cM%>tTsRwN}BVTsFx5geC!`6VF) W!y2xL17U?PZnbGLf<^bSFfcGPu!Buz zWMvR!iegMF%}XxH%+FJZPb^Ce$tcP%FZM{yDM&2}E=epZ(J0YTNGvW+EdnXgQAo?o zN!3xv$;?aDRH)`sP{>SE&?wQ1F9BO|yWeofS!mMVN8P$Wx-1S*!uE9yOK|MsO_W<(GsI Wj0LzNk|UxD5)l9@OI4^W1polkv7Q(J diff --git a/test/stage-4.js b/test/stage-4.js index e53ed22..b981052 100644 --- a/test/stage-4.js +++ b/test/stage-4.js @@ -25,9 +25,9 @@ const buildPreset = (node, v8, options) => proxyquire('../stage-4', { function buildsCorrectPreset(t, node, v8, mapping) { const {plugins} = buildPreset(node, v8); - require(mapping).forEach((module, index) => { + for (const [index, module] of require(mapping).entries()) { t.is(require(module).default, plugins[index], `${module} at index ${index}`); - }); + } } buildsCorrectPreset.title = (_, node) => `builds correct preset for Node.js ${node}`; diff --git a/test/throws-helper.js b/test/throws-helper.js index 6ce24d2..c4e188e 100644 --- a/test/throws-helper.js +++ b/test/throws-helper.js @@ -1,6 +1,6 @@ const test = require('ava'); const babel = require('@babel/core'); -const fn = require('../throws-helper'); +const fn = require('../throws-helper.js'); function transform(input) { return babel.transform(input, { diff --git a/test/transform-test-files.js b/test/transform-test-files.js index d2af439..0b6f1bd 100644 --- a/test/transform-test-files.js +++ b/test/transform-test-files.js @@ -2,8 +2,8 @@ const {runInNewContext} = require('vm'); const test = require('ava'); const babel = require('@babel/core'); const empower = require('empower-core'); -const throwsHelper = require('../throws-helper'); -const buildPreset = require('../transform-test-files'); +const throwsHelper = require('../throws-helper.js'); +const buildPreset = require('../transform-test-files.js'); const ESPOWER_PATTERNS = require('../espower-patterns.json'); @@ -27,12 +27,9 @@ test('resulting preset transforms assertion patterns', t => { const appliedPatterns = []; // Create a stub assertion object that can be enhanced using empower-core - const assert = ESPOWER_PATTERNS - .map(p => /^t\.(.+)\(/.exec(p)[1]) // eslint-disable-line prefer-named-capture-group - .reduce((assert, name) => { - assert[name] = () => {}; - return assert; - }, {}); + const assert = Object.fromEntries(ESPOWER_PATTERNS + .map(p => /^t\.(.+)\(/.exec(p)[1]) + .map(name => [name, () => {}])); runInNewContext(code, { t: empower(assert, { diff --git a/throws-helper.js b/throws-helper.js index ce9fdd3..f80b8a3 100644 --- a/throws-helper.js +++ b/throws-helper.js @@ -1,5 +1,3 @@ -'use strict'; - module.exports = babelCore => { const t = babelCore.types; const wrapArg = babelCore.template('(START(t, ASSERTION, FILE, LINE), END(t, ARG))'); diff --git a/transform-test-files.js b/transform-test-files.js index d8298ee..341416a 100644 --- a/transform-test-files.js +++ b/transform-test-files.js @@ -1,4 +1,3 @@ -'use strict'; const ESPOWER_PATTERNS = require('./espower-patterns.json'); module.exports = (context, options) => { @@ -11,7 +10,7 @@ module.exports = (context, options) => { }]); } - plugins.push(require('./throws-helper')); + plugins.push(require('./throws-helper.js')); return {plugins}; };