Skip to content

Commit

Permalink
Update supported Node.js version and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Jul 4, 2021
1 parent 5e7279b commit 6e68254
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .gitignore
@@ -1,3 +1,2 @@
/.nyc_output
/coverage
/node_modules
30 changes: 12 additions & 18 deletions index.js
@@ -1,4 +1,3 @@
'use strict';
const fs = require('fs');
const path = require('path');
const installPrecompiler = require('@ava/require-precompiled');
Expand All @@ -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');
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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}));
}
Expand Down Expand Up @@ -344,13 +338,13 @@ module.exports = ({negotiateProtocol}) => {
}

return {
extensions: extensions.slice(),
extensions: [...extensions],
lookup
};
},

get extensions() {
return extensions.slice();
return [...extensions];
}
};
},
Expand Down
44 changes: 22 additions & 22 deletions package.json
Expand Up @@ -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",
Expand All @@ -21,46 +21,46 @@
"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": [
"test/**/*.js",
"!test/fixtures/**/*.js"
]
},
"nyc": {
"c8": {
"reporter": [
"html",
"lcov",
Expand Down
3 changes: 1 addition & 2 deletions 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() {
Expand All @@ -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';
}
Expand Down
3 changes: 1 addition & 2 deletions 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;
Expand Down
3 changes: 2 additions & 1 deletion 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;
2 changes: 1 addition & 1 deletion 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);
2 changes: 1 addition & 1 deletion 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);
2 changes: 1 addition & 1 deletion 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() {
Expand Down
2 changes: 1 addition & 1 deletion test/protocol-ava-3.js
Expand Up @@ -124,7 +124,7 @@ test('worker(): load compiled files', withProvider, async (t, provider) => {
t.log(stderr);
}

t.snapshot(stdout, file);
t.snapshot(stdout, `${file}`);
}
});

Expand Down
20 changes: 10 additions & 10 deletions test/snapshots/protocol-ava-3.js.md
Expand Up @@ -2,31 +2,31 @@

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
Error {
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.',
Expand All @@ -40,23 +40,23 @@ 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
Error {
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
Error {
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
Expand Down
Binary file modified test/snapshots/protocol-ava-3.js.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion test/snapshots/throws-helper.js.md
Expand Up @@ -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

Expand Down
Binary file modified test/snapshots/throws-helper.js.snap
Binary file not shown.
4 changes: 2 additions & 2 deletions test/stage-4.js
Expand Up @@ -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}`;
Expand Down
2 changes: 1 addition & 1 deletion 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, {
Expand Down
13 changes: 5 additions & 8 deletions test/transform-test-files.js
Expand Up @@ -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');

Expand All @@ -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, {
Expand Down
2 changes: 0 additions & 2 deletions 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))');
Expand Down
3 changes: 1 addition & 2 deletions transform-test-files.js
@@ -1,4 +1,3 @@
'use strict';
const ESPOWER_PATTERNS = require('./espower-patterns.json');

module.exports = (context, options) => {
Expand All @@ -11,7 +10,7 @@ module.exports = (context, options) => {
}]);
}

plugins.push(require('./throws-helper'));
plugins.push(require('./throws-helper.js'));

return {plugins};
};

0 comments on commit 6e68254

Please sign in to comment.