mirror of
https://github.com/strapi/strapi.git
synced 2025-07-27 02:44:13 +00:00
41 lines
788 B
JavaScript
41 lines
788 B
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
const transformImport = require('./transformers/import');
|
||
|
const normalizeOptions = require('./normalizeOptions');
|
||
|
|
||
|
const importVisitors = {
|
||
|
ImportDeclaration: transformImport,
|
||
|
};
|
||
|
|
||
|
const visitor = {
|
||
|
Program: {
|
||
|
enter(programPath, state) {
|
||
|
programPath.traverse(importVisitors, state);
|
||
|
},
|
||
|
exit(programPath, state) {
|
||
|
programPath.traverse(importVisitors, state);
|
||
|
},
|
||
|
},
|
||
|
};
|
||
|
|
||
|
module.exports = ({ types: t }) => {
|
||
|
return {
|
||
|
name: 'module-resolver',
|
||
|
visitor,
|
||
|
|
||
|
pre(file) {
|
||
|
this.types = t;
|
||
|
|
||
|
const currentFile = file.opts.filename;
|
||
|
|
||
|
this.normalizedOpts = normalizeOptions(currentFile, this.opts);
|
||
|
|
||
|
this.moduleResolverVisited = new Set();
|
||
|
},
|
||
|
|
||
|
post() {
|
||
|
this.moduleResolverVisited.clear();
|
||
|
},
|
||
|
};
|
||
|
};
|