| 1 |
"use strict"; |
| 2 |
|
| 3 |
var isFunction = require("es5-ext/function/is-function") |
| 4 |
, path = require("path") |
| 5 |
, createContext = require("vm").createContext |
| 6 |
, findRoot = require("next/module/find-package-root") |
| 7 |
, requireFirst = require("./require-first-in-tree"); |
| 8 |
|
| 9 |
module.exports = function (lpath, tpath) { |
| 10 |
tpath = path.dirname(tpath); |
| 11 |
return findRoot(tpath)(function (projectPath) { |
| 12 |
var context = requireFirst("__tad", tpath, projectPath); |
| 13 |
if (context) { |
| 14 |
if (context instanceof Error) throw context; |
| 15 |
if (context.context) { |
| 16 |
context = context.context; |
| 17 |
if (isFunction(context)) context = context(lpath); |
| 18 |
context.console = console; |
| 19 |
return createContext(context); |
| 20 |
} |
| 21 |
} |
| 22 |
return global; |
| 23 |
}); |
| 24 |
}; |