'use strict';
module.exports = function addExtensionToImportPaths(context, { extension }) {
const { types } = context;
return {
visitor: {
ImportDeclaration: replaceImportPath,
ExportNamedDeclaration: replaceImportPath,
},
};
function replaceImportPath(path) {
if (!path.node.source) {
return;
}
const source = path.node.source.value;
if (source.startsWith('./') || source.startsWith('../')) {
const newSourceNode = types.stringLiteral(source + '.' + extension);
path.get('source').replaceWith(newSourceNode);
}
}
};