import BabelRootImportHelper from './helper';

export default function({ types: t }) {
  class BabelRootImport {
    constructor() {
      const that = this;
      return {
        visitor: {
          ImportDeclaration(path, state) {
            const givenPath = path.node.source.value;

            var rootPathSuffix = state && state.opts && typeof state.opts.rootPathSuffix === 'string' ?
            '/' + state.opts.rootPathSuffix.replace(/^(\/)|(\/)$/g, '') :
                '';

            if(BabelRootImportHelper().hasRoot(givenPath)) {
              path.node.source.value = BabelRootImportHelper().transformRelativeToRootPath(givenPath, rootPathSuffix);
            }
          }
        }
      };
    }
  }

  return new BabelRootImport();
}

@@ -718,16 +718,301 @@
  %7D%0A  %7D%0A%0A
+  // Here's we detect the use of Meteor and send a dummy plugin.%0A  // That's because, Meteor already do this for us.%0A  //  global.meteorBabelHelpers is something we can see when%0A  //  running inside Meteor.%0A  if (global.meteorBabelHelpers) %7B%0A    return %7B%0A      visitor: %7B%7D%0A    %7D;%0A  %7D%0A%0A
   return

Add support to run inside Meteor. When running this babel-plugin inside Meteor, it gives us weird errors. But, we don't need this to use inside Meteor. Meteor do this for us automatically. So, we simply turn off this when using inside Meteor.