Socket
Socket
Sign inDemoInstall

pkg-dir

Package Overview
Dependencies
6
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.0 to 6.0.0

79

index.d.ts

@@ -1,41 +0,58 @@

declare const pkgDir: {
export interface Options {
/**
Synchronously find the root directory of a Node.js project or npm package.
The directory to start searching from.
@param cwd - Directory to start from. Default: `process.cwd()`.
@returns The project root path or `undefined` if it couldn't be found.
@default process.cwd()
*/
sync: (cwd?: string) => string | undefined;
readonly cwd?: string;
}
/**
Find the root directory of a Node.js project or npm package.
/**
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.
@returns The project root path or `undefined` if it could not be found.
@example
```
// /
// └── Users
// └── sindresorhus
// └── foo
// ├── package.json
// └── bar
// ├── baz
// └── example.js
@example
```
// /
// └── Users
// └── sindresorhus
// └── foo
// ├── package.json
// └── bar
// ├── baz
// └── example.js
// example.js
import pkgDir = require('pkg-dir');
// example.js
import {packageDirectory} from 'pkg-dir';
(async () => {
const rootDir = await pkgDir(__dirname);
console.log(await packageDirectory());
//=> '/Users/sindresorhus/foo'
```
*/
export function packageDirectory(options?: Options): Promise<string>;
console.log(rootDir);
//=> '/Users/sindresorhus/foo'
})();
```
*/
(cwd?: string): Promise<string | undefined>;
};
/**
Synchronously find the root directory of a Node.js project or npm package.
export = pkgDir;
@returns The project root path or `undefined` if it could not be found.
@example
```
// /
// └── Users
// └── sindresorhus
// └── foo
// ├── package.json
// └── bar
// ├── baz
// └── example.js
// example.js
import {packageDirectorySync} from 'pkg-dir';
console.log(packageDirectorySync());
//=> '/Users/sindresorhus/foo'
```
*/
export function packageDirectorySync(options?: Options): string;

@@ -1,15 +0,12 @@

'use strict';
const path = require('path');
const findUp = require('find-up');
import path from 'node:path';
import {findUp, findUpSync} from 'find-up';
const pkgDir = async cwd => {
export async function packageDirectory({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});
export function packageDirectorySync({cwd}) {
const filePath = findUpSync('package.json', {cwd});
return filePath && path.dirname(filePath);
};
}
{
"name": "pkg-dir",
"version": "5.0.0",
"version": "6.0.0",
"description": "Find the root directory of a Node.js project or npm package",
"license": "MIT",
"repository": "sindresorhus/pkg-dir",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {

@@ -12,4 +13,6 @@ "name": "Sindre Sorhus",

},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},

@@ -43,3 +46,2 @@ "scripts": {

"directory",
"dir",
"walk",

@@ -50,10 +52,11 @@ "walking",

"dependencies": {
"find-up": "^5.0.0"
"find-up": "^6.1.0"
},
"devDependencies": {
"ava": "^2.4.0",
"tempy": "^1.0.0",
"tsd": "^0.13.1",
"xo": "^0.33.1"
"ava": "^3.15.0",
"tempy": "^2.0.0",
"tsd": "^0.17.0",
"typescript": "^4.4.3",
"xo": "^0.44.0"
}
}

@@ -1,2 +0,2 @@

# pkg-dir [![Build Status](https://travis-ci.com/sindresorhus/pkg-dir.svg?branch=master)](https://travis-ci.com/github/sindresorhus/pkg-dir)
# pkg-dir

@@ -7,5 +7,5 @@ > Find the root directory of a Node.js project or npm package

```sh
npm install pkg-dir
```
$ npm install pkg-dir
```

@@ -27,10 +27,6 @@ ## Usage

// example.js
const pkgDir = require('pkg-dir');
import {packageDirectory} from 'pkg-dir';
(async () => {
const rootDir = await pkgDir(__dirname);
console.log(rootDir);
//=> '/Users/sindresorhus/foo'
})();
console.log(await packageDirectory());
//=> '/Users/sindresorhus/foo'
```

@@ -40,16 +36,20 @@

### pkgDir(cwd?)
### packageDirectory(option?)
Returns a `Promise` for either the project root path or `undefined` if it couldn't be found.
Returns a `Promise` for either the project root path or `undefined` if it could not be found.
### pkgDir.sync(cwd?)
### packageDirectorySync(options?)
Returns the project root path or `undefined` if it couldn't be found.
Returns the project root path or `undefined` if it could not be found.
#### cwd
#### options
Type: `object`
##### cwd
Type: `string`\
Default: `process.cwd()`
Directory to start from.
The directory to start searching from.

@@ -56,0 +56,0 @@ ## Related

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc