@pagedip/util-resolve
Advanced tools
Comparing version 1.0.0-rc.2 to 1.0.0-rc.3
179
index.js
@@ -11,3 +11,119 @@ 'use strict'; | ||
var Logger = _interopDefault(require('@pagedip/util-logger')); | ||
var findUp = _interopDefault(require('find-up')); | ||
var asyncGenerator = function () { | ||
function AwaitValue(value) { | ||
this.value = value; | ||
} | ||
function AsyncGenerator(gen) { | ||
var front, back; | ||
function send(key, arg) { | ||
return new Promise(function (resolve$$1, reject) { | ||
var request = { | ||
key: key, | ||
arg: arg, | ||
resolve: resolve$$1, | ||
reject: reject, | ||
next: null | ||
}; | ||
if (back) { | ||
back = back.next = request; | ||
} else { | ||
front = back = request; | ||
resume(key, arg); | ||
} | ||
}); | ||
} | ||
function resume(key, arg) { | ||
try { | ||
var result = gen[key](arg); | ||
var value = result.value; | ||
if (value instanceof AwaitValue) { | ||
Promise.resolve(value.value).then(function (arg) { | ||
resume("next", arg); | ||
}, function (arg) { | ||
resume("throw", arg); | ||
}); | ||
} else { | ||
settle(result.done ? "return" : "normal", result.value); | ||
} | ||
} catch (err) { | ||
settle("throw", err); | ||
} | ||
} | ||
function settle(type, value) { | ||
switch (type) { | ||
case "return": | ||
front.resolve({ | ||
value: value, | ||
done: true | ||
}); | ||
break; | ||
case "throw": | ||
front.reject(value); | ||
break; | ||
default: | ||
front.resolve({ | ||
value: value, | ||
done: false | ||
}); | ||
break; | ||
} | ||
front = front.next; | ||
if (front) { | ||
resume(front.key, front.arg); | ||
} else { | ||
back = null; | ||
} | ||
} | ||
this._invoke = send; | ||
if (typeof gen.return !== "function") { | ||
this.return = undefined; | ||
} | ||
} | ||
if (typeof Symbol === "function" && Symbol.asyncIterator) { | ||
AsyncGenerator.prototype[Symbol.asyncIterator] = function () { | ||
return this; | ||
}; | ||
} | ||
AsyncGenerator.prototype.next = function (arg) { | ||
return this._invoke("next", arg); | ||
}; | ||
AsyncGenerator.prototype.throw = function (arg) { | ||
return this._invoke("throw", arg); | ||
}; | ||
AsyncGenerator.prototype.return = function (arg) { | ||
return this._invoke("return", arg); | ||
}; | ||
return { | ||
wrap: function (fn) { | ||
return function () { | ||
return new AsyncGenerator(fn.apply(this, arguments)); | ||
}; | ||
}, | ||
await: function (value) { | ||
return new AwaitValue(value); | ||
} | ||
}; | ||
}(); | ||
var asyncToGenerator = function (fn) { | ||
@@ -42,4 +158,33 @@ return function () { | ||
let loadLerna = (() => { | ||
var _ref = asyncToGenerator(function* () { | ||
if (lernapkgs != null) return lernapkgs; | ||
try { | ||
lerna = require("lerna"); | ||
} catch (e) { | ||
// eat errors | ||
return lernapkgs = false; | ||
} | ||
const lernafile = yield findUp("lerna.json", { cwd: __dirname }); | ||
if (!lernafile) return lernapkgs = false; | ||
lernapkgs = new lerna.LsCommand(["ls"], {}, path.dirname(lernafile)); | ||
lernapkgs.runValidations(); | ||
lernapkgs.runPreparations(); | ||
yield new Promise(function (r) { | ||
return lernapkgs._attempt("initialize", r); | ||
}); | ||
return lernapkgs; | ||
}); | ||
return function loadLerna() { | ||
return _ref.apply(this, arguments); | ||
}; | ||
})(); | ||
let resolve$1 = (() => { | ||
var _ref = asyncToGenerator(function* (name, opts) { | ||
var _ref2 = asyncToGenerator(function* (name, opts) { | ||
if (typeof name !== "string" || !name) return; | ||
@@ -59,6 +204,9 @@ | ||
return function resolve$$1(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
return _ref2.apply(this, arguments); | ||
}; | ||
})(); | ||
let lerna; | ||
let lernapkgs; | ||
exports.isPath = `^\\.{1,2}\\${path.sep}?$|^\\.{1,2}\\${path.sep}|^\\${path.sep}`; | ||
@@ -68,3 +216,3 @@ if (path.sep === "\\") exports.isPath += `|^[a-z]:\\${path.sep}`; | ||
var index = (() => { | ||
var _ref2 = asyncToGenerator(function* (name, opts) { | ||
var _ref3 = asyncToGenerator(function* (name, opts) { | ||
if (typeof name !== "string" || !name) return; | ||
@@ -78,2 +226,4 @@ | ||
const ls = yield loadLerna(); | ||
for (let i = 0; i < leads.length; i++) { | ||
@@ -84,2 +234,23 @@ // don't try leads on file paths | ||
// load local lerna module | ||
if (ls) { | ||
let pkg; | ||
if (isFilePath) { | ||
const fullPath = path.resolve(ls.repository.rootPath, fullname); | ||
pkg = ls.packages.find(function ({ location }) { | ||
return location === fullPath; | ||
}); | ||
} else { | ||
pkg = ls.packages.find(function ({ name: n }) { | ||
return n === fullname; | ||
}); | ||
} | ||
if (pkg) { | ||
const module = yield resolve$1(pkg.location, opts); | ||
if (module) return module; | ||
} | ||
} | ||
// test as a normal module | ||
@@ -101,3 +272,3 @@ logger.debug("looking for local module '%s'", fullname); | ||
return function (_x3, _x4) { | ||
return _ref2.apply(this, arguments); | ||
return _ref3.apply(this, arguments); | ||
}; | ||
@@ -104,0 +275,0 @@ })(); |
{ | ||
"name": "@pagedip/util-resolve", | ||
"version": "1.0.0-rc.2", | ||
"version": "1.0.0-rc.3", | ||
"author": "Tyler Johnson <tyler@beneaththeink.com>", | ||
@@ -12,10 +12,11 @@ "repository": { | ||
"clean": "shx rm -f index.js test.js", | ||
"build-lib": "rollup src/index.js -c > index.js", | ||
"build-test": "rollup test/index.js -c > test.js", | ||
"build": "npm-run-all clean build-lib", | ||
"test": "npm run build-test && node test.js", | ||
"build:full": "npm-run-all clean build", | ||
"build:test": "rollup test/index.js -c > test.js", | ||
"build": "rollup src/index.js -c > index.js", | ||
"test": "npm run build:test && node test.js", | ||
"prepublish": "npm run build" | ||
}, | ||
"dependencies": { | ||
"@pagedip/util-logger": "^1.0.0-rc.2", | ||
"@pagedip/util-logger": "^1.0.0-rc.3", | ||
"find-up": "^2.1.0", | ||
"global-modules": "^1.0.0", | ||
@@ -25,4 +26,4 @@ "resolve": "^1.3.3" | ||
"devDependencies": { | ||
"npm-run-all": "^4.0.2", | ||
"rollup": "^0.43.0", | ||
"npm-run-all": "^4.1.1", | ||
"rollup": "^0.50.0", | ||
"shx": "^0.2.2" | ||
@@ -33,3 +34,3 @@ }, | ||
], | ||
"gitHead": "20d1714a1f559939d8e305eca819818169c894e4" | ||
"gitHead": "5f9462413e50a8f6396637db57e689a387bd25c4" | ||
} |
7509
223
4
+ Addedfind-up@^2.1.0
+ Addedfind-up@2.1.0(transitive)
+ Addedlocate-path@2.0.0(transitive)
+ Addedp-limit@1.3.0(transitive)
+ Addedp-locate@2.0.0(transitive)
+ Addedp-try@1.0.0(transitive)
+ Addedpath-exists@3.0.0(transitive)