Skip to content

Commit 729420a

Browse files
committed
Convert to ESM
1 parent f1ea8c9 commit 729420a

File tree

214 files changed

+1006
-950
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+1006
-950
lines changed

.xo-config.json

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"ignores": [
3+
"media/**",
4+
"test/config/fixtures/config-errors/test.js",
5+
"test/config/fixtures/mjs-with-tests/**",
6+
"test-tap/fixture/ava-paths/target/test.js",
7+
"test-tap/fixture/{source-map-initial,syntax-error}.js",
8+
"test-tap/fixture/snapshots/test-sourcemaps/build/**",
9+
"test-tap/fixture/power-assert.js",
10+
"test-tap/fixture/report/edgecases/ast-syntax-error.js"
11+
],
12+
"rules": {
13+
"import/no-anonymous-default-export": "off",
14+
"import/no-mutable-exports": "off",
15+
"import/order": [
16+
"error",
17+
{
18+
"alphabetize": {
19+
"order": "asc"
20+
},
21+
"newlines-between": "always"
22+
}
23+
],
24+
"import/newline-after-import": "error",
25+
"node/no-unsupported-features/es-syntax": "off",
26+
"no-use-extend-native/no-use-extend-native": "off"
27+
},
28+
"overrides": [
29+
{
30+
"files": "index.d.ts",
31+
"rules": {
32+
"@typescript-eslint/member-ordering": "off",
33+
"@typescript-eslint/method-signature-style": "off",
34+
"@typescript-eslint/prefer-readonly-parameter-types": "off",
35+
"@typescript-eslint/prefer-function-type": "off",
36+
"@typescript-eslint/unified-signatures": "off"
37+
}
38+
},
39+
{
40+
"files": "test-{d,tap}/**/*.ts",
41+
"rules": {
42+
"@typescript-eslint/explicit-function-return-type": "off",
43+
"@typescript-eslint/no-empty-function": "off",
44+
"@typescript-eslint/no-unsafe-call": "off",
45+
"@typescript-eslint/no-unsafe-member-access": "off",
46+
"@typescript-eslint/no-unsafe-return": "off",
47+
"@typescript-eslint/no-unused-vars": "off",
48+
"@typescript-eslint/prefer-readonly-parameter-types": "off",
49+
"import/extensions": "off",
50+
"no-unused-vars": "off"
51+
}
52+
},
53+
{
54+
"files": "test-tap/**/*.js",
55+
"rules": {
56+
"promise/prefer-await-to-then": "off",
57+
"unicorn/error-message": "off",
58+
"unicorn/no-array-reduce": "off",
59+
"unicorn/prevent-abbreviations": "off"
60+
}
61+
},
62+
{
63+
"files": [
64+
"test-tap/fixture/**",
65+
"test/**/fixtures/**"
66+
],
67+
"rules": {
68+
"ava/no-todo-test": "off",
69+
"import/no-extraneous-dependencies": "off",
70+
"import/no-unresolved": "off"
71+
}
72+
}
73+
]
74+
}

entrypoints/cli.mjs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/usr/bin/env node
2-
import * as cli from '../lib/cli.js'; // eslint-disable-line import/extensions
3-
cli.run();
2+
import run from '../lib/cli.js';
3+
4+
run();

entrypoints/main.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import test from '../lib/worker/main.cjs';
2+
23
export default test;

lib/api.js

