File tree 7 files changed +67
-70
lines changed
7 files changed +67
-70
lines changed Original file line number Diff line number Diff line change 10
10
fail-fast : false
11
11
matrix :
12
12
node-version :
13
+ - 16
13
14
- 14
14
15
- 12
15
- - 10
16
16
steps :
17
17
- uses : actions/checkout@v2
18
18
- uses : actions/setup-node@v1
Original file line number Diff line number Diff line change 1
- declare const pkgDir : {
2
- /**
3
- Synchronously find the root directory of a Node.js project or npm package.
4
-
5
- @param cwd - Directory to start from. Default: `process.cwd()`.
6
- @returns The project root path or `undefined` if it couldn't be found.
7
- */
8
- sync : ( cwd ?: string ) => string | undefined ;
9
-
10
- /**
11
- Find the root directory of a Node.js project or npm package.
12
-
13
- @param cwd - Directory to start from. Default: `process.cwd()`.
14
- @returns The project root path or `undefined` if it couldn't be found.
15
-
16
- @example
17
- ```
18
- // /
19
- // └── Users
20
- // └── sindresorhus
21
- // └── foo
22
- // ├── package.json
23
- // └── bar
24
- // ├── baz
25
- // └── example.js
26
-
27
- // example.js
28
- import pkgDir = require('pkg-dir');
29
-
30
- (async () => {
31
- const rootDir = await pkgDir(__dirname);
32
-
33
- console.log(rootDir);
34
- //=> '/Users/sindresorhus/foo'
35
- })();
36
- ```
37
- */
38
- ( cwd ?: string ) : Promise < string | undefined > ;
39
- } ;
40
-
41
- export = pkgDir ;
1
+ /**
2
+ Find the root directory of a Node.js project or npm package.
3
+
4
+ @param cwd - Directory to start from. Default: `process.cwd()`.
5
+ @returns The project root path or `undefined` if it couldn't be found.
6
+
7
+ @example
8
+ ```
9
+ // /
10
+ // └── Users
11
+ // └── sindresorhus
12
+ // └── foo
13
+ // ├── package.json
14
+ // └── bar
15
+ // ├── baz
16
+ // └── example.js
17
+
18
+ // example.js
19
+ import pkgDir = require('pkg-dir');
20
+
21
+ (async () => {
22
+ const rootDir = await pkgDir(__dirname);
23
+
24
+ console.log(rootDir);
25
+ //=> '/Users/sindresorhus/foo'
26
+ })();
27
+ ```
28
+ */
29
+ export function pkgDir ( cwd : any ) : Promise < string > ;
30
+
31
+ /**
32
+ Synchronously find the root directory of a Node.js project or npm package.
33
+
34
+ @param cwd - Directory to start from. Default: `process.cwd()`.
35
+ @returns The project root path or `undefined` if it couldn't be found.
36
+ */
37
+ export function pkgDirSync ( cwd : any ) : string ;
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
- const path = require ( 'path' ) ;
3
- const findUp = require ( 'find-up' ) ;
1
+ import { dirname } from 'node:path' ;
2
+ import { findUp , findUpSync } from 'find-up' ;
4
3
5
- const pkgDir = async cwd => {
4
+ export async function pkgDir ( cwd ) {
6
5
const filePath = await findUp ( 'package.json' , { cwd} ) ;
7
- return filePath && path . dirname ( filePath ) ;
8
- } ;
6
+ return filePath && dirname ( filePath ) ;
7
+ }
9
8
10
- module . exports = pkgDir ;
11
-
12
- module . exports . sync = cwd => {
13
- const filePath = findUp . sync ( 'package.json' , { cwd} ) ;
14
- return filePath && path . dirname ( filePath ) ;
15
- } ;
9
+ export function pkgDirSync ( cwd ) {
10
+ const filePath = findUpSync ( 'package.json' , { cwd} ) ;
11
+ return filePath && dirname ( filePath ) ;
12
+ }
Original file line number Diff line number Diff line change 1
1
import { expectType } from 'tsd' ;
2
- import pkgDir = require ( '.' ) ;
2
+ import { pkgDir , pkgDirSync } from './index.js' ;
3
3
4
- expectType < Promise < string | undefined > > ( pkgDir ( '/Users/project/pkg-dir' ) ) ;
5
- expectType < string | undefined > ( pkgDir . sync ( '/Users/project/pkg-dir' ) ) ;
4
+ expectType < Promise < string > > ( pkgDir ( '/Users/project/pkg-dir' ) ) ;
5
+ expectType < string > ( pkgDirSync ( '/Users/project/pkg-dir' ) ) ;
Original file line number Diff line number Diff line change 9
9
"email" : " sindresorhus@gmail.com" ,
10
10
"url" : " https://sindresorhus.com"
11
11
},
12
+ "type" : " module" ,
12
13
"engines" : {
13
- "node" : " >=10 "
14
+ "node" : " >=12 "
14
15
},
15
16
"scripts" : {
16
17
"test" : " xo && ava && tsd"
45
46
" path"
46
47
],
47
48
"dependencies" : {
48
- "find-up" : " ^5.0 .0"
49
+ "find-up" : " ^6.1 .0"
49
50
},
50
51
"devDependencies" : {
51
- "ava" : " ^2.4 .0" ,
52
- "tempy" : " ^1 .0.0" ,
53
- "tsd" : " ^0.13.1 " ,
54
- "xo" : " ^0.33.1 "
52
+ "ava" : " ^3.15 .0" ,
53
+ "tempy" : " ^2 .0.0" ,
54
+ "tsd" : " ^0.17.0 " ,
55
+ "xo" : " ^0.44.0 "
55
56
}
56
57
}
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ $ npm install pkg-dir
23
23
24
24
``` js
25
25
// example.js
26
- const pkgDir = require ( ' pkg-dir' ) ;
26
+ import { pkgDir , pkgDirSync } from ' pkg-dir' ;
27
27
28
28
(async () => {
29
29
const rootDir = await pkgDir (__dirname );
@@ -39,7 +39,7 @@ const pkgDir = require('pkg-dir');
39
39
40
40
Returns a ` Promise ` for either the project root path or ` undefined ` if it couldn't be found.
41
41
42
- ### pkgDir.sync (cwd?)
42
+ ### pkgDirSync (cwd?)
43
43
44
44
Returns the project root path or ` undefined ` if it couldn't be found.
45
45
Original file line number Diff line number Diff line change 1
- import fs from 'fs' ;
2
- import path from 'path' ;
1
+ import fs from 'node:fs' ;
2
+ import path from 'node:path' ;
3
+ import { fileURLToPath } from 'node:url' ;
3
4
import test from 'ava' ;
4
5
import tempy from 'tempy' ;
5
- import pkgDir from '.' ;
6
+ import { pkgDir , pkgDirSync } from './index.js' ;
7
+
8
+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
6
9
7
10
// Create a disjoint directory, used for the not-found tests
8
11
test . beforeEach ( t => {
@@ -19,6 +22,6 @@ test('async', async t => {
19
22
} ) ;
20
23
21
24
test ( 'sync' , t => {
22
- t . is ( pkgDir . sync ( path . join ( __dirname , 'fixture' ) ) , __dirname ) ;
23
- t . is ( pkgDir . sync ( t . context . disjoint ) , undefined ) ;
25
+ t . is ( pkgDirSync ( path . join ( __dirname , 'fixture' ) ) , __dirname ) ;
26
+ t . is ( pkgDirSync ( t . context . disjoint ) , undefined ) ;
24
27
} ) ;
You can’t perform that action at this time.
0 commit comments