-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathprovider-manager.js
57 lines (46 loc) · 1.46 KB
/
provider-manager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import * as globs from './globs.js';
import pkg from './pkg.cjs';
export const levels = {
// As the protocol changes, comparing levels by integer allows AVA to be
// compatible with different versions.
ava6: 1,
};
const levelsByProtocol = Object.assign(Object.create(null), {
'ava-6': levels.ava6,
});
async function load(providerModule, projectDir, selectProtocol = () => true) {
const ava = {version: pkg.version};
const {default: makeProvider} = await import(providerModule);
let fatal;
let level;
const provider = makeProvider({
negotiateProtocol(identifiers, {version}) {
const identifier = identifiers
.find(identifier => selectProtocol(identifier) && Object.hasOwn(levelsByProtocol, identifier));
if (identifier === undefined) {
fatal = new Error(`This version of AVA (${ava.version}) is not compatible with ${providerModule}@${version}`);
return null;
}
level = levelsByProtocol[identifier];
return {
ava,
async findFiles({extensions, patterns}) {
return globs.findFiles({cwd: projectDir, extensions, filePatterns: patterns});
},
identifier,
normalizeGlobPatterns: globs.normalizePatterns,
projectDir,
};
},
});
if (fatal) {
throw fatal;
}
return {...provider, level};
}
const providerManager = {
async typescript(projectDir, {protocol} = {}) {
return load('@ava/typescript', projectDir, identifier => protocol === undefined || identifier === protocol);
},
};
export default providerManager;