pax_global_header00006660000000000000000000000064131026454320014512gustar00rootroot0000000000000052 comment=c18df2945cd928787f3290042a6c69352b4e13a5 pkg-dir-2.0.0/000077500000000000000000000000001310264543200130465ustar00rootroot00000000000000pkg-dir-2.0.0/.editorconfig000066400000000000000000000002761310264543200155300ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 pkg-dir-2.0.0/.gitattributes000066400000000000000000000000351310264543200157370ustar00rootroot00000000000000* text=auto *.js text eol=lf pkg-dir-2.0.0/.gitignore000066400000000000000000000000151310264543200150320ustar00rootroot00000000000000node_modules pkg-dir-2.0.0/.travis.yml000066400000000000000000000000531310264543200151550ustar00rootroot00000000000000language: node_js node_js: - '6' - '4' pkg-dir-2.0.0/fixture/000077500000000000000000000000001310264543200145345ustar00rootroot00000000000000pkg-dir-2.0.0/fixture/.gitkeep000066400000000000000000000000001310264543200161530ustar00rootroot00000000000000pkg-dir-2.0.0/index.js000066400000000000000000000004511310264543200145130ustar00rootroot00000000000000'use strict'; const path = require('path'); const findUp = require('find-up'); module.exports = cwd => findUp('package.json', {cwd}).then(fp => fp ? path.dirname(fp) : null); module.exports.sync = cwd => { const fp = findUp.sync('package.json', {cwd}); return fp ? path.dirname(fp) : null; }; pkg-dir-2.0.0/license000066400000000000000000000021371310264543200144160ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pkg-dir-2.0.0/package.json000066400000000000000000000015221310264543200153340ustar00rootroot00000000000000{ "name": "pkg-dir", "version": "2.0.0", "description": "Find the root directory of a Node.js project or npm package", "license": "MIT", "repository": "sindresorhus/pkg-dir", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=4" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "package", "json", "root", "npm", "entry", "find", "up", "find-up", "findup", "look-up", "look", "file", "search", "match", "resolve", "parent", "parents", "folder", "directory", "dir", "walk", "walking", "path" ], "dependencies": { "find-up": "^2.1.0" }, "devDependencies": { "ava": "*", "xo": "*" } } pkg-dir-2.0.0/readme.md000066400000000000000000000023171310264543200146300ustar00rootroot00000000000000# pkg-dir [![Build Status](https://travis-ci.org/sindresorhus/pkg-dir.svg?branch=master)](https://travis-ci.org/sindresorhus/pkg-dir) > Find the root directory of a Node.js project or npm package ## Install ``` $ npm install --save pkg-dir ``` ## Usage ``` / └── Users └── sindresorhus └── foo ├── package.json └── bar ├── baz └── example.js ``` ```js // example.js const pkgDir = require('pkg-dir'); pkgDir(__dirname).then(rootDir => { console.log(rootDir); //=> '/Users/sindresorhus/foo' }); ``` ## API ### pkgDir([cwd]) Returns a `Promise` for either the project root path or `null` if it couldn't be found. ### pkgDir.sync([cwd]) Returns the project root path or `null`. #### cwd Type: `string`
Default: `process.cwd()` Directory to start from. ## Related - [pkg-dir-cli](https://github.com/sindresorhus/pkg-dir-cli) - CLI for this module - [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file - [find-up](https://github.com/sindresorhus/find-up) - Find a file by walking up parent directories ## License MIT © [Sindre Sorhus](https://sindresorhus.com) pkg-dir-2.0.0/test.js000066400000000000000000000003641310264543200143660ustar00rootroot00000000000000import path from 'path'; import test from 'ava'; import m from '.'; test('async', async t => { t.is(await m(path.join(__dirname, 'fixture')), __dirname); }); test('sync', t => { t.is(m.sync(path.join(__dirname, 'fixture')), __dirname); });