-
Notifications
You must be signed in to change notification settings - Fork 204
/
index.js
51 lines (40 loc) · 1.18 KB
/
index.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
import normalizeOptions from './normalizeOptions';
import resolvePath from './resolvePath';
import transformCall from './transformers/call';
import transformImport from './transformers/import';
// Public API for external plugins
export { resolvePath };
const importVisitors = {
CallExpression: transformCall,
'ImportDeclaration|ExportDeclaration': transformImport,
};
const visitor = {
Program: {
enter(programPath, state) {
programPath.traverse(importVisitors, state);
},
exit(programPath, state) {
programPath.traverse(importVisitors, state);
},
},
};
export default ({ types }) => ({
name: 'module-resolver',
manipulateOptions(opts) {
if (opts.filename === undefined) {
opts.filename = 'unknown';
}
},
pre(file) {
this.types = types;
const currentFile = file.opts.filename;
this.normalizedOpts = normalizeOptions(currentFile, this.opts);
// We need to keep track of all handled nodes so we do not try to transform them twice,
// because we run before (enter) and after (exit) all nodes are handled
this.moduleResolverVisited = new Set();
},
visitor,
post() {
this.moduleResolverVisited.clear();
},
});