+23-24
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
'use strict';
2-
const fs = require('fs');
3-
const path = require('path');
4-
const os = require('os');
5-
const commonPathPrefix = require('common-path-prefix');
6-
const resolveCwd = require('resolve-cwd');
7-
const debounce = require('lodash/debounce');
8-
const arrify = require('arrify');
9-
const ms = require('ms');
10-
const chunkd = require('chunkd');
11-
const Emittery = require('emittery');
12-
const pMap = require('p-map');
13-
const tempDir = require('temp-dir');
14-
const globs = require('./globs');
15-
const isCi = require('./is-ci');
16-
const RunStatus = require('./run-status');
17-
const fork = require('./fork');
18-
const serializeError = require('./serialize-error');
19-
const {getApplicableLineNumbers} = require('./line-numbers');
20-
const sharedWorkers = require('./plugin-support/shared-workers');
21-
const scheduler = require('./scheduler');
1+
import fs from 'fs';
2+
import os from 'os';
3+
import path from 'path';
4+
5+
import arrify from 'arrify';
6+
import chunkd from 'chunkd';
7+
import commonPathPrefix from 'common-path-prefix';
8+
import Emittery from 'emittery';
9+
import debounce from 'lodash/debounce.js';
10+
import ms from 'ms';
11+
import pMap from 'p-map';
12+
import resolveCwd from 'resolve-cwd';
13+
import tempDir from 'temp-dir';
14+
15+
import fork from './fork.js';
16+
import * as globs from './globs.js';
17+
import isCi from './is-ci.js';
18+
import {getApplicableLineNumbers} from './line-numbers.js';
19+
import * as sharedWorkers from './plugin-support/shared-workers.js';
20+
import RunStatus from './run-status.js';
21+
import * as scheduler from './scheduler.js';
22+
import serializeError from './serialize-error.js';
2223

