├── bower.json ├── .gitignore ├── index.js ├── README.md └── package.json /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cwd", 3 | "version": "0.2.2", 4 | "main": [ 5 | "index.js" 6 | ] 7 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | 4 | tmp 5 | temp 6 | test 7 | TODO.md 8 | 9 | *.sublime-* 10 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * module-root 3 | * Copyright (c) 2014 Jon Schlinkert, contributors. 4 | * Licensed under the MIT license. 5 | */ 6 | 7 | var path = require('path'); 8 | var callsite = require('callsite'); 9 | var findup = require('findup-sync'); 10 | 11 | module.exports = function(name) { 12 | var fullpath; 13 | if (arguments.length > 0) { 14 | fullpath = require.resolve(name); 15 | } else { 16 | fullpath = callsite()[1].getFileName(); 17 | } 18 | var cwd = path.dirname(fullpath); 19 | var pkg = findup('package.json', { cwd: cwd }); 20 | return path.resolve(path.dirname(pkg)); 21 | }; 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # module-root [![NPM version](https://badge.fury.io/js/module-root.png)](http://badge.fury.io/js/module-root) 2 | 3 | > For Node.js projects, set the CWD (current working directory) to the same directory as package.json. 4 | 5 | ## Quickstart 6 | 7 | ```js 8 | var root = require('module-root'); 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | root('lodash'); 15 | //=> ~/your-project/node_modules/lodash 16 | ``` 17 | 18 | ## Author 19 | 20 | **Jon Schlinkert** 21 | 22 | + [github/jonschlinkert](https://github.com/jonschlinkert) 23 | + [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 24 | 25 | ## License 26 | Copyright (c) 2014 [Jon Schlinkert](https://github.com/jonschlinkert), contributors. 27 | Released under the MIT license -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-root", 3 | "description": "Get the resolved path the root (directory) of a package installed in node_modules.", 4 | "version": "0.2.0", 5 | "homepage": "https://github.com/jonschlinkert/module-root", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "jonschlinkert/module-root", 8 | "bugs": { 9 | "url": "https://github.com/jonschlinkert/module-root/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js", 14 | "README.md" 15 | ], 16 | "main": "index.js", 17 | "engines": { 18 | "node": ">= 0.10.0" 19 | }, 20 | "dependencies": { 21 | "callsite": "^1.0.0", 22 | "findup-sync": "^0.4.2" 23 | }, 24 | "keywords": [ 25 | "cwd", 26 | "node_modules", 27 | "npm module", 28 | "root" 29 | ] 30 | } 31 | --------------------------------------------------------------------------------