Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { resolve, dirname } = require('path');
- module.exports = function (file, api) {
- const j = api.jscodeshift;
- const root = j(file.source);
- let fileDir = dirname(resolve(file.path));
- function update (path) {
- const argument = path.value.arguments[0].value;
- if (argument.indexOf('..') !== 0) return;
- const realPath = resolve(fileDir, argument);
- if (realPath.indexOf('cartodb3') === -1) return;
- const aliasPath = realPath.replace(/(.+)(cartodb3\/.+)/g, '$2');
- path.value.arguments[0].value = aliasPath;
- }
- root.find(j.CallExpression, { callee: { name: 'require' } })
- .forEach(update);
- return root.toSource({quote: 'single'});
- };
Add Comment
Please, Sign In to add comment