2324
function resolveModules(modules) {
2425
return arrify(modules).map(name => {
@@ -41,7 +42,7 @@ function getFilePathPrefix(files) {
4142
return commonPathPrefix(files);
4243
}
4344

44-
class Api extends Emittery {
45+
export default class Api extends Emittery {
4546
constructor(options) {
4647
super();
4748

@@ -282,5 +283,3 @@ class Api extends Emittery {
282283
return cacheDir;
283284
}
284285
}
285-
286-
module.exports = Api;

lib/assert.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
'use strict';
2-
const concordance = require('concordance');
3-
const isError = require('is-error');
4-
const isPromise = require('is-promise');
5-
const concordanceOptions = require('./concordance-options').default;
6-
const {CIRCULAR_SELECTOR, isLikeSelector, selectComparable} = require('./like-selector');
7-
const snapshotManager = require('./snapshot-manager');
1+
import concordance from 'concordance';
2+
import isError from 'is-error';
3+
import isPromise from 'is-promise';
4+
5+
import concordanceOptions from './concordance-options.js';
6+
import {CIRCULAR_SELECTOR, isLikeSelector, selectComparable} from './like-selector.js';
7+
import * as snapshotManager from './snapshot-manager.js';
88

99
function formatDescriptorDiff(actualDescriptor, expectedDescriptor, options) {
1010
options = {...options, ...concordanceOptions};
@@ -35,7 +35,7 @@ const notImplemented = () => {
3535
throw new Error('not implemented');
3636
};
3737

38-
class AssertionError extends Error {
38+
export class AssertionError extends Error {
3939
constructor(options) {
4040
super(options.message || '');
4141
this.name = 'AssertionError';
@@ -58,9 +58,8 @@ class AssertionError extends Error {
5858
this.savedError = options.savedError ? options.savedError : getErrorWithLongStackTrace();
5959
}
6060
}
61-
exports.AssertionError = AssertionError;
6261

63-
function checkAssertionMessage(assertion, message) {
62+
export function checkAssertionMessage(assertion, message) {
6463
if (typeof message === 'undefined' || typeof message === 'string') {
6564
return true;
6665
}
@@ -73,8 +72,6 @@ function checkAssertionMessage(assertion, message) {
7372
});
7473
}
7574

76-
exports.checkAssertionMessage = checkAssertionMessage;
77-
7875
function getErrorWithLongStackTrace() {
7976
const limitBefore = Error.stackTraceLimit;
8077
Error.stackTraceLimit = Number.POSITIVE_INFINITY;
@@ -254,7 +251,7 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
254251
}
255252
}
256253

257-
class Assertions {
254+
export class Assertions {
258255
constructor({
259256
pass = notImplemented,
260257
pending = notImplemented,
@@ -990,4 +987,3 @@ class Assertions {
990987
}
991988
}
992989
}
993-
exports.Assertions = Assertions;

lib/chalk.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
'use strict';
2-
const chalk = require('chalk');
1+
import chalk from 'chalk';
32

4-
let ctx = null;
5-
exports.get = () => {
6-
if (!ctx) {
7-
throw new Error('Chalk has not yet been configured');
8-
}
9-
10-
return ctx;
11-
};
3+
let instance = new chalk.Instance();
4+
export default instance;
125

13-
exports.set = options => {
14-
if (ctx) {
6+
let configured = false;
7+
export function set(options) {
8+
if (configured) {
159
throw new Error('Chalk has already been configured');
1610
}
1711

18-
ctx = new chalk.Instance(options);
19-
return ctx;
20-
};
12+
configured = true;
13+
instance = new chalk.Instance(options);
14+
}

lib/cli.js

+43-32
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
1-
'use strict';
2-
const path = require('path');
3-
const del = require('del');
4-
const updateNotifier = require('update-notifier');
5-
const figures = require('figures');
6-
const arrify = require('arrify');
7-
const yargs = require('yargs');
8-
const readPkg = require('read-pkg');
9-
const isCi = require('./is-ci');
10-
const {loadConfig} = require('./load-config');
1+
import {createRequire} from 'module';
2+
import path from 'path';
3+
4+
import arrify from 'arrify';
5+
import ciParallelVars from 'ci-parallel-vars';
6+
import del from 'del';
7+
import figures from 'figures';
8+
import readPkg from 'read-pkg';
9+
import updateNotifier from 'update-notifier';
10+
11+
import Api from './api.js';
12+
import chalk from './chalk.js';
13+
import validateEnvironmentVariables from './environment-variables.js';
14+
import normalizeExtensions from './extensions.js';
15+
import {normalizeGlobs, normalizePattern} from './globs.js';
16+
import {controlFlow} from './ipc-flow-control.cjs';
17+
import isCi from './is-ci.js';
18+
import {splitPatternAndLineNumbers} from './line-numbers.js';
19+
import {loadConfig} from './load-config.js';
20+
import normalizeModuleTypes from './module-types.js';
21+
import normalizeNodeArguments from './node-arguments.js';
22+
import avaPackage from './pkg.cjs';
23+
import * as providerManager from './provider-manager.js';
24+
import DefaultReporter from './reporters/default.js';
25+
import TapReporter from './reporters/tap.js';
26+
import Watcher from './watcher.js';
27+
28+
const yargs = createRequire(import.meta.url)('yargs'); // FIXME: Use ESM
1129

1230
function exit(message) {
13-
console.error(`\n ${require('./chalk').get().red(figures.cross)} ${message}`);
31+
console.error(`\n ${chalk.red(figures.cross)} ${message}`);
1432
process.exit(1); // eslint-disable-line unicorn/no-process-exit
1533
}
1634

@@ -83,7 +101,7 @@ const FLAGS = {
83101
}
84102
};
85103

86-
exports.run = async () => { // eslint-disable-line complexity
104+
export default async () => { // eslint-disable-line complexity
87105
let conf = {};
88106
let confError = null;
89107
try {
@@ -96,7 +114,13 @@ exports.run = async () => { // eslint-disable-line complexity
96114
// Enter debug mode if the main process is being inspected. This assumes the
97115
// worker processes are automatically inspected, too. It is not necessary to
98116
// run AVA with the debug command, though it's allowed.
99-
const activeInspector = require('inspector').url() !== undefined; // eslint-disable-line node/no-unsupported-features/node-builtins
117+
let activeInspector = false;
118+
try {
119+
const {default: inspector} = await import('inspector');
120+
121+
activeInspector = inspector.url() !== undefined;
122+
} catch {}
123+
100124
let debug = activeInspector ?
101125
{
102126
active: true,
@@ -207,8 +231,9 @@ exports.run = async () => { // eslint-disable-line complexity
207231
}
208232
}
209233

210-
const chalkOptions = {level: combined.color === false ? 0 : require('chalk').level};
211-
const chalk = require('./chalk').set(chalkOptions);
234+
const chalkOptions = {level: combined.color === false ? 0 : (await import('chalk')).level};
235+
const {set: setChalk} = await import('./chalk.js');
236+
setChalk(chalkOptions);
212237

213238
if (confError) {
214239
if (confError.parent) {
@@ -218,7 +243,7 @@ exports.run = async () => { // eslint-disable-line complexity
218243
}
219244
}
220245

221-
updateNotifier({pkg: require('../package.json')}).notify();
246+
updateNotifier({pkg: avaPackage}).notify();
222247

223248
const {nonSemVerExperiments: experiments, projectDir} = conf;
224249
if (resetCache) {
@@ -285,19 +310,6 @@ exports.run = async () => { // eslint-disable-line complexity
285310
exit('’sources’ has been removed. Use ’ignoredByWatcher’ to provide glob patterns of files that the watcher should ignore.');
286311
}
287312

288-
const ciParallelVars = require('ci-parallel-vars');
289-
const Api = require('./api');
290-
const DefaultReporter = require('./reporters/default');
291-
const TapReporter = require('./reporters/tap');
292-
const Watcher = require('./watcher');
293-
const normalizeExtensions = require('./extensions');
294-
const normalizeModuleTypes = require('./module-types');
295-
const {normalizeGlobs, normalizePattern} = require('./globs');
296-
const normalizeNodeArguments = require('./node-arguments');
297-
const validateEnvironmentVariables = require('./environment-variables');
298-
const {splitPatternAndLineNumbers} = require('./line-numbers');
299-
const providerManager = require('./provider-manager');
300-
301313
let pkg;
302314
try {
303315
pkg = readPkg.sync({cwd: projectDir});
@@ -312,7 +324,7 @@ exports.run = async () => { // eslint-disable-line complexity
312324
const providers = [];
313325
if (Reflect.has(conf, 'babel')) {
314326
try {
315-
const {level, main} = providerManager.babel(projectDir);
327+
const {level, main} = await providerManager.babel(projectDir);
316328
providers.push({
317329
level,
318330
main: main({config: conf.babel}),
@@ -325,7 +337,7 @@ exports.run = async () => { // eslint-disable-line complexity
325337

326338
if (Reflect.has(conf, 'typescript')) {
327339
try {
328-
const {level, main} = providerManager.typescript(projectDir);
340+
const {level, main} = await providerManager.typescript(projectDir);
329341
providers.push({
330342
level,
331343
main: main({config: conf.typescript}),
@@ -430,7 +442,6 @@ exports.run = async () => { // eslint-disable-line complexity
430442
reporter.startRun(plan);
431443

432444
if (process.env.AVA_EMIT_RUN_STATUS_OVER_IPC === 'I\'ll find a payphone baby / Take some time to talk to you') {
433-
const {controlFlow} = require('./ipc-flow-control');
434445
const bufferedSend = controlFlow(process);
435446

436447
plan.status.on('stateChange', evt => {

lib/code-excerpt.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
'use strict';
2-
const fs = require('fs');
3-
const equalLength = require('equal-length');
4-
const codeExcerpt = require('code-excerpt');
5-
const truncate = require('cli-truncate');
6-
const chalk = require('./chalk').get();
1+
import fs from 'fs';
2+
3+
import truncate from 'cli-truncate';
4+
import codeExcerpt from 'code-excerpt';
5+
import equalLength from 'equal-length';
6+
7+
import chalk from './chalk.js';
78

89
const formatLineNumber = (lineNumber, maxLineNumber) =>
910
' '.repeat(Math.max(0, String(maxLineNumber).length - String(lineNumber).length)) + lineNumber;
1011

11-
module.exports = (source, options = {}) => {
12+
export default (source, options = {}) => {
1213
if (!source.isWithinProject || source.isDependency) {
1314
return null;
1415
}

0 commit comments

Comments
 (0)