Skip to content

Commit

Permalink
Dependency updates
Browse files Browse the repository at this point in the history
* Fix reference to chalk's color level

* Upgrade XO and reformat

* Update dev dependencies

* Update production dependencies

* Rebuild lockfile

* CI: Continue when 'npm ls' errors in TypeScript compatibility job
  • Loading branch information
novemberborn committed Jan 2, 2022
1 parent 29024af commit 0187779
Show file tree
Hide file tree
Showing 24 changed files with 1,868 additions and 2,046 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Expand Up @@ -58,6 +58,7 @@ jobs:
env:
TS_VERSION: ${{ matrix.ts-version }}
- run: npm ls typescript
continue-on-error: true
- run: npx tsd

lockfile_churn:
Expand Down
9 changes: 9 additions & 0 deletions .xo-config.cjs
Expand Up @@ -40,6 +40,15 @@ module.exports = {
'unicorn/prefer-module': 'off',
},
},
{
files: [
'test/**/fixtures/**',
'test-tap/**fixture/**',
],
rules: {
'unicorn/no-empty-file': 'off',
},
},
{
// TODO: Update tests.
files: 'test/**',
Expand Down
4 changes: 1 addition & 3 deletions entrypoints/main.mjs
@@ -1,3 +1 @@
import test from '../lib/worker/main.cjs';

export default test;
export {default} from '../lib/worker/main.cjs';
9 changes: 6 additions & 3 deletions lib/api.js
Expand Up @@ -232,10 +232,13 @@ export default class Api extends Emittery {
}
});

const providerStates = (await Promise.all(providers.map(async ({type, main}) => {
const providerStates = [];
await Promise.all(providers.map(async ({type, main}) => {
const state = await main.compile({cacheDir: this._createCacheDir(), files: testFiles});
return state === null ? null : {type, state};
}))).filter(state => state !== null);
if (state !== null) {
providerStates.push({type, state});
}
}));

// Resolve the correct concurrency value.
let concurrency = Math.min(os.cpus().length, isCi ? 2 : Number.POSITIVE_INFINITY);
Expand Down
9 changes: 4 additions & 5 deletions lib/chalk.js
@@ -1,9 +1,8 @@
import chalk from 'chalk';
import {Chalk} from 'chalk'; // eslint-disable-line unicorn/import-style

let instance = new chalk.Instance(); // eslint-disable-line import/no-mutable-exports
export default instance;
let chalk = new Chalk(); // eslint-disable-line import/no-mutable-exports

export {instance as chalk};
export {chalk};

let configured = false;
export function set(options) {
Expand All @@ -12,5 +11,5 @@ export function set(options) {
}

configured = true;
instance = new chalk.Instance(options);
chalk = new Chalk(options);
}
7 changes: 6 additions & 1 deletion lib/cli.js
Expand Up @@ -231,7 +231,12 @@ export default async function loadCli() { // eslint-disable-line complexity
}
}

const chalkOptions = {level: combined.color === false ? 0 : (await import('chalk')).level}; // eslint-disable-line node/no-unsupported-features/es-syntax
const chalkOptions = {level: 0};
if (combined.color !== false) {
const {supportsColor: {level}} = await import('chalk'); // eslint-disable-line node/no-unsupported-features/es-syntax, unicorn/import-style
chalkOptions.level = level;
}

const {set: setChalk} = await import('./chalk.js'); // eslint-disable-line node/no-unsupported-features/es-syntax
setChalk(chalkOptions);

Expand Down
3 changes: 2 additions & 1 deletion lib/concordance-options.js
@@ -1,11 +1,12 @@
import {inspect} from 'node:util';

import ansiStyles from 'ansi-styles';
import {Chalk} from 'chalk'; // eslint-disable-line unicorn/import-style
import stripAnsi from 'strip-ansi';

import {chalk} from './chalk.js';

const forceColor = new chalk.Instance({level: Math.max(chalk.level, 1)});
const forceColor = new Chalk({level: Math.max(chalk.level, 1)});

const colorTheme = {
boolean: ansiStyles.yellow,
Expand Down
2 changes: 1 addition & 1 deletion lib/fork.js
Expand Up @@ -4,7 +4,7 @@ import {fileURLToPath} from 'node:url';
import {Worker} from 'node:worker_threads';

import Emittery from 'emittery';
import pEvent from 'p-event';
import {pEvent} from 'p-event';

import {controlFlow} from './ipc-flow-control.cjs';
import serializeError from './serialize-error.js';
Expand Down
18 changes: 8 additions & 10 deletions lib/globs.js
Expand Up @@ -4,27 +4,23 @@ import path from 'node:path';
import {globby, globbySync} from 'globby';

import {
classify,
defaultIgnorePatterns,
hasExtension,
isHelperish,
matches,
normalizeFileForMatching,
normalizePattern,
normalizePatterns,
processMatchingPatterns,
} from './glob-helpers.cjs';

export {
classify,
defaultIgnorePatterns,
hasExtension,
isHelperish,
matches,
normalizeFileForMatching,
normalizePattern,
defaultIgnorePatterns,
hasExtension,
normalizeFileForMatching,
normalizePatterns,
};
} from './glob-helpers.cjs';

