-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (31 loc) · 946 Bytes
/
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
'use strict';
var path = require('path');
module.exports = function() {
function renameAlias(source, options) {
var baseUrl = options.basePath || process.cwd();
if (source.substr(0, 4) === 'npm:') {
source = path.join(baseUrl, 'node_modules', source.substr(4));
}
return source.replace(/\\/g, '/');
}
return {
visitor: {
ModuleDeclaration: {
enter: function(path, state) {
if (path.node.source) {
path.node.source.value = renameAlias(path.node.source.value, state.opts);
}
}
}
},
post: function(file) {
var opts = this.opts;
file.metadata.modules.imports.forEach(function(importData) {
importData.source = renameAlias(importData.source, opts);
});
file.metadata.modules.exports.specifiers.forEach(function(exportData) {
exportData.source = renameAlias(exportData.source, opts);
});
}
};
};