[Pkg-javascript-commits] [node-module-deps] 153/444: resolve transforms based on the package.json directory name
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 15 09:47:51 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-module-deps.
commit a82197229eb00ec8aefa95d12c7f8f00569062fa
Author: James Halliday <mail at substack.net>
Date: Fri Jan 3 20:12:45 2014 -0800
resolve transforms based on the package.json directory name
---
index.js | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/index.js b/index.js
index 475ed88..f733ba4 100644
--- a/index.js
+++ b/index.js
@@ -52,11 +52,13 @@ module.exports = function (mains, opts) {
var dirs = parents(path.dirname(main));
(function next () {
if (dirs.length === 0) return done();
- var pkgfile = path.join(dirs.shift(), 'package.json');
+ var dir = dirs.shift();
+ var pkgfile = path.join(dir, 'package.json');
fs.readFile(pkgfile, function (err, src) {
if (err) return next();
try { var pkg = JSON.parse(src) }
catch (err) { return done() }
+ pkg.__dirname = dir;
pkgCache[id] = pkg;
done();
});
@@ -112,7 +114,12 @@ module.exports = function (mains, opts) {
: resolve;
;
- if (opts.packageFilter) parent.packageFilter = opts.packageFilter;
+ var pkgdir;
+ parent.packageFilter = function (p, x) {
+ pkgdir = x;
+ if (opts.packageFilter) return opts.packageFilter(p, x);
+ else return p;
+ };
if (opts.extensions) parent.extensions = opts.extensions;
if (opts.modules) parent.modules = opts.modules;
@@ -123,6 +130,8 @@ module.exports = function (mains, opts) {
parent.filename
].join('')));
+ if (pkg && pkgdir) pkg.__dirname = pkgdir;
+
if (cb) cb(file);
if (visited[file]) {
if (--pending === 0) output.queue(null);
@@ -160,7 +169,12 @@ module.exports = function (mains, opts) {
opts.transformKey.forEach(function (key) {
if (n && typeof n === 'object') n = n[key];
});
- trx = [].concat(n).filter(Boolean);
+ trx = [].concat(n).filter(Boolean).map(function (x) {
+ if (pkg && pkg.__dirname && /^\./.test(x)) {
+ return path.resolve(pkg.__dirname, x);
+ }
+ return x;
+ });
}
return trx.concat(opts.globalTransform || []);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-module-deps.git
More information about the Pkg-javascript-commits
mailing list