pax_global_header00006660000000000000000000000064137423320110014506gustar00rootroot0000000000000052 comment=db14a380461b9dcce58bb3845df7d463ffd67628 pkg-dir-5.0.0/000077500000000000000000000000001374233201100130455ustar00rootroot00000000000000pkg-dir-5.0.0/.editorconfig000066400000000000000000000002571374233201100155260ustar00rootroot00000000000000root = 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-5.0.0/.gitattributes000066400000000000000000000000231374233201100157330ustar00rootroot00000000000000* text=auto eol=lf pkg-dir-5.0.0/.github/000077500000000000000000000000001374233201100144055ustar00rootroot00000000000000pkg-dir-5.0.0/.github/funding.yml000066400000000000000000000001611374233201100165600ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/pkg-dir custom: https://sindresorhus.com/donate pkg-dir-5.0.0/.github/security.md000066400000000000000000000002631374233201100165770ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. pkg-dir-5.0.0/.gitignore000066400000000000000000000000271374233201100150340ustar00rootroot00000000000000node_modules yarn.lock pkg-dir-5.0.0/.npmrc000066400000000000000000000000231374233201100141600ustar00rootroot00000000000000package-lock=false pkg-dir-5.0.0/.travis.yml000066400000000000000000000000661374233201100151600ustar00rootroot00000000000000language: node_js node_js: - '14' - '12' - '10' pkg-dir-5.0.0/fixture/000077500000000000000000000000001374233201100145335ustar00rootroot00000000000000pkg-dir-5.0.0/fixture/.gitkeep000066400000000000000000000000001374233201100161520ustar00rootroot00000000000000pkg-dir-5.0.0/index.d.ts000066400000000000000000000017431374233201100147530ustar00rootroot00000000000000declare const pkgDir: { /** 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; /** 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; }; export = pkgDir; pkg-dir-5.0.0/index.js000066400000000000000000000005631374233201100145160ustar00rootroot00000000000000'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; module.exports.sync = cwd => { const filePath = findUp.sync('package.json', {cwd}); return filePath && path.dirname(filePath); }; pkg-dir-5.0.0/index.test-d.ts000066400000000000000000000003211374233201100157170ustar00rootroot00000000000000import {expectType} from 'tsd'; import pkgDir = require('.'); expectType>(pkgDir('/Users/project/pkg-dir')); expectType(pkgDir.sync('/Users/project/pkg-dir')); pkg-dir-5.0.0/license000066400000000000000000000021351374233201100144130ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://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-5.0.0/package.json000066400000000000000000000015231374233201100153340ustar00rootroot00000000000000{ "name": "pkg-dir", "version": "5.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": "https://sindresorhus.com" }, "engines": { "node": ">=10" }, "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": "^5.0.0" }, "devDependencies": { "ava": "^2.4.0", "tempy": "^1.0.0", "tsd": "^0.13.1", "xo": "^0.33.1" } } pkg-dir-5.0.0/readme.md000066400000000000000000000031611374233201100146250ustar00rootroot00000000000000# pkg-dir [![Build Status](https://travis-ci.com/sindresorhus/pkg-dir.svg?branch=master)](https://travis-ci.com/github/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 ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
pkg-dir-5.0.0/test.js000066400000000000000000000011321374233201100143570ustar00rootroot00000000000000import 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); });