pax_global_header00006660000000000000000000000064134707416060014522gustar00rootroot0000000000000052 comment=e25e5342c5ec425bb4a2c93787a880c29cbf0a49 pkg-dir-4.2.0/000077500000000000000000000000001347074160600130625ustar00rootroot00000000000000pkg-dir-4.2.0/.editorconfig000066400000000000000000000002571347074160600155430ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 pkg-dir-4.2.0/.gitattributes000066400000000000000000000000231347074160600157500ustar00rootroot00000000000000* text=auto eol=lf pkg-dir-4.2.0/.gitignore000066400000000000000000000000271347074160600150510ustar00rootroot00000000000000node_modules yarn.lock pkg-dir-4.2.0/.npmrc000066400000000000000000000000231347074160600141750ustar00rootroot00000000000000package-lock=false pkg-dir-4.2.0/.travis.yml000066400000000000000000000000651347074160600151740ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' pkg-dir-4.2.0/fixture/000077500000000000000000000000001347074160600145505ustar00rootroot00000000000000pkg-dir-4.2.0/fixture/.gitkeep000066400000000000000000000000001347074160600161670ustar00rootroot00000000000000pkg-dir-4.2.0/index.d.ts000066400000000000000000000020521347074160600147620ustar00rootroot00000000000000declare const pkgDir: { /** Find the root directory of a Node.js project or npm package. @param cwd - Directory to start from. Default: `process.cwd()`. @returns The project root path or `undefined` if it couldn't be found. @example ``` // / // └── Users // └── sindresorhus // └── foo // ├── package.json // └── bar // ├── baz // └── example.js // example.js import pkgDir = require('pkg-dir'); (async () => { const rootDir = await pkgDir(__dirname); console.log(rootDir); //=> '/Users/sindresorhus/foo' })(); ``` */ (cwd?: string): Promise; /** Synchronously find the root directory of a Node.js project or npm package. @param cwd - Directory to start from. Default: `process.cwd()`. @returns The project root path or `undefined` if it couldn't be found. */ sync(cwd?: string): string | undefined; // TODO: Remove this for the next major release default: typeof pkgDir; }; export = pkgDir; pkg-dir-4.2.0/index.js000066400000000000000000000007041347074160600145300ustar00rootroot00000000000000'use strict'; const path = require('path'); const findUp = require('find-up'); const pkgDir = async cwd => { const filePath = await findUp('package.json', {cwd}); return filePath && path.dirname(filePath); }; module.exports = pkgDir; // TODO: Remove this for the next major release module.exports.default = pkgDir; module.exports.sync = cwd => { const filePath = findUp.sync('package.json', {cwd}); return filePath && path.dirname(filePath); }; pkg-dir-4.2.0/index.test-d.ts000066400000000000000000000003211347074160600157340ustar00rootroot00000000000000import {expectType} from 'tsd'; import pkgDir = require('.'); expectType>(pkgDir('/Users/project/pkg-dir')); expectType(pkgDir.sync('/Users/project/pkg-dir')); pkg-dir-4.2.0/license000066400000000000000000000021251347074160600144270ustar00rootroot00000000000000MIT License 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-4.2.0/package.json000066400000000000000000000015111347074160600153460ustar00rootroot00000000000000{ "name": "pkg-dir", "version": "4.2.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": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "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": "^4.0.0" }, "devDependencies": { "ava": "^1.4.1", "tempy": "^0.3.0", "tsd": "^0.7.2", "xo": "^0.24.0" } } pkg-dir-4.2.0/readme.md000066400000000000000000000024021347074160600146370ustar00rootroot00000000000000# 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 pkg-dir ``` ## Usage ``` / └── Users └── sindresorhus └── foo ├── package.json └── bar ├── baz └── example.js ``` ```js // example.js const pkgDir = require('pkg-dir'); (async () => { const rootDir = await pkgDir(__dirname); console.log(rootDir); //=> '/Users/sindresorhus/foo' })(); ``` ## API ### pkgDir([cwd]) Returns a `Promise` for either the project root path or `undefined` if it couldn't be found. ### pkgDir.sync([cwd]) Returns the project root path or `undefined` if it couldn't be found. #### 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-4.2.0/test.js000066400000000000000000000011321347074160600143740ustar00rootroot00000000000000import fs from 'fs'; import path from 'path'; import test from 'ava'; import tempy from 'tempy'; import pkgDir from '.'; // Create a disjoint directory, used for the not-found tests test.beforeEach(t => { t.context.disjoint = tempy.directory(); }); test.afterEach(t => { fs.rmdirSync(t.context.disjoint); }); test('async', async t => { t.is(await pkgDir(path.join(__dirname, 'fixture')), __dirname); t.is(await pkgDir(t.context.disjoint), undefined); }); test('sync', t => { t.is(pkgDir.sync(path.join(__dirname, 'fixture')), __dirname); t.is(pkgDir.sync(t.context.disjoint), undefined); });