Commit d06b9ac 1 parent d4720d7 commit d06b9ac Copy full SHA for d06b9ac
File tree 4 files changed +53
-2
lines changed
4 files changed +53
-2
lines changed Original file line number Diff line number Diff line change 187
187
"vitepress@npm:1.0.0-alpha.34" : " patch:vitepress@npm%3A1.0.0-alpha.34#patches/vitepress+1.0.0-alpha.34.dev.patch"
188
188
},
189
189
"engines" : {
190
- "node" : " >=14.16 " ,
190
+ "node" : " >=14.17.0 " ,
191
191
"yarn" : " 4.0.0-rc.34"
192
192
},
193
193
"packageManager" : " yarn@4.0.0-rc.34" ,
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @file Unit Tests - isFile
3
+ * @module mlly/internal/tests/unit/isFile
4
+ */
5
+
6
+ import testSubject from '../is-file'
7
+
8
+ describe ( 'unit:internal/isFile' , ( ) => {
9
+ it ( 'should return false if id is not path to module' , ( ) => {
10
+ // Arrange
11
+ const cases : Parameters < typeof testSubject > [ ] = [
12
+ [ 'file.txt' ] ,
13
+ [ 'node_modules/@flex-development/mkbuild/dist/index.mjs/package.json' ]
14
+ ]
15
+
16
+ // Act + Expect
17
+ cases . forEach ( ( [ id ] ) => expect ( testSubject ( id ) ) . to . be . false )
18
+ } )
19
+
20
+ it ( 'should return false if id is path to directory' , ( ) => {
21
+ expect ( testSubject ( 'src' ) ) . to . be . false
22
+ } )
23
+
24
+ it ( 'should return true if id is path to file' , ( ) => {
25
+ expect ( testSubject ( 'src/index.ts' ) ) . to . be . true
26
+ } )
27
+ } )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @file Internal - isFile
3
+ * @module mlly/internal/isFile
4
+ */
5
+
6
+ import fs from 'node:fs'
7
+ import type { URL } from 'node:url'
8
+
9
+ /**
10
+ * Checks if a file exists at `id`.
11
+ *
12
+ * @param {URL | string } id - Module id to evaluate
13
+ * @return {boolean } `true` if file exists at `id`
14
+ */
15
+ const isFile = ( id : URL | string ) : boolean => {
16
+ try {
17
+ return fs . statSync ( id , { throwIfNoEntry : false } ) ?. isFile ( ) ?? false
18
+ } catch {
19
+ return false
20
+ }
21
+ }
22
+
23
+ export default isFile
Original file line number Diff line number Diff line change 3
3
* @module mlly/utils/readPackageJson
4
4
*/
5
5
6
+ import isFile from '#src/internal/is-file'
6
7
import validateString from '#src/internal/validate-string'
7
8
import validateURLString from '#src/internal/validate-url-string'
8
9
import {
@@ -57,7 +58,7 @@ const readPackageJson = (
57
58
const path : string = pathe . toNamespacedPath ( pathe . join ( dir , 'package.json' ) )
58
59
59
60
// return null if package.json file does not exist
60
- if ( ! fs . existsSync ( path ) ) return null
61
+ if ( ! isFile ( path ) ) return null
61
62
62
63
/**
63
64
* Possible `package.json` object.
You can’t perform that action at this time.
0 commit comments