File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " aws-sdk-js-codemod " : patch
3
+ ---
4
+
5
+ Check for package.json exists before reading
Original file line number Diff line number Diff line change 3
3
4
4
// @ts -nocheck
5
5
6
- import { readFileSync } from "fs" ;
6
+ import { existsSync , readFileSync } from "fs" ;
7
7
import { dirname , join } from "path" ;
8
8
import { DEFAULT_EXTENSIONS } from "@babel/core" ;
9
9
import argsParser from "jscodeshift/dist/argsParser" ;
@@ -15,11 +15,11 @@ const requirePackage = (name: string) => {
15
15
const entry = require . resolve ( name ) ;
16
16
let dir = dirname ( entry ) ;
17
17
while ( dir !== "/" ) {
18
- try {
19
- // eslint-disable-next-line @typescript-eslint/no-var-requires
20
- const pkg = require ( join ( dir , "package.json " ) ) ;
21
- return pkg . name === name ? pkg : { } ;
22
- } catch ( error ) { } // eslint-disable-line no-empty
18
+ const packageJsonPath = join ( dir , "package.json" ) ;
19
+ if ( existsSync ( packageJsonPath ) ) {
20
+ const packageJson = JSON . parse ( readFileSync ( packageJsonPath , "utf8 " ) ) ;
21
+ return packageJson . name === name ? packageJson : { } ;
22
+ }
23
23
dir = dirname ( dir ) ;
24
24
}
25
25
return { } ;
You can’t perform that action at this time.
0 commit comments