@@ -2,11 +2,13 @@ import { getByPath } from "dot-path-value";
2
2
import { existsSync , realpathSync } from "node:fs" ;
3
3
import module from "node:module" ;
4
4
import { dirname , join } from "node:path" ;
5
+ import { cwd , env , exit , versions } from "node:process" ;
5
6
import type { NormalizedPackageJson } from "read-pkg" ;
6
7
import readPkgUp from "read-pkg-up" ;
7
8
8
9
const { packageJson, path : packagePath } = readPkgUp . sync ( {
9
- cwd : realpathSync ( process . cwd ( ) ) ,
10
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
11
+ cwd : realpathSync ( cwd ( ) ) ,
10
12
} ) ?? { packageJson : undefined , path : undefined } ;
11
13
12
14
const atLatest = ( name : string ) : string => {
@@ -25,11 +27,17 @@ export const getPackageProperty = <T = unknown>(property: string): T | undefined
25
27
return getByPath ( packageJson , property ) as T | undefined ;
26
28
} ;
27
29
28
- export const getPackageSubProperty = < T = unknown > ( packageProperty : string ) => ( property : string ) : T | undefined => getPackageProperty < T > ( `${ packageProperty } .${ property } ` ) ;
30
+ export const getPackageSubProperty =
31
+ < T = unknown > ( packageProperty : string ) =>
32
+ ( property : string ) : T | undefined =>
33
+ getPackageProperty < T > ( `${ packageProperty } .${ property } ` ) ;
29
34
30
35
export const hasPackageProperty = ( property : string ) : boolean => Boolean ( packageJson !== undefined && getByPath ( packageJson , property ) ) ;
31
36
32
- export const hasPackageSubProperty = ( packageProperty : string ) => ( property : string ) : boolean => hasPackageProperty ( `${ packageProperty } .${ property } ` ) ;
37
+ export const hasPackageSubProperty =
38
+ ( packageProperty : string ) =>
39
+ ( property : string ) : boolean =>
40
+ hasPackageProperty ( `${ packageProperty } .${ property } ` ) ;
33
41
34
42
export const hasPackageProperties = ( properties : string [ ] , strict ?: boolean ) : boolean => {
35
43
if ( strict ) {
@@ -39,19 +47,25 @@ export const hasPackageProperties = (properties: string[], strict?: boolean): bo
39
47
return properties . some ( ( property : string ) => hasPackageProperty ( property ) ) ;
40
48
} ;
41
49
42
- export const hasPackageSubProperties = ( packageProperty : string ) => ( properties : string [ ] , strict ?: boolean ) : boolean => hasPackageProperties (
50
+ export const hasPackageSubProperties =
51
+ ( packageProperty : string ) =>
52
+ ( properties : string [ ] , strict ?: boolean ) : boolean =>
53
+ hasPackageProperties (
43
54
properties . map ( ( p ) => `${ packageProperty } .${ p } ` ) ,
44
55
strict ,
45
56
) ;
46
57
47
- export const environmentIsSet = ( name : string ) : boolean => Boolean ( process . env [ name ] && process . env [ name ] !== "undefined" ) ;
58
+ // eslint-disable-next-line security/detect-object-injection
59
+ export const environmentIsSet = ( name : string ) : boolean => Boolean ( env [ name ] && env [ name ] !== "undefined" ) ;
48
60
49
61
export const parseEnvironment = ( name : string , defaultValue : unknown ) : any => {
50
62
if ( environmentIsSet ( name ) ) {
51
63
try {
52
- return JSON . parse ( process . env [ name ] ?? "" ) ;
64
+ // eslint-disable-next-line security/detect-object-injection
65
+ return JSON . parse ( env [ name ] ?? "" ) ;
53
66
} catch {
54
- return process . env [ name ] ;
67
+ // eslint-disable-next-line security/detect-object-injection
68
+ return env [ name ] ;
55
69
}
56
70
}
57
71
@@ -62,6 +76,7 @@ export const projectPath: string = packagePath ? dirname(packagePath) : "";
62
76
// @deprecated Use `projectPath` instead.
63
77
export const appDirectory : string = projectPath ;
64
78
export const fromRoot = ( ...p : string [ ] ) : string => join ( projectPath , ...p ) ;
79
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
65
80
export const hasFile = ( ...p : string [ ] ) : boolean => existsSync ( fromRoot ( ...p ) ) ;
66
81
67
82
export const hasScripts = hasPackageSubProperties ( "scripts" ) ;
@@ -80,8 +95,8 @@ export const hasDevDependencies = hasPackageSubProperties("devDependencies");
80
95
// @deprecated Use `hasDevDependencies` instead.
81
96
export const hasDevelopmentDep = hasDevDependencies ;
82
97
83
- // eslint-disable-next-line max-len
84
- export const hasAnyDep = ( arguments_ : string [ ] , options ?: { peerDeps ?: boolean ; strict ?: boolean } ) : boolean => [ hasDependencies , hasDevDependencies , options ?. peerDeps === false ? ( ) => false : hasPeerDependencies ] . some (
98
+ export const hasAnyDep = ( arguments_ : string [ ] , options ?: { peerDeps ?: boolean ; strict ?: boolean } ) : boolean =>
99
+ [ hasDependencies , hasDevDependencies , options ?. peerDeps === false ? ( ) => false : hasPeerDependencies ] . some (
85
100
( function_ : ( arguments_ : string [ ] , strict ?: boolean ) => boolean ) => function_ ( arguments_ , options ?. strict ) ,
86
101
) ;
87
102
@@ -91,7 +106,7 @@ export const packageIsTypeModule = hasPackageProperties(["type"]) && packageJson
91
106
92
107
export const resolvePackage = ( packageName : string ) : string | undefined => {
93
108
// See https://yarnpkg.com/advanced/pnpapi
94
- if ( process . versions [ "pnp" ] ) {
109
+ if ( versions [ "pnp" ] ) {
95
110
const targetModule = import . meta. url ;
96
111
// @ts -expect-error TS2339: Property 'findPnpApi' does not exist on type 'typeof Module'.
97
112
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
158
173
${ options . postMessage ?? "" } \n
159
174
` ) ;
160
175
161
- if ( process . env [ "NODE_ENV" ] !== "test" || options . exit === true ) {
162
- process . exit ( 1 ) ; // eslint-disable-line unicorn/no-process-exit
176
+ if ( env [ "NODE_ENV" ] !== "test" || options . exit === true ) {
177
+ exit ( 1 ) ;
163
178
}
164
179
} ;
165
180
0 commit comments