const defaultIgnoredByWatcherPatterns = [
'**/*.snap.md', // No need to rerun tests when the Markdown files change.
Expand Down Expand Up @@ -120,11 +116,13 @@ const globDirectoriesSync = (cwd, patterns) => {
};

export async function findFiles({cwd, extensions, filePatterns}) {
return (await globFiles(cwd, filePatterns)).filter(file => hasExtension(extensions, file));
const files = await globFiles(cwd, filePatterns);
return files.filter(file => hasExtension(extensions, file));
}

export async function findTests({cwd, extensions, filePatterns}) {
return (await findFiles({cwd, extensions, filePatterns})).filter(file => !path.basename(file).startsWith('_'));
const files = await findFiles({cwd, extensions, filePatterns});
return files.filter(file => !path.basename(file).startsWith('_'));
}

export function getChokidarIgnorePatterns({ignoredByWatcherPatterns}) {
Expand Down
6 changes: 4 additions & 2 deletions lib/load-config.js
Expand Up @@ -86,11 +86,13 @@ export async function loadConfig({configFile, resolveFrom = process.cwd(), defau
let searchDir = projectDir;
const stopAt = path.dirname(repoRoot);
do {
[{config: fileConf, fileForErrorMessage, configFile} = {config: NO_SUCH_FILE, fileForErrorMessage: undefined}, ...conflicting] = (await Promise.all([ // eslint-disable-line no-await-in-loop
const results = await Promise.all([ // eslint-disable-line no-await-in-loop
loadConfigFile({projectDir, configFile: path.join(searchDir, 'ava.config.js')}),
loadConfigFile({projectDir, configFile: path.join(searchDir, 'ava.config.cjs')}),
loadConfigFile({projectDir, configFile: path.join(searchDir, 'ava.config.mjs')}),
])).filter(result => result !== null);
]);

[{config: fileConf, fileForErrorMessage, configFile} = {config: NO_SUCH_FILE, fileForErrorMessage: undefined}, ...conflicting] = results.filter(result => result !== null);

searchDir = path.dirname(searchDir);
} while (fileConf === NO_SUCH_FILE && searchDir !== stopAt);
Expand Down
10 changes: 5 additions & 5 deletions lib/worker/base.js
Expand Up @@ -123,13 +123,13 @@ const run = async options => {
// Install before processing options.require, so if helpers are added to the
// require configuration the *compiled* helper will be loaded.
const {projectDir, providerStates = []} = options;
const providers = (await Promise.all(providerStates.map(async ({type, state}) => {
const providers = [];
await Promise.all(providerStates.map(async ({type, state}) => {
if (type === 'typescript') {
return (await providerManager.typescript(projectDir)).worker({extensionsToLoadAsModules, state});
const provider = await providerManager.typescript(projectDir);
providers.push(provider.worker({extensionsToLoadAsModules, state}));
}

return null;
}))).filter(provider => provider !== null);
}));

const require = createRequire(import.meta.url);
const load = async ref => {
Expand Down
36 changes: 34 additions & 2 deletions lib/worker/channel.cjs
Expand Up @@ -3,12 +3,44 @@ const events = require('events');
const process = require('process');
const {MessageChannel, threadId} = require('worker_threads');

const pEvent = require('p-event');

const timers = require('../now-and-timers.cjs');

const {isRunningInChildProcess, isRunningInThread} = require('./utils.cjs');

let pEvent = async (emitter, event, options) => {
// We need to import p-event, but import() is asynchronous. Buffer any events
// emitted in the meantime. Don't handle errors.
const buffer = [];
const addToBuffer = (...args) => buffer.push(args);
emitter.on(event, addToBuffer);

try {
({pEvent} = await import('p-event')); // eslint-disable-line node/no-unsupported-features/es-syntax
} finally {
emitter.off(event, addToBuffer);
}

if (buffer.length === 0) {
return pEvent(emitter, event, options);
}

// Now replay buffered events.
const replayEmitter = new events.EventEmitter();
const promise = pEvent(replayEmitter, event, options);
for (const args of buffer) {
replayEmitter.emit(event, ...args);
}

const replay = (...args) => replayEmitter.emit(event, ...args);
emitter.on(event, replay);

try {
return await promise;
} finally {
emitter.off(event, replay);
}
};

const selectAvaMessage = type => message => message.ava && message.ava.type === type;

class RefCounter {
Expand Down
3 changes: 1 addition & 2 deletions lib/worker/guard-environment.cjs
Expand Up @@ -6,12 +6,11 @@ const {isRunningInThread, isRunningInChildProcess} = require('./utils.cjs');

// Check if the test is being run without AVA cli
if (!isRunningInChildProcess && !isRunningInThread) {
const chalk = require('chalk'); // Use default Chalk instance.
if (process.argv[1]) {
const fp = path.relative('.', process.argv[1]);

console.log();
console.error(`Test files must be run with the AVA CLI:\n\n ${chalk.grey.dim('$')} ${chalk.cyan('ava ' + fp)}\n`);
console.error(`Test files must be run with the AVA CLI:\n\n $ ava ${fp}\n`);

process.exit(1); // eslint-disable-line unicorn/no-process-exit
} else {
Expand Down

0 comments on commit 0187779

Please sign in to comment.