import resolve from "../../resolve";

function createModule (overrides) {
  return Object.assign({
    path: null,
    ns: null,
    nsPath: null,
    nsRoot: null,
    rawSource: null,
    ast: null,
    requireNodes: null,
    dependencies: null,
    hash: null
  }, overrides);
}

export default function resolveModule (requireStr, contextPath, ns, nsRoot) {
  var asset, resolved;

  contextPath = contextPath || this.opts.root;
  requireStr = this.applyPlugins("preresolve", requireStr, contextPath);

  resolved = resolve(
    requireStr,
    contextPath || this.opts.root,
    ns || this.opts.ns,
    nsRoot || this.opts.root,
    this.opts.extensions
  );

  if (!resolved) {
    throw new Error("Cannot resolve '" + requireStr + "' from '" + contextPath + "'.");
  }

  asset = this.applyPlugins("postresolve", createModule(resolved), requireStr);
  return asset;
}

import * as Pluggable from "../../pluggable";
import resolve from "../../resolve";

const createModule = Pluggable.sync(function createModule (overrides) {
  return Object.assign({
    path: null,
    ns: null,
    nsPath: null,
    nsRoot: null,
    rawSource: null,
    ast: null,
    requireNodes: null,
    dependencies: null,
    hash: null
  }, overrides);
});

const preresolve = Pluggable.sync(function preresolve (requireStr) {
  return requireStr;
});

function resolveModule (requireStr, contextPath, ns, nsRoot) {
  contextPath = contextPath || this.opts.root;

  requireStr = this.preresolve(requireStr, contextPath);

  const resolved = resolve(
    requireStr,
    contextPath || this.opts.root,
    ns || this.opts.ns,
    nsRoot || this.opts.root,
    this.opts.extensions
  );

  if (!resolved) {
    throw new Error("Cannot resolve '" + requireStr + "' from '" + contextPath + "'.");
  }

  return this.createModule(resolved);
}

export default Pluggable.sync(resolveModule, { preresolve, createModule });

Change `module/resolve` to new pluggable architecture.