1 | const pkg = require('../package.json');
|
2 | const globs = require('./globs');
|
3 |
|
4 | const levels = {
|
5 | ava3: 1,
|
6 | pathRewrites: 2
|
7 | };
|
8 |
|
9 | exports.levels = levels;
|
10 |
|
11 | const levelsByProtocol = {
|
12 | 'ava-3': levels.ava3,
|
13 | 'ava-3.2': levels.pathRewrites
|
14 | };
|
15 |
|
16 | function load(providerModule, projectDir) {
|
17 | const ava = {version: pkg.version};
|
18 | const makeProvider = require(providerModule);
|
19 |
|
20 | let fatal;
|
21 | let level;
|
22 | const provider = makeProvider({
|
23 | negotiateProtocol(identifiers, {version}) {
|
24 | const identifier = identifiers.find(identifier => Reflect.has(levelsByProtocol, identifier));
|
25 |
|
26 | if (identifier === undefined) {
|
27 | fatal = new Error(`This version of AVA (${ava.version}) is not compatible with ${providerModule}@${version}`);
|
28 | return null;
|
29 | }
|
30 |
|
31 | level = levelsByProtocol[identifier];
|
32 |
|
33 | return {
|
34 | ava,
|
35 | async findFiles({extensions, patterns}) {
|
36 | return globs.findFiles({cwd: projectDir, extensions, filePatterns: patterns});
|
37 | },
|
38 | identifier,
|
39 | normalizeGlobPatterns: globs.normalizePatterns,
|
40 | projectDir
|
41 | };
|
42 | }
|
43 | });
|
44 |
|
45 | if (fatal) {
|
46 | throw fatal;
|
47 | }
|
48 |
|
49 | return {...provider, level};
|
50 | }
|
51 |
|
52 | exports.babel = projectDir => load('@ava/babel', projectDir);
|
53 | exports.typescript = projectDir => load('@ava/typescript', projectDir);
|