2019-01-12 03:33:27 +00:00
|
|
|
'use strict';
|
2018-03-19 09:51:47 +00:00
|
|
|
|
2020-10-19 08:43:10 +00:00
|
|
|
const { dirname } = require('path');
|
2019-01-12 03:33:27 +00:00
|
|
|
const fs = require('fs');
|
2020-10-19 08:43:10 +00:00
|
|
|
const { getProjectPath } = require('./utils/projectHelper');
|
2018-03-19 09:51:47 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
function replacePath(path) {
|
2018-03-19 09:51:47 +00:00
|
|
|
if (path.node.source && /\/lib\//.test(path.node.source.value)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
const esModule = path.node.source.value.replace('/lib/', '/es/');
|
2020-10-19 08:43:10 +00:00
|
|
|
const esPath = dirname(getProjectPath('node_modules', esModule));
|
2018-03-19 09:51:47 +00:00
|
|
|
if (fs.existsSync(esPath)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
path.node.source.value = esModule;
|
2018-03-19 09:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
function replaceLib() {
|
2018-03-19 09:51:47 +00:00
|
|
|
return {
|
|
|
|
visitor: {
|
|
|
|
ImportDeclaration: replacePath,
|
|
|
|
ExportNamedDeclaration: replacePath,
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-19 09:51:47 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
module.exports = replaceLib;
|